Chapter II:
Create, Destroy window, display image
CVAPI (int) Cvnamedwindow (const char* name, int flags Cv_default (cv_window_autosize)); Name to create the window name, identifier.
Cvapi (void) Cvdestroywindow (const char* name); //
Flags are properties of the window: typically cv_window_autosize, which automatically adjusts the window size based on what is displayed
CVAPI (int) cvcreatetrackbar (const char* trackbar_name, const char* window_name,int* value, int count, Cvtrackbarcallback On_change);//Create a slider
WINDOW_NAME specifies which window to create, value represents the data interchange object of the slider (real-time indicates the slider position), count represents the total step of the slider, and the On_change callback function (the declaration format is:
void ontrackbarslide (int pos), which represents a handler called by the system after the slider is dragged
Cvapi (void) cvsettrackbarpos (const char* trackbar_name, const char* window_name, int pos); Set the position of the slider
From capture, release image stream
Cvapi (cvcapture*) cvcreatefilecapture (const char* filename); Create an image stream from the file filename
Cvapi (cvcapture*) cvcreatecameracapture (int index); Capture the video stream (frame) from the camera and index to distinguish which camera
Cvapi (cvvideowriter*) cvcreatevideowriter (const char* filename, int fourcc,double fps, cvsize frame_size,int is_color CV _default (1)); Create an AVI writer
Cvapi (void) Cvreleasevideowriter (cvvideowriter** writer); Close the AVI video writer.
Cvapi (Double) cvgetcaptureproperty (cvcapture* capture, int property_id); Get the properties of an image stream
CVAPI (int) cvsetcaptureproperty (cvcapture* capture, int property_id, double value); Set the properties of an image stream
Cvapi (iplimage*) cvqueryframe (cvcapture* capture); Get an image from the image stream without cvreleaseimage yourself
Cvapi (void) cvreleasecapture (cvcapture** capture); Release
of which: property_id:
#define CV_CAP_PROP_POS_MSEC 0//?
#define Cv_cap_prop_pos_frames 1//position of the current frame
#define CV_CAP_PROP_POS_AVI_RATIO 2//
#define CV_CAP_PROP_FRAME_WIDTH 3//Frame width
#define CV_CAP_PROP_FRAME_HEIGHT 4//Frame height
#define CV_CAP_PROP_FPS 5//frame rate
#define CV_CAP_PROP_FOURCC 6
#define CV_CAP_PROP_FRAME_COUNT 7//Total frame count
#define CV_CAP_PROP_FORMAT 8//format
#define Cv_cap_prop_mode 9
#define Cv_cap_prop_brightness 10
#define CV_CAP_PROP_CONTRAST 11
#define Cv_cap_prop_saturation 12
#define Cv_cap_prop_hue 13
#define Cv_cap_prop_gain 14
#define Cv_cap_prop_exposure 15
#define CV_CAP_PROP_CONVERT_RGB 16
#define Cv_cap_prop_white_balance 17
#define Cv_cap_prop_rectification
Create, display image Cvapi (void) cvshowimage (const char* name, const cvarr* image); Displays the image in the specified name window
Cvapi (void) cvreleaseimage (iplimage** image); Releases the image data, the image pointer is set to NULL by the function
Cvapi (cvsize) cvgetsize (const cvarr* arr); Arr can be iplimage, get size
Cvapi (iplimage*) cvcreateimage (cvsize size, int depth, int channels); Create an image structure with size of image, depth for image bit bit size, channels for several heads
The depth can be:
#define IPL_DEPTH_1U 1//1 bits indicate
#define IPL_DEPTH_8U 8//1 bytes (unsigned number)
#define IPL_DEPTH_16U 16//2 byte unsigned number
#define IPL_DEPTH_32F 32//4 bytes Floating-point number
Channels refers to the color channel. such as RGB color image is represented by 3 components, so 3 channel storage; Grayscale Image 1 channel number
Cvapi (void) cvcvtcolor (const cvarr* SRC, cvarr* dst, int code); Convert the color of an image
Code can be used, generally:
#define Cv_rgb2gray 7//rgb turn grayscale
#define CV_RGB2XYZ 33//.
#define CV_XYZ2RGB 35
#define CV_RGB2YCRCB 37
#define CV_YCRCB2RGB 39
#define CV_RGB2HSV 41
#define CV_RGB2LAB 45
#define CV_HSV2RGB 55
Keyboard input related CVAPI (int) cvwaitkey (int delay cv_default (0)); Wait for keyboard input
Delay indicates the wait time. The default is 0, which indicates that the program waits until a key is entered and returns the ASCII value of the key. If not 0, wait up to delay (MS)
Filter function
Cvapi (void) cvsmooth (const cvarr* SRC, cvarr* dst, int smoothtype cv_default (cv_gaussian), int size1 Cv_default (3), int s Ize2 cv_default (0), double sigma1 cv_default (0), double sigma2 Cv_default (0)); Smoothing Images
In is input, out is a parameter that has been allocated good memory
Cvapi (void) cvpyrdown (const cvarr* SRC, cvarr* dst, int filter cv_default (cv_gaussian_5x5)); It is filtered with filter and then sampled (the output image is wide and the height is half the original.) If the width is odd, the returned image can be either WIDTH/2 or WIDTH/2 +1; SRC and DST are the same depth, with the same number of channels
Cvapi (void) cvcanny (const cvarr* image, cvarr* edges, double threshold1,double threshold2, int aperture_size cv_default (3)); Canny edge Detection
The input image must be a single-channel image, and the output image is also a single-channel image. Depth the same as the input is grayscale 8U, edges should also be a single channel 8U