Opencv_image processing

image reading

cv2.imread(filename, flags)->Mat

The second parameter is a flag that specifies how to read the image.

cv.IMREAD_COLOR: Load a color image. Any image transparency is ignored. It is the default flag.

cv.IMREAD_GRAYSCALE: load the image in grayscale mode

cv.IMREAD_UNCHANGED: loaded image, including alpha channel

Note 1:  In addition to these three flags, you can simply pass integers 1 , 0 or -1 respectively

Note 2: The 3 channels read by OpenCV are BGR

image display

cv2.imshow(winname, Mat)
cv2.waitkey(1000)
cv2.destroyWindows()
print(img)
cv2.imwrite(filename, img)

image conversion

Image conversion to grayscale image

cv2.imread(filename, cv2.IMREAD_GRAYSCALE)  #0
cv2.cvtColor(src, code)

Image conversion - binary image

cv2.imread(filename, cv2.IMREAD_GRAYSCALE)  #0
cv2.threshold(src, thresh, maxval,type[,dst])
Among them , thresh : the middle threshold, which can be any value between 0 and 255 ; maxval : the maximum threshold, which should be set to 255 ; type : the type of threshold algorithm, 0 means the conventional threshold algorithm, if the current pixel value is greater than thresh , modify it to maxval , otherwise, change to 0 .

Color separation and merging

cv2.split(m, mv)->mv

• Among them, m is a multi-channel array; mv is a channel vector.

cv2.merge(mv, dst)->dst
Where dst : result map; mv is channel vector

Common image processing functions in OpenCV

cv2.imread()
cv2.imshow()
cv2.imwrite()
cv2.cvtColor()
cv2.threshold()
cv2.hstack(())
cv2.split()
cv2.merge()

Guess you like

Origin blog.csdn.net/CHENG15234944691/article/details/123541805