opencv--optional color object tracking function

Table of contents

1. Function introduction

1. cv2.createTrackbar()

2. cv2.getTrackbarPos()

3. bitwise_and()

4.cv2.morphologyEx()

5. cv2.GaussianBlur()


1. Function introduction

1. cv2.createTrackbar()

Function: Create a slider

cv2.createTrackbar(Track_name, img, min, max, TrackbarCallback)

- Track_name : The name of the slider.

- img : the canvas where the slider is located.

- min : The minimum value of the slider.

- max : The maximum value of the slider.

- TrackbarCallback : the callback function of the slider.

2. cv2.getTrackbarPos()

Function: call the callback function to receive the value of the specified slider.

cv2.getTrackbarPos(Track_name, img)

- Track_name : The name of the slider.

- img : the canvas where the slider is located.

The function return value is the current position of the slider.

3. bitwise_and()

Function: Perform " AND " operation on binary data, that is, perform binary " AND " operation on each pixel value of the image (either grayscale image or color image), 1&1=1 , 1&0=0 , 0&1=0 , 0&0=0

bitwise_and(src1, src2, dst=None, mask=None)

Parameter Description:

 src1 , src2 : input image or scalar, scalar can be a single value or a quadruple

 dst : Optional output variable, if you need to use non- None , you must define it first, and its size is the same as the input variable

 mask : Image mask, an optional parameter, is an 8 -bit single-channel grayscale image, used to specify the elements of the output image array to be changed, that is, only the part of the output image pixel whose corresponding position element of the mask is not 0 is output, otherwise All channel components of the pixel at this location are set to 0

The return value is the result image matrix. If dst is passed in as an actual parameter, the return value is the same as the corresponding actual parameter of dst .

4.cv2.morphologyEx()

Corrosion and expansion are the basis of image morphology operations. Combining expansion and corrosion can result in different forms of operations such as opening and closing operations, gradients, top hats, and black hats:

Open operation cv2.MORPH_OPEN : first corrode and then expand --dilate(erode(img))

Closed operation cv2.MORPH_CLOSE : first expand and then corrode --erode(dilate(img))

Morphological gradient cv2.MORPH_GRADIENT : expansion map - corrosion map --dilate(img)-erode(img)

Top hat operation cv2.MORPH_TOPHAT : also called top hat operation, original image - open operation result -- img-open(img)

Black hat operation cv2.MORPH_BLACKHAT: closed operation result - original image - close(img)-img

Hit does not hit cv2.MORPH_HITMISS: intersection of foreground and background erosion operations -- intersection(erode(img), erode(notimg))

API: cv2.morphologyEx(img, op, kernel, anchor, iterations, borderType)

Among them, the parameter op is the above types.

Reference notes:

opencv study notes (eight): Image Morphology Operations-Knowledge

5. cv2.GaussianBlur()

Gaussian filtering is a linear smoothing filter, which is suitable for eliminating Gaussian noise and is widely used in the noise reduction process of image processing.

cv2.GaussianBlur(src, ksize, sigmaX, sigmaY, borderType)-> dst

- src input image.

- The size and type of the dst output image is the same as that of src .

--ksize Gaussian kernel size . ksize.width and ksize.height can be different, but they both must be positive and odd, or zero, and then calculated from sigmaX and sigmaY .

- sigmaX Gaussian kernel standard deviation in the X direction.

- sigmaY Gaussian kernel standard deviation in the Y direction; if sigmaY is zero, set it equal to sigmaX ; if both sigmas are zero, they are calculated from ksize.width and ksize.height respectively; for full control over the result , regardless of possible future modifications to all these semantics, it is recommended that all ksize , sigmaX and sigmaY be specified . 

Guess you like

Origin blog.csdn.net/ChenWenHaoHaoHao/article/details/130116688