Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Matching 2 .tiff images pixel-by-pixel
Qt 6.12 LTS is out! See what's new in the release blog

Matching 2 .tiff images pixel-by-pixel

Scheduled Pinned Locked Moved Solved General and Desktop
55 Posts 5 Posters 43.8k Views 2 Watching
  • 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.
  • J john_hobbyist

    @jsulm: I added this:

    import rubberband
    

    but again does not work! What should I do?

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #35

    @john_hobbyist Please read more carefully! Nobody is talking about "rubberband"!
    The question was about: "NameError: name 'rubberBand' is not defined"
    rubberband != rubberBand
    So, one more time I repeat the question: was rubberBand defined anywhere?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #36

      There are some errors in the python document snippet that will be fixed.

      Here's an example:

      import sys
      
      from PySide2.QtCore import QRect
      from PySide2.QtCore import QSize
      from PySide2.QtWidgets import QWidget
      from PySide2.QtWidgets import QRubberBand
      from PySide2.QtWidgets import QApplication
      
      class Widget(QWidget):
          def __init__(self, parent=None):
              super().__init__(parent)
      
              self.rubberBand = None
              self.origin = None
      
          def mousePressEvent(self, event):
              self.origin = event.pos()
              if not self.rubberBand:
                  self.rubberBand = QRubberBand(QRubberBand.Rectangle, self)
              self.rubberBand.setGeometry(QRect(self.origin, QSize()))
              self.rubberBand.show()
      
          def mouseMoveEvent(self, event):
              self.rubberBand.setGeometry(QRect(self.origin, event.pos()).normalized())
      
          def mouseReleaseEvent(self, event):
              self.rubberBand.hide()
              # determine selection, for example using QRect.intersects()
              # and QRect.contains().
      
      if __name__ == "__main__":
          app = QApplication(sys.argv)
          widget = Widget()
          widget.show()
          sys.exit(app.exec_())
      

      On a side note, it looks like you are a beginner with Python, I would recommend getting the basics first before going further.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      3
      • J Offline
        J Offline
        john_hobbyist
        wrote on last edited by
        #37

        @jsulm : No

        @SGaist: Thanks, I am looking at it...

        1 Reply Last reply
        0
        • J Offline
          J Offline
          john_hobbyist
          wrote on last edited by john_hobbyist
          #38

          @SGaist: I installed PySide2 and your code runs perfectly! Many thanks!

          I combined your above code with my code and tried to run it, but I get this error:

          File "code.py", line 30, in <module>
            from PySide2.QtCore import QRect
          ImportError: /lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.15' not found (required by /home/john/.local/lib/python3.8/site-packages/PySide2/QtCore.abi3.so)
          

          After google search I found and followed the suggestions from this tutorial: https://stackoverflow.com/questions/63903441/python3-importerror-lib-x86-64-linux-gnu-libqt5core-so-5-version-qt-5-15-n which does not help because it is related to PyQt5 and not PySide2.

          I have to note at this point that in my code I use both PyQt5 and PySide2 packages. Could the above error be a result of conflict between the packages?

          I also study this: https://forum.qt.io/topic/89263/qt5-pyqt5-and-opencv-problem-with-import

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #39

            How did you install them both ?
            Did you do that in the same environment ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • J Offline
              J Offline
              john_hobbyist
              wrote on last edited by
              #40

              @SGaist : Yes I did that on the same environment.

              I tried this:

              sudo apt-get install python3-pyqt5.qtwebengine
              

              and this:

              sudo apt-get install python3-pyqt5
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #41

                You did not install PySide2 in the same manner.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply
                1
                • SGaistS SGaist

                  You did not install PySide2 in the same manner.

                  J Offline
                  J Offline
                  john_hobbyist
                  wrote on last edited by
                  #42

                  @SGaist : Yes.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #43

                    @john_hobbyist said in Matching 2 .tiff images pixel-by-pixel:

                    required by /home/john/.local/lib/python3.8/site-packages/PySide2/QtCore.abi3.so)

                    This suggests that it's not the case.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • J Offline
                      J Offline
                      john_hobbyist
                      wrote on last edited by
                      #44

                      @SGaist: So what should I do?

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #45

                        Cleanup your environment and use something like Python's virtualenv or conda to create local environments for your Python development where you can have exactly what you need.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • J Offline
                          J Offline
                          john_hobbyist
                          wrote on last edited by
                          #46

                          Ok I have activated virtual environment and have installed everything from the beginning. This is the error I got, which I am trying to solve for many hours without any success....

                          QObject::moveToThread: Current thread (0x2b4f9a0) is not the object's thread (0x37b2280).
                          Cannot move to target thread (0x2b4f9a0)
                          
                          qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/john/Desktop/venv/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
                          This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
                          
                          Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.
                          
                          Aborted (core dumped)
                          

                          Then I followed this solution: https://forum.qt.io/topic/125009/problem-with-qt-qpa-plugin-running-on-a-docker-in-kubuntu/18 and basically I installed these libraries (all with sudo):

                          pip3 install opencv-python-headless
                          apt-get update ##[edited]
                          apt-get install ffmpeg libsm6 libxext6  -y
                          pip3 install matplotlib
                          apt-get install python3-pyqt5 -y
                          pip3 install pyqt5
                          pip3 install wheel
                          pip3 install pandas
                          pip3 install openpyxl
                          pip3 install geopandas
                          apt update -y
                          apt install libpq-dev -y
                          apt install gdal-bin -y
                          apt install libgdal-dev -y
                          pip3 install numba
                          pip3 install GDAL
                          apt-get install qt5-default -y
                          pip3 install numpy
                          ldd /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so
                          apt-get update -y
                          apt-get install -y '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev 
                          apt-get install -y libxcb-util-dev
                          QT_DEBUG_PLUGINS=1
                          

                          and I now I am getting this error:

                          qt.qpa.xcb: could not connect to display :1.0
                          qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
                          This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
                          
                          Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.
                          
                          Aborted (core dumped)
                          

                          Any idea???

                          jsulmJ 1 Reply Last reply
                          0
                          • J john_hobbyist

                            Ok I have activated virtual environment and have installed everything from the beginning. This is the error I got, which I am trying to solve for many hours without any success....

                            QObject::moveToThread: Current thread (0x2b4f9a0) is not the object's thread (0x37b2280).
                            Cannot move to target thread (0x2b4f9a0)
                            
                            qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/john/Desktop/venv/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
                            This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
                            
                            Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.
                            
                            Aborted (core dumped)
                            

                            Then I followed this solution: https://forum.qt.io/topic/125009/problem-with-qt-qpa-plugin-running-on-a-docker-in-kubuntu/18 and basically I installed these libraries (all with sudo):

                            pip3 install opencv-python-headless
                            apt-get update ##[edited]
                            apt-get install ffmpeg libsm6 libxext6  -y
                            pip3 install matplotlib
                            apt-get install python3-pyqt5 -y
                            pip3 install pyqt5
                            pip3 install wheel
                            pip3 install pandas
                            pip3 install openpyxl
                            pip3 install geopandas
                            apt update -y
                            apt install libpq-dev -y
                            apt install gdal-bin -y
                            apt install libgdal-dev -y
                            pip3 install numba
                            pip3 install GDAL
                            apt-get install qt5-default -y
                            pip3 install numpy
                            ldd /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so
                            apt-get update -y
                            apt-get install -y '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev 
                            apt-get install -y libxcb-util-dev
                            QT_DEBUG_PLUGINS=1
                            

                            and I now I am getting this error:

                            qt.qpa.xcb: could not connect to display :1.0
                            qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
                            This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
                            
                            Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.
                            
                            Aborted (core dumped)
                            

                            Any idea???

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #47

                            @john_hobbyist Do

                            export QT_DEBUG_PLUGINS=1
                            ./YOUR_APP
                            

                            And post the output here.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            1
                            • J Offline
                              J Offline
                              john_hobbyist
                              wrote on last edited by john_hobbyist
                              #48

                              @jsulm: Thank you!! You are awesome!!

                              I have this error:

                              File "code.py", line 231, in __init__
                                empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
                              TypeError: 'PySide2.QtWidgets.QWidget.setSizePolicy' called with wrong argument types:
                              PySide2.QtWidgets.QWidget.setSizePolicy(Policy, Policy)
                              Supported signatures:
                              PySide2.QtWidgets.QWidget.setSizePolicy(PySide2.QtWidgets.QSizePolicy)
                              PySide2.QtWidgets.QWidget.setSizePolicy(PySide2.QtWidgets.QSizePolicy.Policy, PySide2.QtWidgets.QSizePolicy.Policy)
                              

                              So, I changed this line:

                              empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
                              

                              to this:

                              empty.setSizePolicy(PySide2.QtWidgets.QSizePolicy.Policy.Expanding, PySide2.QtWidgets.QSizePolicy.Policy.Expanding)
                              

                              And then I get this error:

                              File "code.py", line 234, in __init__
                                self.tb.addWidget(empty)
                              TypeError: addWidget(self, QWidget): argument 1 has unexpected type 'PySide2.QtWidgets.QWidget'
                              

                              what I am supposed to do? If I fix the one, the other becomes bug and vice-versa.... I mean what should change here?

                              jsulmJ 1 Reply Last reply
                              0
                              • J john_hobbyist

                                @jsulm: Thank you!! You are awesome!!

                                I have this error:

                                File "code.py", line 231, in __init__
                                  empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
                                TypeError: 'PySide2.QtWidgets.QWidget.setSizePolicy' called with wrong argument types:
                                PySide2.QtWidgets.QWidget.setSizePolicy(Policy, Policy)
                                Supported signatures:
                                PySide2.QtWidgets.QWidget.setSizePolicy(PySide2.QtWidgets.QSizePolicy)
                                PySide2.QtWidgets.QWidget.setSizePolicy(PySide2.QtWidgets.QSizePolicy.Policy, PySide2.QtWidgets.QSizePolicy.Policy)
                                

                                So, I changed this line:

                                empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
                                

                                to this:

                                empty.setSizePolicy(PySide2.QtWidgets.QSizePolicy.Policy.Expanding, PySide2.QtWidgets.QSizePolicy.Policy.Expanding)
                                

                                And then I get this error:

                                File "code.py", line 234, in __init__
                                  self.tb.addWidget(empty)
                                TypeError: addWidget(self, QWidget): argument 1 has unexpected type 'PySide2.QtWidgets.QWidget'
                                

                                what I am supposed to do? If I fix the one, the other becomes bug and vice-versa.... I mean what should change here?

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #49

                                @john_hobbyist said in Matching 2 .tiff images pixel-by-pixel:

                                self.tb

                                What is tb?
                                It would also be helpful if you would post the relevant code.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                1
                                • J Offline
                                  J Offline
                                  john_hobbyist
                                  wrote on last edited by john_hobbyist
                                  #50
                                  . . . 
                                  self.tb = QToolBar("File")
                                  print("101")
                                  empty = QWidget()
                                  # empty = PySide2.QtWidgets.QWidget()  
                                  print("102")
                                  # empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
                                  empty.setSizePolicy(PySide2.QtWidgets.QSizePolicy.Policy.Expanding, PySide2.QtWidgets.QSizePolicy.Policy.Expanding) 
                                  print("103")
                                  self.tb.addWidget(empty)
                                  . . . 
                                  
                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #51

                                    Please provide a minimal runnable script that shows this error.

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    1
                                    • J Offline
                                      J Offline
                                      john_hobbyist
                                      wrote on last edited by john_hobbyist
                                      #52

                                      Could this be a problem of using PyQt and PySide2 on the same program? The rationale that I have followed is that I took the initial code that was running perfectly and I put the Qrubberband code and then I have those strange errors...How do I indicate to the code that in this method I want to use PyQt5 and in the other method I want to use PySide2?

                                      UPDATE: I changed everything to PyQt5 and I deleted PySide2.... and the previously mentioned error appeared:

                                      Traceback (most recent call last):
                                        File "code.4.py", line 195, in mouseMoveEvent
                                          rubberBand.setGeometry(QRect(origin, event.pos()).normalized())
                                      NameError: name 'rubberBand' is not defined
                                      Aborted (core dumped)
                                      
                                      

                                      So I believe that the Qrubberband code posted by @SGaist needs PySide2 in order to function properly? Right?

                                      SGaistS 1 Reply Last reply
                                      0
                                      • SGaistS SGaist

                                        There are some errors in the python document snippet that will be fixed.

                                        Here's an example:

                                        import sys
                                        
                                        from PySide2.QtCore import QRect
                                        from PySide2.QtCore import QSize
                                        from PySide2.QtWidgets import QWidget
                                        from PySide2.QtWidgets import QRubberBand
                                        from PySide2.QtWidgets import QApplication
                                        
                                        class Widget(QWidget):
                                            def __init__(self, parent=None):
                                                super().__init__(parent)
                                        
                                                self.rubberBand = None
                                                self.origin = None
                                        
                                            def mousePressEvent(self, event):
                                                self.origin = event.pos()
                                                if not self.rubberBand:
                                                    self.rubberBand = QRubberBand(QRubberBand.Rectangle, self)
                                                self.rubberBand.setGeometry(QRect(self.origin, QSize()))
                                                self.rubberBand.show()
                                        
                                            def mouseMoveEvent(self, event):
                                                self.rubberBand.setGeometry(QRect(self.origin, event.pos()).normalized())
                                        
                                            def mouseReleaseEvent(self, event):
                                                self.rubberBand.hide()
                                                # determine selection, for example using QRect.intersects()
                                                # and QRect.contains().
                                        
                                        if __name__ == "__main__":
                                            app = QApplication(sys.argv)
                                            widget = Widget()
                                            widget.show()
                                            sys.exit(app.exec_())
                                        

                                        On a side note, it looks like you are a beginner with Python, I would recommend getting the basics first before going further.

                                        J Offline
                                        J Offline
                                        john_hobbyist
                                        wrote on last edited by
                                        #53
                                        This post is deleted!
                                        1 Reply Last reply
                                        0
                                        • J john_hobbyist

                                          Could this be a problem of using PyQt and PySide2 on the same program? The rationale that I have followed is that I took the initial code that was running perfectly and I put the Qrubberband code and then I have those strange errors...How do I indicate to the code that in this method I want to use PyQt5 and in the other method I want to use PySide2?

                                          UPDATE: I changed everything to PyQt5 and I deleted PySide2.... and the previously mentioned error appeared:

                                          Traceback (most recent call last):
                                            File "code.4.py", line 195, in mouseMoveEvent
                                              rubberBand.setGeometry(QRect(origin, event.pos()).normalized())
                                          NameError: name 'rubberBand' is not defined
                                          Aborted (core dumped)
                                          
                                          

                                          So I believe that the Qrubberband code posted by @SGaist needs PySide2 in order to function properly? Right?

                                          SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #54

                                          @john_hobbyist said in Matching 2 .tiff images pixel-by-pixel:

                                          So I believe that the Qrubberband code posted by @SGaist needs PySide2 in order to function properly? Right?

                                          Wrong, you did not copy my code properly and missing a self. in yours.

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          1

                                          • Login

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