Results 1 to 19 of 19

Thread: the cv::imread OpenCV function can't read image file in Qt Creator

  1. #1
    Join Date
    Jan 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Question Re: the cv::imread OpenCV function can't read image file in Qt Creator

    my codes are following:

    1, the code of the project file:

    #-------------------------------------------------
    #
    # Project created by QtCreator
    #
    #-------------------------------------------------

    QT -= gui

    TARGET = myQtConsoleProject
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    INCLUDEPATH += E:\opencv\build\include\

    LIBS += -LE:\opencv\build\x86\vc10\lib \
    -lopencv_core243 \
    -lopencv_highgui243 \
    -lopencv_imgproc243 \
    -lopencv_features2d243 \
    -lopencv_calib3d243


    2, the code of the only C++ file of the project----main.cpp:

    #include <QCoreApplication>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    // read an image
    cv::Mat image= cv::imread("img.jpg");
    // create image window named "My Image"
    cv::namedWindow("My Image");
    // show the image on window
    cv::imshow("My Image", image);
    // wait key for 5000 ms
    cv::waitKey(5000);

    return a.exec();
    }


    The OS used is Windows xp, the VS2010 has been completely installed, and OpenCV 2.4.3 has been installed. The project posted above cab be built successfully.

    The problem is that the project built can't run normoally because of the cv::imread can't read the image file.

    please help me. Thanks.


    Added after 1 59 minutes:


    The plateform is Windowsxp + MSVS2010 + Qt 5.0 for Windows +
    Qt Creator 2.6.1 for Windows.

    Quote Originally Posted by northbear View Post
    my codes are following:

    1, the code of the project file:

    #-------------------------------------------------
    #
    # Project created by QtCreator
    #
    #-------------------------------------------------

    QT -= gui

    TARGET = myQtConsoleProject
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    INCLUDEPATH += E:\opencv\build\include\

    LIBS += -LE:\opencv\build\x86\vc10\lib \
    -lopencv_core243 \
    -lopencv_highgui243 \
    -lopencv_imgproc243 \
    -lopencv_features2d243 \
    -lopencv_calib3d243


    2, the code of the only C++ file of the project----main.cpp:

    #include <QCoreApplication>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    // read an image
    cv::Mat image= cv::imread("img.jpg");
    // create image window named "My Image"
    cv::namedWindow("My Image");
    // show the image on window
    cv::imshow("My Image", image);
    // wait key for 5000 ms
    cv::waitKey(5000);

    return a.exec();
    }


    The OS used is Windows xp, the VS2010 has been completely installed, and OpenCV 2.4.3 has been installed. The project posted above cab be built successfully.

    The problem is that the project built can't run normoally because of the cv::imread can't read the image file.

    please help me. Thanks.
    Last edited by northbear; 23rd January 2013 at 15:08.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    So why are you posting this question in a Qt forum? What does this have to do with Qt besides the fact that you instantiate a QCoreApplication - it looks like an OpenCV problem to me. Find an OpenCV forum and post it there.

    The simplest problem you could have is that OpenCV may not be looking for your jpg file where you think it is looking and it isn't finding the file.

    Or your JPG file could be corrupt.

    Or OpenCV needs some plugin to read JPG files, and you don't have the plugin installed.

    Or the "imread" method isn't the right one to use to read JPG files.

    Or any one of a thousand other things which Qt programmer have no idea about, since most of us aren't OpenCV programmers.

  3. #3
    Join Date
    Jan 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    Sorry, I see. I will accept your suggestion.

    The same code has been compiled in the VS2010 IDE onece, the executable file generated can run normally, that is it can read the image file and display it.

    But, The same code has been compiled in the Qt Creator, the problem occurs.

    So, Hope the experienced Qt creator programmers help me.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    Since Qt Creator is not a compiler or linker and this is not a failing Qt library call this still has nothing to do with Qt. The involvement of Qt ended when qmake wrote a Makefile for your compiler and linker based on your PRO file.

    An OpenCV function failed, why not ask the OpenCV library for a reason?
    Or Google up some interesting things like this quirk in OpenCV: http://stackoverflow.com/questions/9...ease-libraries

    My first guess is the same as d_stranz: the image file is not in the current working directory of the running program. Please note this is generally not the same thing as the source code directory.

  5. #5
    Join Date
    Jan 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    Thank u for paying attention to my problem. I knew Qt Creator is not a compiler or linker.

    I want to know how to develop a application with OpenCV by using Qt Creator!

  6. #6
    Join Date
    Jan 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    The Problem has been solved.
    Just modify the .pro file as the following:
    QT -= gui

    TARGET = myQtConsoleProject
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    INCLUDEPATH += E:\opencv\build\include\

    CONFIG(debug,debug|release){
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_core243d.lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_highgui243d.li b
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_imgproc243d.li b
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_features2d243d .lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_calib3d243d.li b
    }

    CONFIG(release,debug|release){
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_core243.lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_highgui243.lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_imgproc243.lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_features2d243. lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_calib3d243.lib
    }

    share this with all of you.

  7. #7
    Join Date
    Sep 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Talking Re: the cv::imread OpenCV function can't read image file in Qt Creator

    Hi,
    Same problem here but under Ubuntu . I tried the above solution but no luck .
    Any suggestions?
    Everything works fine outside qtcreator.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    Search the forum for OpenCV. This has been covered numerous times in this forum (most recently this morning), and it is even in the documentation

  9. #9
    Join Date
    Sep 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    This has been covered numerous times in this forum
    Thanks for reply. I already did and tried those solutions but still negative. Maybe I didn't correctly. Here is my environment:
    openSUSE 12.3 64 bits with Gnome Desktop 3.6.2
    I have installed openCV using install/remove software tool comes with gnome. I have installed qtcreator 2.8.0 manually. Qt 4.8.4 is already installed in openSUSE.
    In usr/include/ there are two opencv folders
    opencv
    opencv2
    all opencv libraries and links files are in usr/libs64
    e.g. libopencv_core.so.2.4.6
    libopencv_core.so.2.4
    libopencv_core.so

    Here is my .pro contents:
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-09-05T12:37:35
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    9. TARGET = QTopenCV03
    10. TEMPLATE = app
    11.  
    12. INCLUDEPATH += /usr/include/opencv2
    13.  
    14. LIBS += -L/usr/lib64
    15. LIBS += -lopencv_core
    16. LIBS += -lopencv_imgproc
    17. LIBS += -lopencv_highgui
    18. LIBS += -lopencv_features2d
    19. LIBS += -lopencv_calib3d
    20.  
    21. SOURCES += main.cpp\
    22. mainwindow.cpp
    23.  
    24. HEADERS += mainwindow.h
    25.  
    26. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    The contents of main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    The contents of mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <opencv2/core/core.hpp>
    6. #include <opencv2/highgui/highgui.hpp>
    7. using namespace cv;
    8. namespace Ui {
    9. class MainWindow;
    10. }
    11.  
    12. class MainWindow : public QMainWindow
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit MainWindow(QWidget *parent = 0);
    18. ~MainWindow();
    19.  
    20. private slots:
    21. void on_pushButton_clicked( );
    22.  
    23. private:
    24. Ui::MainWindow *ui;
    25. };
    26.  
    27. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    The contents of mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "opencv2/highgui/highgui.hpp"
    4. #include <iostream>
    5.  
    6. using namespace cv;
    7.  
    8.  
    9. MainWindow::MainWindow(QWidget *parent) :
    10. QMainWindow(parent),
    11. ui(new Ui::MainWindow)
    12. {
    13. ui->setupUi(this);
    14. }
    15.  
    16. MainWindow::~MainWindow()
    17. {
    18. delete ui;
    19. }
    20.  
    21. void MainWindow::on_pushButton_clicked()
    22. {
    23.  
    24. IplImage* pImg = cvLoadImage("./HappyFish.jpg");
    25. if(pImg == NULL)
    26. std::cout<< "Error loading image"<<std::endl;
    27. cvShowImage("Image", pImg);
    28.  
    29. cvReleaseImage(&pImg);
    30.  
    31.  
    32. std::cout<< "start **********"<<std::endl;
    33. Mat image;
    34. image = imread("./HappyFish.jpg"); // Read the file
    35.  
    36. if( !image.data ) { std::cout<< "Error loading src again"<<std::endl; }
    37. namedWindow( "Display window", 1 );// Create a window for display.
    38. imshow( "Display window", image ); // Show our image inside it.
    39.  
    40. waitKey(5000); // Wait for a keystroke in the window
    41. }
    To copy to clipboard, switch view to plain text mode 

    The compiler output:
    Qt Code:
    1. Starting /home/ibr/projects/build-QTopenCV03-Desktop-Release/QTopenCV03...
    2. Error loading image
    3. start **********
    4. Error loading src again
    5. OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/abuild/rpmbuild/BUILD/opencv-2.4.6.1/modules/highgui/src/window.cpp, line 269
    6. Qt has caught an exception thrown from an event handler. Throwing
    7. exceptions from an event handler is not supported in Qt. You must
    8. reimplement QApplication::notify() and catch all exceptions there.
    9.  
    10. terminate called after throwing an instance of 'cv::Exception'
    11. what(): /home/abuild/rpmbuild/BUILD/opencv-2.4.6.1/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow
    12.  
    13. The program has unexpectedly finished.
    14. /home/ibr/projects/build-QTopenCV03-Desktop-Release/QTopenCV03 exited with code 0
    To copy to clipboard, switch view to plain text mode 

    Is there something I did wrong? The same code works with out problem outside qtcreator.
    any suggestions?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    Quote Originally Posted by ibr_ex View Post
    The same code works with out problem outside qtcreator.
    Do you mean that it works if you build the project using the command line (cd, qmake, make), it works, and the same project (with the same .pro file) built by pushing the "build" button in QtCreator doesn't work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    You are opening a file using a relative path. The process current working directory is different between when it "works with out problem outside qtcreator" versus when Qt Creator runs the process on your behalf. Different base directory, different absolute path to the file it tries to open, different result.

    It crashes terribly because OpenCv throws exceptions and Qt is not able to handle this in slot code. You must avoid or catch the exception and handle it yourself.

    Since your OpenCV install is in the system standard directory your INCLUDEPATH does not need to be modified for OpenCV.
    The LIBS variable does not need a search path (-L) addition because the libs are already on the default search path.

  12. #12
    Join Date
    Sep 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    Thanks guys for your reply.
    Do you mean that it works if you build the project using the command line (cd, qmake, make), it works, and the same project (with the same .pro file) built by pushing the "build" button in QtCreator doesn't work?
    I mean when I write a code like bellow in a single cpp file and compile it using this line
    Qt Code:
    1. g++ myCVex01.cpp -o myCVex01 -I /usr/local/include/opencv -L /usr/local/lib -lm -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
    To copy to clipboard, switch view to plain text mode 
    every thing works fine. Here is the code:
    Qt Code:
    1. #include "opencv2/highgui/highgui.hpp"
    2. #include <iostream>
    3.  
    4. using namespace cv;
    5.  
    6. int main( void ){
    7.  
    8. IplImage* pImg = cvLoadImage("./HappyFish.jpg");
    9. if(pImg == NULL)
    10. std::cout<< "Error loading image"<<std::endl;
    11. cvShowImage("Image", pImg);
    12.  
    13. cvReleaseImage(&pImg);
    14.  
    15.  
    16. std::cout<< "start **********"<<std::endl;
    17. Mat image;
    18. image = imread("./cat.jpg"); // Read the file
    19.  
    20. if( !image.data ) { std::cout<< "Error loading src again"<<std::endl; }
    21. namedWindow( "Display window", 1 );// Create a window for display.
    22. imshow( "Display window", image ); // Show our image inside it.
    23.  
    24. waitKey(5000); // Wait for a keystroke in the window
    25. }
    To copy to clipboard, switch view to plain text mode 

    Since your OpenCV install is in the system standard directory your INCLUDEPATH does not need to be modified for OpenCV.
    The LIBS variable does not need a search path (-L) addition because the libs are already on the default search path.
    If I remove the INCLUDEPATH and LIBS part from the project I get many errors like this
    Qt Code:
    1. /home/ibr/projects/QTopenCV03/mainwindow.cpp:-1: error: undefined reference to `cvLoadImage'
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    So why don't you repeat the same line in your project file by adding the libraries to LIBS and include search paths to INCLUDEPATH.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Sep 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    So why don't you repeat the same line in your project file by adding the libraries to LIBS and include search paths to INCLUDEPATH
    I tried this but also negative.

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    What is negative? Do you get the exact same error? What does your project file look like?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    Quote Originally Posted by ibr_ex View Post
    Quote Originally Posted by Me
    Since your OpenCV install is in the system standard directory your INCLUDEPATH does not need to be modified for OpenCV.
    The LIBS variable does not need a search path (-L) addition because the libs are already on the default search path.
    If I remove the INCLUDEPATH and LIBS part from the project I get many errors like this
    Qt Code:
    1. /home/ibr/projects/QTopenCV03/mainwindow.cpp:-1: error: undefined reference to `cvLoadImage'
    To copy to clipboard, switch view to plain text mode 
    Read my advice again. It does not say remove the LIBS entry, it says you do not need the -L option that specifies the standard system path because the linker will search there anyway. The LIBS entry contains more than just the -L options, and these must stay. It does not say remove the INCLUDEPATH, it says the INCLUDEPATH does not need to be modified for OpenCV. There may be other things in INCLUDEPATH that need to stay.

    Now your manual compilation command is implying that OpenCV is not installed where you were previously telling us, i.e. under/usr/local rather than /usr.

    All that is secondary to the program that crashes after it is successfully compiled and linked. The reason for that is already in this thread.
    Last edited by ChrisW67; 18th September 2013 at 07:33.

  17. #17
    Join Date
    Sep 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    ========================================
    SOLVED I added the codes and my comments
    ========================================

    What is negative? Do you get the exact same error? What does your project file look like?
    Yes, same error code. The project file looks like this:
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-09-05T12:37:35
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    9. TARGET = QTopenCV03
    10. TEMPLATE = app
    11.  
    12. INCLUDEPATH += /usr/include/opencv2
    13.  
    14. LIBS += -L/usr/lib64
    15. LIBS += -lopencv_core
    16. LIBS += -lopencv_imgproc
    17. LIBS += -lopencv_highgui
    18. LIBS += -lopencv_features2d
    19. LIBS += -lopencv_calib3d
    20.  
    21. SOURCES += main.cpp\
    22. mainwindow.cpp
    23.  
    24. HEADERS += mainwindow.h
    25.  
    26. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    Read my advice again. It does not say remove the LIBS entry, it says you do not need the -L option that specifies the standard system path because the linker will search there anyway. The LIBS entry contains more than just the -L options, and these must stay. It does not say remove the INCLUDEPATH, it says the INCLUDEPATH does not need to be modified for OpenCV. There may be other things in INCLUDEPATH that need to stay.
    Sorry but still not clear which parts should be removed.
    ow your manual compilation command is implying that OpenCV is not installed where you were previously telling us, i.e. under/usr/local rather than /usr.
    I tried both of them. Not working!

    Anyway, today a friend helped me to solve it (thanks Urs). I would like to thank all members participated in this thread. It looks like the problem is with one of the images and the path for the images. Here is the content of the project file:
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-09-05T12:37:35
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    9. TARGET = QTopenCV03
    10. TEMPLATE = app
    11.  
    12. INCLUDEPATH += /usr/local/include/opencv
    13.  
    14. LIBS += -L /usr/local/lib
    15. LIBS += -lm
    16. LIBS += -lopencv_core
    17. LIBS += -lopencv_imgproc
    18. LIBS += -lopencv_highgui
    19. LIBS += -lopencv_objdetect
    20. LIBS += -lopencv_calib3d
    21.  
    22. SOURCES += main.cpp\
    23. mainwindow.cpp
    24.  
    25. HEADERS += mainwindow.h
    26.  
    27. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    and here is the contents of mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "opencv2/highgui/highgui.hpp"
    4. #include <iostream>
    5.  
    6. using namespace cv;
    7.  
    8. MainWindow::MainWindow(QWidget *parent) :
    9. QMainWindow(parent),
    10. ui(new Ui::MainWindow)
    11. {
    12. ui->setupUi(this);
    13. }
    14.  
    15. MainWindow::~MainWindow()
    16. {
    17. delete ui;
    18. }
    19.  
    20. void MainWindow::on_pushButton_clicked()
    21. {
    22.  
    23. // IplImage* pImg = cvLoadImage("./HappyFish.jpg"); // this one works only if I change the project work directory value
    24. IplImage* pImg = cvLoadImage("/home/ibr/projects/QTopenCV03/HappyFish.jpg"); // I should provide the complete path
    25. if(pImg == NULL)
    26. std::cout<< "Error loading image"<<std::endl; // no more error message
    27. namedWindow( "Display window 1", 1 );// Create a window for display. // not needed I guess
    28. cvShowImage("Image", pImg);
    29.  
    30. cvReleaseImage(&pImg);
    31.  
    32.  
    33. std::cout<< "start **********"<<std::endl;
    34. Mat image;
    35. // image = imread("/home/ibr/projects/QTopenCV03/catd.jpg"); // This image does not work but I will check this later, maybe qtcreator does not like cats :-P
    36. image = imread("/home/ibr/projects/QTopenCV03/HappyFish.jpg"); //works just fine
    37.  
    38. if( !image.data ) { std::cout<< "Error loading src again"<<std::endl; } // no more error message
    39. namedWindow( "Display window 2", 1 );// Create a window for display. // not needed I guess
    40. imshow( "Display window", image ); // Show our image inside it.
    41.  
    42.  
    43. //waitKey(5000); // wait 5 seconds
    44. waitKey(0); // Wait for a keystroke in the window
    45. }
    To copy to clipboard, switch view to plain text mode 


    See you guys in another problem :-D

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: the cv::imread OpenCV function can't read image file in Qt Creator

    I don't think an incorrect path to an image can cause a function to be missing in a library... If you compare your two project files, you will notice totally different directories set in INCLUDEPATH and LIBS.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Aug 2015
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Thumbs up Re: the cv::imread OpenCV function can't read image file in Qt Creator

    Quote Originally Posted by northbear View Post
    The Problem has been solved.
    Just modify the .pro file as the following:
    QT -= gui

    TARGET = myQtConsoleProject
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    INCLUDEPATH += E:\opencv\build\include\

    CONFIG(debug,debug|release){
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_core243d.lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_highgui243d.li b
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_imgproc243d.li b
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_features2d243d .lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_calib3d243d.li b
    }

    CONFIG(release,debug|release){
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_core243.lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_highgui243.lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_imgproc243.lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_features2d243. lib
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_calib3d243.lib
    }

    share this with all of you.
    Thanks, this worked for me

Similar Threads

  1. OpenCV integration with Qt creator
    By mind_freak in forum Qt Programming
    Replies: 11
    Last Post: 8th January 2013, 23:50
  2. read webcam with opencv
    By rodolfo.marques in forum Newbie
    Replies: 5
    Last Post: 1st July 2012, 09:30
  3. Qt Creator and OpenCV , .dll missing
    By schludy in forum Newbie
    Replies: 0
    Last Post: 30th November 2011, 11:11
  4. Using OpenCV with QT creator
    By gmiller39 in forum Newbie
    Replies: 3
    Last Post: 7th July 2010, 16:32
  5. Replies: 1
    Last Post: 16th October 2006, 08:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.