PDA

View Full Version : OpenCV 2.1 + Qt 4.6 on WindowsXP



pamalite
13th July 2010, 11:38
Hi,

I have been trying all day to get a very simple OpenCV based program to compile. I tried on a Mac with OpenCV installed from source, all work as expected and the program is able to load and process an image provided. However, I am having a ton of difficulties to even get it to compile on WindowsXP, let alone run it!

I have searched Google and this forum for all the possible resolutions, but they all failed. I tried using the reimp, dlltool and pexports tools to convert the pre-compiled DLLs and LIBs from OpenCV and tried to link it. The compiler will not compile at all, but keep spitting out 2 errors:

1. undefined reference to OpenCV's methods and functions; or
2. ld.exe cannot find the *.a file even it is there.

These were what I did:

1. undefined reference

a. I use the reimp tool to generate a *.def and *.a file from the supplied LIB files downloaded from OpenCV's website.

b. I updated the pro file with


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

win32:LIBS += "C:\OpenCV2.1-1\lib\libcv210.a" \
"C:\OpenCV2.1-1\lib\libcvaux210.a" \
"C:\OpenCV2.1-1\lib\libcxcore210.a" \
"C:\OpenCV2.1-1\lib\libhighgui210.a" \


The error I got:



debug/main.o: In function `main':
C:\cygwin\home\kwong13\opencv_test1/main.cpp:36: undefined reference to `cv::namedWindow(std::string const&, int)'
C:\cygwin\home\kwong13\opencv_test1/main.cpp:51: undefined reference to `cv::imshow(std::string const&, cv::Mat const&)'
C:\cygwin\home\kwong13\opencv_test1/main.cpp:55: undefined reference to `cv::waitKey(int)'
debug/main.o:C:\cygwin\home\kwong13\opencv_test1/../../../../OpenCV2.1/include/opencv/cxmat.hpp:378: undefined reference to `cv::fastFree(void*)'
collect2: ld returned 1 exit status


I have also tried following the MinGW tutorial on how to convert VC++ LIBs to MinGW's *.a. To no avail.



2. ld.exe cannot find the library even the file is there

a. I changed the pro file to


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

win32:LIBS += -l"C:\OpenCV2.1-1\lib\libcv210.a" \
-l"C:\OpenCV2.1-1\lib\libcvaux210.a" \
-l"C:\OpenCV2.1-1\lib\libcxcore210.a" \
-l"C:\OpenCV2.1-1\lib\libhighgui210.a"


And I get the following error:



g++ -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug\opencv_test1.exe debug/main.o -L"c:\Qt\2010.02.1\qt\lib" -lC:\OpenCV2.1-1\lib\libcv210.a -lC:\OpenCV2.1-1\lib\libcvaux210.a -lC:\OpenCV2.1-1\lib\libcxcore210.a -lC:\OpenCV2.1-1\lib\libhighgui210.a -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/cygwin/home/myhome/opencv_test1'
mingw32-make: Leaving directory `C:/cygwin/home/myhome/opencv_test1'
c:/qt/2010.02.1/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lC:\OpenCV2.1-1\lib\libcv210.a
collect2: ld returned 1 exit status


I have also tried with this entry in the pro file:


win32:LIBS += -L"C:/OpenCV2.1-1/lib" -lcv210 -lhighgui210 -lcxcore210


Same error.


Perhaps is there anyone had successfully got this working?

I did find one or two forum threads stating they got it working. However, they never share how they did it, and the entry date was quite old. Thus, I assume they have no intention of sharing their success.

Please, can someone, anyone, please help me! I am really stuck with this for the passed 8 hours. I do not want to compile OpenCV on WindowsXP as I am afraid it will break my another app that uses OpenCV through Java.

Please help!

pamalite
16th July 2010, 11:44
Problem solved!

I inevitably have to compile OpenCV 2.1 myself using MinGW to get it working.

