python opencv遍历每一个像素点
1.使用循环遍历的方法如下:
            
            
              python
              
              
            
          
          import cv2
# 读取图像
image = cv2.imread('image.jpg')
# 获取图像的宽和高
height, width = image.shape[:2]
# 遍历每一个像素点
for y in range(height):
    for x in range(width):
        # 获取当前像素点的数值
        pixel = image[y, x]
        # 处理像素点的数值
        # ...
# 显示图像
cv2.imshow('image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()2.使用迭代器遍历的方法如下:
            
            
              python
              
              
            
          
          mport cv2
# 读取图像
image = cv2.imread('image.jpg')
# 遍历每一个像素点
for row in image:
    for pixel in row:
        # 处理像素点的数值
        # ...
# 显示图像
cv2.imshow('image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()