opencv learn the basic operation of the image notes (jupyter tool)

. 1  Import CV2 # opecnv reading method is the BGR 
2 IMG = cv2.imread ( ' cat.jpg ' )
 . 3 cv2.imshow ( ' IMG ' , IMG)
 . 4  cv2.waitKey (0)
 . 5 cv2.destoryAllWindows ()

This is opencv read picture format for a standard, on cv2.waitKey () function, there are a variety of writing. 0 indicates any key to terminate. Can be rewritten as cv2.waitKey (100) , the parameter is passed millisecond counts, it will automatically after 0.1 seconds, exit the current window. Can also be written this way both cv2.waitKey (100) & 0xFF == ord ( 'q') after the character received from the keyboard q, before continuing. Note that cv2.waitKey () function has a blocking effect, both in the absence of finishes with the current state of the task, the program will not continue operation.

In cv2.imread function, such parameters may be used img = cv2.imread ( 'cat.jpg', cv2.IMREAD_GRAYSCALE) is a color image reading default, the parameter may become a given grayscale image. For the image has been read you can see the current picture information. First, when a picture of them passed the program, which is a three-dimensional array in python which will be automatically converted into numpy.ndarray data types. image.shape: Print data structure (that is, the length and width of the image) image.size: the size of the print array, the total number of elements. image.dtype: print array type.

Finally, use cv2.imwrite ( 'myimage.png', img) to save the image locally

Guess you like

Origin www.cnblogs.com/huanhuana/p/11165439.html