源代码:
import cv2 as cv
import numpy as num
def access_pixels(image):
print(image.shape)
height=image.shape[0]
width=image.shape[1]
channels=image.shape[2]
print('height:%s width:%s channels:%s'%(height,width,channels))
for row in range(height):
for col in range(width):
for c in range(channels):
pv=image[height,width,channels]
image[row,col,c]= 255 - pv
cv.imshow('pixels_demo',image)
src=cv.imread('D:\girl.jpg')
src1=cv.resize(src,(1,200),)
cv.namedWindow('input image',cv.WINDOW_AUTOSIZE)
cv.imshow('input image',src1)
access_pixels(src1)
cv.waitKey(0)
cv.destroyAllWindows()
运行后,出现的问题:
C:\ProgramData\Anaconda3\python.exe D:/pythonProject3/main.py
(200, 1, 3)
height:200 width:1 channels:3
Traceback (most recent call last):
File "D:/pythonProject3/main.py", line 21, in <module>
access_pixels(src1)
File "D:/pythonProject3/main.py", line 13, in access_pixels
pv=image[height,width,channels]
IndexError: index 200 is out of bounds for axis 0 with size 200
Process finished with exit code 1
即IndexError,200这个数值怎么调整都不行。