Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
f2353b85
Commit
f2353b85
authored
Jul 23, 2010
by
Yannick Verdie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
QT new functions:
- cvCreateOpenGLCallback: draw 3D on top of the image
parent
d352db7e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
91 deletions
+86
-91
CMakeLists.txt
CMakeLists.txt
+2
-1
highgui_c.h
modules/highgui/include/opencv2/highgui/highgui_c.h
+1
-1
window_QT.cpp
modules/highgui/src/window_QT.cpp
+71
-83
window_QT.h
modules/highgui/src/window_QT.h
+12
-6
No files found.
CMakeLists.txt
View file @
f2353b85
...
...
@@ -507,7 +507,7 @@ endif()
############################### QT ################################
set
(
WITH_QT OFF CACHE BOOL
"Build with QT Backend support"
)
set
(
WITH_QT_OPENGL O
N
CACHE BOOL
"Add OpenGL extension to QT"
)
set
(
WITH_QT_OPENGL O
FF
CACHE BOOL
"Add OpenGL extension to QT"
)
set
(
HAVE_QT 0
)
set
(
HAVE_QT_OPENGL 0
)
...
...
@@ -519,6 +519,7 @@ if (WITH_QT)
find_package
(
OpenGL QUIET
)
if
(
QT_QTOPENGL_FOUND AND OPENGL_FOUND
)
set
(
HAVE_QT_OPENGL 1
)
add_definitions
(
-DHAVE_QT_OPENGL
)
endif
()
endif
()
endif
()
...
...
modules/highgui/include/opencv2/highgui/highgui_c.h
View file @
f2353b85
...
...
@@ -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
);
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
)
cvLoadWindowParameters
(
const
char
*
name
);
...
...
modules/highgui/src/window_QT.cpp
View file @
f2353b85
...
...
@@ -274,6 +274,7 @@ CV_IMPL int cvWaitKey( int arg )
}
}
guiMainThread
.
_bTimeOut
=
false
;
}
return
result
;
...
...
@@ -393,8 +394,8 @@ int icvInitSystem()
wasInitialized
=
1
;
qDebug
()
<<
"init done"
;
#if defined(
OPENCV_
GL)//OK tested !
qDebug
()
<<
"opengl support available"
;
#if defined(
HAVE_QT_OPEN
GL)//OK tested !
qDebug
()
<<
"opengl support available"
;
#endif
}
...
...
@@ -533,14 +534,17 @@ CV_IMPL int cvCreateButton(const char* button_name,CvButtonCallback on_change, v
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
,
"setOpenGLCallback"
,
Qt
::
AutoConnection
,
Q_ARG
(
QString
,
QString
(
window_name
)),
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
()
);
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
)
...
...
@@ -1251,7 +1255,7 @@ CvWindow::CvWindow(QString arg, int arg2)
//2: my view
int
mode_display
=
CV_MODE_NORMAL
;
#if defined(
OPENCV_
GL)
#if defined(
HAVE_QT_OPEN
GL)
mode_display
=
CV_MODE_OPENGL
;
#endif
createView
(
mode_display
);
...
...
@@ -1507,9 +1511,9 @@ void CvWindow::createView(int mode)
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
()
...
...
@@ -1714,11 +1718,14 @@ ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
on_openGL_draw3D
=
NULL
;
#if defined(
OPENCV_
GL)
#if defined(
HAVE_QT_OPEN
GL)
if
(
mode_display
==
CV_MODE_OPENGL
)
{
//QGLWidget* wGL = new QGLWidget(QGLFormat(QGL::SampleBuffers));
setViewport
(
new
QGLWidget
(
QGLFormat
(
QGL
::
SampleBuffers
)));
angle
=
DEFAULT_ANGLE
;
zmin
=
DEFAULT_ZMIN
;
zmax
=
DEFAULT_ZMAX
;
initGL
();
}
#endif
...
...
@@ -1770,6 +1777,13 @@ void ViewPort::saveView()
{
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..
if
(
QString
::
compare
(
extension
,
"png"
,
Qt
::
CaseInsensitive
)
==
0
)
{
...
...
@@ -1912,10 +1926,28 @@ void ViewPort::setMouseCallBack(CvMouseCallback m, void* 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_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
()
...
...
@@ -2181,57 +2213,45 @@ void ViewPort::resizeEvent ( QResizeEvent *event)
void
ViewPort
::
paintEvent
(
QPaintEvent
*
event
)
{
//first paint on a file (to be able to save it if needed)
// --------- START PAINTING FILE -------------- //
QPainter
myPainter
(
&
image2Draw_qt_resized
);
myPainter
.
setWorldTransform
(
param_matrixWorld
);
draw2D
(
&
myPainter
);
QPainter
myPainter
(
viewport
());
myPainter
.
setWorldTransform
(
param_matrixWorld
);
#if defined(OPENCV_GL)
if
(
mode_display
==
CV_MODE_OPENGL
&&
on_openGL_draw3D
)
{
//myPainter.beginNativePainting();
draw2D
(
&
myPainter
);
#if defined(HAVE_QT_OPENGL)
if
(
mode_display
==
CV_MODE_OPENGL
&&
on_openGL_draw3D
)
{
myPainter
.
save
();
// Needed when using the GL1 engine
myPainter
.
beginNativePainting
();
// Needed when using the GL2 engine
setGL
(
width
(),
height
());
on_openGL_draw3D
(
on_openGL_param
);
//draw3D();
unsetGL
();
//myPainter.endNativePainting();
}
myPainter
.
endNativePainting
();
// Needed when using the GL2 engine
myPainter
.
restore
();
// Needed when using the GL1 engine
}
#endif
//Now disable matrixWorld for overlay display
myPainter
.
setWorldMatrixEnabled
(
false
);
//Now disable matrixWorld for overlay display
//
myPainter.setWorldMatrixEnabled (false );
//in mode zoom/panning
if
(
param_matrixWorld
.
m11
()
>
1
)
{
if
(
param_matrixWorld
.
m11
()
>=
threshold_zoom_img_region
)
drawImgRegion
(
&
myPainter
);
drawViewOverview
(
&
myPainter
);
}
//for information overlay
if
(
drawInfo
)
drawInstructions
(
&
myPainter
);
// --------- END PAINTING FILE -------------- //
myPainter
.
end
();
//in mode zoom/panning
if
(
param_matrixWorld
.
m11
()
>
1
)
{
if
(
param_matrixWorld
.
m11
()
>=
threshold_zoom_img_region
)
drawImgRegion
(
&
myPainter
);
drawViewOverview
(
&
myPainter
);
}
//and now display the file
myPainter
.
begin
(
viewport
());
myPainter
.
drawImage
(
0
,
0
,
image2Draw_qt_resized
);
//end display
//for information overlay
if
(
drawInfo
)
drawInstructions
(
&
myPainter
);
//for statusbar
if
(
centralWidget
->
myStatusBar
)
drawStatusBar
();
QGraphicsView
::
paintEvent
(
event
);
QGraphicsView
::
paintEvent
(
event
);
}
void
ViewPort
::
draw2D
(
QPainter
*
painter
)
...
...
@@ -2403,7 +2423,7 @@ void ViewPort::drawInstructions(QPainter *painter)
#if defined(
OPENCV_
GL)//all this section -> not tested
#if defined(
HAVE_QT_OPEN
GL)//all this section -> not tested
void
ViewPort
::
initGL
()
{
...
...
@@ -2435,7 +2455,7 @@ void ViewPort::setGL(int width, int height)
glMatrixMode
(
GL_PROJECTION
);
glPushMatrix
();
glLoadIdentity
();
icvgluPerspective
(
45
,
float
(
width
)
/
float
(
height
),
0.01
,
1000
);
icvgluPerspective
(
angle
,
float
(
width
)
/
float
(
height
),
zmin
,
zmax
);
glMatrixMode
(
GL_MODELVIEW
);
glPushMatrix
();
glLoadIdentity
();
...
...
@@ -2447,38 +2467,6 @@ void ViewPort::unsetGL()
glMatrixMode
(
GL_PROJECTION
);
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
modules/highgui/src/window_QT.h
View file @
f2353b85
...
...
@@ -43,7 +43,7 @@
#include "precomp.hpp"
#if defined(OPENCV_GL)
#if defined(
HAVE_QT_OPENGL)//
OPENCV_GL)
#include <QtOpenGL>
#include <QGLWidget>
#endif
...
...
@@ -96,6 +96,7 @@ enum { shortcut_zoom_normal = Qt::CTRL + Qt::Key_Z,
shortcut_panning_down
=
Qt
::
CTRL
+
Qt
::
Key_Down
};
//end enum
class
CvWindow
;
...
...
@@ -133,7 +134,7 @@ public slots:
void
setRatioWindow
(
QString
name
,
double
arg2
);
void
saveWindowParameters
(
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
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
readSettings
();
void
writeSettings
();
void
setOpenGLCallback
(
CvOpenGLCallback
arg1
,
void
*
userdata
);
void
setOpenGLCallback
(
CvOpenGLCallback
arg1
,
void
*
userdata
,
double
angle
,
double
zmin
,
double
zmax
);
void
hideTools
();
void
showTools
();
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
{
Q_OBJECT
...
...
@@ -335,7 +339,7 @@ public:
void
updateImage
(
void
*
arr
);
void
startDisplayInfo
(
QString
text
,
int
delayms
);
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
();
void
setRatio
(
int
arg
);
...
...
@@ -407,8 +411,10 @@ private:
void
icvmouseHandler
(
QMouseEvent
*
event
,
type_mouse_event
category
,
int
&
cv_event
,
int
&
flags
);
void
icvmouseProcessing
(
QPointF
pt
,
int
cv_event
,
int
flags
);
#if defined(OPENCV_GL)
void
draw3D
();
#if defined(HAVE_QT_OPENGL)
double
angle
;
double
zmin
;
double
zmax
;
void
unsetGL
();
void
initGL
();
void
setGL
(
int
width
,
int
height
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment