OpenCV-005:图片的基本像素操作

来源:互联网 发布:电脑软件服务打不开 编辑:程序博客网 时间:2024/06/06 05:37
#https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_core/py_basic_ops/py_basic_ops.html#basic-ops###############################################Import Module                      ####import cv2import numpy as np###############################################Global Parameter                   ####img = cv2.imread('D:\\Data\\016_ComputerVision\\img\\messi5.jpg',cv2.IMREAD_COLOR)###############################################Main Function                      #### print imgprint img.shapeprint img.size#img.dtype is very important while debugging because a large number of errors in OpenCV-Python code is caused by invalid datatype.print img.dtypecv2.imshow("opencv005-1",img) cv2.waitKey (1000)  px = img[100,100]#read the pixel's colorprint px#accessing only blue pixel,BGR File#every img is created by value matrix,#for example 2*2 image:#in datastorage ,saved as this#[[0,0,[255.128.0]][0,1,[255.128.0]],[1,0,[255.128.0]][1,1,[255.128.0]]]# Y X  BGR values#[0,0,[255.128.0]],[0,1,[255.128.0]]#[1,0,[255.128.0]],[1,1,[255.128.0]]#every pixel contains three values:x-position,y-position,BGR Color,0:B,1:G,2:Rblue = img[100,100,0]print bluegreen = img[100,100,1]print greenred = img[100,100,2]print red#paint a white point on the imageimg[100,150] = [255,255,255]#Notice:There is a white point on the image!!!cv2.imshow("opencv005-2",img) cv2.waitKey(0)cv2.destroyAllWindows()  

原创粉丝点击