第一次在这里向stackoverflow发帖提问。对不起,如果我屠杀格式化!
我正在尝试关注openCV的基础教程,即这个: http://aishack.in/tutorials/tracking-colored-objects-in-opencv/
我在线查看了有关如何安装openCV的各种教程,包括:
Setup OpenCV-2.3 for Visual Studio 2010 和 opencv.willowgarage.com/wiki/VisualC%2B%2B
没有太多运气。我现在运行的当前版本是OpenCV 2.3.0。 我目前正在使用Microsoft Visual C ++ Express 2010在Windows 7上运行。
每当我尝试构建并运行我的代码时,都会出现以下错误:
1>------ Build started: Project: Camera, Configuration: Debug Win32 ------
1>camera.obj : error LNK2019: unresolved external symbol _cvReleaseImage referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage@@YAPAU_IplImage@@PAU1@@Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvInRangeS referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage@@YAPAU_IplImage@@PAU1@@Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvCvtColor referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage@@YAPAU_IplImage@@PAU1@@Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvCreateImage referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage@@YAPAU_IplImage@@PAU1@@Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvGetSize referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage@@YAPAU_IplImage@@PAU1@@Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvReleaseCapture referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvWaitKey referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvShowImage referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvAdd referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvLine referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvGetCentralMoment referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvGetSpatialMoment referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvMoments referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvQueryFrame referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvNamedWindow referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvCreateCameraCapture referenced in function _main
1>C:\Users\Kevin\Documents\Visual Studio 2010\Projects\Camera\Debug\Camera.exe : fatal error LNK1120: 16 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我的代码如下:
#include "cv.h"
#include "highgui.h"
IplImage* GetThresholdedImage(IplImage* img)
{
IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
cvCvtColor(img, imgHSV, CV_BGR2HSV);
IplImage* imgThreshed = cvCreateImage(cvGetSize(img), 8, 1);
cvInRangeS(imgHSV, cvScalar(20, 100, 100), cvScalar(30, 255, 255), imgThreshed);
cvReleaseImage(&imgHSV);
return imgThreshed;
}
int main()
{
CvCapture* capture = 0;
capture = cvCaptureFromCAM(1);
if(!capture)
{
printf("Could not initialize capturing...\n");
getchar();
return -1;
}
cvNamedWindow("video");
cvNamedWindow("thresh");
IplImage* imgScribble = NULL;
while(1)
{
IplImage* frame = 0;
frame = cvQueryFrame(capture);
if(!frame)
break;
//cvErode(frame, frame, 0, 2); // ADD this line
//initalize the scribble frame if has not already been done yet
if(imgScribble == NULL)
{
imgScribble = cvCreateImage(cvGetSize(frame), 8, 3);
}
IplImage* imgYellowThresh = GetThresholdedImage(frame);
CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments));
cvMoments(imgYellowThresh, moments, 1);
// The actual moment values
double moment10 = cvGetSpatialMoment(moments, 1, 0);
double moment01 = cvGetSpatialMoment(moments, 0, 1);
double area = cvGetCentralMoment(moments, 0, 0);
// Holding the last and current ball positions
static int posX = 0;
static int posY = 0;
int lastX = posX;
int lastY = posY;
posX = moment10/area;
posY = moment01/area;
printf("position (%d,%d)\n", posX, posY);
// We want to draw a line only if its a valid position
if(lastX>0 && lastY>0 && posX>0 && posY>0)
{
// Draw a yellow line from the previous point to the current point
cvLine(imgScribble, cvPoint(posX, posY), cvPoint(lastX, lastY), cvScalar(0,255,255), 5);
}
cvAdd(frame, imgScribble, frame);
cvShowImage("thresh", imgYellowThresh);
cvShowImage("video", frame);
int c = cvWaitKey(5);
if((char)c==27 )
break;
// Release the thresholded image+moments... we need no memory leaks.. please
cvReleaseImage(&imgYellowThresh);
delete moments;
}
// We're done using the camera. Other applications can now use it
cvReleaseCapture(&capture);
cvReleaseCapture(&capture);
return 0;
}
我已经安装了Open CV
C:\OpenCV2.3
我添加了其他依赖项,其他目录等。 对于我的项目的偏好,它们如下:
附加依赖项:
enter code here
opencv_core230.lib
opencv_highgui230.lib
opencv_legacy230.lib
opencv_video230.lib
opencv_ml230.lib
opencv_core230d.lib
opencv_highgui230d.lib
opencv_legacy230d.lib
opencv_video230d.lib
opencv_ml230d.lib
opencv_calib3d230d.lib
传统图书馆目录:
C:\OpenCV2.3\build\x64\vc10\lib;C:\OpenCV2.3\build\x64\vc10\bin;C:\OpenCV2.3\build\x64\vc10\staticlib;%(AdditionalLibraryDirectories)
其他包含目录:
C:\OpenCV2.3\build\include\opencv;C:\OpenCV2.3\build\include\opencv2;C:\OpenCV2.3\build\include
我还在Windows的路径变量中包含了DLL的路径:
;C:\OpenCV2.3\build\x64\vc10\bin;C:\OpenCV2.3\build\bin;
我看过其他论坛,其他堆栈溢出问题等等,没有太多帮助。 我一直试图让这个周末的大部分工作。任何帮助将不胜感激!
答案 0 :(得分:20)
如果您明确设置了与所有必需库的链接,但链接错误仍然显示,则可能会混合使用64/32位库和应用程序。
即。如果要构建32位应用程序,请确保所有库都包含指向32位版本的库。
答案 1 :(得分:3)
当我尝试使用Visual Studio 2010在Windows 7 32位上编译cvblob库(http://code.google.com/p/cvblob/)时,我遇到了类似的问题。
如果其他一切都正确完成,请尝试我的猜测,如下所示。 如果不是从这些教程开始:
配置项目以构建和使用opencv:http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#windows-visual-studio-how-to。
更改某些项目后,这些silimar链接器错误消失了 属性:
我得到的错误是:
错误24错误LNK2019:未解析的外部符号_cvSetImageROI 在函数中引用 _cvSetImageROItoBlob C:\ cvblob \ build \ lib \ cvblob.obj cvblob
错误25错误LNK2019:未解析的外部符号_cvSaveImage 在函数中引用 _cvSaveImageBlob C:\ cvblob \ build \ lib \ cvblob.obj cvblob
错误26错误LNK2019:未解析的外部符号_cvGetImageROI 在函数中引用 _cvSaveImageBlob C:\ cvblob \ build \ lib \ cvblob.obj cvblob
错误27错误LNK2001:未解析的外部符号 _cvError C:\ cvblob \ build \ lib \ cvcolor.obj cvblob
错误28错误LNK2019:未解析的外部符号_cvError已引用 在函数_cvRenderBlob C:\ cvblob \ build \ lib \ cvblob.obj cvblob
错误29错误LNK2001:未解析的外部符号 _cvError C:\ cvblob \ build \ lib \ cvlabel.obj cvblob
错误30错误LNK2001:未解析的外部符号 _cvError C:\ cvblob \ build \ lib \ cvcontour.obj cvblob
错误31错误LNK2001:未解析的外部符号 _cvError C:\ cvblob \ build \ lib \ cvtrack.obj cvblob
错误32错误LNK2019:引用了未解析的外部符号_cvLine 在函数_cvRenderBlob C:\ cvblob \ build \ lib \ cvblob.obj cvblob
错误33错误LNK2001:未解析的外部符号 _cvLine C:\ cvblob \ build \ lib \ cvcontour.obj cvblob
错误34错误LNK2019:未解析的外部符号_cvRectangle 在函数中引用 _cvRenderBlob C:\ cvblob \ build \ lib \ cvblob.obj cvblob
错误35错误LNK2001:未解析的外部符号 _cvRectangle C:\ cvblob \ build \ lib \ cvtrack.obj cvblob
错误36错误LNK2019:未解析的外部符号_cvSetZero 函数_cvLabel中引用C:\ cvblob \ build \ lib \ cvlabel.obj cvblob
错误37错误LNK2019:未解析的外部符号_cvPutText 在函数中引用 _cvRenderTracks C:\ cvblob \ build \ lib \ cvtrack.obj cvblob
错误38错误LNK2019:未解析的外部符号_cvInitFont 在函数中引用 _cvRenderTracks C:\ cvblob \ build \ lib \ cvtrack.obj cvblob
错误39错误LNK1120:9未解决 外部C:\ cvblob \ build \ lib \ libs \ Release \ cvblob.dll cvblob
我希望它能帮助有人在visual studio 2010中编译cvblob库。
答案 2 :(得分:2)
我在vs10中遇到了类似的问题,我忘了添加cv210d.lib
。将其添加到项目属性 - >配置属性 - > Linker-> Input-> Aditional Dependencies帮助我解决了这个问题。我从问题中发现opencv_cv230.lib
未包含在其他依赖项中,这有助于解决问题。
答案 3 :(得分:1)
我在vs10中遇到了同样的问题
我错过了要添加的“opencv_core246d.lib”。将其添加到链接器 - >输入 - > Aditional Dependencies已修复错误。
答案 4 :(得分:1)
这可能对新版本有所帮助 对于2.4.8版,添加opencv_imgproc248.lib可解决以下链接错误:
error LNK2019: unresolved external symbol _cvRemap referenced in function _main
error LNK2019: unresolved external symbol _cvInitUndistortMap referenced in function _main
error LNK2019: unresolved external symbol _cvFindCornerSubPix referenced in function _main
error LNK2019: unresolved external symbol _cvCvtColor referenced in function _main
答案 5 :(得分:0)
对我来说,通过在输入下明确添加两个lib名称来解决此错误(配置属性 - >链接器 - >输入 - >其他依赖项)。
安装opencv时,根据版本,它会附加一个数字。例如,我有opencv2.4.13并且它的所有库附加了2413,opencv_highgui2413.lib(用于调试版本的opencv_highgui2413d.lib)。
现在,检查哪些库具有错误中显示的功能。 highgui有cvshowimage函数 - >你可以通过在线搜索得到这个。 http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html
然后添加该lib以输入和构建您的解决方案。