zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Python代码库OpenCV之06访问与修改图片像素(含代码)

PythonOpencv代码 修改 图片 访问 06 像素
2023-09-11 14:18:32 时间

Python代码库OpenCV之06访问与修改图片像素(含代码)

代码

import numpy
import cv2
filename="D:\\pythondev\\dev\\opencv\\img\\tu.png"
#read the flower image and load it into a variable flower_image
flower_image=cv2.imread(filename)
#access a specific pixel using the coordinate based access  from the matrix
pixel=flower_image[200,250]

#see what color space this pixel represents - this is an RBG representation
print(pixel)

#lets change the pixel color value to blue
flower_image[200,250]=(255,0,0)
#lets change the pixel color value to blue in a region range as against
flower_image[200:250,200:350]=(0,255,0)
cv2.imshow('modified pixel', flower_image)
cv2.waitKey(0)


运行效果

41085-d305d1e1beb7b090.png
访问与修改图片像素