Opencv image pixel operation

Read the pixel value of a certain pixel

#读取图片
img = cv2.imread("E:/code/conputer_visual/data/0.jpg", 1)
#读取坐标(100,100)的像素值
(b, g, r) = img[100,100]
#打印像素值
print(b, g, r)

216 240 145

Modify the pixel value of some pixels

import cv2
img = cv2.imread("E:/code/conputer_visual/data/0.jpg", 1)
for i in range(220):
	#将图片宽度200,高度0-220的像素点改为蓝色
    img[i, 200] = (255, 0, 0)
cv2.imshow("image_window", img)
cv2.waitKey()

Insert picture description here

Guess you like

Origin blog.csdn.net/cyj5201314/article/details/113406563