HighGUI Reference Manual

Source: Internet
Author: User
Tags gtk
Simple graphical interface address: http://fsa.ia.ac.cn/opencv-doc-cn/opencv-doc-cn-0.9.7/ref/opencvref_highgui.cn.htm

 

CvNamedWindow

Create window

int cvNamedWindow( const char* name, int flags );
Name
Window name, which is used to distinguish different windows and is displayed as the window title.
Flags
Window property flag. Currently, the only supported flag is CV_WINDOW_AUTOSIZE. When this flag is set, if you cannot manually change the window size, the window size is automatically adjusted to fit the displayed image (see cvShowImage ).

FunctioncvNamedWindowCreate a window where images and trackbar can be placed. The created windows can be referenced by their names.

If a window with this name already exists, this function will not do anything.

CvDestroyWindow

Destroy a window

void cvDestroyWindow( const char* name );
Name
The name of the window to be destroyed.

FunctioncvDestroyWindowDestroy the window with the specified name.

CvDestroyAllWindows

Destroy all highgui windows

void cvDestroyAllWindows(void);

FunctioncvDestroyAllWindowsDestroys all opened highgui windows.

CvResizeWindow

Set window size

void cvResizeWindow( const char* name, int width, int height );
Name
The name of the window to be set.
Width
The new window width.
Height
The new window height.

FunctioncvResizeWindowChange the window size.

CvMoveWindow

Set the window position

void cvMoveWindow( const char* name, int x, int y );
Name
The name of the window to be set.
X
X coordinate in the upper left corner of the window.
Y
Y coordinate in the upper left corner of the window.

FunctioncvMoveWindowChange the position of the window.

Cvget?whandle

Get window handle by name

void* cvGetWindowHandle( const char* name );
Name
Window name.

FunctioncvGetWindowHandleReturn the original window handle (in Win32 cases, return hwnd, GTK +, and gtkwidget)

CvGetWindowName

Get the window name through the handle

const char* cvGetWindowName( void* window_handle );
Window_handle
Window handle.

Given FunctioncvGetWindowNameA window handle (hwnd in Win32 and gtkwidget in GTK +). The function returns the window name.

CvShowImage

Display images in a specified window

void cvShowImage( const char* name, const CvArr* image );
Name
Window name.
Image
The displayed image.

FunctioncvShowImageDisplay the image in the specified window. If the flag is set when the window is createdCV_WINDOW_AUTOSIZEOtherwise, the image is scaled to fit the window size.

CvCreateTrackbar

Create a trackbar and add it to the specified window.

CV_EXTERN_C_FUNCPTR( void (*CvTrackbarCallback)(int pos) );int cvCreateTrackbar( const char* trackbar_name, const char* window_name,                      int* value, int count, CvTrackbarCallback on_change );
Trackbar_name
The name of the created trackbar.
Window_name
Window name, which is the parent object of the trackbar.
Value
Integer pointer. Its value reflects the position of the slider. This variable specifies the slider position during creation.
Count
The maximum value of the slider position. The minimum value is always 0.
On_change
The pointer of the called function each time the slider position is changed. This function should be declared void Foo(int);If there is no callback function, this value can be set to NULL.

FunctioncvCreateTrackbarUse the specified name and range to create a trackbar (slider or range control), specify the variables to be synchronized with the trackbar position, and specify the callback function called when the trackbar position is changed. The created trackbar is displayed at the top of the specified window.

CvGetTrackbarPos

Obtain the position of the trackbar

int cvGetTrackbarPos( const char* trackbar_name, const char* window_name );
Trackbar_name
The name of the trackbar.
Window_name
The name of the parent window of trackbar.

FunctioncvGetTrackbarPosReturns the current position of the specified trackbar.

CvSetTrackbarPos

Set trackbar position

void cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos );
Trackbar_name
The name of the trackbar.
Window_name
The name of the parent window of trackbar.
Pos
New location.

FunctioncvSetTrackbarPosSet the position of the specified trackbar.

CvSetMouseCallback

Set the mouse Event Callback Function

#define CV_EVENT_MOUSEMOVE      0#define CV_EVENT_LBUTTONDOWN    1#define CV_EVENT_RBUTTONDOWN    2#define CV_EVENT_MBUTTONDOWN    3#define CV_EVENT_LBUTTONUP      4#define CV_EVENT_RBUTTONUP      5#define CV_EVENT_MBUTTONUP      6#define CV_EVENT_LBUTTONDBLCLK  7#define CV_EVENT_RBUTTONDBLCLK  8#define CV_EVENT_MBUTTONDBLCLK  9#define CV_EVENT_FLAG_LBUTTON   1#define CV_EVENT_FLAG_RBUTTON   2#define CV_EVENT_FLAG_MBUTTON   4#define CV_EVENT_FLAG_CTRLKEY   8#define CV_EVENT_FLAG_SHIFTKEY  16#define CV_EVENT_FLAG_ALTKEY    32CV_EXTERN_C_FUNCPTR( void (*CvMouseCallback )(int event, int x, int y, int flags, void* param) );void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse, void* param=NULL );
Window_name
Window name.
On_mouse
Specifies the function pointer that is called every time the mouse times occur in the window. The prototype of this function should be

