请告诉如何获取整个图像的 rgb 值。我打印了每个像素的 rgb 值

Please tell how to get rgb value of whole image. I have printed rgb value of each pixel

请告知如何获取整张图片的rgb值。我打印了每个像素的 rgb 值

import cv2
# LOAD AN IMAGE USING 'IMREAD'
img = cv2.imread("tiger.jpg")
# DISPLAYg
cv2.imshow("Tiger", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
print(img.shape)
[x,y,z]=img.shape


count=0
for i in range(1,x-1):
    for j in range(1,y-1):
        print(img[i,j]) 
        count=count+1
        print(count)

您已经有了像素。当您使用

读取图像时
img = cv2.imread('tiger.jpg')

img 包含图像的像素,您不需要使用循环来获取它们。你可以通过打印它来检查它。

print(img)

#it gives you something like

[[[182 194 166]
  [182 194 166]
  [182 194 166]
  ...
  [255 176 109]
  [255 176 109]
  [255 176 109]]

 [[182 194 166]
  [182 194 166]
  [182 194 166]
  ...
  [255 176 109]
  [255 176 109]
  [255 176 109]]

 [[182 194 166]
  [182 194 166]
  [182 194 166]
  ...
  [255 176 109]
  [255 176 109]
  [255 176 109]]
  ...
  [132 171 210]
  [135 174 213]
  [137 176 215]]]

img 是 numpy 数组的类型 (numpy.ndarray) 你可以通过这个检查它:

print(type(img))