New functions with QT GUI:
- save/load window parameters implemented !
This commit is contained in:
@@ -67,6 +67,8 @@ CV_EXPORTS double getWindowProperty(const string& winname, int prop_id);//YV
|
|||||||
//Only for QT
|
//Only for QT
|
||||||
CV_EXPORTS void displayOverlay(const string& winname, const string& text, int delayms);
|
CV_EXPORTS void displayOverlay(const string& winname, const string& text, int delayms);
|
||||||
CV_EXPORTS void displayStatusBar(const string& winname, const string& text, int delayms);
|
CV_EXPORTS void displayStatusBar(const string& winname, const string& text, int delayms);
|
||||||
|
CV_EXPORTS void saveWindowParameters(const string& windowName);
|
||||||
|
CV_EXPORTS void loadWindowParameters(const string& windowName);
|
||||||
CV_EXPORTS int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]);
|
CV_EXPORTS int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]);
|
||||||
CV_EXPORTS void stopLoop();
|
CV_EXPORTS void stopLoop();
|
||||||
|
|
||||||
|
@@ -60,6 +60,8 @@ extern "C" {
|
|||||||
//-----------New for QT
|
//-----------New for QT
|
||||||
CVAPI(void) cvDisplayOverlay(const char* name, const char* text, int delayms);
|
CVAPI(void) cvDisplayOverlay(const char* name, const char* text, int delayms);
|
||||||
CVAPI(void) cvDisplayStatusBar(const char* name, const char* text, int delayms);
|
CVAPI(void) cvDisplayStatusBar(const char* name, const char* text, int delayms);
|
||||||
|
CVAPI(void) cvSaveWindowParameters(const char* name);
|
||||||
|
CVAPI(void) cvLoadWindowParameters(const char* name);
|
||||||
CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]);
|
CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]);
|
||||||
CVAPI(void) cvStopLoop();
|
CVAPI(void) cvStopLoop();
|
||||||
//----------------------
|
//----------------------
|
||||||
|
@@ -160,6 +160,16 @@ int waitKey(int delay)
|
|||||||
return cvWaitKey(delay);
|
return cvWaitKey(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void saveWindowParameters(const string& windowName)
|
||||||
|
{
|
||||||
|
cvSaveWindowParameters(windowName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadWindowParameters(const string& windowName)
|
||||||
|
{
|
||||||
|
cvLoadWindowParameters(windowName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
int createTrackbar(const string& trackbarName, const string& winName,
|
int createTrackbar(const string& trackbarName, const string& winName,
|
||||||
int* value, int count, TrackbarCallback callback,
|
int* value, int count, TrackbarCallback callback,
|
||||||
void* userdata)
|
void* userdata)
|
||||||
|
@@ -42,7 +42,6 @@
|
|||||||
#ifdef HAVE_QT
|
#ifdef HAVE_QT
|
||||||
|
|
||||||
#include <window_QT.h>
|
#include <window_QT.h>
|
||||||
#include <QVarLengthArray>
|
|
||||||
|
|
||||||
//Static and global first
|
//Static and global first
|
||||||
static GuiReceiver guiMainThread;
|
static GuiReceiver guiMainThread;
|
||||||
@@ -132,6 +131,22 @@ CV_IMPL void cvDisplayOverlay(const char* name, const char* text, int delayms)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CV_IMPL void cvSaveWindowParameters(const char* name)
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(&guiMainThread,
|
||||||
|
"saveWindowParameters",
|
||||||
|
Qt::AutoConnection,
|
||||||
|
Q_ARG(QString, QString(name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_IMPL void cvLoadWindowParameters(const char* name)
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(&guiMainThread,
|
||||||
|
"loadWindowParameters",
|
||||||
|
Qt::AutoConnection,
|
||||||
|
Q_ARG(QString, QString(name)));
|
||||||
|
}
|
||||||
|
|
||||||
CV_IMPL void cvDisplayStatusBar(const char* name, const char* text, int delayms)
|
CV_IMPL void cvDisplayStatusBar(const char* name, const char* text, int delayms)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -235,7 +250,7 @@ CV_IMPL CvWindow* icvFindWindowByName( const char* arg )
|
|||||||
foreach (QWidget *widget, QApplication::topLevelWidgets())
|
foreach (QWidget *widget, QApplication::topLevelWidgets())
|
||||||
{
|
{
|
||||||
w = (CvWindow*) widget;
|
w = (CvWindow*) widget;
|
||||||
if (w->name==name)
|
if (w->param_name==name)
|
||||||
{
|
{
|
||||||
window = w;
|
window = w;
|
||||||
break;
|
break;
|
||||||
@@ -258,8 +273,9 @@ CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_w
|
|||||||
QString nameQt = QString(name_trackbar);
|
QString nameQt = QString(name_trackbar);
|
||||||
QPointer<CvTrackbar> t;
|
QPointer<CvTrackbar> t;
|
||||||
|
|
||||||
//Warning ---- , asume the location 0 is myview and max-1 the status bar
|
//Warning ---- , asume the location 0 is myview and max-1 the status bar
|
||||||
for (int i = 1; i < w->layout->layout()->count()-2; ++i)
|
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
||||||
|
for (int i = 1; i < w->layout->layout()->count()-1; ++i)
|
||||||
{
|
{
|
||||||
|
|
||||||
t = (CvTrackbar*) w->layout->layout()->itemAt(i);
|
t = (CvTrackbar*) w->layout->layout()->itemAt(i);
|
||||||
@@ -467,6 +483,22 @@ GuiReceiver::GuiReceiver() : _bTimeOut(false)
|
|||||||
qApp->setQuitOnLastWindowClosed ( false );//maybe the user would like to access this setting
|
qApp->setQuitOnLastWindowClosed ( false );//maybe the user would like to access this setting
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiReceiver::saveWindowParameters(QString name)
|
||||||
|
{
|
||||||
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
||||||
|
|
||||||
|
if (w)
|
||||||
|
w->writeSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiReceiver::loadWindowParameters(QString name)
|
||||||
|
{
|
||||||
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
||||||
|
|
||||||
|
if (w)
|
||||||
|
w->readSettings();
|
||||||
|
}
|
||||||
|
|
||||||
double GuiReceiver::getRatioWindow(QString name)
|
double GuiReceiver::getRatioWindow(QString name)
|
||||||
{
|
{
|
||||||
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
||||||
@@ -504,7 +536,7 @@ double GuiReceiver::getPropWindow(QString name)
|
|||||||
if (!w)
|
if (!w)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return (double)w->flags;
|
return (double)w->param_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiReceiver::setPropWindow(QString name, double arg2 )
|
void GuiReceiver::setPropWindow(QString name, double arg2 )
|
||||||
@@ -516,7 +548,7 @@ void GuiReceiver::setPropWindow(QString name, double arg2 )
|
|||||||
|
|
||||||
int flags = (int) arg2;
|
int flags = (int) arg2;
|
||||||
|
|
||||||
if (w->flags == flags)//nothing to do
|
if (w->param_flags == flags)//nothing to do
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
@@ -524,11 +556,11 @@ void GuiReceiver::setPropWindow(QString name, double arg2 )
|
|||||||
{
|
{
|
||||||
case CV_WINDOW_NORMAL:
|
case CV_WINDOW_NORMAL:
|
||||||
w->layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
w->layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||||
w->flags = flags;
|
w->param_flags = flags;
|
||||||
break;
|
break;
|
||||||
case CV_WINDOW_AUTOSIZE:
|
case CV_WINDOW_AUTOSIZE:
|
||||||
w->layout->setSizeConstraint(QLayout::SetFixedSize);
|
w->layout->setSizeConstraint(QLayout::SetFixedSize);
|
||||||
w->flags = flags;
|
w->param_flags = flags;
|
||||||
break;
|
break;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
@@ -757,16 +789,16 @@ void CvTrackbar::createDialog()
|
|||||||
int max = slider->maximum();
|
int max = slider->maximum();
|
||||||
|
|
||||||
int i = QInputDialog::getInt(this->parentWidget(),
|
int i = QInputDialog::getInt(this->parentWidget(),
|
||||||
tr("Slider %1").arg(trackbar_name),
|
tr("Slider %1").arg(trackbar_name),
|
||||||
tr("New value:"),
|
tr("New value:"),
|
||||||
value,
|
value,
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
step,
|
step,
|
||||||
&ok);
|
&ok);
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
slider->setValue(i);
|
slider->setValue(i);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,7 +808,7 @@ void CvTrackbar::update(int myvalue)
|
|||||||
|
|
||||||
*dataSlider = myvalue;
|
*dataSlider = myvalue;
|
||||||
if (callback)
|
if (callback)
|
||||||
callback(myvalue);
|
callback(myvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CvTrackbar::setLabel(int myvalue)
|
void CvTrackbar::setLabel(int myvalue)
|
||||||
@@ -796,13 +828,13 @@ CvTrackbar::~CvTrackbar()
|
|||||||
CvWindow::CvWindow(QString arg, int arg2)
|
CvWindow::CvWindow(QString arg, int arg2)
|
||||||
{
|
{
|
||||||
moveToThread(qApp->instance()->thread());
|
moveToThread(qApp->instance()->thread());
|
||||||
name = arg;
|
param_name = arg;
|
||||||
flags = arg2;
|
param_flags = arg2;
|
||||||
|
|
||||||
setAttribute(Qt::WA_DeleteOnClose);//in other case, does not release memory
|
setAttribute(Qt::WA_DeleteOnClose);//in other case, does not release memory
|
||||||
setContentsMargins(0,0,0,0);
|
setContentsMargins(0,0,0,0);
|
||||||
setWindowTitle(name);
|
setWindowTitle(param_name);
|
||||||
setObjectName(name);
|
setObjectName(param_name);
|
||||||
|
|
||||||
resize(400,300);
|
resize(400,300);
|
||||||
|
|
||||||
@@ -811,22 +843,20 @@ CvWindow::CvWindow(QString arg, int arg2)
|
|||||||
myview->setAlignment(Qt::AlignHCenter);
|
myview->setAlignment(Qt::AlignHCenter);
|
||||||
|
|
||||||
|
|
||||||
shortcut_r_Zoom = new QShortcut(Qt::CTRL + Qt::Key_P, this);
|
shortcutZ = new QShortcut(Qt::CTRL + Qt::Key_P, this);
|
||||||
QObject::connect( shortcut_r_Zoom, SIGNAL( activated ()),myview, SLOT( resetZoom( ) ));
|
QObject::connect( shortcutZ, SIGNAL( activated ()),myview, SLOT( resetZoom( ) ));
|
||||||
shortcut_imgRegion = new QShortcut(Qt::CTRL + Qt::Key_O, this);
|
shortcutPlus = new QShortcut(QKeySequence(QKeySequence::ZoomIn), this);
|
||||||
QObject::connect( shortcut_imgRegion, SIGNAL( activated ()),myview, SLOT( imgRegion( ) ));
|
QObject::connect( shortcutPlus, SIGNAL( activated ()),myview, SLOT( ZoomIn() ));
|
||||||
shortcut_Plus = new QShortcut(QKeySequence(QKeySequence::ZoomIn), this);
|
shortcutMinus = new QShortcut(QKeySequence(QKeySequence::ZoomOut), this);
|
||||||
QObject::connect( shortcut_Plus, SIGNAL( activated ()),myview, SLOT( ZoomIn() ));
|
QObject::connect(shortcutMinus, SIGNAL( activated ()),myview, SLOT( ZoomOut() ));
|
||||||
shortcut_Minus = new QShortcut(QKeySequence(QKeySequence::ZoomOut), this);
|
shortcutLeft = new QShortcut(Qt::CTRL + Qt::Key_Left, this);
|
||||||
QObject::connect(shortcut_Minus, SIGNAL( activated ()),myview, SLOT( ZoomOut() ));
|
QObject::connect( shortcutLeft, SIGNAL( activated ()),myview, SLOT( siftWindowOnLeft() ));
|
||||||
shortcut_Left = new QShortcut(Qt::CTRL + Qt::Key_Left, this);
|
shortcutRight = new QShortcut(Qt::CTRL + Qt::Key_Right, this);
|
||||||
QObject::connect( shortcut_Left, SIGNAL( activated ()),myview, SLOT( siftWindowOnLeft() ));
|
QObject::connect( shortcutRight, SIGNAL( activated ()),myview, SLOT( siftWindowOnRight() ));
|
||||||
shortcut_Right = new QShortcut(Qt::CTRL + Qt::Key_Right, this);
|
shortcutUp = new QShortcut(Qt::CTRL + Qt::Key_Up, this);
|
||||||
QObject::connect( shortcut_Right, SIGNAL( activated ()),myview, SLOT( siftWindowOnRight() ));
|
QObject::connect(shortcutUp, SIGNAL( activated ()),myview, SLOT( siftWindowOnUp() ));
|
||||||
shortcut_Up = new QShortcut(Qt::CTRL + Qt::Key_Up, this);
|
shortcutDown = new QShortcut(Qt::CTRL + Qt::Key_Down, this);
|
||||||
QObject::connect(shortcut_Up, SIGNAL( activated ()),myview, SLOT( siftWindowOnUp() ));
|
QObject::connect(shortcutDown, SIGNAL( activated ()),myview, SLOT( siftWindowOnDown() ));
|
||||||
shortcut_Down = new QShortcut(Qt::CTRL + Qt::Key_Down, this);
|
|
||||||
QObject::connect(shortcut_Down, SIGNAL( activated ()),myview, SLOT( siftWindowOnDown() ));
|
|
||||||
|
|
||||||
layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||||
//layout = new CustomLayout;
|
//layout = new CustomLayout;
|
||||||
@@ -837,8 +867,8 @@ CvWindow::CvWindow(QString arg, int arg2)
|
|||||||
layout->addWidget(myview,Qt::AlignCenter);
|
layout->addWidget(myview,Qt::AlignCenter);
|
||||||
//layout->addStretch(0);
|
//layout->addStretch(0);
|
||||||
|
|
||||||
if (flags == CV_WINDOW_AUTOSIZE)
|
if (param_flags == CV_WINDOW_AUTOSIZE)
|
||||||
layout->setSizeConstraint(QLayout::SetFixedSize);
|
layout->setSizeConstraint(QLayout::SetFixedSize);
|
||||||
|
|
||||||
//now status bar
|
//now status bar
|
||||||
myBar = new QStatusBar;
|
myBar = new QStatusBar;
|
||||||
@@ -864,29 +894,28 @@ CvWindow::~CvWindow()
|
|||||||
|
|
||||||
if (layout)
|
if (layout)
|
||||||
{
|
{
|
||||||
while ((child = layout->takeAt(0)) != 0)
|
while ((child = layout->takeAt(0)) != 0)
|
||||||
delete child;
|
delete child;
|
||||||
|
|
||||||
delete layout;
|
delete layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete myBar;
|
delete myBar;
|
||||||
delete myBar_msg;
|
delete myBar_msg;
|
||||||
|
|
||||||
|
|
||||||
delete shortcut_r_Zoom;
|
delete shortcutZ;
|
||||||
delete shortcut_imgRegion;
|
delete shortcutPlus;
|
||||||
delete shortcut_Plus;
|
delete shortcutMinus;
|
||||||
delete shortcut_Minus;
|
delete shortcutLeft;
|
||||||
delete shortcut_Left;
|
delete shortcutRight;
|
||||||
delete shortcut_Right;
|
delete shortcutUp;
|
||||||
delete shortcut_Up;
|
delete shortcutDown;
|
||||||
delete shortcut_Down;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewPort* CvWindow::getView()
|
ViewPort* CvWindow::getView()
|
||||||
{
|
{
|
||||||
return myview;
|
return myview;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CvWindow::displayInfo(QString text,int delayms)
|
void CvWindow::displayInfo(QString text,int delayms)
|
||||||
@@ -925,53 +954,128 @@ void CvWindow::keyPressEvent(QKeyEvent *event)
|
|||||||
|
|
||||||
if (key>=20 && key<=255 )
|
if (key>=20 && key<=255 )
|
||||||
{
|
{
|
||||||
key = (int)event->text().toLocal8Bit().at(0);
|
key = (int)event->text().toLocal8Bit().at(0);
|
||||||
goodKey = true;
|
goodKey = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == Qt::Key_Escape)
|
if (key == Qt::Key_Escape)
|
||||||
{
|
{
|
||||||
key = 27;
|
key = 27;
|
||||||
goodKey = true;
|
goodKey = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions
|
//control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions
|
||||||
if (event->modifiers() != Qt::ControlModifier && goodKey)
|
if (event->modifiers() != Qt::ControlModifier && goodKey)
|
||||||
{
|
{
|
||||||
mutexKey.lock();
|
mutexKey.lock();
|
||||||
last_key = key;
|
last_key = key;
|
||||||
//last_key = event->nativeVirtualKey ();
|
//last_key = event->nativeVirtualKey ();
|
||||||
mutexKey.unlock();
|
mutexKey.unlock();
|
||||||
key_pressed.wakeAll();
|
key_pressed.wakeAll();
|
||||||
//event->accept();
|
//event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget::keyPressEvent(event);
|
QWidget::keyPressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CvWindow::readSettings()//not tested
|
void CvWindow::readSettings()
|
||||||
{
|
{
|
||||||
QSettings settings("Trolltech", "Application Example");
|
//organisation and application's name
|
||||||
|
QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());
|
||||||
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
|
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
|
||||||
QSize size = settings.value("size", QSize(400, 400)).toSize();
|
QSize size = settings.value("size", QSize(400, 400)).toSize();
|
||||||
|
param_name = settings.value("name_window",param_name).toString();
|
||||||
|
|
||||||
|
param_flags = settings.value("mode_resize",param_flags).toInt();
|
||||||
|
qreal m11 = settings.value("matrix_view.m11",myview->param_matrixWorld.m11()).toReal();
|
||||||
|
qreal m12 = settings.value("matrix_view.m12",myview->param_matrixWorld.m12()).toReal();
|
||||||
|
qreal m13 = settings.value("matrix_view.m13",myview->param_matrixWorld.m13()).toReal();
|
||||||
|
qreal m21 = settings.value("matrix_view.m21",myview->param_matrixWorld.m21()).toReal();
|
||||||
|
qreal m22 = settings.value("matrix_view.m22",myview->param_matrixWorld.m22()).toReal();
|
||||||
|
qreal m23 = settings.value("matrix_view.m23",myview->param_matrixWorld.m23()).toReal();
|
||||||
|
qreal m31 = settings.value("matrix_view.m31",myview->param_matrixWorld.m31()).toReal();
|
||||||
|
qreal m32 = settings.value("matrix_view.m32",myview->param_matrixWorld.m32()).toReal();
|
||||||
|
qreal m33 = settings.value("matrix_view.m33",myview->param_matrixWorld.m33()).toReal();
|
||||||
|
myview->param_matrixWorld = QTransform(m11,m12,m13,m21,m22,m23,m31,m32,m33);
|
||||||
|
|
||||||
|
//trackbar here
|
||||||
|
icvLoadTrackbars(&settings);
|
||||||
|
|
||||||
resize(size);
|
resize(size);
|
||||||
move(pos);
|
move(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CvWindow::writeSettings()//not tested
|
void CvWindow::writeSettings()
|
||||||
{
|
{
|
||||||
QSettings settings("Trolltech", "Application Example");
|
//organisation and application's name
|
||||||
|
QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());
|
||||||
|
settings.setValue("name_window",param_name);
|
||||||
settings.setValue("pos", pos());
|
settings.setValue("pos", pos());
|
||||||
settings.setValue("size", size());
|
settings.setValue("size", size());
|
||||||
|
settings.setValue("mode_resize",param_flags);
|
||||||
|
settings.setValue("view_aspectRatio",myview->param_keepRatio);
|
||||||
|
|
||||||
|
settings.setValue("matrix_view.m11",myview->param_matrixWorld.m11());
|
||||||
|
settings.setValue("matrix_view.m12",myview->param_matrixWorld.m12());
|
||||||
|
settings.setValue("matrix_view.m13",myview->param_matrixWorld.m13());
|
||||||
|
settings.setValue("matrix_view.m21",myview->param_matrixWorld.m21());
|
||||||
|
settings.setValue("matrix_view.m22",myview->param_matrixWorld.m22());
|
||||||
|
settings.setValue("matrix_view.m23",myview->param_matrixWorld.m23());
|
||||||
|
settings.setValue("matrix_view.m31",myview->param_matrixWorld.m31());
|
||||||
|
settings.setValue("matrix_view.m32",myview->param_matrixWorld.m32());
|
||||||
|
settings.setValue("matrix_view.m33",myview->param_matrixWorld.m33());
|
||||||
|
|
||||||
|
icvSaveTrackbars(&settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CvWindow::icvLoadTrackbars(QSettings *settings)
|
||||||
|
{
|
||||||
|
int size = settings->beginReadArray("trackbars");
|
||||||
|
QPointer<CvTrackbar> t;
|
||||||
|
//Warning ---- , asume the location 0 is myview and max-1 the status bar
|
||||||
|
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
||||||
|
|
||||||
|
//trackbar are saved in the same order, so no need to use icvFindTrackbarByName
|
||||||
|
if (layout->layout()->count()-2 == size)//if not the same number, the window saved and loaded is not the same (nb trackbar not equal)
|
||||||
|
for (int i = 0; i < size; ++i)
|
||||||
|
{
|
||||||
|
settings->setArrayIndex(i);
|
||||||
|
t = (CvTrackbar*) layout->layout()->itemAt(i+1);//+1 because index 0 is myview (see Warning)
|
||||||
|
|
||||||
|
if (t->trackbar_name == settings->value("name").toString())
|
||||||
|
{
|
||||||
|
t->slider->setValue(settings->value("value").toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
settings->endArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CvWindow::icvSaveTrackbars(QSettings *settings)
|
||||||
|
{
|
||||||
|
QPointer<CvTrackbar> t;
|
||||||
|
|
||||||
|
//Warning ---- , asume the location 0 is myview and max-1 the status bar
|
||||||
|
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
||||||
|
settings->beginWriteArray("trackbars");
|
||||||
|
for (int i = 0; i < layout->layout()->count()-2; ++i) {
|
||||||
|
t = (CvTrackbar*) layout->layout()->itemAt(i+1);//+1 because index 0 is myview (see Warning)
|
||||||
|
settings->setArrayIndex(i);
|
||||||
|
settings->setValue("name", t->trackbar_name);
|
||||||
|
settings->setValue("value", t->slider->value());
|
||||||
|
}
|
||||||
|
settings->endArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Here is ViewPort
|
//Here is ViewPort
|
||||||
ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
|
ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
|
||||||
{
|
{
|
||||||
centralWidget = arg,
|
centralWidget = arg,
|
||||||
mode = arg2;
|
mode_display = arg2;
|
||||||
keepRatio = arg3;
|
param_keepRatio = arg3;
|
||||||
|
|
||||||
setupViewport(centralWidget);
|
setupViewport(centralWidget);
|
||||||
setContentsMargins(0,0,0,0);
|
setContentsMargins(0,0,0,0);
|
||||||
@@ -988,7 +1092,7 @@ ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
|
|||||||
|
|
||||||
|
|
||||||
#if defined(OPENCV_GL)
|
#if defined(OPENCV_GL)
|
||||||
if (mode == CV_MODE_OPENGL)
|
if ( mode_display == CV_MODE_OPENGL)
|
||||||
{
|
{
|
||||||
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
||||||
initGL();
|
initGL();
|
||||||
@@ -1013,62 +1117,57 @@ ViewPort::~ViewPort()
|
|||||||
|
|
||||||
void ViewPort::setRatio(int flags)
|
void ViewPort::setRatio(int flags)
|
||||||
{
|
{
|
||||||
keepRatio = flags;
|
param_keepRatio = flags;
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ViewPort::getRatio()
|
int ViewPort::getRatio()
|
||||||
{
|
{
|
||||||
return keepRatio;
|
return param_keepRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPort::resetZoom()
|
void ViewPort::resetZoom()
|
||||||
{
|
{
|
||||||
matrixWorld.reset();
|
param_matrixWorld.reset();
|
||||||
controlImagePosition();
|
controlImagePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPort::imgRegion( )
|
|
||||||
{
|
|
||||||
scaleView(threshold_zoom_img_region/matrixWorld.m11(), QPointF(size().width()/2,size().height()/2),false);//false = do not process the 1st param
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewPort::ZoomIn()
|
void ViewPort::ZoomIn()
|
||||||
{
|
{
|
||||||
scaleView( 0.5,QPointF(size().width()/2,size().height()/2),true);
|
scaleView( 0.5,QPointF(size().width()/2,size().height()/2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPort::ZoomOut()
|
void ViewPort::ZoomOut()
|
||||||
{
|
{
|
||||||
scaleView( -0.5,QPointF(size().width()/2,size().height()/2),true);
|
scaleView( -0.5,QPointF(size().width()/2,size().height()/2));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Note: move 2 percent of the window
|
//Note: move 2 percent of the window
|
||||||
void ViewPort::siftWindowOnLeft()
|
void ViewPort::siftWindowOnLeft()
|
||||||
{
|
{
|
||||||
float delta = 2*width()/(100.0*matrixWorld.m11());
|
float delta = 2*width()/(100.0*param_matrixWorld.m11());
|
||||||
moveView(QPointF(delta,0));
|
moveView(QPointF(delta,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Note: move 2 percent of the window
|
//Note: move 2 percent of the window
|
||||||
void ViewPort::siftWindowOnRight()
|
void ViewPort::siftWindowOnRight()
|
||||||
{
|
{
|
||||||
float delta = -2*width()/(100.0*matrixWorld.m11());
|
float delta = -2*width()/(100.0*param_matrixWorld.m11());
|
||||||
moveView(QPointF(delta,0));
|
moveView(QPointF(delta,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Note: move 2 percent of the window
|
//Note: move 2 percent of the window
|
||||||
void ViewPort::siftWindowOnUp()
|
void ViewPort::siftWindowOnUp()
|
||||||
{
|
{
|
||||||
float delta = 2*height()/(100.0*matrixWorld.m11());
|
float delta = 2*height()/(100.0*param_matrixWorld.m11());
|
||||||
moveView(QPointF(0,delta));
|
moveView(QPointF(0,delta));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Note: move 2 percent of the window
|
//Note: move 2 percent of the window
|
||||||
void ViewPort::siftWindowOnDown()
|
void ViewPort::siftWindowOnDown()
|
||||||
{
|
{
|
||||||
float delta = -2*height()/(100.0*matrixWorld.m11());
|
float delta = -2*height()/(100.0*param_matrixWorld.m11());
|
||||||
moveView(QPointF(0,delta));
|
moveView(QPointF(0,delta));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1125,30 +1224,30 @@ void ViewPort::controlImagePosition()
|
|||||||
qreal left, top, right, bottom;
|
qreal left, top, right, bottom;
|
||||||
|
|
||||||
//after check top-left, bottom right corner to avoid getting "out" during zoom/panning
|
//after check top-left, bottom right corner to avoid getting "out" during zoom/panning
|
||||||
matrixWorld.map(0,0,&left,&top);
|
param_matrixWorld.map(0,0,&left,&top);
|
||||||
|
|
||||||
if (left > 0)
|
if (left > 0)
|
||||||
{
|
{
|
||||||
matrixWorld.translate(-left,0);
|
param_matrixWorld.translate(-left,0);
|
||||||
left = 0;
|
left = 0;
|
||||||
}
|
}
|
||||||
if (top > 0)
|
if (top > 0)
|
||||||
{
|
{
|
||||||
matrixWorld.translate(0,-top);
|
param_matrixWorld.translate(0,-top);
|
||||||
top = 0;
|
top = 0;
|
||||||
}
|
}
|
||||||
//-------
|
//-------
|
||||||
|
|
||||||
QSize sizeImage = size();
|
QSize sizeImage = size();
|
||||||
matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom);
|
param_matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom);
|
||||||
if (right < sizeImage.width())
|
if (right < sizeImage.width())
|
||||||
{
|
{
|
||||||
matrixWorld.translate(sizeImage.width()-right,0);
|
param_matrixWorld.translate(sizeImage.width()-right,0);
|
||||||
right = sizeImage.width();
|
right = sizeImage.width();
|
||||||
}
|
}
|
||||||
if (bottom < sizeImage.height())
|
if (bottom < sizeImage.height())
|
||||||
{
|
{
|
||||||
matrixWorld.translate(0,sizeImage.height()-bottom);
|
param_matrixWorld.translate(0,sizeImage.height()-bottom);
|
||||||
bottom = sizeImage.height();
|
bottom = sizeImage.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1156,51 +1255,48 @@ void ViewPort::controlImagePosition()
|
|||||||
positionCorners.setTopLeft(QPoint(left,top));
|
positionCorners.setTopLeft(QPoint(left,top));
|
||||||
positionCorners.setBottomRight(QPoint(right,bottom));
|
positionCorners.setBottomRight(QPoint(right,bottom));
|
||||||
//save also the inv matrix
|
//save also the inv matrix
|
||||||
matrixWorld_inv = matrixWorld.inverted();
|
matrixWorld_inv = param_matrixWorld.inverted();
|
||||||
|
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPort::moveView(QPointF delta)
|
void ViewPort::moveView(QPointF delta)
|
||||||
{
|
{
|
||||||
matrixWorld.translate(delta.x(),delta.y());
|
param_matrixWorld.translate(delta.x(),delta.y());
|
||||||
controlImagePosition();
|
controlImagePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
//factor is -0.5 (zoom out) or 0.5 (zoom in)
|
//factor is -0.5 (zoom out) or 0.5 (zoom in)
|
||||||
void ViewPort::scaleView(qreal factor,QPointF center,bool process_factor)
|
void ViewPort::scaleView(qreal factor,QPointF center)
|
||||||
{
|
{
|
||||||
if (process_factor)
|
factor/=5;//-0.1 <-> 0.1
|
||||||
{
|
factor+=1;//0.9 <-> 1.1
|
||||||
factor/=5;//-0.1 <-> 0.1
|
|
||||||
factor+=1;//0.9 <-> 1.1
|
|
||||||
}
|
|
||||||
|
|
||||||
//limit zoom out ---
|
//limit zoom out ---
|
||||||
if (matrixWorld.m11()==1 && factor < 1)
|
if (param_matrixWorld.m11()==1 && factor < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (matrixWorld.m11()*factor<1)
|
if (param_matrixWorld.m11()*factor<1)
|
||||||
factor = 1/matrixWorld.m11();
|
factor = 1/param_matrixWorld.m11();
|
||||||
|
|
||||||
|
|
||||||
//limit zoom int ---
|
//limit zoom int ---
|
||||||
if (matrixWorld.m11()>100 && factor > 1)
|
if (param_matrixWorld.m11()>100 && factor > 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//inverse the transform
|
//inverse the transform
|
||||||
int a, b;
|
int a, b;
|
||||||
matrixWorld_inv.map(center.x(),center.y(),&a,&b);
|
matrixWorld_inv.map(center.x(),center.y(),&a,&b);
|
||||||
|
|
||||||
matrixWorld.translate(a-factor*a,b-factor*b);
|
param_matrixWorld.translate(a-factor*a,b-factor*b);
|
||||||
matrixWorld.scale(factor,factor);
|
param_matrixWorld.scale(factor,factor);
|
||||||
|
|
||||||
controlImagePosition();
|
controlImagePosition();
|
||||||
|
|
||||||
//display new zoom
|
//display new zoom
|
||||||
centralWidget->displayStatusBar(tr("Zoom: %1%").arg(matrixWorld.m11()*100),1000);
|
centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000);
|
||||||
|
|
||||||
if (matrixWorld.m11()>1)
|
if (param_matrixWorld.m11()>1)
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
else
|
else
|
||||||
unsetCursor();
|
unsetCursor();
|
||||||
@@ -1208,7 +1304,7 @@ void ViewPort::scaleView(qreal factor,QPointF center,bool process_factor)
|
|||||||
|
|
||||||
void ViewPort::wheelEvent(QWheelEvent *event)
|
void ViewPort::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
scaleView( -event->delta() / 240.0,event->pos(),true);//true means process the 1st parameter
|
scaleView( -event->delta() / 240.0,event->pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPort::mousePressEvent(QMouseEvent *event)
|
void ViewPort::mousePressEvent(QMouseEvent *event)
|
||||||
@@ -1220,7 +1316,7 @@ void ViewPort::mousePressEvent(QMouseEvent *event)
|
|||||||
icvmouseHandler(event, mouse_down, cv_event, flags);
|
icvmouseHandler(event, mouse_down, cv_event, flags);
|
||||||
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
||||||
|
|
||||||
if (matrixWorld.m11()>1)
|
if (param_matrixWorld.m11()>1)
|
||||||
{
|
{
|
||||||
setCursor(Qt::ClosedHandCursor);
|
setCursor(Qt::ClosedHandCursor);
|
||||||
positionGrabbing = event->pos();
|
positionGrabbing = event->pos();
|
||||||
@@ -1239,7 +1335,7 @@ void ViewPort::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
icvmouseHandler(event, mouse_up, cv_event, flags);
|
icvmouseHandler(event, mouse_up, cv_event, flags);
|
||||||
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
||||||
|
|
||||||
if (matrixWorld.m11()>1)
|
if (param_matrixWorld.m11()>1)
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
|
||||||
QWidget::mouseReleaseEvent(event);
|
QWidget::mouseReleaseEvent(event);
|
||||||
@@ -1267,9 +1363,9 @@ void ViewPort::mouseMoveEvent(QMouseEvent *event)
|
|||||||
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
||||||
|
|
||||||
|
|
||||||
if (matrixWorld.m11()>1 && event->buttons() == Qt::LeftButton)
|
if (param_matrixWorld.m11()>1 && event->buttons() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
QPointF dxy = (pt - positionGrabbing)/matrixWorld.m11();
|
QPointF dxy = (pt - positionGrabbing)/param_matrixWorld.m11();
|
||||||
|
|
||||||
positionGrabbing = event->pos();
|
positionGrabbing = event->pos();
|
||||||
|
|
||||||
@@ -1357,7 +1453,7 @@ void ViewPort::resizeEvent ( QResizeEvent *event)
|
|||||||
ratioX=width()/float(image2Draw_ipl->width);
|
ratioX=width()/float(image2Draw_ipl->width);
|
||||||
ratioY=height()/float(image2Draw_ipl->height);
|
ratioY=height()/float(image2Draw_ipl->height);
|
||||||
|
|
||||||
if(keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio
|
if(param_keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio
|
||||||
{
|
{
|
||||||
QSize newSize = QSize(image2Draw_ipl->width,image2Draw_ipl->height);
|
QSize newSize = QSize(image2Draw_ipl->width,image2Draw_ipl->height);
|
||||||
newSize.scale(event->size(),Qt::KeepAspectRatio);
|
newSize.scale(event->size(),Qt::KeepAspectRatio);
|
||||||
@@ -1382,13 +1478,13 @@ void ViewPort::resizeEvent ( QResizeEvent *event)
|
|||||||
void ViewPort::paintEvent(QPaintEvent* event)
|
void ViewPort::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
QPainter myPainter(viewport());
|
QPainter myPainter(viewport());
|
||||||
myPainter.setWorldTransform(matrixWorld);
|
myPainter.setWorldTransform(param_matrixWorld);
|
||||||
|
|
||||||
draw2D(&myPainter);
|
draw2D(&myPainter);
|
||||||
|
|
||||||
|
|
||||||
#if defined(OPENCV_GL)
|
#if defined(OPENCV_GL)
|
||||||
if (mode == CV_MODE_OPENGL && false)//disable it for now
|
if ( mode_display == CV_MODE_OPENGL && false)//disable it for now
|
||||||
{
|
{
|
||||||
setGL(this->width(),this->height());
|
setGL(this->width(),this->height());
|
||||||
draw3D();
|
draw3D();
|
||||||
@@ -1397,12 +1493,12 @@ void ViewPort::paintEvent(QPaintEvent* event)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//in mode zoom/panning
|
//in mode zoom/panning
|
||||||
if (matrixWorld.m11()>1)
|
if (param_matrixWorld.m11()>1)
|
||||||
{
|
{
|
||||||
|
|
||||||
myPainter.setWorldMatrixEnabled (false );
|
myPainter.setWorldMatrixEnabled (false );
|
||||||
|
|
||||||
if (matrixWorld.m11()>=threshold_zoom_img_region)
|
if (param_matrixWorld.m11()>=threshold_zoom_img_region)
|
||||||
drawImgRegion(&myPainter);
|
drawImgRegion(&myPainter);
|
||||||
|
|
||||||
drawViewOverview(&myPainter);
|
drawViewOverview(&myPainter);
|
||||||
@@ -1463,23 +1559,23 @@ void ViewPort::drawStatusBar()
|
|||||||
|
|
||||||
void ViewPort::drawImgRegion(QPainter *painter)
|
void ViewPort::drawImgRegion(QPainter *painter)
|
||||||
{
|
{
|
||||||
qreal offsetX = matrixWorld.dx()/matrixWorld.m11();
|
qreal offsetX = param_matrixWorld.dx()/param_matrixWorld.m11();
|
||||||
offsetX = offsetX - floor(offsetX);
|
offsetX = offsetX - floor(offsetX);
|
||||||
qreal offsetY = matrixWorld.dy()/matrixWorld.m11();
|
qreal offsetY = param_matrixWorld.dy()/param_matrixWorld.m11();
|
||||||
offsetY = offsetY - floor(offsetY);
|
offsetY = offsetY - floor(offsetY);
|
||||||
|
|
||||||
QSize view = size();
|
QSize view = size();
|
||||||
QVarLengthArray<QLineF, 30> linesX;
|
QVarLengthArray<QLineF, 30> linesX;
|
||||||
for (qreal x = offsetX*matrixWorld.m11(); x < view.width(); x += matrixWorld.m11() )
|
for (qreal x = offsetX*param_matrixWorld.m11(); x < view.width(); x += param_matrixWorld.m11() )
|
||||||
linesX.append(QLineF(x, 0, x, view.height()));
|
linesX.append(QLineF(x, 0, x, view.height()));
|
||||||
|
|
||||||
QVarLengthArray<QLineF, 30> linesY;
|
QVarLengthArray<QLineF, 30> linesY;
|
||||||
for (qreal y = offsetY*matrixWorld.m11(); y < view.height(); y += matrixWorld.m11() )
|
for (qreal y = offsetY*param_matrixWorld.m11(); y < view.height(); y += param_matrixWorld.m11() )
|
||||||
linesY.append(QLineF(0, y, view.width(), y));
|
linesY.append(QLineF(0, y, view.width(), y));
|
||||||
|
|
||||||
|
|
||||||
QFont f = painter->font();
|
QFont f = painter->font();
|
||||||
f.setPointSize(threshold_zoom_img_region/3+(matrixWorld.m11()-threshold_zoom_img_region)/6);
|
f.setPixelSize(6+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);
|
||||||
//f.setStretch(0);
|
//f.setStretch(0);
|
||||||
painter->setFont(f);
|
painter->setFont(f);
|
||||||
QString val;
|
QString val;
|
||||||
@@ -1489,11 +1585,11 @@ void ViewPort::drawImgRegion(QPainter *painter)
|
|||||||
QPointF point2;//idem
|
QPointF point2;//idem
|
||||||
|
|
||||||
|
|
||||||
for (int j=-1;j<view.height()/matrixWorld.m11();j++)
|
for (int j=-1;j<view.height()/param_matrixWorld.m11();j++)
|
||||||
for (int i=-1;i<view.width()/matrixWorld.m11();i++)
|
for (int i=-1;i<view.width()/param_matrixWorld.m11();i++)
|
||||||
{
|
{
|
||||||
point1.setX((i+offsetX)*matrixWorld.m11());
|
point1.setX((i+offsetX)*param_matrixWorld.m11());
|
||||||
point1.setY((j+offsetY)*matrixWorld.m11());
|
point1.setY((j+offsetY)*param_matrixWorld.m11());
|
||||||
|
|
||||||
matrixWorld_inv.map(point1.x(),point1.y(),&point2.rx(),&point2.ry());
|
matrixWorld_inv.map(point1.x(),point1.y(),&point2.rx(),&point2.ry());
|
||||||
|
|
||||||
@@ -1502,22 +1598,21 @@ void ViewPort::drawImgRegion(QPainter *painter)
|
|||||||
else
|
else
|
||||||
rgbValue = qRgb(0,0,0);
|
rgbValue = qRgb(0,0,0);
|
||||||
|
|
||||||
const int margin = 1;
|
|
||||||
if (nbChannelOriginImage==3)
|
if (nbChannelOriginImage==3)
|
||||||
{
|
{
|
||||||
val = tr("%1").arg(qRed(rgbValue));
|
val = tr("%1").arg(qRed(rgbValue));
|
||||||
painter->setPen(QPen(Qt::red, 1));
|
painter->setPen(QPen(Qt::red, 1));
|
||||||
painter->drawText(QRect(point1.x(),point1.y()+margin,matrixWorld.m11(),matrixWorld.m11()/3),
|
painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/3),
|
||||||
Qt::AlignCenter, val);
|
Qt::AlignCenter, val);
|
||||||
|
|
||||||
val = tr("%1").arg(qGreen(rgbValue));
|
val = tr("%1").arg(qGreen(rgbValue));
|
||||||
painter->setPen(QPen(Qt::green, 1));
|
painter->setPen(QPen(Qt::green, 1));
|
||||||
painter->drawText(QRect(point1.x(),point1.y()+matrixWorld.m11()/3+margin,matrixWorld.m11(),matrixWorld.m11()/3),
|
painter->drawText(QRect(point1.x(),point1.y()+param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),
|
||||||
Qt::AlignCenter, val);
|
Qt::AlignCenter, val);
|
||||||
|
|
||||||
val = tr("%1").arg(qBlue(rgbValue));
|
val = tr("%1").arg(qBlue(rgbValue));
|
||||||
painter->setPen(QPen(Qt::blue, 1));
|
painter->setPen(QPen(Qt::blue, 1));
|
||||||
painter->drawText(QRect(point1.x(),point1.y()+2*matrixWorld.m11()/3+margin,matrixWorld.m11(),matrixWorld.m11()/3),
|
painter->drawText(QRect(point1.x(),point1.y()+2*param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),
|
||||||
Qt::AlignCenter, val);
|
Qt::AlignCenter, val);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1525,7 +1620,7 @@ void ViewPort::drawImgRegion(QPainter *painter)
|
|||||||
{
|
{
|
||||||
|
|
||||||
val = tr("%1").arg(qRed(rgbValue));
|
val = tr("%1").arg(qRed(rgbValue));
|
||||||
painter->drawText(QRect(point1.x(),point1.y(),matrixWorld.m11(),matrixWorld.m11()),
|
painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()),
|
||||||
Qt::AlignCenter, val);
|
Qt::AlignCenter, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1549,7 +1644,7 @@ void ViewPort::drawViewOverview(QPainter *painter)
|
|||||||
painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height()));
|
painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height()));
|
||||||
|
|
||||||
//daw the view's location inside the image
|
//daw the view's location inside the image
|
||||||
qreal ratioSize = 1/matrixWorld.m11();
|
qreal ratioSize = 1/param_matrixWorld.m11();
|
||||||
qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height());
|
qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height());
|
||||||
painter->setPen(Qt::darkBlue);
|
painter->setPen(Qt::darkBlue);
|
||||||
painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin,
|
painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin,
|
||||||
|
@@ -69,6 +69,7 @@
|
|||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
|
#include <QVarLengthArray>
|
||||||
|
|
||||||
//Macro here
|
//Macro here
|
||||||
#define CV_MODE_NORMAL 0
|
#define CV_MODE_NORMAL 0
|
||||||
@@ -108,7 +109,9 @@ public slots:
|
|||||||
double getPropWindow(QString name);
|
double getPropWindow(QString name);
|
||||||
void setPropWindow(QString name, double flags );
|
void setPropWindow(QString name, double flags );
|
||||||
double getRatioWindow(QString name);
|
double getRatioWindow(QString name);
|
||||||
void setRatioWindow(QString name, double arg2 );
|
void setRatioWindow(QString name, double arg2 );
|
||||||
|
void saveWindowParameters(QString name);
|
||||||
|
void loadWindowParameters(QString name);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CvTrackbar : public QHBoxLayout
|
class CvTrackbar : public QHBoxLayout
|
||||||
@@ -133,6 +136,7 @@ private:
|
|||||||
CvTrackbarCallback callback;
|
CvTrackbarCallback callback;
|
||||||
QPointer<CvWindow> parent;
|
QPointer<CvWindow> parent;
|
||||||
int* dataSlider;
|
int* dataSlider;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CvWindow : public QWidget
|
class CvWindow : public QWidget
|
||||||
@@ -146,37 +150,39 @@ public:
|
|||||||
void updateImage(void* arr);
|
void updateImage(void* arr);
|
||||||
void displayInfo(QString text, int delayms );
|
void displayInfo(QString text, int delayms );
|
||||||
void displayStatusBar(QString text, int delayms );
|
void displayStatusBar(QString text, int delayms );
|
||||||
|
void readSettings();
|
||||||
|
void writeSettings();
|
||||||
ViewPort* getView();
|
ViewPort* getView();
|
||||||
|
|
||||||
QString name;
|
|
||||||
int flags;
|
|
||||||
QPointer<QBoxLayout> layout;
|
QPointer<QBoxLayout> layout;
|
||||||
QPointer<QStatusBar> myBar;
|
QPointer<QStatusBar> myBar;
|
||||||
QPointer<QLabel> myBar_msg;
|
QPointer<QLabel> myBar_msg;
|
||||||
//QPointer<CustomLayout> layout;
|
|
||||||
|
//parameters (will be save/load)
|
||||||
|
QString param_name;
|
||||||
|
int param_flags;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void readSettings();
|
|
||||||
void writeSettings();
|
|
||||||
|
|
||||||
virtual void keyPressEvent(QKeyEvent *event);
|
virtual void keyPressEvent(QKeyEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<ViewPort> myview;
|
QPointer<ViewPort> myview;
|
||||||
|
QPointer<QShortcut> shortcutZ;
|
||||||
|
QPointer<QShortcut> shortcutPlus;
|
||||||
|
QPointer<QShortcut> shortcutMinus;
|
||||||
|
QPointer<QShortcut> shortcutLeft;
|
||||||
|
QPointer<QShortcut> shortcutRight;
|
||||||
|
QPointer<QShortcut> shortcutUp;
|
||||||
|
QPointer<QShortcut> shortcutDown;
|
||||||
|
|
||||||
int status;//0 normal, 1 fullscreen (YV)
|
void icvLoadTrackbars(QSettings *settings);
|
||||||
QPointer<QShortcut> shortcut_r_Zoom;
|
void icvSaveTrackbars(QSettings *settings);
|
||||||
QPointer<QShortcut> shortcut_imgRegion;
|
|
||||||
QPointer<QShortcut> shortcut_Plus;
|
|
||||||
QPointer<QShortcut> shortcut_Minus;
|
|
||||||
QPointer<QShortcut> shortcut_Left;
|
|
||||||
QPointer<QShortcut> shortcut_Right;
|
|
||||||
QPointer<QShortcut> shortcut_Up;
|
|
||||||
QPointer<QShortcut> shortcut_Down;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum type_mouse_event {mouse_up = 0, mouse_down = 1, mouse_dbclick = 2, mouse_move = 3};
|
enum type_mouse_event {mouse_up = 0, mouse_down = 1, mouse_dbclick = 2, mouse_move = 3};
|
||||||
|
|
||||||
static const int tableMouseButtons[][3]={
|
static const int tableMouseButtons[][3]={
|
||||||
@@ -186,6 +192,7 @@ static const int tableMouseButtons[][3]={
|
|||||||
{CV_EVENT_MOUSEMOVE,CV_EVENT_MOUSEMOVE,CV_EVENT_MOUSEMOVE} //mouse_move
|
{CV_EVENT_MOUSEMOVE,CV_EVENT_MOUSEMOVE,CV_EVENT_MOUSEMOVE} //mouse_move
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ViewPort : public QGraphicsView
|
class ViewPort : public QGraphicsView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -195,20 +202,24 @@ public:
|
|||||||
void updateImage(void* arr);
|
void updateImage(void* arr);
|
||||||
void startDisplayInfo(QString text, int delayms);
|
void startDisplayInfo(QString text, int delayms);
|
||||||
void setMouseCallBack(CvMouseCallback m, void* param);
|
void setMouseCallBack(CvMouseCallback m, void* param);
|
||||||
|
int getRatio();
|
||||||
|
void setRatio(int arg);
|
||||||
|
|
||||||
|
//parameters (will be save/load)
|
||||||
|
QTransform param_matrixWorld;
|
||||||
|
|
||||||
|
int param_keepRatio;
|
||||||
|
|
||||||
IplImage* image2Draw_ipl;
|
IplImage* image2Draw_ipl;
|
||||||
QImage image2Draw_qt;
|
QImage image2Draw_qt;
|
||||||
|
int mode_display;//opengl or native
|
||||||
int nbChannelOriginImage;
|
int nbChannelOriginImage;
|
||||||
void setRatio(int flags);
|
|
||||||
int getRatio();
|
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//reference:
|
//reference:
|
||||||
//http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming
|
//http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming
|
||||||
//http://doc.qt.nokia.com/4.6/gestures-imagegestures-imagewidget-cpp.html
|
//http://doc.qt.nokia.com/4.6/gestures-imagegestures-imagewidget-cpp.html
|
||||||
void scaleView(qreal scaleFactor, QPointF center, bool process1stParam);
|
void scaleView(qreal scaleFactor, QPointF center);
|
||||||
void imgRegion( );
|
|
||||||
void moveView(QPointF delta);
|
void moveView(QPointF delta);
|
||||||
void resetZoom();
|
void resetZoom();
|
||||||
void ZoomIn();
|
void ZoomIn();
|
||||||
@@ -220,21 +231,14 @@ public slots:
|
|||||||
void resizeEvent ( QResizeEvent * );
|
void resizeEvent ( QResizeEvent * );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPoint deltaOffset;
|
|
||||||
QPoint computeOffset();
|
|
||||||
QPoint mouseCoordinate;
|
QPoint mouseCoordinate;
|
||||||
QPointF positionGrabbing;
|
QPointF positionGrabbing;
|
||||||
QRect positionCorners;
|
QRect positionCorners;
|
||||||
QTransform matrixWorld;
|
|
||||||
QTransform matrixWorld_inv;
|
QTransform matrixWorld_inv;
|
||||||
float ratioX, ratioY;
|
float ratioX, ratioY;
|
||||||
|
|
||||||
CvMouseCallback on_mouse;
|
CvMouseCallback on_mouse;
|
||||||
void* on_mouse_param;
|
void* on_mouse_param;
|
||||||
|
|
||||||
int mode;
|
|
||||||
int keepRatio;
|
|
||||||
|
|
||||||
bool isSameSize(IplImage* img1,IplImage* img2);
|
bool isSameSize(IplImage* img1,IplImage* img2);
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
QPointer<CvWindow> centralWidget;
|
QPointer<CvWindow> centralWidget;
|
||||||
@@ -270,64 +274,66 @@ private slots:
|
|||||||
void stopDisplayInfo();
|
void stopDisplayInfo();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//here css for trackbar
|
//here css for trackbar
|
||||||
/* from http://thesmithfam.org/blog/2010/03/10/fancy-qslider-stylesheet */
|
/* from http://thesmithfam.org/blog/2010/03/10/fancy-qslider-stylesheet */
|
||||||
static const QString str_Trackbar_css = QString("")
|
static const QString str_Trackbar_css = QString("")
|
||||||
+ "QSlider::groove:horizontal {"
|
+ "QSlider::groove:horizontal {"
|
||||||
+ "border: 1px solid #bbb;"
|
+ "border: 1px solid #bbb;"
|
||||||
+ "background: white;"
|
+ "background: white;"
|
||||||
+ "height: 10px;"
|
+ "height: 10px;"
|
||||||
+ "border-radius: 4px;"
|
+ "border-radius: 4px;"
|
||||||
+ "}"
|
+ "}"
|
||||||
|
|
||||||
+ "QSlider::sub-page:horizontal {"
|
+ "QSlider::sub-page:horizontal {"
|
||||||
+ "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
+ "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
||||||
+ "stop: 0 #66e, stop: 1 #bbf);"
|
+ "stop: 0 #66e, stop: 1 #bbf);"
|
||||||
+ "background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1,"
|
+ "background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1,"
|
||||||
+ "stop: 0 #bbf, stop: 1 #55f);"
|
+ "stop: 0 #bbf, stop: 1 #55f);"
|
||||||
+ "border: 1px solid #777;"
|
+ "border: 1px solid #777;"
|
||||||
+ "height: 10px;"
|
+ "height: 10px;"
|
||||||
+ "border-radius: 4px;"
|
+ "border-radius: 4px;"
|
||||||
+ "}"
|
+ "}"
|
||||||
|
|
||||||
+ "QSlider::add-page:horizontal {"
|
+ "QSlider::add-page:horizontal {"
|
||||||
+ "background: #fff;"
|
+ "background: #fff;"
|
||||||
+ "border: 1px solid #777;"
|
+ "border: 1px solid #777;"
|
||||||
+ "height: 10px;"
|
+ "height: 10px;"
|
||||||
+ "border-radius: 4px;"
|
+ "border-radius: 4px;"
|
||||||
+ "}"
|
+ "}"
|
||||||
|
|
||||||
+ "QSlider::handle:horizontal {"
|
+ "QSlider::handle:horizontal {"
|
||||||
+ "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
|
+ "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
|
||||||
+ "stop:0 #eee, stop:1 #ccc);"
|
+ "stop:0 #eee, stop:1 #ccc);"
|
||||||
+ "border: 1px solid #777;"
|
+ "border: 1px solid #777;"
|
||||||
+ "width: 13px;"
|
+ "width: 13px;"
|
||||||
+ "margin-top: -2px;"
|
+ "margin-top: -2px;"
|
||||||
+ "margin-bottom: -2px;"
|
+ "margin-bottom: -2px;"
|
||||||
+ "border-radius: 4px;"
|
+ "border-radius: 4px;"
|
||||||
+ "}"
|
+ "}"
|
||||||
|
|
||||||
+ "QSlider::handle:horizontal:hover {"
|
+ "QSlider::handle:horizontal:hover {"
|
||||||
+ "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
|
+ "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
|
||||||
+ "stop:0 #fff, stop:1 #ddd);"
|
+ "stop:0 #fff, stop:1 #ddd);"
|
||||||
+ "border: 1px solid #444;"
|
+ "border: 1px solid #444;"
|
||||||
+ "border-radius: 4px;"
|
+ "border-radius: 4px;"
|
||||||
+ "}"
|
+ "}"
|
||||||
|
|
||||||
+ "QSlider::sub-page:horizontal:disabled {"
|
+ "QSlider::sub-page:horizontal:disabled {"
|
||||||
+ "background: #bbb;"
|
+ "background: #bbb;"
|
||||||
+ "border-color: #999;"
|
+ "border-color: #999;"
|
||||||
+ "}"
|
+ "}"
|
||||||
|
|
||||||
+ "QSlider::add-page:horizontal:disabled {"
|
+ "QSlider::add-page:horizontal:disabled {"
|
||||||
+ "background: #eee;"
|
+ "background: #eee;"
|
||||||
+ "border-color: #999;"
|
+ "border-color: #999;"
|
||||||
+ "}"
|
+ "}"
|
||||||
|
|
||||||
+ "QSlider::handle:horizontal:disabled {"
|
+ "QSlider::handle:horizontal:disabled {"
|
||||||
+ "background: #eee;"
|
+ "background: #eee;"
|
||||||
+ "border: 1px solid #aaa;"
|
+ "border: 1px solid #aaa;"
|
||||||
+ "border-radius: 4px;"
|
+ "border-radius: 4px;"
|
||||||
+ "}";
|
+ "}";
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user