开发者

OpenCV 2.3 with Qt 4.3.7

开发者 https://www.devze.com 2023-03-25 12:54 出处:网络
I have succ开发者_运维知识库essfully build and ran both Qt 4.3.7 and OpenCV 2.3 with Qt enabled. When I start a window using:

I have succ开发者_运维知识库essfully build and ran both Qt 4.3.7 and OpenCV 2.3 with Qt enabled. When I start a window using:

cvNamedWindow( "video", 0 );

I successfully load a full Qt interface! wonderful :)

However!! when I use the command

void callbackButton(int state, void* userdata){
int x;
x=3;
}

cvCreateButton(nameb2,callbackButton,nameb2,CV_CHECKBOX,0);

I get the error message

error LNK2001: unresolved external symbol _cvCreateButton

I don't understand as the Qt interface already has lots of buttons on it? could someone please explain what I am missing from the include that could cause this?

Thanks!


You use the wrong parameters for to call to cvCreateButton. According to the documentation here the signature of the function is

cvCreateButton(const char* button_name CV_DEFAULT(NULL), CvButtonCallback on_change CV_DEFAULT(NULL), void* userdata CV_DEFAULT(NULL), int button_type CV_DEFAULT(CV_PUSH_BUTTON), int initial_button_state CV_DEFAULT(0)

and sample calls are:

cvCreateButton(NULL,callbackButton);
cvCreateButton("button2",callbackButton,NULL,CV_CHECKBOX,0);
cvCreateButton("button3",callbackButton,&value);
cvCreateButton("button5",callbackButton1,NULL,CV_RADIOBOX);
cvCreateButton("button6",callbackButton2,NULL,CV_PUSH_BUTTON,1);

and the declaration of the callback function has to be:

CV_EXTERN_C_FUNCPTR( *CvButtonCallback)(int state, void* userdata));

You get a linking error and not a compiler error because cvCreateButton has extern "C" linkage - which means that parameters cannot be checked at compile time.


I solved this issue by calling the function cv::createButton instead of cvCreateButton (which is if I am correct the way to call methods in OpenCV2).


The third argument must be a void*. Change to:

cvCreateButton(nameb2,callbackButton,NULL,CV_CHECKBOX,0);

and it will work.

Edit

The statement above was given an error. The third needed argument is a "void *" - this is compatible with anything and thus neither C nor C++ should have a problem with what you were providing. You can not raise a linker error with that.

The only reason a linker error can be raised by coding is when you don't use prototypes (forgot to use the header file) in C++ and then C++ creates a mangled name on its own that wont be part of any library. In such a case the compiler will first tell you with a warning at compile time that you are missing the prototype (for C and C++) - and then the linker will probably raise an error (for c++ only).

If you don't see a prototype warning from the compiler then that is not your problem.


This is a linking error. Try to add the opencv .lib file (or files) to the project libraries path. This may help : VS2010 OpenCV.

Edit

Refined problem: Even if adding any OpenCV libary to your project the linking will fail.

Reason: The symbol is often simply not there in the libraries.

Solution: You have to change a few settings and compile them on your own.

See also: openCV 2.2 createButton LNK 2019 error in Visual Studio 2010

0

精彩评论

暂无评论...
验证码 换一张
取 消