首页 > 代码库 > Python OpenCV —— Modifying

Python OpenCV —— Modifying

  一些索引和修改图像像素点数据等的操作,可打印观察运行结果。

# -*- coding: utf-8 -*-"""Created on Wed Sep 28 00:11:07 2016@author: Administrator"""import cv2import numpy as np# length,588;width,468img = cv2.imread(‘cute.jpg‘)px = img[100,100]print(px)# accessing only blue pixel# remember b,g,rblue = img[100,100,0]print(blue)# modify the pixelimg[100,100] = [255,255,255]# accesing RED valuep_item = img.item(10,10,2)# modyfying RED valuepp_item = img.itemset((10,10,2),100)# length width 3p_shape = img.shape# length*width*3p_size = img.size# data typep_dtype = img.dtype# Image ROI# 将一块区域复制到另一区域ball = img[280:340,330:390]img[273:333,100:160] = ballcv2.imshow(‘image‘,img)k = cv2.waitKey(0)if k == 27:	cv2.destroyAllWindows()# Splitting and Merging Image Channelsb,g,r = cv2.split(img)  # costlyimg = cv2.merge((b,g,r))b = img[:,:,0]  # blue# make all the red pixels to zeroimg[:,:,0] = 0

  

Python OpenCV —— Modifying