I found another thread, not here, that redirected me to download TDM-GCC (http://tdm-gcc.tdragon.net/download), and abandoned the original MinGW. The reason is OpenCV 2.1 needs GCC 4.4.0 and above. The original MinGW comes with GCC 3.8.x. This can compile only up to maybe 40% of the framework and gives out errors.

So, what I did was:

1. Download and install CMake 2.8
2. Download and install MinGW by TDM.
3. Set a PATH to TDM MinGW's bin folder, if it is not set.
4. Generate the Makefiles needed using CMake by choosing MinGW option when asked.
5. Launch cmd, go to OpenCV's directory and type "mingw-make" or "mingw32-make".

After step 5, the DLLs will be placed in the bin/ folder and the *.dll.a files will be placed in the lib/ folder.

6. Update my PRO file with:


LIBS += "C:\OpenCV2.1\lib\libcv210.dll.a" \
"C:\OpenCV2.1\lib\libcvaux210.dll.a" \
"C:\OpenCV2.1\lib\libcxcore210.dll.a" \
"C:\OpenCV2.1\lib\libhighgui210.dll.a"

7. Build my OpenCV code and done. The build should work.

8. Copy the DLL files from the OpenCV2.1/bin folder to the debug/ or release/ folders, depends on the build mode, and run the code.

The copying is needed because I did not set a PATH to OpenCV and I plan to distribute my Qt apps with the DLLs. If you think this is troublesome, you will need to set a path to those DLLs.

9. You are done!


NOTE: As of this writing, somehow the methods found in highgui module is bugged. I cannot get it to display a window properly. However, I think this is not a too big of an issue as I can always display images as QImage, and I found a lot of tutorials and forum threads on how to do this in Qt. Hopefully the OpenCV developers fix the problem.

GopakumarG
10th December 2010, 06:57
Problem solved!

I inevitably have to compile OpenCV 2.1 myself using MinGW to get it working.

I found another thread, not here, that redirected me to download TDM-GCC (http://tdm-gcc.tdragon.net/download), and abandoned the original MinGW. The reason is OpenCV 2.1 needs GCC 4.4.0 and above. The original MinGW comes with GCC 3.8.x. This can compile only up to maybe 40% of the framework and gives out errors.

So, what I did was:

1. Download and install CMake 2.8
2. Download and install MinGW by TDM.
3. Set a PATH to TDM MinGW's bin folder, if it is not set.
4. Generate the Makefiles needed using CMake by choosing MinGW option when asked.
5. Launch cmd, go to OpenCV's directory and type "mingw-make" or "mingw32-make".

After step 5, the DLLs will be placed in the bin/ folder and the *.dll.a files will be placed in the lib/ folder.

6. Update my PRO file with:


LIBS += "C:\OpenCV2.1\lib\libcv210.dll.a" \
"C:\OpenCV2.1\lib\libcvaux210.dll.a" \
"C:\OpenCV2.1\lib\libcxcore210.dll.a" \
"C:\OpenCV2.1\lib\libhighgui210.dll.a"

7. Build my OpenCV code and done. The build should work.

8. Copy the DLL files from the OpenCV2.1/bin folder to the debug/ or release/ folders, depends on the build mode, and run the code.

The copying is needed because I did not set a PATH to OpenCV and I plan to distribute my Qt apps with the DLLs. If you think this is troublesome, you will need to set a path to those DLLs.

9. You are done!


NOTE: As of this writing, somehow the methods found in highgui module is bugged. I cannot get it to display a window properly. However, I think this is not a too big of an issue as I can always display images as QImage, and I found a lot of tutorials and forum threads on how to do this in Qt. Hopefully the OpenCV developers fix the problem.

Hi, I am very new to QT, and OpenCV. But I want to learn both, and I like to develop an Image Processing Application. I have installed Qt 4.6 and OpenCV 2.2. I opened a new GUI application in Qt and Simply paste the following code as main.cpp.
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QtGui>
#include<cv.h>
#include<highgui.h>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//MainWindow w;
//w.show();
cvNamedWindow( "My Window", 1 );
IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
CvFont font;
double hScale = 1.0;
double vScale = 1.0;
int lineWidth = 1;
cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
hScale, vScale, 0, lineWidth );
cvPutText( img, "Hello World!", cvPoint( 200, 400 ), &font,
cvScalar( 255, 255, 0 ) );
cvShowImage( "My Window", img );
cvWaitKey();
return a.exec();
}
Then did edit the .PRO file for INCLUDEPATH and LIBS as
INCLUDEPATH += C:\OpenCV2.2\include C:\OpenCV2.2\include\opencv
LIBS += C:\OpenCV2.2\lib\*.lib.

I didn't get any error message during build. But when I tried to run the program, I got the following error message Starting
C:\Qt\Examples\NewTest-build-desktop\debug\NewTest.exe...
C:\Qt\Examples\NewTest-build-desktop\debug\NewTest.exe exited with code -1073741510. I might be wrong. But your help will make me a quick start. Can anyone tell me, where did I went wrong...............

nman76
18th January 2011, 05:36
gopakkumarg.....I've tried your code and it's work but you must edit in your project *.pro on line:


LIBS += C:\OpenCV2.2\lib\*.lib.

change to


LIBS += C:\OpenCV2.2\bin\*.dll

here the result after i run it.

http://img14.imageshack.us/img14/4277/resultte.jpg

I use Qt 4.7, OpenCV 2.2 compiled in Mingw on windows7 OS.
May be this can help you..

jmarone
9th February 2011, 16:02
I have the same problem with opencv 2.2 . Don't Work . Help me please!!

5904

stampede
12th February 2011, 00:14
I didn't get any error message during build. But when I tried to run the program, I got the following error message Starting

I've had the same problem today.
Compiled OpenCV 2.2 on Windows XP ( g++ 4.5.2 ), everything is great until I run my program - everytime an OpenCV method is called, the app crashes.
Launched with gdb - crash was in void cv::cvt_( CvMat *, CvMat * ) everytime.

I have fixed this by recompiling OpenCV with SSE support disabled.
So, if you can build your app with OpenCV 2.2, but can't run it, try to recompile OpenCV without SSE / SSE2 support.

I've found this suggestion here: link (http://osdir.com/ml/digikam-devel/2010-11/msg00189.html)
I've used CMake, so I've only un-checked SSE / SSE2 options (instead of modifying CMakeList.txt file manually).

BennM
22nd February 2011, 00:33
Hi,

is it possible to use
double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS); with your setup when you capture a video from a webcam?

This is not possible to use too:

cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);

I only get fps = 0.0 on windows xp, opencv 2.2 and qt4.7