#https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_core/py_basic_ops/py_basic_ops.html#basic-ops
###########################################
####Import Module ####
import cv2
import numpy as np
###########################################
####Global Parameter ####
img = cv2.imread('D:\\Data\\016_ComputerVision\\img\\messi5.jpg',cv2.IMREAD_COLOR)
###########################################
####Main Function ####
print img
print img.shape
print 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.dtype
cv2.imshow("opencv005-1",img)
cv2.waitKey (1000)
px = img[100,100]
#read the pixel's color
print 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:R
blue = img[100,100,0]
print blue
green = img[100,100,1]
print green
red = img[100,100,2]
print red
#paint a white point on the image
img[100,150] = [255,255,255]
#Notice:There is a white point on the image!!!
cv2.imshow("opencv005-2",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
OpenCV-005:图片的基本像素操作
最新推荐文章于 2024-01-17 17:20:03 发布