The Cv2 of Python

Source: Internet
Author: User

1. Reading pictures

Import= cv2.imread ('./test.jpg')

The picture that is read is Numpy.ndarray format, the value is 0~255, img shape is (picture height, picture width, picture channel number), print value come out to discover channel order is BGR, not RGB.

2. Change the image size

Import Cv2  = + = Cv2.imread ('./test.jpg ' = Cv2.resize (img , (width, height), interpolation=cv2. Inter_area) cv2.imshow (", img) cv2.waitkey (0) cv2.destroyallwindows ()

The size of this transformation, you need to put the specified width of the picture in front, the height of the image is placed behind, and the size of the IMG shape is inconsistent.

3. Grayscale Conversion

Import= cv2.imread ('./test.jpg'= Cv2.cvtcolor (img, Cv2. Color_bgr2gray)

Shape after conversion (picture height, picture width)

Some other conversions:

Import= cv2.imread ('./test.jpg'== =  = Cv2.cvtcolor (Img_gray, Cv2. COLOR_GRAY2RGB)

4. Save the picture

Import=+ = Cv2.imread ('./test.jpg'= Cv2.resize (IMG, (width, height), interpolation=cv2. Inter_area) cv2.imwrite ('test_changed.png', IMG)

Implement CV2 Yourself

 from Import Image Import NumPy as NP def imread (filename):     return np.array (image.open (filename)) [:,:,;:-1]

The Cv2 of Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.