01_opencv image reading and display

Objective: To complete the image reading opencv show written

 

Reads the image:

 

 

 1. Import cv2 2. imread 3. read image using an image display imshow

imread ( "(path) + image name", 0), the second part of the figure or may be filled 0 1 1 0 is the grayscale image is a color image

imshow ( "window name", img) img = imread using the read image

waitKey () within a given time (in ms) trigger wait for a key, if the user key is not pressed, the connection wait (cycles)

Output:

 

 

 

Modify the image:

 

 (B, g, r) = img [100,100] # print the pixel of interest for the b, g, r)

Use a for loop, write blue straight line [10, 100] - [110, 100]

Output:

 

 

Writes the image:

Can generate new images directly, you can also compress the image size according to their needs

 

 JPG smaller the number the higher the compression ratio the more easily blurred image (0-100)

Compression results

The lower the number the larger the PNG compression ratio the lower the size of the picture (File Size: 0> 9) the range of 0-9

 

Generated directly cv2.imwrite ( 'dog.jpg', img) img wherein raw data is decoded

 

Guess you like

Origin www.cnblogs.com/charls0404/p/11495244.html