void Foo(int event, int x, int y, int flags, void* param);

WhereeventYesCV_EVENT_*One of the variables,xAndyIs the coordinates of the mouse pointer in the image coordinate system (not the window coordinate system ),flagsYesCV_EVENT_FLAGCombination,paramIs user-defined transfercvSetMouseCallbackFunction call parameters.

Param
User-Defined parameters passed to the callback function.

FunctioncvSetMouseCallbackSpecifies the callback function when a window mouse event occurs. For more information, see opencv/samples/c/ffilldemo. c demo.

CvWaitKey

Waiting for button events

int cvWaitKey( int delay=0 );
Delay
Delay in milliseconds.

FunctioncvWaitKeyUnlimited waiting for button events (delay <= 0), or delay of "delay" milliseconds. The return value is the key value. If the value exceeds the specified time,-1 is returned.

Note: This function is the only function in HighGUI that can obtain and operate events. Therefore, it needs to be called periodically in general event processing, unless HighGUI is used in some environments that can handle events.

Read and save images CvLoadImage

Read images from files

IplImage* cvLoadImage( const char* filename, int iscolor=1 );
Filename
The name of the file to be read.
Iscolor
Specify the color of the image to be read:
If the value is greater than 0, the read image is forcibly converted to a 3-channel color image;
If the value is 0, the read image is forcibly converted to a grayscale image;
If <0, the read image will be the same as its original color information (the number of color channels is determined by the image file ).

FunctioncvLoadImageReads an image from a specified file and returns the pointer to the image. Currently, the following file formats are supported:

  • Windows bitmap files-BMP, DIB;
  • JPEG file-JPEG, JPG, JPE;
  • Portable Network image-PNG;
  • Portable image formats-PBM, PGM, and PPM;
  • Sun rasters-SR, RAS;
  • TIFF file-TIFF, TIF.

 

CvSaveImage

Save images to files

int cvSaveImage( const char* filename, const CvArr* image );
Filename
File Name.
Image
The image to save.

FunctioncvSaveImageSave the image to a specified file. Image Format selection depends onfilenameFor more information, see cvLoadImage. This function can be used to save an 8-bit single channel or 3-channel (the channel sequence is 'bgr. If the format, depth, or channel does not meet the requirements, usecvCvtScaleAndcvCvtColorConversion; or use a commoncvSaveSave the image in XML or YAML format.

Video read/write Functions CvCapture

Video Acquisition Structure

typedef struct CvCapture CvCapture;

The structure CvCapture does not have a public interface. It can only be used as a parameter for video obtaining functions.

CvCaptureFromFile

Initialize video retrieval from File

CvCapture* cvCaptureFromFile( const char* filename );
Filename
Video file name.

FunctioncvCaptureFromFileAllocate and initialize the CvCapture structure to the video stream in the specified file.

When the allocated structure is no longer used, it should be released using the cvReleaseCapture function.

CvCaptureFromCAM

Initialize video retrieval from camera

CvCapture* cvCaptureFromCAM( int index );
Index
The index of the camera to use. If there is only one camera or which camera is used, you can use parameter-1.

FunctioncvCaptureFromCAMAllocate and initialize the CvCapture structure to the video streams from the camera. Currently, two interfaces can be used in Windows: Video for Windows (VFW) and Matrox Imaging Library (MIL); and V4L and FireWire (IEEE1394) in Linux ).

Release this structure and use the cvReleaseCapture function.

CvReleaseCapture

Release the CvCapture Structure

void cvReleaseCapture( CvCapture** capture );
Capture
Obtains the structure pointer of a video.

FunctioncvReleaseCaptureRelease the CvCapture structure applied by cvCaptureFromFile or cvCaptureFromCAM.

CvGrabFrame

Capture frames from cameras or video files

int cvGrabFrame( CvCapture* capture );
Capture
Obtains the structure pointer of a video.

FunctioncvGrabFrameCapture frames from cameras or files. Captured frames are stored internally. The purpose of this function isFastThis is very important for the synchronization of data read from several cameras at the same time. Captured frames may be compressed (defined by the camera/driver), so they are not published. If you want to retrieve the obtained frame, use cvRetrieveFrame.

CvRetrieveFrame

Retrieve the image captured by the cvGrabFrame Function

IplImage* cvRetrieveFrame( CvCapture* capture );
Capture
The structure of the video.

FunctioncvRetrieveFrameReturns the pointer to the image captured by the cvGrabFrame function. The returned image cannot be released or modified by the user.

CvQueryFrame

Capture from the camera or file and return a frame

IplImage* cvQueryFrame( CvCapture* capture );
Capture
The structure of the video.

