"AI Basics" python:opencv--image processing (1)

Source: Internet
Author: User

basic operation of OPENCV Image: Using package Cv2,numpy

import cv2import numpy as npimg = cv2.imread(‘1.jpg‘)cv2.imshow(‘image‘,img)k = cv2.waitKey(0)"把一个RGB图片看成一个3维的数组"img2 = img[20:300, 100:400]cv2.imshow(‘img2‘,img2)k = cv2.waitKey(0)"快速矩阵运算是numpy的优点,批量像素修改不需要使用循环,使用矩阵运算"px=img[100,100]print(px)blue = img[100,100,0]print(blue)img[100:200,100:200]=[255,255,255]print(img[101,101])cv2.imshow(‘image‘,img)k = cv2.waitKey(0)img = cv2.imread(‘1.jpg‘)" img.shape可以获得图像的形状,返回值是一个包含行数,列数,通道数的元组"" 灰度图,返回值仅有行数和列数"print(img.shape)"img.size可以返回图像的像素数目"print(img.size)"图像的特定区域  拷贝操作"logo = img[30:130, 330:430]img[100:200,100:200] = logocv2.imshow(‘image‘,img)k = cv2.waitKey(0)"拆分及合并图像通道  对RGB三个通道分别操作""cv2.split()是比较耗时的操作,能用numpy就尽量使用"r,g,b=cv2.split(img)#拆分#img=cv2.merge(r,g,b)#合并cv2.imshow(‘b‘,b)k = cv2.waitKey(0)img[:,:,2]=0cv2.imshow(‘img‘,img)k = cv2.waitKey(0)

AI Basics python:opencv--image processing (1)

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.