opencv的颜色通道中顺序是B,G,R。
图像属性
import cv2img = cv2.imread('jk.jpg')
print(f'shape={img.shape}')
print(f'size={img.size}')
print(f'dtype={img.dtype}')
shape:图像像素的行,列,通道
size:行数 X 列数 X 通道数
dtype:图像的数据类型
像素的BGR值
import cv2
img = cv2.imread('jk.jpg')
cv2.imshow('Before the change', img)
pt_y = 169
pt_x = 118
px = img[pt_y,pt_x]
print(type(px))
print(f'BGR={px}')
blue = img[pt_y,pt_x,0]
green = img[pt_y,pt_x,1]
red = img[pt_y,pt_x,2]
print(f'BGR={blue},{green},{red}')
for y in range(img.shape[0]-50, img.shape[0]):for x in range(img.shape[1]-50, img.shape[1]):img[y,x] = [255,255,255]
cv2.imshow("After the change", img)
cv2.waitKey(0)
cv2.destroyAllWindows()