Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. io.imread and Qpixmap
Forum Updated to NodeBB v4.3 + New Features

io.imread and Qpixmap

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 648 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kurtan
    wrote on last edited by
    #1

    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'
    
    JonBJ 1 Reply Last reply
    0
    • K Kurtan

      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'
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Kurtan said in io.imread and Qpixmap:

      self.image = io.imread(self.filename)

      What is io.imread()? Some Python numpy thing, a numpy.ndarray? Why do you read an image file in with io.imread() to produce a numpy.ndarray if you want to pass it to Qt's QPixmap() which knows nothing about numpy.ndarray? E.g. QPixmap(self.filename) returns a QPixmap from the file content without going anywhere near numpy.ndarray....

      If you really have to a have a io.imread()/numpy.ndarray for some reason then I suggest you Google for pyqt5 numpy image or pysize numpy image or pyqt5 numpy array to qpixmap and pick one of the many hits for code to do the conversion.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved