Basic use of OpenCV2 __OPENCV

Source: Internet
Author: User

This paper mainly expounds the use of some basic functions of OpenCV2.

Install the OpenCV2 under Ubuntu:

Pip Install Opencv-python

Read images with Cv2.imread ()

Cv2.imwrite for stored images ()

Scaling using Cv2.resize ()

Example

Import Cv2

# read an image
test_img = cv2.imread (' test.jpg ')
print (test_img)

# Zoom a 200*200 picture
Img_ Resize = Cv2.resize (test_img, (200,200))
# Zoom to the previous half
img_resize1 = Cv2.resize (test_img, (0,0), fx=0.5, fy=0.5)

# Store Img_resize picture, specify picture quality of 90, default
Cv2.imwrite (' test_new.jpg ', Img_resize, Cv2. imwrite_jpeg_quality)

# to cut 0:200 pictures of the first dimension of the array, that is, take the picture matrix 0 to 200 rows, that is, the high patch_img of the interception of pictures
= img[0:200, 300:600]


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.