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. QFileDialog and OpenCV's imread()-Problem
Forum Updated to NodeBB v4.3 + New Features

QFileDialog and OpenCV's imread()-Problem

Scheduled Pinned Locked Moved Unsolved Qt for Python
14 Posts 5 Posters 2.2k 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.
  • Pablo J. RoginaP Offline
    Pablo J. RoginaP Offline
    Pablo J. Rogina
    wrote on last edited by
    #4

    @Denni-0 said in QFileDialog and OpenCV's imread()-Problem:

    I do not have a problem with the forward slashes in a Windows environment

    From this Python examples page for cv2.imread(), it seems to be the case since the examples looks like Windows paths (D: drive) with forward slashes

    img = cv2.imread('D:/image-1.png')
    

    Upvote the answer(s) that helped you solve the issue
    Use "Topic Tools" button to mark your post as Solved
    Add screenshots via postimage.org
    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

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

      I remember reading that recent versions of Windows (well the command line / power shell / maybe another one) improved the support for that. But the OP didn't say which one he is running.

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

      JonBJ 1 Reply Last reply
      0
      • SGaistS SGaist

        I remember reading that recent versions of Windows (well the command line / power shell / maybe another one) improved the support for that. But the OP didn't say which one he is running.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #6

        @SGaist
        Once the OP just puts in print(name) we won't have to guess any more....

        E 1 Reply Last reply
        0
        • JonBJ JonB

          @SGaist
          Once the OP just puts in print(name) we won't have to guess any more....

          E Offline
          E Offline
          elias_hh
          wrote on last edited by
          #7

          @JonB If i do print(name) then i get the following path like: C:/Users/Image_name . I think the problem is "/". Windows or OpenCV cant handle path with "/". If i use the same code with my macbook, it works fine.

          JonBJ 1 Reply Last reply
          0
          • E elias_hh

            @JonB If i do print(name) then i get the following path like: C:/Users/Image_name . I think the problem is "/". Windows or OpenCV cant handle path with "/". If i use the same code with my macbook, it works fine.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #8

            @elias_hh
            If that's so, it looks like exactly what @SGaist suggested. If you are saying when you use a literal "C:\\Users\\Image_name" (i.e. value C:\Users\Image_name) it works but when you pass the result from QFileDialog.getOpenFileNames() which is C:/Users/Image_name it does not, then you have your difference/answer. cv2.imread(), does not appear to like forward slashes under Windows (forward slashes would be correctly native under Mac/Linux), though that seems to go against the example quoted by @Pablo-J-Rogina ....

            In any case, try what @SGaist suggested:

            nativeName = QDir.toNativeSeparators(name)
            pic = cv2.imread(nativeName, cv2.IMREAD_ANYDEPTH)
            

            Does that indeed now work?

            In any case, I would always use https://doc.qt.io/qt-5/qdir.html#toNativeSeparators when passing any Qt-generated path to anything non-Qt, unless the external documentation states it expects paths to be in forward-slash format.

            Under Windows each program can deal with paths with / vs \ differently. For example, the following two OS commands differ:

            dir \w
            dir /w
            

            The first lists a file named w in the root directory on the current drive (i.e. \w). The second lists files in the current directory, using the /w listing option.

            1 Reply Last reply
            1
            • E Offline
              E Offline
              elias_hh
              wrote on last edited by elias_hh
              #9

              Hi, guys,

              i apologize for the unnecessary confusion. the problem all along was not the back slash or the fordwar slash, but something completely different. I already mentioned that i get C:/Users/Image_name by using print(name). But apparently it has nothing to do with it. The bottom line is that the problem is the following:

              (Pre-information: my code is in the folder "GUI" and in "GUI" is also the folder with the images named "pics")

              when i select an image from this path C:/Users/Myname/Desktop/GUI/pics --> it doesn work, i become for pic = cv2.imread(name, cv2.IMREAD_ANYDEPTH) a print(pic) = none

              And here comes the weird part:

              when i select the same image from another path like: C:/Users/Myname/pics --> it works ! But i have realy no idea why.

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

                Any chances that your Windows is not in English ?

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

                E 1 Reply Last reply
                0
                • SGaistS SGaist

                  Any chances that your Windows is not in English ?

                  E Offline
                  E Offline
                  elias_hh
                  wrote on last edited by
                  #11

                  @SGaist i dont thing so

                  JonBJ 1 Reply Last reply
                  0
                  • E elias_hh

                    @SGaist i dont thing so

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #12

                    @elias_hh
                    Show the actual paths printed out via the print(name), copied & pasted to here not typed in, of what does work and what does not.

                    E 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @elias_hh
                      Show the actual paths printed out via the print(name), copied & pasted to here not typed in, of what does work and what does not.

                      E Offline
                      E Offline
                      elias_hh
                      wrote on last edited by
                      #13

                      @JonB Ok. I show you the print(name). This is the path, which doesnt work:

                      C:/Users/hrezaie/Desktop/Hamid Rezaie/GUI/pics/mocim_FPLERW_3_3CM_10mm_MPW_6.0_für_Ex_Versuch1.bmp

                      So, and if i choose the same image but from another path, it works. see here:

                      C:/Users/hrezaie/Desktop/Hamid Rezaie/pics/mocim_FPLERW_3_3CM_10mm_MPW_6.0_für_Ex_Versuch1.bmp

                      Again, to repeat. My Python code is in "GUI".

                      JonBJ 1 Reply Last reply
                      0
                      • E elias_hh

                        @JonB Ok. I show you the print(name). This is the path, which doesnt work:

                        C:/Users/hrezaie/Desktop/Hamid Rezaie/GUI/pics/mocim_FPLERW_3_3CM_10mm_MPW_6.0_für_Ex_Versuch1.bmp

                        So, and if i choose the same image but from another path, it works. see here:

                        C:/Users/hrezaie/Desktop/Hamid Rezaie/pics/mocim_FPLERW_3_3CM_10mm_MPW_6.0_für_Ex_Versuch1.bmp

                        Again, to repeat. My Python code is in "GUI".

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #14

                        @elias_hh
                        Then show me from a Command Prompt :

                        dir "C:\Users\hrezaie\Desktop\Hamid Rezaie\GUI\pics\mocim_FPLERW_3_3CM_10mm_MPW_6.0_für_Ex_Versuch1.bmp"
                        

                        Please use copy & paste from what I have written. (In Command Prompt, right click should insert what you have copied to the clipboard, or click its menu in top-left-hand corner and Edit > Paste.)

                        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