一些索引和修改图像像素点数据等的操作,可打印观察运行结果。
# -*- coding: utf-8 -*- """ Created on Wed Sep 28 00:11:07 2016 @author: Administrator """ import cv2 import numpy as np # length,588;width,468 img = cv2.imread(‘cute.jpg‘) px = img[100,100] print(px) # accessing only blue pixel # remember b,g,r blue = img[100,100,0] print(blue) # modify the pixel img[100,100] = [255,255,255] # accesing RED value p_item = img.item(10,10,2) # modyfying RED value pp_item = img.itemset((10,10,2),100) # length width 3 p_shape = img.shape # length*width*3 p_size = img.size # data type p_dtype = img.dtype # Image ROI # 将一块区域复制到另一区域 ball = img[280:340,330:390] img[273:333,100:160] = ball cv2.imshow(‘image‘,img) k = cv2.waitKey(0) if k == 27: cv2.destroyAllWindows() # Splitting and Merging Image Channels b,g,r = cv2.split(img) # costly img = cv2.merge((b,g,r)) b = img[:,:,0] # blue # make all the red pixels to zero img[:,:,0] = 0
时间: 2024-10-07 02:37:55