本文介绍了在Visual Studios 2010 Express C ++中为OpenCV2.3导入库时出现未解决的外部符号错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一次在这里向stackoverflow发布问题.对不起,如果我屠夫格式化!

我正在尝试遵循有关openCV的基础教程,即本教程: http://aishack.in/tutorials/tracking-colored-objects-in -opencv/

我在线上看过各种有关如何安装openCV的教程,包括:

为Visual Studio 2010设置OpenCV-2.3 和 opencv.willowgarage.com/wiki/VisualC%2B%2B

运气不好.

我当前正在运行的当前版本是OpenCV 2.3.0.我目前正在Windows 7和Microsoft Visual C ++ Express 2010上运行.

每当我尝试构建和运行代码时,都会出现以下错误:

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的path变量中包含DLL的路径:

;C:\OpenCV2.3\build\x64\vc10\bin;C:\OpenCV2.3\build\bin;

我看了其他论坛,其他堆栈溢出问题,等等,没有太多帮助.我一直在努力使它在周末的大部分时间里都能正常工作.任何帮助将不胜感激!

解决方案

如果您DID明确设置了与所有必需库的链接,但是仍然显示链接错误,则可能是在混用64/32位库和应用程序. /p>

即如果要构建32位应用程序,请确保所有库都包含指向32位版本的库.

first time posting a question here to stackoverflow. Sorry if I butcher the formatting!

I am attempting to follow a basic tutorial on openCV, namely this one:http://aishack.in/tutorials/tracking-colored-objects-in-opencv/

I have looked at various tutorial online on how to install openCV, including:

Setup OpenCV-2.3 for Visual Studio 2010and opencv.willowgarage.com/wiki/VisualC%2B%2B

without much luck.

The current version I have running right now is OpenCV 2.3.0.I am currently running on Windows 7 with Microsoft Visual C++ Express 2010.

Whenever I try to build and run my code, I get the following errors:

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 ==========

My code is as follows:

#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;

}

I have installed Open CV toC:\OpenCV2.3

I have added additional dependencies, additional directories, ect.For the preferences for my project, they are as follows:

Additional Dependencies:

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

Aditional Library Directories:C:\OpenCV2.3\build\x64\vc10\lib;C:\OpenCV2.3\build\x64\vc10\bin;C:\OpenCV2.3\build\x64\vc10\staticlib;%(AdditionalLibraryDirectories)

Additional Include Directories:

C:\OpenCV2.3\build\include\opencv;C:\OpenCV2.3\build\include\opencv2;C:\OpenCV2.3\build\include

I also included a path to the DLL's on my path variable for windows:

;C:\OpenCV2.3\build\x64\vc10\bin;C:\OpenCV2.3\build\bin;

I've looked at other forums, other stack overflow questions, ect without much help.I have been trying to get this to work for the better part of a weekend. Any help would be much appreciated!

解决方案

If you DID explicitly set up linking with all the necessary libraries, but linking errors still show, you might be mixing up 64/32 bit libraries and application.

I.e. make sure that all library includes point to 32 bit version of libraries if you are building 32 bit application.

这篇关于在Visual Studios 2010 Express C ++中为OpenCV2.3导入库时出现未解决的外部符号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 14:46