QtCreator, OpenCV245: No debugger, No output



  • Hi All,

    I am seeking to integrate OpenCV 245 with Qt using pre-built binaries from OpenCV for Microsoft's Visual Studio 2010. However, while I can include my opencv headers, and the libraries are not throwing any linking errors, when running the program, Qt skips over all the opencv code showing me the console with a request to press return to close the console. In addition (thinking Qt can't find my image with an absolute or relative path), the breakpoint(s) I set is completely missed by Qt throwing me aa debugger crashed message.

    My question is: 1) Is my integration with opencv(in terms of the .pro file and the use of correct bitsize libraries) fine? 2) Is there a way to verify if my debugger is working correctly?

    Any help is greatly appreciated.

    I am using Qt Creator 5.1.1, with 32-bit compiler, and 64bit cdb debugger. My system is Win.7, 64bit.

    Here is the code to run in Qt
    #include <QCoreApplication>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    cv::Mat im2g;
    im2g = cv::imread("img.jpg");
    if(im2g.empty())
    return -1;
    cv::namedWindow("Test");
    cv::imshow("Test",im2g);
    cv::waitKey(0);
    return a.exec();
    }

    Here is the .pro file:
    QT += core
    QT -= gui
    TARGET = testOpenCVOpenNI
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    INCLUDEPATH += C:\opencv\build\include
    CONFIG(release,debug|release)
    {
    LIBS += -LC:\opencv\build\x86\vc10\lib
    -lopencv_core245
    -lopencv_highgui245
    -lopencv_imgproc245
    -lopencv_features2d245
    -lopencv_calib3d245
    }

    CONFIG(debug,debug|release)
    {
    LIBS += -LC:\opencv\build\x86\vc10\lib
    -lopencv_core245d
    -lopencv_highgui245d
    -lopencv_imgproc245d
    -lopencv_features2d245d
    -lopencv_calib3d245d
    }

    Here are a subset of the debugging output I get:
    *** WARNING: Unable to verify checksum for TestOpenCV2.exe
    Obtained breakpoint 0x2ed3b8 (#1), at 0x2e1394, module: 'TestOpenCV2'
    All breakpoints have been resolved.
    Assembly options: source_line
    Qt Creator CDB extension version 2.8 64 bit built Aug 6 2013.
    dTaking notice of pid 8208
    dNOTE: INFERIOR SETUP OK
    dState changed from InferiorSetupRequested(4) to InferiorSetupOk(6) [master]
    dState changed from InferiorSetupOk(6) to EngineRunRequested(7) [master]
    dQUEUE: RUN ENGINE
    dCALL: RUN ENGINE
    <g

    dNOTE: ENGINE RUN AND INFERIOR RUN OK
    sRunning.
    dState changed from EngineRunRequested(7) to InferiorRunOk(11) [master]
    ModLoad: 0000000076c80000 0000000076d9f000 WOW64_IMAGE_SECTION
    ModLoad: 0000000076900000 0000000076a10000 WOW64_IMAGE_SECTION
    ModLoad: 0000000076c80000 0000000076d9f000 NOT_AN_IMAGE
    ModLoad: 0000000076da0000 0000000076e9a000 NOT_AN_IMAGE
    ModLoad: 0000000076900000 0000000076a10000 C:\Windows\syswow64\kernel32.dll
    ModLoad: 0000000076840000 0000000076887000 C:\Windows\syswow64\KERNELBASE.dll
    sProcess exited (3221225781)
    eERROR: Process crashed
    eERROR: CDB crashed
    dNOTE: ENGINE SPONTANEOUS SHUTDOWN
    dState changed BY FORCE from InferiorRunOk(11) to EngineShutdownOk(22) [master]
    dState changed from EngineShutdownOk(22) to DebuggerFinished(23) [master]
    dQUEUE: FINISH DEBUGGER
    dNOTE: FINISH DEBUGGER
    dHANDLE RUNCONTROL FINISHED
    sDebugger finished.

    Any help to get this done will be appreciated.



  • A few things I did to make sure I can read:

    I put my image in the same directory as my .exe file for the build I am working on. For instance, doing a debug build for 32bit MSVS10 compiler, I put the image in the build_projectname_compiler_debug folder. This seems to be ok with opencv and opencv can read the image.

    With the above code, I do a clean all, run qmake, build, then run. I get the console window telling me to press return to close the window. If I try a debug (click the beetle) after setting a breakpoint, the debugger crashes. OK

    With the above code, I change the .pro file to the following:

    ... everything same as above...
    CONFIG(release,debug|release)
    {
    LIBS += -LC:\opencv\build\x86\vc10\bin \ #<<change here
    -lopencv_core245
    -lopencv_highgui245
    -lopencv_imgproc245
    -lopencv_features2d245
    -lopencv_calib3d245
    }

    CONFIG(debug,debug|release)
    {
    LIBS += -LC:\opencv\build\x86\vc10\bin \ #change here
    -lopencv_core245d
    -lopencv_highgui245d
    -lopencv_imgproc245d
    -lopencv_features2d245d
    -lopencv_calib3d245d
    }

    OTHER_FILES += \ #Was also included in the failed run
    img.JPG

    Then I do another qmake (no clean), build only project, run, and presto, everything works as it should. If I do another clean all, run qmake, and build, everything stops working and I get a build error that it can't link to one of the opencv files (core245).

    Can anyone tell me what I am doing incorrectly? It would help so that I can reproduce correct opencv interaction with qt later.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    -LC:\opencv\build\x86\vc10\XXX << should point to where the OpenCV vc10 .lib files can be found.

    When running your application, you have to ensure that the dlls can be found. Check the PATH environment variable in the run panel and add C:\opencv\build\x86\vc10\bin (i assume the dlls are there) to it.

    When opening a file (image or other) from your application using relative path you have to keep in mind that this path is relative to your executable file and not the source of your code. To avoid this kind of problem while developing, use absolute file paths so you ensure that they'll be found.

    Hope it helps



  • Thank you SGaist for the quick reply.

    I have another question: In VS10, I can do a post build event that copies the required dlls to a folder VS10 can read. Is there an equivalent in Qt for this? This is to circumvent using the PATH environment.



  • At present, my solution is not working. My . pro file is as follows:

    SOURCES += main.cpp

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

    CONFIG(release,debug|release)
    {
    LIBS += -LC:\opencv\build\x86\vc10\lib
    -lopencv_core245
    -lopencv_highgui245
    -lopencv_imgproc245
    -lopencv_features2d245
    -lopencv_calib3d245
    }

    CONFIG(debug,debug|release)
    {
    LIBS += -LC:\opencv\build\x86\vc10\lib
    -lopencv_core245d
    -lopencv_highgui245d
    -lopencv_imgproc245d
    -lopencv_features2d245d
    -lopencv_calib3d245d
    }

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

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    cv::Mat im2g;
    im2g = cv::imread("img.jpg");//images for opencv in the build folder where .exe app is
    if(im2g.empty())
    return -1;
    cv::namedWindow("Test");
    cv::namedWindow("Test2");
    cv::Mat tl;
    im2g.copyTo(tl);
    cv::add(tl,100,tl);
    cv::imshow("Test2",tl);
    cv::imshow("Test",im2g);
    cv::waitKey(0);
    return a.exec();
    }
    My image (img.jpg), is in every folder in my build directory.

    With this, I am still getting a blank console, with a request to press return to close the screen. My debugger also is not working (does not stop at breakpoints-flashes a screen, says Process crashed, CDB crashed.

    Anyone have any ideas that can help me out?
    Thanks

    My code is as follows:


  • Lifetime Qt Champion

    Please use coding tags when you write code, it'll make it readable (you can edit your post and add them)

    Did you update the PATH environment variable in the Run panel ?



  • Thanks SGaist for the quick reply. I did not know how to make the code look prettier but now I do.

    Also, I apologize for how late MY reply is. It has been a busy week.

    In order to get QT working with OpenCV from the .pro environment, I modified my code to the following:

    In the .pro file for a qt console application:
    @
    QT += core
    QT -= gui
    TARGET = TestCV
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp

    #OpenCV 2.4.5 includes, library files (.lib), dll files (.dll) in the bin folder
    #Using Visual Studio 2010 build, for x86 compiler
    INCLUDEPATH += C:\opencv\build\include\

    LIBS+= -LC:\opencv\build\x86\vc10\lib
    -lopencv_calib3d245d
    -lopencv_contrib245d
    -lopencv_core245d
    -lopencv_features2d245d
    -lopencv_flann245d
    -lopencv_gpu245d
    -lopencv_highgui245d
    -lopencv_haartraining_engined
    -lopencv_imgproc245d
    -lopencv_legacy245d
    -lopencv_ml245d
    -lopencv_nonfree245d
    -lopencv_objdetect245d
    -lopencv_photo245d
    -lopencv_stitching245d
    -lopencv_superres245d
    -lopencv_ts245d
    -lopencv_video245d
    -lopencv_videostab245d

    LIBS+= -LC:\opencv\build\x86\vc10\bin #directory for .dlls
    @

    My code to test this is as follows:

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

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    //try to load image using absolute path
    cv::Mat image = cv::imread("C:/images/testImg.jpg");

    //Check if successful load image
    if(!image.data)
    {
    //Tell user image loading did not work
    std::cout <<"No image loaded. No image found"<<std::endl;
    }
    else
    {
    //Image loading worked so display to user
    cv::namedWindow("Test");
    cv::imshow("Test",image);
    }

    return a.exec&#40;&#41;;
    

    }@

    The .pro file seems to modify PATH environment at runtime to include the two locations added with LIB variable.

    This seems easier than modifying the PATH environment in the RUN settings.

    Does anyone know if this is a good method to use?


  • Lifetime Qt Champion

    You are right, Creator seems to update PATH adding the directories added to LIBS.

    It's not necessarily "The Right Thing To Do ™" since it won't help outside Qt Creator and basically not the purpose of LIBS, but you can keep that as a workaround



  • Thanks SGaist. I will keep it until something better comes along. I appreciate all the help.


  • Lifetime Qt Champion

    You're welcome !

    In between since you got it working, please update the thread title prepending [solved] so other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.