opencv basic knowledge point notes

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right

1.cv2.goodFeaturesToTrach(): This function can calculate Harris corners and Shi-tomasi corners, but by default it is Shi-tomasi corners

void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
                              int maxCorners, double qualityLevel, double minDistance,
                              InputArray _mask, int blockSize,
                              bool useHarrisDetector, double harrisK )

_image: single-channel 8-bit or 32-bit floating-point image;  _ corners: save the detected corners;  maxCorners: the maximum number of corners;  qualityLevel: the quality factor of the corners;  blockSize: the window size when calculating the covariance matrix ;  harrisK: The k value required for Harris corner detection. minDistance: If other corners appear in the initially selected corners, they will be deleted;  _mask: Specify the area of ​​interest, and you can specify to find the corners in the area of ​​interest;  useHarrisDetector:  Indicate whether to use Harris corner detection, if not specified , then calculate the shi-tomasi corner point;

2. cv2.line(img, pt1, pt2, color[, thickness[,shift]]): the coordinates of the connecting points pt1 and pt2 in the image img, and color indicates the color of the line.

import cv2 as cv
import numpy as np
color = np.random.randint(0,255,(100,3))   # 随机产生一种颜色
# 将mask中坐标1(a,b)和坐标2(c,d)连线
mask = cv2.line(mask, (a,b),(c,d), color[i].tolist(), 2)  

3. cv2.circle(img, center, radius, color[, thinckness[, lineType]]): Draw a circle according to the provided center and radius radius.

thickness:  the thickness of the outline; lineType: boundary type; shift: the number of decimal places in the center coordinate and radius value;

4. pl, st, err = cv2.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params):  used to obtain the corner position after optical flow detection

Parameter description: pl indicates the corner position after optical flow detection, st indicates whether it is a moving corner, err indicates whether there is an error, old_gray indicates the input of the previous frame image, frame_gray indicates the next frame image, p0 indicates the corner point to be detected , lk_params: winSize indicates how many points are selected to solve u and v, and maxLevel indicates the number of layers of the spatial pyramid.

import cv2
lk_params = dict( winSize  = (15,15),maxLevel = 2, criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03))
p1, st, err = cv2.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params)

5. cv2.putText() :  Add content at the specified position of the picture.

cv2.putText(img, text, org, fontFace, fontScale, color, thickness=None, lineType=None, bottomLeftOrigin=None)

img naturally refers to the picture to add text; text is the content you want to add; fontFace: font style setting; fontScale: font size setting; color: font color setting; thickness: font thickness setting.

import cv2
show_time = '1cm'
cv2.putText(mask, show_time, (520, 341), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 1, cv2.LINE_AA)

Guess you like

Origin blog.csdn.net/weixin_45303602/article/details/127721404