1. The 0 in waitKey(0) means waiting and press any key to terminate;
2. The order of Img.shape is h, w, c and the order of c is BGR;
3. The read image img = img+10 is equivalent Add 10 to each pixel;
4. The size of the two images must be equal during image fusion, otherwise an error will be reported: Solution: zoom a picture or crop a picture, the former may change the shape of the picture;
5. Boundary padding:
6
.Image threshold: THRESH_OTSU will automatically find a suitable threshold, suitable for double peaks, and the threshold parameter needs to be set to 0
thresh = cv2.threshold(gradX, 0, 255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
7. Mean filter: the middle element is equal to the surrounding corresponding position multiplied by 9, generally choose an odd convolution kernel
Gaussian filter: determine the threshold in the convolution kernel by the degree of distance
8. A little trick: display all pictures side by side;
9. Corrosion Operation (morphological operations are for the white part): shrink the image inside, which is an operation performed after binarization;
10. Expansion operation: restore the damage caused by the corrosion operation to the image. Holes are filled;
11. Open operation and closed operation:
Close operation: Connect the features together to look more like a block, which is helpful for detecting the outer contour.
12. Gradient operation: get boundary information.
13. Sobel operator: mixing is not recommended Calculating together, the effect is not good;
at least the image should be grayed before edge detection, because the gradient calculation does not reflect the difference of color changes, so it is better to convert to a gray image with only one color channel Perform edge detection. After having an in-depth understanding of image binarization and edge detection, I think that you can either directly use grayscale images for edge detection, or you can perform edge detection after binarization. The purpose of binarization is to further simplify the grayscale image and make the image The information in is more pure, and the edge brightness changes more obviously. If the threshold is selected well, unwanted weak edges can be filtered out, so that the outline of the image after edge processing is clearer. Another method is to perform edge detection first, and then binarization. This situation is generally applicable: If you want to obtain a binarized image, but because the original image has uneven lighting, the foreground and background grayscale differences are small, we cannot To get the complete target directly, then we can use the insensitivity of edge detection to light changes. First, we can do edge detection on the image to detect the contour of the target that we want to study further, and then calculate the original image based on the edge-only image. The average value of pixels of all edge points of the image, using this value as a threshold to perform binary processing on the original image, the target area can be obtained very well, and the connectivity of the target area is also very good;
14. Canny edge detection steps:
Among them: 80 and 150 respectively represent dual thresholds.
15. Image pyramid:
down-sampling: down sampling is called down sampling along the pyramid, which is a reduction operation, the length and width become half of the original, and the area becomes 1/4 of the original.
Up-sampling:
Opencv code (the second one is continuous up/down sampling): Note: The color and clarity of the picture obtained by first up and then down or first down and up are not as good as before, regardless of upsampling or down sampling, the original information will be lost
16. Image contour, what is contour: scattered edges are not contours, but the contours are integral.
How to perform contour detection? Generally use binary image, processing into binary image can only be operated, the parameter usually uses RETR_TREE;
this function returns several values, namely: binary image, contour information, hierarchical structure, parameter: what to draw/return contour information on /Draw a few outlines -1 default all /drawing color/line width
17. Outline feature: take out each outline for calculation
18. Outline approximation: use a threshold to judge, one line segment can be used, one line segment can be used, otherwise it will be divided into two gradually
Approximate function: parameter: which contour/specified comparison value, generally used as a percentage of the perimeter
Source code:
19.
Circumscribed rectangle: circumscribed circle:
20. Template matching:
Normalized, normalized results are more reliable : The
current method is as small as possible. The minimum value returned is the point in the upper left corner:
Draw a rectangle:
Result:
21. Histogram operation: generally convert to grayscale for input image, if there is no grayscale conversion , Parameter two can specify the image, parameter three is a mask, you can use this if you want to count the histogram of a fixed area, parameter four is to specify the size of the abscissa of the histogram, such as 1, 2, 3, or 1 10 , 1020. Parameter five is the pixel range, usually parameter four and parameter five are fixed. The returned (256, 1) represents a two-dimensional, each abscissa corresponds to an ordinate
22. Mask operation:
23. Histogram equalization
Principle: How to do the basic mapping
Source code:
Note:
24. Fu Li Leaf transformation: idft is an inverse transformation, which must be changed back when displayed. The input image in opencv must be converted to float32 format.
25.argparse module: