Machine Learning Library OpenCV



  • i've tried to compile the CvEM example of the documentation (http://opencv.willowgarage.com/wiki/MachineLearning#Expectation-Maximization). i've set the library search path to opencv\lib and also the include path. i inlcude the -lml machine learning library however i got the following error:

    undefined reference to `CvEM::CvEM()'

    // CvEM em_model; CvEMParams params;

    if i comment CvEM em_model the code compiles - CvEMParams doesn't result in an error. so i think that i didn't have problems with the include paths!? does anyone know how to solve this problem? thank you in advance

    Also if i run the code in Visual Studio, it runs perfectly. best regards



  • Here what i have in the .pro

    INCLUDEPATH += "C:/OpenCV2.1/include/opencv"

    LIBS += -L"C:/OpenCV2.1/bin" -lcv210 -lcxcore210 -lcvaux210 -lhighgui210 -lml210 -lcxts210
    -lnetapi32



  • I gather that the code actually compiles fine, but fails at the linking stage? As you mention, that implies that your INCLUDE path is fine (especially since it's correctly finding the definition of the CvEMParams struct). Can you paste in the actual linker command that is failing?



  • Thank you Chris, here is the compilation output.
    @
    Running build steps for project Check...
    Configuration unchanged, skipping qmake step.
    Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
    C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory C:/Documents and Settings/Bush/Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug' g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -o debug\mainwindow.o ..\Check\mainwindow.cpp g++ -mthreads -Wl,-subsystem,windows -o debug\Check.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"c:\QtSDK\Desktop\Qt\4.7.4\mingw\lib" -lmingw32 -lqtmaind -LC:/OpenCV2.1/bin -lcv210 -lcxcore210 -lcvaux210 -lhighgui210 -lml210 -lcxts210 -lnetapi32 -lQtGuid4 -lQtCored4 -LC:\OpenSSL-Win32_full\lib debug/mainwindow.o: In functionMainWindow':
    C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:23: undefined reference to CvEM::CvEM()' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:49: undefined reference toCvEM::train(CvMat const*, CvMat const*, CvEMParams, CvMat*)'
    C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop
    -MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:59: undefined reference to CvEM::predict(CvMat const*, CvMat*) const' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference toCvEM::~CvEM()'
    C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop
    -MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference to CvEM::~CvEM()' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:23: undefined reference toCvEM::CvEM()'
    C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop
    -MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:49: undefined reference to CvEM::train(CvMat const*, CvMat const*, CvEMParams, CvMat*)' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:59: undefined reference toCvEM::predict(CvMat const*, CvMat*) const'
    C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop
    -MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference to CvEM::~CvEM()' mingw32-make[1]: Leaving directoryC:/Documents and Settings/Bush/Check-build-desktop-Qt_4_7_4_for_Desktop-MinGW_4_4__Qt_SDK__Debug'
    C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop
    -_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference to `CvEM::~CvEM()'
    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [debug\Check.exe] Error 1
    mingw32-make: *** [debug] Error 2
    The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project Check (target: Desktop)
    When executing build step 'Make' @



  • I see you are telling it to look for OpenCV in "C:/OpenCV2.1/bin" -- do you mean to be using "C:/OpenCV2.1/lib"?



  • I haven't noticed that, but for some bizarre reason it runs perfectly with the above syntax. I changed to /lib and same problem still persist. Here is the new compilation code

    @Running build steps for project Check...
    Configuration unchanged, skipping qmake step.
    Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
    C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory C:/Documents and Settings/Bush/Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug' c:\QtSDK\Desktop\Qt\4.7.4\mingw\bin\uic.exe ..\Check\mainwindow.ui -o ui_mainwindow.h g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -o debug\main.o ..\Check\main.cpp g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -o debug\mainwindow.o ..\Check\mainwindow.cpp C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -D__GNUC__ -DWIN32 ..\Check\mainwindow.h -o debug\moc_mainwindow.cpp g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include" -I"..\..\..\OpenCV2.1\include" -I"..\..\..\OpenCV2.1\include\opencv" -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"." -I"..\Check" -I"." -I"..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++" -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp g++ -mthreads -Wl,-subsystem,windows -o debug\Check.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"c:\QtSDK\Desktop\Qt\4.7.4\mingw\lib" -lmingw32 -lqtmaind -LC:/OpenCV2.1/lib -lcv210 -lcxcore210 -lcvaux210 -lhighgui210 -lml210 -lcxts210 -lnetapi32 -lQtGuid4 -lQtCored4 -LC:\OpenSSL-Win32_full\lib mingw32-make[1]: Leaving directoryC:/Documents and Settings/Bush/Check-build-desktop-Qt_4_7_4_for_Desktop_-MinGW_4_4__Qt_SDK__Debug'
    debug/mainwindow.o: In function MainWindow': C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:23: undefined reference toCvEM::CvEM()'
    C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop
    -MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference to CvEM::~CvEM()' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference toCvEM::~CvEM()'
    C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop
    -MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:23: undefined reference to CvEM::CvEM()' C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference toCvEM::~CvEM()'
    C:\Documents and Settings\Bush\Check-build-desktop-Qt_4_7_4_for_Desktop
    -_MinGW_4_4__Qt_SDK__Debug/../Check/mainwindow.cpp:76: undefined reference to `CvEM::~CvEM()'
    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [debug\Check.exe] Error 1
    mingw32-make: *** [debug] Error 2
    The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project Check (target: Desktop)
    When executing build step 'Make'@



  • Ordinarily the linker will tell you if it can't find a library, so presumably it is in fact finding cv210 someplace, but wherever it is, it does not actually contain the definition of the CvEM class. Did you compile it yourself, or download a binary? I'm not sure how to examine the contents of a library on windows, but on Linux and Mac the "nm" command will list all the symbols defined in there: you could grep that list for CvEM to make sure it's in there.



  • I downloaded it and didn't compile the library myself. The weird thing, if i copy/paste my code on visual studio, it runs perfectly without any problems which indicates the CvEM is there.

    Is it possible that ml210.lib compiled file is compatible with VS2010 and not with Qt, so maybe i need to compile the file myself ? (sorry for the noob question, i am not really experienced there)



  • Chris, I can't read/understand the compilation report i posted. Does it say that the library is linked properly or it doesn't mention such thing ? Many thanks



  • It doesn't say anything about the library: if it could not find the library I'd expect to see "library not found for -lcv210" or some such. When you compile it with VS, you are telling it to find this library in the same place it's looking here?



  • Yes Sir. And the same code just compile right away.



  • I'm afraid I'm not familiar enough with Windows libraries to help you much, then. Is there a difference between a library for use with VS2010 and one for use with gcc/mingw? If so then you should just need to compile a new version of OpenCV.



  • Hello Chris,

    I finally solved the issue. I just recompiled opencv with mingw (which qt uses) . Despite there were some libraries that worked with the cmake for vs2010 but apparently the one i wanted didn't.

    Hope the solution help some other dude.

    Cheers


Log in to reply
 

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