FunctioncvQueryFrameCapture a frame from the camera or file, decompress it, and return the frame. This function is only a combination of cvGrabFrame and cvRetrieveFrame. The returned image cannot be released or modified by the user.

CvGetCaptureProperty

Obtain the attributes of the video structure.

double cvGetCaptureProperty( CvCapture* capture, int property_id );
Capture
The structure of the video.
Property_id
Attribute ID. It can be one of the following:
CV_CAP_PROP_POS_MSEC-Current Position of the video, in milliseconds or when the video gets the timestamp
CV_CAP_PROP_POS_FRAMES-The frame index to be extracted/retrieved by the next step, starting from 0
CV_CAP_PROP_POS_AVI_RATIO-Relative Position of the video file (0-start of the video, 1-end of the video)
CV_CAP_PROP_FRAME_WIDTH-Frame width in the Video Stream
CV_CAP_PROP_FRAME_HEIGHT-Frame height in the Video Stream
CV_CAP_PROP_FPS-Frame Rate
CV_CAP_PROP_FOURCC-Four Characters of codec CV_CAP_PROP_FRAME_COUNT-Total number of frames in a video file

FunctioncvGetCapturePropertyObtain the specified attributes of the camera or video file.

Note: Sometimes this function returns the correct value after cvQueryFrame is called and cvGetCaptureProperty is called.

CvSetCaptureProperty

Set Video Acquisition attributes

int cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
Capture
The structure of the video.
Property_id
Property identifier. It can be one of the following:
CV_CAP_PROP_POS_MSEC-Starting from the file, in milliseconds
CV_CAP_PROP_POS_FRAMES-The unit is the number of frames (only valid for video files)
CV_CAP_PROP_POS_AVI_RATIO-Relative Position of the video file (0-start of the video, 1-end of the video)
CV_CAP_PROP_FRAME_WIDTH-Video Stream frame width (only valid for cameras)
CV_CAP_PROP_FRAME_HEIGHT-Frame height of the video stream (only valid for the camera)
CV_CAP_PROP_FPS-Frame Rate (only valid for cameras)
CV_CAP_PROP_FOURCC-Four Characters of codec (only valid for cameras)
Value
Attribute Value.

FunctioncvSetCapturePropertySet the attributes of the specified video. Currently, this function only supports video files:CV_CAP_PROP_POS_MSEC, CV_CAP_PROP_POS_FRAMES, CV_CAP_PROP_POS_AVI_RATIO

CvCreateVideoWriter

Create a video file writer

typedef struct CvVideoWriter CvVideoWriter;CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc, double fps, CvSize frame_size, int is_color=1 );
Filename
Output video file name.
Fourcc
The four characters are used to indicate the codec of the compressed frame. For example, CV_FOURCC('P','I','M','1')Is MPEG-1 codec, CV_FOURCC('M','J','P','G')Is motion-jpeg codec. In Win32, if-1 is input, you can select the compression method and parameters from a dialog box.
FPS
Frame Rate of the created video stream.
Frame_size
The size of the video stream.
Is_color
If it is not zero, the encoder will want to get a color frame and encode it; otherwise, it is a grayscale frame (this flag is only supported in Windows ).

FunctioncvCreateVideoWriterCreate the structure of the video writer.

CvReleaseVideoWriter

Release video writer

void cvReleaseVideoWriter( CvVideoWriter** writer );
Writer
Pointer to the video writer.

FunctioncvReleaseVideoWriterEnd video file writing and release this structure.

Cvwriteframe

Write a frame to a video file

int cvWriteFrame( CvVideoWriter* writer, const IplImage* image );
Writer
The structure of the video writer.
Image
The frame to be written.

FunctioncvWriteFrameWrite/attach a frame to a video file.

Practical functions and system functions Cvinitsystem

Initialize HighGUI

int cvInitSystem( int argc, char** argv );
Argc
Number of command line parameters.
Argv
Command Line Parameter array.

FunctioncvInitSystemInitialize HighGUI. If the function cannot be explicitly called by the user before the first window is created, the function will use the Parameterargc= 0,argv= NULL is called implicitly. In Win32, there is no need to explicitly call this function. In X Window, parameters may be used to customize the appearance of a HighGUI Window and control.

Cvconvertimage

Converts one image to another with optional vertical flip

void cvConvertImage( const CvArr* src, CvArr* dst, int flags=0 );
SRC
Enter the image.
DST
Target Image. Must be a single channel or 3-Channel 8-bit image.
Flags
Operation flag:
CV_CVTIMG_FLIP-Flip the image vertically. CV_CVTIMG_SWAP_RB-Exchange the red and blue channels. In opencv, the channel sequence of the color image is BGRHowever, in some systems, the channel sequence should be flipped before the explicit image (cvshowimage can be automatically converted ).

FunctioncvConvertImageConvert an image to another image and flip the image vertically if needed. This function is used by cvShowImage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.