Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't access image (.jpeg) folder in main() using OpenCV
Forum Update on Monday, May 27th 2025

Can't access image (.jpeg) folder in main() using OpenCV

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 4 Posters 1.6k 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.
  • G Offline
    G Offline
    georgiav
    wrote on 14 Feb 2021, 11:30 last edited by
    #1

    Hi it seems like in main() I can't access the image folder using OpenCV functions even though OpenCV libraries are linked correctly and the folder path is right. How can I fix it?

        int main(int argc, char *argv[])
        {     vector<cv::String> fn;
              cv::glob("/home/csimage/project/images/*", fn, false);
        
              vector<cv::Mat> imagesResized;
              size_t count = fn.size();
              for (size_t i=0; i<count; i++)
                {
                  //resize images to the same size
                 cv::Mat dst;
                  cv::Mat src =cv::imread(fn[i]);
                  cv::resize(src,dst,cv::Size(20,20));
                  imagesResized.push_back(dst);
                }
             //I GET THE FIRST ERROR HERE WHEN IT TRIES TO READ THE IMAGES
               cv::Mat inputImage=cv::imread("/home/csimage/project/church.JPEG");
               vector<cv::Mat> imageTiles= split(inputImage,40,40);
               cv::Mat matchingImage;
               vector<cv::Mat> final;
        
                 for ( int i=0;i<imageTiles.size();i++)
                      { matchingImage=comparer(imageTiles[i],imagesResized);
                       final.push_back(matchingImage);}
                       cv::Mat image_collage= imageCollage(final,40,40);
        
                          imshow("Image collage",image_collage);
                          cv::waitKey(0);
        
                return 0;
        }4
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 14 Feb 2021, 11:33 last edited by
      #2

      Hi
      Are you sure the file extension is JPEG with big letters ?

      Also you dont mention what error you get?

      G 1 Reply Last reply 14 Feb 2021, 11:40
      0
      • M mrjj
        14 Feb 2021, 11:33

        Hi
        Are you sure the file extension is JPEG with big letters ?

        Also you dont mention what error you get?

        G Offline
        G Offline
        georgiav
        wrote on 14 Feb 2021, 11:40 last edited by
        #3

        @mrjj Hi, sorry I could't insert the image with the error before, actually the first error is at cv::imread(fn[i]) which tries to do the same thing, here's the photo

        484de870-8581-4928-8f48-ebf391580307-image.png

        J 1 Reply Last reply 14 Feb 2021, 11:48
        0
        • G georgiav
          14 Feb 2021, 11:40

          @mrjj Hi, sorry I could't insert the image with the error before, actually the first error is at cv::imread(fn[i]) which tries to do the same thing, here's the photo

          484de870-8581-4928-8f48-ebf391580307-image.png

          J Offline
          J Offline
          JonB
          wrote on 14 Feb 2021, 11:48 last edited by JonB
          #4

          @georgiav
          So these are linker errors for the methods shown. Either you're not linking with the right library (most likely), or just possibly you're passing the wrong parameters.

          G 1 Reply Last reply 14 Feb 2021, 11:52
          1
          • J JonB
            14 Feb 2021, 11:48

            @georgiav
            So these are linker errors for the methods shown. Either you're not linking with the right library (most likely), or just possibly you're passing the wrong parameters.

            G Offline
            G Offline
            georgiav
            wrote on 14 Feb 2021, 11:52 last edited by
            #5

            @JonB I had the problem with linking the libraries before and it's been solved, I don't have errors like 'Mat object undefined' and the paths should be fine as the same program works fine when run from a shell

            M J 2 Replies Last reply 14 Feb 2021, 12:30
            0
            • G georgiav
              14 Feb 2021, 11:52

              @JonB I had the problem with linking the libraries before and it's been solved, I don't have errors like 'Mat object undefined' and the paths should be fine as the same program works fine when run from a shell

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 14 Feb 2021, 12:30 last edited by
              #6

              @georgiav
              Hi
              So exact same source and .pro file can be compiled and run when compiling in shell
              but in Creator you get undefined errors?

              G 1 Reply Last reply 14 Feb 2021, 12:40
              0
              • M mrjj
                14 Feb 2021, 12:30

                @georgiav
                Hi
                So exact same source and .pro file can be compiled and run when compiling in shell
                but in Creator you get undefined errors?

                G Offline
                G Offline
                georgiav
                wrote on 14 Feb 2021, 12:40 last edited by georgiav
                #7

                @mrjj Just the c++ file with the program which is supposed to be a photo collage , not the qt part. I fixed the .pro file for one library name was spelled wrong sorry about that, and now it works but I only get an empty MainWindow

                and the result should be this ( it's the same code)
                Screenshot from 2021-02-14 12-41-39.png

                1 Reply Last reply
                0
                • G georgiav
                  14 Feb 2021, 11:52

                  @JonB I had the problem with linking the libraries before and it's been solved, I don't have errors like 'Mat object undefined' and the paths should be fine as the same program works fine when run from a shell

                  J Offline
                  J Offline
                  JonB
                  wrote on 14 Feb 2021, 12:47 last edited by JonB
                  #8

                  @georgiav said in Can't access image (.jpeg) folder in main() using OpenCV:

                  I had the problem with linking the libraries before and it's been solved,

                  What "has been solved"?

                  I don't have errors like 'Mat object undefined'

                  No, instead you have "undefined reference" at link time on some cv functions.

                  and the paths should be fine as the same program works fine when run from a shell

                  What program? The errors show that you cannot link the executable. So no "program" is being generated in this build. If you have something you linked before, you have some other (successfully-linked, maybe library search path was different, or other difference) executable elsewhere, not the one not-generated from this link.

                  G 1 Reply Last reply 14 Feb 2021, 13:10
                  0
                  • J JonB
                    14 Feb 2021, 12:47

                    @georgiav said in Can't access image (.jpeg) folder in main() using OpenCV:

                    I had the problem with linking the libraries before and it's been solved,

                    What "has been solved"?

                    I don't have errors like 'Mat object undefined'

                    No, instead you have "undefined reference" at link time on some cv functions.

                    and the paths should be fine as the same program works fine when run from a shell

                    What program? The errors show that you cannot link the executable. So no "program" is being generated in this build. If you have something you linked before, you have some other (successfully-linked, maybe library search path was different, or other difference) executable elsewhere, not the one not-generated from this link.

                    G Offline
                    G Offline
                    georgiav
                    wrote on 14 Feb 2021, 13:10 last edited by
                    #9

                    @JonB check post above ( the link to the libraries is now ok and works, a library name was misspelled.) The program compiles and runs but only shows an empty window.

                    80ab96d7-a68c-4057-ac39-8c00241e95b7-image.png

                    Can I do something about it?

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 14 Feb 2021, 13:15 last edited by
                      #10

                      Isn't there a forum for OpenCV out there? Or what is the relation to Qt here?

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      G 1 Reply Last reply 14 Feb 2021, 13:20
                      0
                      • Christian EhrlicherC Christian Ehrlicher
                        14 Feb 2021, 13:15

                        Isn't there a forum for OpenCV out there? Or what is the relation to Qt here?

                        G Offline
                        G Offline
                        georgiav
                        wrote on 14 Feb 2021, 13:20 last edited by
                        #11

                        @Christian-Ehrlicher since the program works fine using just OpenCV and it doesn't work when trying to run it in QT I thought it's more likely to be a Qt problem rather than an Opencv one. Maybe there are specific things to add in the .pro file or other settings I'm not aware of since I'm new to Qt.

                        M Christian EhrlicherC 2 Replies Last reply 14 Feb 2021, 13:31
                        0
                        • G georgiav
                          14 Feb 2021, 13:20

                          @Christian-Ehrlicher since the program works fine using just OpenCV and it doesn't work when trying to run it in QT I thought it's more likely to be a Qt problem rather than an Opencv one. Maybe there are specific things to add in the .pro file or other settings I'm not aware of since I'm new to Qt.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 14 Feb 2021, 13:31 last edited by
                          #12

                          @georgiav
                          Hi
                          But the code you have shown in the first post does nothing with MainWindow ( or even has one)
                          So what is the thing that doesn't work ?
                          What should been on the MainWindow ?
                          and how did you add it ?

                          G 1 Reply Last reply 14 Feb 2021, 13:38
                          0
                          • M mrjj
                            14 Feb 2021, 13:31

                            @georgiav
                            Hi
                            But the code you have shown in the first post does nothing with MainWindow ( or even has one)
                            So what is the thing that doesn't work ?
                            What should been on the MainWindow ?
                            and how did you add it ?

                            G Offline
                            G Offline
                            georgiav
                            wrote on 14 Feb 2021, 13:38 last edited by
                            #13

                            @mrjj Hi, I think those were the mainwindow.cpp and mainwindow.h files that were already there when I created the project but I didn't add anything in them so I just removed them and tried to run again and now I get this :

                            fe630f7c-b690-4597-bd37-bd5298cfedf9-image.png

                            but unfortunately I don't understand where those errors come from

                            1 Reply Last reply
                            0
                            • G georgiav
                              14 Feb 2021, 13:20

                              @Christian-Ehrlicher since the program works fine using just OpenCV and it doesn't work when trying to run it in QT I thought it's more likely to be a Qt problem rather than an Opencv one. Maybe there are specific things to add in the .pro file or other settings I'm not aware of since I'm new to Qt.

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on 14 Feb 2021, 13:43 last edited by Christian Ehrlicher
                              #14

                              @georgiav said in Can't access image (.jpeg) folder in main() using OpenCV:

                              Since the program works fine using just OpenCV and it doesn't work when trying to run it in QT I thought it's more likely to be a Qt problem rather than an Opencv

                              Your code does not use any Qt class at all...

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              G 1 Reply Last reply 14 Feb 2021, 13:49
                              0
                              • Christian EhrlicherC Christian Ehrlicher
                                14 Feb 2021, 13:43

                                @georgiav said in Can't access image (.jpeg) folder in main() using OpenCV:

                                Since the program works fine using just OpenCV and it doesn't work when trying to run it in QT I thought it's more likely to be a Qt problem rather than an Opencv

                                Your code does not use any Qt class at all...

                                G Offline
                                G Offline
                                georgiav
                                wrote on 14 Feb 2021, 13:49 last edited by
                                #15

                                @Christian-Ehrlicher I'm trying to create a GUI for my program but first the c++ program should run fine , right?

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 14 Feb 2021, 14:10 last edited by
                                  #16

                                  Hi
                                  I wonder if you need to link additional libs
                                  besides opencv_core
                                  like opencv_imgcodecs

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    georgiav
                                    wrote on 14 Feb 2021, 14:40 last edited by
                                    #17

                                    Hi, no, I figure it out what it was , I didn't write QApplication a(argc, argv); at the beginning in the main function. Now it works fine ! Thank you anyway for trying to help.

                                    M 1 Reply Last reply 14 Feb 2021, 15:37
                                    1
                                    • G georgiav
                                      14 Feb 2021, 14:40

                                      Hi, no, I figure it out what it was , I didn't write QApplication a(argc, argv); at the beginning in the main function. Now it works fine ! Thank you anyway for trying to help.

                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 14 Feb 2021, 15:37 last edited by
                                      #18

                                      @georgiav

                                      Oh so after you added that all the other errors went away ?
                                      well good it works :)
                                      happy coding

                                      1 Reply Last reply
                                      0

                                      1/18

                                      14 Feb 2021, 11:30

                                      • Login

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