QT new functions:
- cvCreateOpenGLCallback: draw 3D on top of the image
This commit is contained in:
parent
d352db7ec4
commit
f2353b8523
@ -507,7 +507,7 @@ endif()
|
|||||||
############################### QT ################################
|
############################### QT ################################
|
||||||
|
|
||||||
set(WITH_QT OFF CACHE BOOL "Build with QT Backend support")
|
set(WITH_QT OFF CACHE BOOL "Build with QT Backend support")
|
||||||
set(WITH_QT_OPENGL ON CACHE BOOL "Add OpenGL extension to QT")
|
set(WITH_QT_OPENGL OFF CACHE BOOL "Add OpenGL extension to QT")
|
||||||
|
|
||||||
set(HAVE_QT 0)
|
set(HAVE_QT 0)
|
||||||
set(HAVE_QT_OPENGL 0)
|
set(HAVE_QT_OPENGL 0)
|
||||||
@ -519,6 +519,7 @@ if (WITH_QT)
|
|||||||
find_package (OpenGL QUIET)
|
find_package (OpenGL QUIET)
|
||||||
if (QT_QTOPENGL_FOUND AND OPENGL_FOUND)
|
if (QT_QTOPENGL_FOUND AND OPENGL_FOUND)
|
||||||
set(HAVE_QT_OPENGL 1)
|
set(HAVE_QT_OPENGL 1)
|
||||||
|
add_definitions(-DHAVE_QT_OPENGL)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@ -87,7 +87,7 @@ 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);
|
||||||
|
|
||||||
typedef void (CV_CDECL *CvOpenGLCallback)(void* userdata);
|
typedef void (CV_CDECL *CvOpenGLCallback)(void* userdata);
|
||||||
CVAPI(void) cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback callbackOpenGL, void* userdata CV_DEFAULT(NULL));
|
CVAPI(void) cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback callbackOpenGL, void* userdata CV_DEFAULT(NULL), double angle CV_DEFAULT(-1), double zmin CV_DEFAULT(-1), double zmax CV_DEFAULT(-1));
|
||||||
|
|
||||||
CVAPI(void) cvSaveWindowParameters(const char* name);
|
CVAPI(void) cvSaveWindowParameters(const char* name);
|
||||||
CVAPI(void) cvLoadWindowParameters(const char* name);
|
CVAPI(void) cvLoadWindowParameters(const char* name);
|
||||||
|
@ -274,6 +274,7 @@ CV_IMPL int cvWaitKey( int arg )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
guiMainThread._bTimeOut = false;
|
guiMainThread._bTimeOut = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -393,7 +394,7 @@ int icvInitSystem()
|
|||||||
wasInitialized = 1;
|
wasInitialized = 1;
|
||||||
qDebug()<<"init done";
|
qDebug()<<"init done";
|
||||||
|
|
||||||
#if defined(OPENCV_GL)//OK tested !
|
#if defined(HAVE_QT_OPENGL)//OK tested !
|
||||||
qDebug()<<"opengl support available";
|
qDebug()<<"opengl support available";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -533,14 +534,17 @@ CV_IMPL int cvCreateButton(const char* button_name,CvButtonCallback on_change, v
|
|||||||
return 1;//dummy value
|
return 1;//dummy value
|
||||||
}
|
}
|
||||||
|
|
||||||
CV_IMPL void cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback callbackOpenGL, void* userdata)
|
CV_IMPL void cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback callbackOpenGL, void* userdata, double angle, double zmin, double zmax)
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(&guiMainThread,
|
QMetaObject::invokeMethod(&guiMainThread,
|
||||||
"setOpenGLCallback",
|
"setOpenGLCallback",
|
||||||
Qt::AutoConnection,
|
Qt::AutoConnection,
|
||||||
Q_ARG(QString, QString(window_name)),
|
Q_ARG(QString, QString(window_name)),
|
||||||
Q_ARG(void*, (void*)callbackOpenGL),
|
Q_ARG(void*, (void*)callbackOpenGL),
|
||||||
Q_ARG(void*, userdata)
|
Q_ARG(void*, userdata),
|
||||||
|
Q_ARG(double, angle),
|
||||||
|
Q_ARG(double, zmin),
|
||||||
|
Q_ARG(double, zmax)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,12 +847,12 @@ void GuiReceiver::destroyAllWindow()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiReceiver::setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata)
|
void GuiReceiver::setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata, double angle, double zmin, double zmax)
|
||||||
{
|
{
|
||||||
QPointer<CvWindow> w = icvFindWindowByName( window_name.toLatin1().data() );
|
QPointer<CvWindow> w = icvFindWindowByName( window_name.toLatin1().data() );
|
||||||
|
|
||||||
if (w && callbackOpenGL)
|
if (w && callbackOpenGL)
|
||||||
w->setOpenGLCallback((CvOpenGLCallback) callbackOpenGL, userdata);
|
w->setOpenGLCallback((CvOpenGLCallback) callbackOpenGL, userdata,angle,zmin,zmax);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiReceiver::moveWindow(QString name, int x, int y)
|
void GuiReceiver::moveWindow(QString name, int x, int y)
|
||||||
@ -1251,7 +1255,7 @@ CvWindow::CvWindow(QString arg, int arg2)
|
|||||||
|
|
||||||
//2: my view
|
//2: my view
|
||||||
int mode_display = CV_MODE_NORMAL;
|
int mode_display = CV_MODE_NORMAL;
|
||||||
#if defined(OPENCV_GL)
|
#if defined(HAVE_QT_OPENGL)
|
||||||
mode_display = CV_MODE_OPENGL;
|
mode_display = CV_MODE_OPENGL;
|
||||||
#endif
|
#endif
|
||||||
createView(mode_display);
|
createView(mode_display);
|
||||||
@ -1507,9 +1511,9 @@ void CvWindow::createView(int mode)
|
|||||||
myview->setAlignment(Qt::AlignHCenter);
|
myview->setAlignment(Qt::AlignHCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CvWindow::setOpenGLCallback(CvOpenGLCallback func,void* userdata)
|
void CvWindow::setOpenGLCallback(CvOpenGLCallback func,void* userdata, double angle, double zmin, double zmax)
|
||||||
{
|
{
|
||||||
myview->setOpenGLCallback(func,userdata);
|
myview->setOpenGLCallback(func,userdata, angle, zmin, zmax );
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewPort* CvWindow::getView()
|
ViewPort* CvWindow::getView()
|
||||||
@ -1714,11 +1718,14 @@ ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
|
|||||||
on_openGL_draw3D = NULL;
|
on_openGL_draw3D = NULL;
|
||||||
|
|
||||||
|
|
||||||
#if defined(OPENCV_GL)
|
#if defined(HAVE_QT_OPENGL)
|
||||||
if ( mode_display == CV_MODE_OPENGL)
|
if ( mode_display == CV_MODE_OPENGL)
|
||||||
{
|
{
|
||||||
//QGLWidget* wGL = new QGLWidget(QGLFormat(QGL::SampleBuffers));
|
//QGLWidget* wGL = new QGLWidget(QGLFormat(QGL::SampleBuffers));
|
||||||
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
||||||
|
angle = DEFAULT_ANGLE;
|
||||||
|
zmin = DEFAULT_ZMIN;
|
||||||
|
zmax = DEFAULT_ZMAX;
|
||||||
initGL();
|
initGL();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1770,6 +1777,13 @@ void ViewPort::saveView()
|
|||||||
{
|
{
|
||||||
QString extension = fileName.right(3);
|
QString extension = fileName.right(3);
|
||||||
|
|
||||||
|
#if defined(HAVE_QT_OPENGL)
|
||||||
|
image2Draw_qt_resized = ((QGLWidget*)viewport())->grabFrameBuffer();
|
||||||
|
#else
|
||||||
|
QPainter saveimage(&image2Draw_qt_resized);
|
||||||
|
this->render(&saveimage);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Save it..
|
// Save it..
|
||||||
if (QString::compare(extension, "png", Qt::CaseInsensitive) == 0)
|
if (QString::compare(extension, "png", Qt::CaseInsensitive) == 0)
|
||||||
{
|
{
|
||||||
@ -1912,10 +1926,28 @@ void ViewPort::setMouseCallBack(CvMouseCallback m, void* param)
|
|||||||
on_mouse_param = param;
|
on_mouse_param = param;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPort::setOpenGLCallback(CvOpenGLCallback func,void* userdata)
|
void ViewPort::setOpenGLCallback(CvOpenGLCallback func,void* userdata, double angle_arg, double zmin_arg, double zmax_arg)
|
||||||
{
|
{
|
||||||
on_openGL_draw3D = func;
|
on_openGL_draw3D = func;
|
||||||
on_openGL_param = userdata;
|
on_openGL_param = userdata;
|
||||||
|
|
||||||
|
if (angle_arg > 0)
|
||||||
|
angle = angle_arg;
|
||||||
|
else
|
||||||
|
angle = DEFAULT_ANGLE;
|
||||||
|
|
||||||
|
|
||||||
|
if (zmin_arg >= 0)
|
||||||
|
zmin = zmin_arg;
|
||||||
|
else
|
||||||
|
zmin = DEFAULT_ZMIN;
|
||||||
|
|
||||||
|
|
||||||
|
if (zmax_arg > 0)
|
||||||
|
zmax = zmax_arg;
|
||||||
|
else
|
||||||
|
zmax = DEFAULT_ZMAX;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPort::controlImagePosition()
|
void ViewPort::controlImagePosition()
|
||||||
@ -2181,29 +2213,29 @@ void ViewPort::resizeEvent ( QResizeEvent *event)
|
|||||||
|
|
||||||
void ViewPort::paintEvent(QPaintEvent* event)
|
void ViewPort::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
//first paint on a file (to be able to save it if needed)
|
|
||||||
// --------- START PAINTING FILE -------------- //
|
QPainter myPainter(viewport());
|
||||||
QPainter myPainter(&image2Draw_qt_resized);
|
|
||||||
myPainter.setWorldTransform(param_matrixWorld);
|
myPainter.setWorldTransform(param_matrixWorld);
|
||||||
|
|
||||||
draw2D(&myPainter);
|
draw2D(&myPainter);
|
||||||
|
|
||||||
#if defined(OPENCV_GL)
|
#if defined(HAVE_QT_OPENGL)
|
||||||
if ( mode_display == CV_MODE_OPENGL && on_openGL_draw3D)
|
if ( mode_display == CV_MODE_OPENGL && on_openGL_draw3D)
|
||||||
{
|
{
|
||||||
//myPainter.beginNativePainting();
|
myPainter.save(); // Needed when using the GL1 engine
|
||||||
|
myPainter.beginNativePainting(); // Needed when using the GL2 engine
|
||||||
|
|
||||||
setGL(width(),height());
|
setGL(width(),height());
|
||||||
on_openGL_draw3D(on_openGL_param);
|
on_openGL_draw3D(on_openGL_param);
|
||||||
//draw3D();
|
|
||||||
unsetGL();
|
unsetGL();
|
||||||
|
|
||||||
//myPainter.endNativePainting();
|
myPainter.endNativePainting(); // Needed when using the GL2 engine
|
||||||
|
myPainter.restore(); // Needed when using the GL1 engine
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Now disable matrixWorld for overlay display
|
//Now disable matrixWorld for overlay display
|
||||||
myPainter.setWorldMatrixEnabled (false );
|
//myPainter.setWorldMatrixEnabled (false );
|
||||||
|
|
||||||
//in mode zoom/panning
|
//in mode zoom/panning
|
||||||
if (param_matrixWorld.m11()>1)
|
if (param_matrixWorld.m11()>1)
|
||||||
@ -2218,18 +2250,6 @@ void ViewPort::paintEvent(QPaintEvent* event)
|
|||||||
if (drawInfo)
|
if (drawInfo)
|
||||||
drawInstructions(&myPainter);
|
drawInstructions(&myPainter);
|
||||||
|
|
||||||
// --------- END PAINTING FILE -------------- //
|
|
||||||
myPainter.end();
|
|
||||||
|
|
||||||
|
|
||||||
//and now display the file
|
|
||||||
myPainter.begin(viewport());
|
|
||||||
myPainter.drawImage(0, 0, image2Draw_qt_resized);
|
|
||||||
//end display
|
|
||||||
|
|
||||||
//for statusbar
|
|
||||||
if (centralWidget->myStatusBar)
|
|
||||||
drawStatusBar();
|
|
||||||
|
|
||||||
QGraphicsView::paintEvent(event);
|
QGraphicsView::paintEvent(event);
|
||||||
}
|
}
|
||||||
@ -2403,7 +2423,7 @@ void ViewPort::drawInstructions(QPainter *painter)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(OPENCV_GL)//all this section -> not tested
|
#if defined(HAVE_QT_OPENGL)//all this section -> not tested
|
||||||
|
|
||||||
void ViewPort::initGL()
|
void ViewPort::initGL()
|
||||||
{
|
{
|
||||||
@ -2435,7 +2455,7 @@ void ViewPort::setGL(int width, int height)
|
|||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
icvgluPerspective(45, float(width) / float(height), 0.01, 1000);
|
icvgluPerspective(angle, float(width) / float(height), zmin, zmax);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@ -2447,38 +2467,6 @@ void ViewPort::unsetGL()
|
|||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPort::draw3D()
|
|
||||||
{
|
|
||||||
//draw scene here
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
glTranslated(10.0, 10.0, -1.0);
|
|
||||||
// QVector3D p = convert(mouseCoordinate);
|
|
||||||
//glTranslated(p.x(),p.y(),p.z());
|
|
||||||
|
|
||||||
glRotatef( 55, 1, 0, 0 );
|
|
||||||
glRotatef( 45, 0, 1, 0 );
|
|
||||||
glRotatef( 0, 0, 0, 1 );
|
|
||||||
|
|
||||||
static const int coords[6][4][3] = {
|
|
||||||
{ { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } },
|
|
||||||
{ { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } },
|
|
||||||
{ { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } },
|
|
||||||
{ { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } },
|
|
||||||
{ { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } },
|
|
||||||
{ { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < 6; ++i) {
|
|
||||||
glColor3ub( i*20, 100+i*10, i*42 );
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
for (int j = 0; j < 4; ++j) {
|
|
||||||
glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2]);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
#if defined(OPENCV_GL)
|
#if defined(HAVE_QT_OPENGL)//OPENCV_GL)
|
||||||
#include <QtOpenGL>
|
#include <QtOpenGL>
|
||||||
#include <QGLWidget>
|
#include <QGLWidget>
|
||||||
#endif
|
#endif
|
||||||
@ -96,6 +96,7 @@ enum { shortcut_zoom_normal = Qt::CTRL + Qt::Key_Z,
|
|||||||
shortcut_panning_down = Qt::CTRL + Qt::Key_Down
|
shortcut_panning_down = Qt::CTRL + Qt::Key_Down
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//end enum
|
//end enum
|
||||||
|
|
||||||
class CvWindow;
|
class CvWindow;
|
||||||
@ -133,7 +134,7 @@ public slots:
|
|||||||
void setRatioWindow(QString name, double arg2 );
|
void setRatioWindow(QString name, double arg2 );
|
||||||
void saveWindowParameters(QString name);
|
void saveWindowParameters(QString name);
|
||||||
void loadWindowParameters(QString name);
|
void loadWindowParameters(QString name);
|
||||||
void setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata);
|
void setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata, double angle, double zmin, double zmax);
|
||||||
void putText(void* arg1, QString text, QPoint org, void* font);
|
void putText(void* arg1, QString text, QPoint org, void* font);
|
||||||
void addButton(QString button_name, int button_type, int initial_button_state , void* on_change, void* userdata);
|
void addButton(QString button_name, int button_type, int initial_button_state , void* on_change, void* userdata);
|
||||||
|
|
||||||
@ -267,7 +268,7 @@ public:
|
|||||||
void displayStatusBar(QString text, int delayms );
|
void displayStatusBar(QString text, int delayms );
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
void setOpenGLCallback(CvOpenGLCallback arg1,void* userdata);
|
void setOpenGLCallback(CvOpenGLCallback arg1,void* userdata, double angle, double zmin, double zmax);
|
||||||
void hideTools();
|
void hideTools();
|
||||||
void showTools();
|
void showTools();
|
||||||
static CvButtonbar* createButtonbar(QString bar_name);
|
static CvButtonbar* createButtonbar(QString bar_name);
|
||||||
@ -326,6 +327,9 @@ static const int tableMouseButtons[][3]={
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static const double DEFAULT_ANGLE = 45.0;
|
||||||
|
static const double DEFAULT_ZMIN = 0.01;
|
||||||
|
static const double DEFAULT_ZMAX = 1000.0;
|
||||||
class ViewPort : public QGraphicsView
|
class ViewPort : public QGraphicsView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -335,7 +339,7 @@ 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);
|
||||||
void setOpenGLCallback(CvOpenGLCallback func,void* userdata);
|
void setOpenGLCallback(CvOpenGLCallback func,void* userdata, double arg3, double arg4, double arg5);
|
||||||
int getRatio();
|
int getRatio();
|
||||||
void setRatio(int arg);
|
void setRatio(int arg);
|
||||||
|
|
||||||
@ -407,8 +411,10 @@ private:
|
|||||||
void icvmouseHandler(QMouseEvent *event, type_mouse_event category, int &cv_event, int &flags);
|
void icvmouseHandler(QMouseEvent *event, type_mouse_event category, int &cv_event, int &flags);
|
||||||
void icvmouseProcessing(QPointF pt, int cv_event, int flags);
|
void icvmouseProcessing(QPointF pt, int cv_event, int flags);
|
||||||
|
|
||||||
#if defined(OPENCV_GL)
|
#if defined(HAVE_QT_OPENGL)
|
||||||
void draw3D();
|
double angle;
|
||||||
|
double zmin;
|
||||||
|
double zmax;
|
||||||
void unsetGL();
|
void unsetGL();
|
||||||
void initGL();
|
void initGL();
|
||||||
void setGL(int width, int height);
|
void setGL(int width, int height);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user