io.imread and Qpixmap
-
I'm trying to load and image,then convert it to grayscale format.I did some code but I got the error message when loading an image with using io.imread.What should I change to fix error ?
def loadImage(self): self.filename = QFileDialog.getOpenFileName(filter="Image (*.*)")[0] self.image = io.imread(self.filename) self.setPhoto(self.image) def setPhoto(self,image): self.tmp = image self.label.setPixmap(QPixmap(image))
and error is that
runfile('C:/Users/user/Desktop/pyqt5/open2Gray.py', wdir='C:/Users/user/Desktop/pyqt5') Traceback (most recent call last): File "C:\Users\user\Desktop\pyqt5\open2Gray.py", line 62, in loadImage self.setPhoto(self.image) File "C:\Users\user\Desktop\pyqt5\open2Gray.py", line 69, in setPhoto self.label.setPixmap(QPixmap(image)) TypeError: QPixmap(): argument 1 has unexpected type 'numpy.ndarray'
-
I'm trying to load and image,then convert it to grayscale format.I did some code but I got the error message when loading an image with using io.imread.What should I change to fix error ?
def loadImage(self): self.filename = QFileDialog.getOpenFileName(filter="Image (*.*)")[0] self.image = io.imread(self.filename) self.setPhoto(self.image) def setPhoto(self,image): self.tmp = image self.label.setPixmap(QPixmap(image))
and error is that
runfile('C:/Users/user/Desktop/pyqt5/open2Gray.py', wdir='C:/Users/user/Desktop/pyqt5') Traceback (most recent call last): File "C:\Users\user\Desktop\pyqt5\open2Gray.py", line 62, in loadImage self.setPhoto(self.image) File "C:\Users\user\Desktop\pyqt5\open2Gray.py", line 69, in setPhoto self.label.setPixmap(QPixmap(image)) TypeError: QPixmap(): argument 1 has unexpected type 'numpy.ndarray'
@Kurtan said in io.imread and Qpixmap:
self.image = io.imread(self.filename)
What is
io.imread()
? Some Python numpy thing, anumpy.ndarray
? Why do you read an image file in withio.imread()
to produce anumpy.ndarray
if you want to pass it to Qt'sQPixmap()
which knows nothing aboutnumpy.ndarray
? E.g.QPixmap(self.filename)
returns aQPixmap
from the file content without going anywhere nearnumpy.ndarray
....If you really have to a have a
io.imread()
/numpy.ndarray
for some reason then I suggest you Google forpyqt5 numpy image
orpysize numpy image
orpyqt5 numpy array to qpixmap
and pick one of the many hits for code to do the conversion.