Python 为什么QImage';s像素功能超出范围?
在row=394和col=700中,我有高度=394和宽度=700的图像。但是,当我试图通过Python 为什么QImage';s像素功能超出范围?,python,qt,qimage,Python,Qt,Qimage,在row=394和col=700中,我有高度=394和宽度=700的图像。但是,当我试图通过gray\u img.pixel(row,col)访问给定像素的像素值时,我得到了超出范围的错误。由于某种原因,灰度图像。像素(列,行)起作用 有人能帮我弄清楚,为什么我在执行灰度像素(行、列)时会出现超出范围的错误,而不是相反 我以为索引会变成(行,列),因为 (0,0)、(0,1)、(0,2)…(0699) (1,0)、(1,1)、(1,2)…(1699) (393,0)、(393,1)、(393,
gray\u img.pixel(row,col)
访问给定像素的像素值时,我得到了超出范围的错误。由于某种原因,灰度图像。像素(列,行)
起作用
有人能帮我弄清楚,为什么我在执行灰度像素(行、列)
时会出现超出范围的错误,而不是相反
我以为索引会变成(行,列),因为
(0,0)、(0,1)、(0,2)…(0699)
(1,0)、(1,1)、(1,2)…(1699)
(393,0)、(393,1)、(393,2)…(393699)
QImage::pixel
函数作为参数(int x,int y)
作为(列,行)
值QImage::pixel
函数作为参数(int x,int y)
作为(列,行)
值你认为你混淆了x和y的顺序吗?通常的顺序是(x,y)(即(宽度,高度)),而不是相反。它认为你混淆了x和y的顺序?通常的顺序是(x,y)(即(宽度,高度)),而不是相反。
from PyQt5.QtGui import QImage, qGray
# read jpg image and convert it to grey scale.
grey_img = QImage("test_img.jpg").convertToFormat(QImage.Format_Grayscale8)
# print the pixel value of each pixel form the grey scale image.
img_height = grey_img.height()
img_width = grey_img.width()
print("height = ", img_height)
print("width = ", img_width)
# height = 394
# width = 700
for row in range(0, img_height):
for col in range(0, img_width):
# works
gray_val = qGray(grey_img.pixel(col, row))
# does not work
# gives out of range error
# QImage::pixel: coordinate (179,482) out of range
# gray_val = qGray(grey_img.pixel(row, col))