C++ visualc&x2B+;包含OpenCV 2.4.9编译错误
我正在尝试编写一个代码,以便在VisualStudio2010环境中在windows窗体上显示来自摄像头的视频。下面是我的代码:C++ visualc&x2B+;包含OpenCV 2.4.9编译错误,c++,opencv,C++,Opencv,我正在尝试编写一个代码,以便在VisualStudio2010环境中在windows窗体上显示来自摄像头的视频。下面是我的代码: #pragma once #include <opencv\cv.h> #include <opencv\highgui.h> extern CvCapture* cam; extern IplImage* image,*image_copy; static CvMemStorage* storage = 0; static CvHaar
#pragma once
#include <opencv\cv.h>
#include <opencv\highgui.h>
extern CvCapture* cam;
extern IplImage* image,*image_copy;
static CvMemStorage* storage = 0;
static CvHaarClassifierCascade* cascade = 0;
extern const char* cascade_name;
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
cam=cvCaptureFromCAM(-1);
image=cvQueryFrame(cam);
if ((videoBox->Image==nullptr))
{
Bitmap^img1=gcnew Bitmap(videoBox->Width,videoBox->Height);
videoBox->Image=img1;
}
cascade=(CvHaarClassifierCascade*)cvLoad(cascade_name,0,0,0);
storage=cvCreateMemStorage(0);
if(cam)
{
{
if(!image_copy)
image_copy=cvCreateImage(cvSize(image->width,image->height),IPL_DEPTH_8U,image->nChannels);
if(image->origin==IPL_ORIGIN_TL)
cvCopy(image,image_copy,0);
else cvFlip(image,image_copy,0);
//khai bao mang mau
static CvScalar colors[] =
{
{{0,0,255}},//red
{{0,128,255}},//orange
{{0,255,255}},//cyan
{{0,255,0}},//green
{{255,128,0}},//blue
{{255,255,0}},//yellow
{{255,0,0}},//blue+
{{255,0,255}}//pink
};
double scale = 1.3;
IplImage* gray = cvCreateImage( cvSize(image_copy->width,image_copy->height), 8, 1 );
IplImage* small_img = cvCreateImage( cvSize( cvRound (image_copy->width/scale),cvRound (image_copy->height/scale)),8,1);
//int i;
cvCvtColor( image_copy, gray, CV_BGR2GRAY );
cvResize( gray, small_img, CV_INTER_LINEAR );
cvEqualizeHist( small_img, small_img );
cvClearMemStorage( storage );
Graphics^ g = Graphics::FromImage(videoBox->Image);
Bitmap^ anh2 = gcnew Bitmap(image_copy->width,image_copy->height,image_copy->widthStep,System::Drawing::Imaging::PixelFormat::Format24bppRgb, IntPtr(image_copy->imageData));
g->DrawImage(anh2, (videoBox->Width-image_copy->width)/2, (videoBox->Height-image_copy->height)/2);
videoBox->Refresh();
delete(g);
}
}
}
您能告诉我如何处理这个问题吗?您可以尝试将代码进一步缩减到最低限度,以后在这里询问之前您应该这样做。总之,我从一个简短的角度猜测,问题在于您的“extern”告诉编译器某个地方有一个给定类型和名称的对象,但您必须确保它确实存在。您可能想要告诉编译器创建这样的对象(注意,指针是一个对象,根据C++对象模型),通过删除“Extn”来实现。
如果将来由于多个定义的符号而导致链接器错误,请执行相反的操作:只保留一个没有extern的位置,其他所有位置都有extern。您所说的“附带OpenCV 2.4.9”是什么意思?据我所知,OpenCV未随Visual Studio 2010安装。它是一个附加组件,你必须从它下载吗?请不要使用OpenCV的不受欢迎的C-API,而是C++ API(CV:MAT)。为什么所有的外部修饰符?这些变量是否在别处定义?(如果没有,这是您的链接器错误)我已经删除了“extern”并重新声明如下:名称空间{CvCapture*cam=0;IplImage*image,image\u copy=0;const char cascade\u name=“haarcascade\u frontalface\u alt2.xml”;}但是,我仍然得到相同的错误。你能告诉我如何纠正这些错误吗?非常感谢你。
1>Manual_Mode.obj : error LNK2020: unresolved token (0A0007F1) "extern "C" void __cdecl cvClearMemStorage(struct CvMemStorage *)" (?cvClearMemStorage@@$$J0YAXPAUCvMemStorage@@@Z)
1>Control_Interface.obj : error LNK2028: unresolved token (0A0007FF) "extern "C" void __cdecl cvClearMemStorage(struct CvMemStorage *)" (?cvClearMemStorage@@$$J0YAXPAUCvMemStorage@@@Z) referenced in function "private: void __clrcall Control_Interface::Manual_Mode::timer1_Tick(class System::Object ^,class System::EventArgs ^)" (?timer1_Tick@Manual_Mode@Control_Interface@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Control_Interface.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z) referenced in function "public: void __thiscall cv::SparseMat::addref(void)" (?addref@SparseMat@cv@@$$FQAEXXZ)
1>Manual_Mode.obj : error LNK2001: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z)
1>C:\Users\admin\Desktop\Control_Interface\Debug\Control_Interface.exe : fatal error LNK1120: 51 unresolved externals