我正在尝试编写代码以在Visual Studio 2010环境中的Windows窗体上显示来自摄像头的视频。以下是我的代码:
#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);
}
}
}
}; }
首先,我的计算机上安装了.NET Framework 4.5.1。但是当我编译代码时,我收到了这个错误:
&#34; LINK:致命错误LNK1123:转换为COFF期间失败:文件无效或损坏&#34;
我寻找解决方案,发现Visual Studio 2010只适用于.NET Framework 4.我卸载了4.5.1版并安装了版本4.但之后,我收到了这个错误:
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
你能告诉我如何处理这件事吗?
答案 0 :(得分:1)
您可以尝试将代码进一步降低到最低限度,在此之前您应该这样做。无论如何,我想从短视角来看问题是你的&#34; extern&#34;告诉编译器某处有给定类型和名称的对象,但你必须确保它确实存在。您可能想要的是告诉编译器创建这样一个对象(请注意,指针是一个对象,根据C ++对象模型),您可以通过删除&#34; extern&#34;来实现。
如果将来由于多重定义的符号而导致链接器错误,请执行相反的操作:只保留一个没有extern的地方,其他所有地方都是extern。