2011-02-23 04:43:26 +08:00
Qt new functions
================
.. highlight :: cpp
.. image :: ../../pics/Qt_GUI.png
2011-02-26 19:05:10 +08:00
This figure explains the new functionalities implemented with Qt GUI. As we can see, the new GUI provides a statusbar, a toolbar, and a control panel. The control panel can have trackbars and buttonbars attached to it.
2011-02-23 04:43:26 +08:00
*
2011-03-01 05:26:43 +08:00
To attach a trackbar, the window name parameter must be NULL.
2011-02-23 04:43:26 +08:00
*
2011-02-26 19:05:10 +08:00
To attach a buttonbar, a button must be created.
If the last bar attached to the control panel is a buttonbar, the new button is added on the right of the last button.
If the last bar attached to the control panel is a trackbar, or the control panel is empty, a new buttonbar is created. Then a new button is attached to it.
The following code is an example used to generate the figure. ::
int main(int argc, char *argv[])
int value = 50;
int value2 = 0;
cvNamedWindow("main1",CV_WINDOW_NORMAL);
cvNamedWindow("main2",CV_WINDOW_AUTOSIZE | CV_GUI_NORMAL);
cvCreateTrackbar( "track1", "main1", &value, 255, NULL);//OK tested
char* nameb1 = "button1";
char* nameb2 = "button2";
cvCreateButton(nameb1,callbackButton,nameb1,CV_CHECKBOX,1);
cvCreateButton(nameb2,callbackButton,nameb2,CV_CHECKBOX,0);
cvCreateTrackbar( "track2", NULL, &value2, 255, NULL);
cvCreateButton("button5",callbackButton1,NULL,CV_RADIOBOX,0);
cvCreateButton("button6",callbackButton2,NULL,CV_RADIOBOX,1);
cvSetMouseCallback( "main2",on_mouse,NULL );
IplImage* img1 = cvLoadImage("files/flower.jpg");
IplImage* img2 = cvCreateImage(cvGetSize(img1),8,3);
CvCapture* video = cvCaptureFromFile("files/hockey.avi");
IplImage* img3 = cvCreateImage(cvGetSize(cvQueryFrame(video)),8,3);
while(cvWaitKey(33) != 27)
{
cvAddS(img1,cvScalarAll(value),img2);
cvAddS(cvQueryFrame(video),cvScalarAll(value2),img3);
cvShowImage("main1",img2);
cvShowImage("main2",img3);
}
cvDestroyAllWindows();
cvReleaseImage(&img1);
cvReleaseImage(&img2);
cvReleaseImage(&img3);
cvReleaseCapture(&video);
return 0;
}
2011-02-23 04:43:26 +08:00
.. index :: setWindowProperty
2011-03-01 05:26:43 +08:00
setWindowProperty
2011-02-23 04:43:26 +08:00
---------------------
2011-03-01 05:26:43 +08:00
.. c:function :: void setWindowProperty(const string& name, int prop_id, double prop_value)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Change the parameters of the window dynamically.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param name: Name of the window.
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
:param prop_id: Window's property to edit. The operation flags:
2011-02-26 19:05:10 +08:00
* **CV_WND_PROP_FULLSCREEN** Change if the window is fullscreen ( `` CV_WINDOW_NORMAL `` or `` CV_WINDOW_FULLSCREEN `` ).
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_WND_PROP_AUTOSIZE** Change if the user can resize the window (texttt {CV\_WINDOW\_NORMAL} or `` CV_WINDOW_AUTOSIZE `` ).
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_WND_PROP_ASPECTRATIO** Change if the image's aspect ratio is preserved (texttt {CV\_WINDOW\_FREERATIO} or `` CV_WINDOW_KEEPRATIO `` ).
2011-03-01 05:26:43 +08:00
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
:param prop_value: New value of the Window's property. The operation flags:
2011-02-26 19:05:10 +08:00
* **CV_WINDOW_NORMAL** Change the window in normal size, or allows the user to resize the window.
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_WINDOW_AUTOSIZE** The user cannot resize the window, the size is constrainted by the image displayed.
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_WINDOW_FULLSCREEN** Change the window to fullscreen.
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_WINDOW_FREERATIO** The image expends as much as it can (no ratio constraint)
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_WINDOW_KEEPRATIO** The ration image is respected.
2011-03-01 05:26:43 +08:00
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` setWindowProperty `` allows to change the window's properties.
2011-02-23 04:43:26 +08:00
.. index :: getWindowProperty
2011-03-01 05:26:43 +08:00
getWindowProperty
2011-02-23 04:43:26 +08:00
---------------------
2011-03-01 05:26:43 +08:00
.. c:function :: void getWindowProperty(const char* name, int prop_id)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Get the parameters of the window.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param name: Name of the window.
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
:param prop_id: Window's property to retrive. The operation flags:
2011-02-26 19:05:10 +08:00
* **CV_WND_PROP_FULLSCREEN** Change if the window is fullscreen ( `` CV_WINDOW_NORMAL `` or `` CV_WINDOW_FULLSCREEN `` ).
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_WND_PROP_AUTOSIZE** Change if the user can resize the window (texttt {CV\_WINDOW\_NORMAL} or `` CV_WINDOW_AUTOSIZE `` ).
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_WND_PROP_ASPECTRATIO** Change if the image's aspect ratio is preserved (texttt {CV\_WINDOW\_FREERATIO} or `` CV_WINDOW_KEEPRATIO `` ).
2011-03-01 05:26:43 +08:00
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
See
:ref: `setWindowProperty` to know the meaning of the returned values.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` getWindowProperty `` return window's properties.
2011-02-23 04:43:26 +08:00
.. index :: fontQt
2011-03-01 05:26:43 +08:00
fontQt
2011-02-23 04:43:26 +08:00
----------
2011-03-01 05:26:43 +08:00
.. c:function :: CvFont fontQt(const string& nameFont, int pointSize = -1, Scalar color = Scalar::all(0), int weight = CV_FONT_NORMAL, int style = CV_STYLE_NORMAL, int spacing = 0)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Create the font to be used to draw text on an image.
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
:param nameFont: Name of the font. The name should match the name of a system font (such as *Times*). If the font is not found, a default one will be used.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param pointSize: Size of the font. If not specified, equal zero or negative, the point size of the font is set to a system-dependent default value. Generally, this is 12 points.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param color: Color of the font in BGRA -- A = 255 is fully transparent. Use the macro CV _ RGB for simplicity.
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
:param weight: The operation flags:
2011-02-26 19:05:10 +08:00
* **CV_FONT_LIGHT** Weight of 25
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_FONT_NORMAL** Weight of 50
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_FONT_DEMIBOLD** Weight of 63
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_FONT_BOLD** Weight of 75
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_FONT_BLACK** Weight of 87
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
You can also specify a positive integer for more control.
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
:param style: The operation flags:
2011-02-26 19:05:10 +08:00
* **CV_STYLE_NORMAL** Font is normal
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_STYLE_ITALIC** Font is in italic
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
* **CV_STYLE_OBLIQUE** Font is oblique
2011-03-01 05:26:43 +08:00
2011-02-26 19:05:10 +08:00
:param spacing: Spacing between characters. Can be negative or positive
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` fontQt `` creates a CvFont object. This CvFont is not compatible with putText.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
A basic usage of this function is: ::
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
CvFont font = fontQt(''Times'');
addText( img1, `` Hello World !'', Point(50,50), font);
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
.. index :: addText
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
addText
2011-02-26 19:05:10 +08:00
-----------
2011-03-01 05:26:43 +08:00
.. c:function :: void addText(const Mat& img, const string& text, Point location, CvFont *font)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Create the font to be used to draw text on an image
:param img: Image where the text should be drawn
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param text: Text to write on the image
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param location: Point(x,y) where the text should start on the image
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param font: Font to use to draw the text
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` addText `` draw
2011-02-23 04:43:26 +08:00
*text*
2011-02-26 19:05:10 +08:00
on the image
2011-02-23 04:43:26 +08:00
*img*
2011-02-26 19:05:10 +08:00
using a specific font
2011-02-23 04:43:26 +08:00
*font*
2011-02-26 19:05:10 +08:00
(see example
:ref: `fontQt` )
2011-02-23 04:43:26 +08:00
.. index :: displayOverlay
2011-03-01 05:26:43 +08:00
displayOverlay
2011-02-23 04:43:26 +08:00
------------------
2011-03-01 05:26:43 +08:00
.. c:function :: void displayOverlay(const string& name, const string& text, int delay)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Display text on the window's image as an overlay for delay milliseconds. This is not editing the image's data. The text is display on the top of the image.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param name: Name of the window
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param text: Overlay text to write on the window's image
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param delay: Delay to display the overlay text. If this function is called before the previous overlay text time out, the timer is restarted and the text updated. . If this value is zero, the text never disapers.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` displayOverlay `` aims at displaying useful information/tips on the window for a certain amount of time
2011-02-23 04:43:26 +08:00
*delay*
2011-02-26 19:05:10 +08:00
. This information is display on the top of the window.
2011-02-23 04:43:26 +08:00
.. index :: displayStatusBar
2011-03-01 05:26:43 +08:00
displayStatusBar
2011-02-23 04:43:26 +08:00
--------------------
2011-03-01 05:26:43 +08:00
.. c:function :: void displayStatusBar(const string& name, const string& text, int delayms)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Display text on the window's statusbar as for delay milliseconds.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param name: Name of the window
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param text: Text to write on the window's statusbar
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param delay: Delay to display the text. If this function is called before the previous text time out, the timer is restarted and the text updated. If this value is zero, the text never disapers.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` displayOverlay `` aims at displaying useful information/tips on the window for a certain amount of time
*delay*
. This information is displayed on the window's statubar (the window must be created with `` CV_GUI_EXPANDED `` flags).
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
.. index :: createOpenGLCallback
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
createOpenGLCallback
2011-02-26 19:05:10 +08:00
------------------------
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
.. c:function :: void createOpenGLCallback( const string& window_name, OpenGLCallback callbackOpenGL, void* userdata CV_DEFAULT(NULL), double angle CV_DEFAULT(-1), double zmin CV_DEFAULT(-1), double zmax CV_DEFAULT(-1)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Create a callback function called to draw OpenGL on top the the image display by windowname.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param window_name: Name of the window
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param callbackOpenGL:
Pointer to the function to be called every frame.
This function should be prototyped as `` void Foo(*void); `` .
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param userdata: pointer passed to the callback function. *(Optional)*
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param angle: Specifies the field of view angle, in degrees, in the y direction.. *(Optional - Default 45 degree)*
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param zmin: Specifies the distance from the viewer to the near clipping plane (always positive). *(Optional - Default 0.01)*
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param zmax: Specifies the distance from the viewer to the far clipping plane (always positive). *(Optional - Default 1000)*
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` createOpenGLCallback `` can be used to draw 3D data on the window. An example of callback could be: ::
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
void on_opengl(void* param)
{
glLoadIdentity();
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
glTranslated(0.0, 0.0, -1.0);
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
glRotatef( 55, 1, 0, 0 );
glRotatef( 45, 0, 1, 0 );
glRotatef( 0, 0, 0, 1 );
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
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 } }
};
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
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();
}
}
2011-02-23 04:43:26 +08:00
.. index :: saveWindowParameters
2011-03-01 05:26:43 +08:00
saveWindowParameters
2011-02-23 04:43:26 +08:00
------------------------
2011-03-01 05:26:43 +08:00
.. c:function :: void saveWindowParameters(const string& name)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Save parameters of the window windowname.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param name: Name of the window
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` saveWindowParameters `` saves size, location, flags, trackbars' value, zoom and panning location of the window
2011-02-23 04:43:26 +08:00
*window_name*
.. index :: loadWindowParameters
2011-03-01 05:26:43 +08:00
loadWindowParameters
2011-02-23 04:43:26 +08:00
------------------------
2011-03-01 05:26:43 +08:00
.. c:function :: void loadWindowParameters(const string& name)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Load parameters of the window windowname.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param name: Name of the window
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` loadWindowParameters `` load size, location, flags, trackbars' value, zoom and panning location of the window
2011-02-23 04:43:26 +08:00
*window_name*
.. index :: createButton
2011-03-01 05:26:43 +08:00
createButton
2011-02-23 04:43:26 +08:00
----------------
2011-03-01 05:26:43 +08:00
.. c:function :: createButton( const string& button_name CV_DEFAULT(NULL),ButtonCallback on_change CV_DEFAULT(NULL), void* userdata CV_DEFAULT(NULL), int button_type CV_DEFAULT(CV_PUSH_BUTTON), int initial_button_state CV_DEFAULT(0))
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Create a callback function called to draw OpenGL on top the the image display by windowname.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param button_name: Name of the button *( if NULL, the name will be "button <number of boutton>")*
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param on_change:
Pointer to the function to be called every time the button changed its state.
This function should be prototyped as `` void Foo(int state,*void); `` . *state* is the current state of the button. It could be -1 for a push button, 0 or 1 for a check/radio box button.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param userdata: pointer passed to the callback function. *(Optional)*
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The `` button_type `` parameter can be :
2011-03-01 05:26:43 +08:00
* (Optional -- Will be a push button by default.)
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
* **CV_PUSH_BUTTON** The button will be a push button.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
* **CV_CHECKBOX** The button will be a checkbox button.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
* **CV_RADIOBOX** The button will be a radiobox button. The radiobox on the same buttonbar (same line) are exclusive; one on can be select at the time.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
* **initial_button_state** Default state of the button. Use for checkbox and radiobox, its value could be 0 or 1. *(Optional)*
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` createButton `` attach a button to the control panel. Each button is added to a buttonbar on the right of the last button.
A new buttonbar is create if nothing was attached to the control panel before, or if the last element attached to the control panel was a trackbar.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
Here are various example of `` createButton `` function call: ::
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
createButton(NULL,callbackButton);//create a push button "button 0", that will call callbackButton.
createButton("button2",callbackButton,NULL,CV_CHECKBOX,0);
createButton("button3",callbackButton,&value);
createButton("button5",callbackButton1,NULL,CV_RADIOBOX);
createButton("button6",callbackButton2,NULL,CV_PUSH_BUTTON,1);
2011-03-01 05:26:43 +08:00
2011-02-23 04:43:26 +08:00
..
2011-03-01 05:26:43 +08:00