2012-05-06 29 views
7

lần đầu tiên đăng câu hỏi ở đây để stackoverflow. Xin lỗi nếu tôi bán thịt định dạng!lỗi biểu tượng bên ngoài chưa được giải quyết khi nhập thư viện cho OpenCV2.3 trong Visual Studio 2010 Express C++

Tôi đang cố gắng làm theo một hướng dẫn cơ bản về OpenCV, cụ thể là cái này: http://aishack.in/tutorials/tracking-colored-objects-in-opencv/

tôi đã xem xét nhiều hướng dẫn trực tuyến về cách cài đặt OpenCV, bao gồm:

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

mà không có nhiều may mắn.

Phiên bản hiện tại tôi đang chạy ngay bây giờ là OpenCV 2.3.0. Tôi hiện đang chạy trên Windows 7 với Microsoft Visual C++ nhanh 2010.

Bất cứ khi nào tôi cố gắng xây dựng và chạy mã của tôi, tôi nhận được các lỗi sau đây:

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 *)" ([email protected]@[email protected]@[email protected]@Z) 
1>camera.obj : error LNK2019: unresolved external symbol _cvInRangeS referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" ([email protected]@[email protected]@[email protected]@Z) 
1>camera.obj : error LNK2019: unresolved external symbol _cvCvtColor referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" ([email protected]@[email protected]@[email protected]@Z) 
1>camera.obj : error LNK2019: unresolved external symbol _cvCreateImage referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetTh[email protected]@[email protected]@[email protected]@Z) 
1>camera.obj : error LNK2019: unresolved external symbol _cvGetSize referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" ([email protected]@[email protected]@[email protected]@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 ========== 

Mã của tôi là như sau:

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

} 

tôi đã cài đặt mở CV để C:\OpenCV2.3

tôi đã thêm phụ thuộc bổ sung, thêm thư mục itional, vv. Đối với các ưu đãi cho dự án của tôi, họ là như sau:

Dependencies bổ sung:

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 Thư viện Thư mục: Bao gồm C:\OpenCV2.3\build\x64\vc10\lib;C:\OpenCV2.3\build\x64\vc10\bin;C:\OpenCV2.3\build\x64\vc10\staticlib;%(AdditionalLibraryDirectories)

bổ sung Thư mục:

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

Tôi cũng bao gồm một đường dẫn đến DLL trên biến đường dẫn của tôi cho các cửa sổ:

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

Tôi đã xem các diễn đàn khác, các câu hỏi tràn ngăn xếp khác, vv mà không cần trợ giúp nhiều. Tôi đã cố gắng để có được điều này để làm việc cho một phần tốt hơn của một ngày cuối tuần. Bất kì sự trợ giúp nào đều được đánh giá cao!

+1

tại sao cùng một câu hỏi được hỏi hai lần trong vòng 4 giờ: http://stackoverflow.com/questions/10472393/opencv-wont-compile-due-to-unresolved-externals-lnk2019#comment13530952_10472393 – guinny

Trả lời

19

Nếu bạn DID rõ ràng thiết lập liên kết với tất cả các cần thiết thư viện, nhưng các lỗi liên kết vẫn hiển thị, bạn có thể đang trộn các thư viện và ứng dụng 64/32 bit.

I.e. đảm bảo rằng tất cả thư viện bao gồm điểm tới phiên bản 32 bit của thư viện nếu bạn đang xây dựng ứng dụng 32 bit.

+3

FYI: BUILD -> Trình quản lý cấu hình. kiểm tra 'nền tảng' là 'x64'. – plhn

+0

+1 cho cài đặt nền tảng Trình quản lý cấu hình. Thx plhn. – user1738934

3

Tôi đã có một vấn đề tương tự trong khi tôi đang cố gắng để biên dịch cvblob thư viện (http://code.google.com/p/cvblob/) trên Windows 7 32bit với Visual Studio 2010.

Nếu tất cả mọi thứ khác được thực hiện đúng thử đoán của tôi được viết dưới đây. Nếu không bắt đầu với những hướng dẫn:

  • Cài đặt OpenCV: http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html#cpptutwindowsmakeown
  • Cấu hình dự án của bạn để xây dựng và làm việc với opencv: http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#windows-visual-studio-how-to.

    Những lỗi mối liên kết silimar biến mất sau khi thay đổi một số dự án tính:

    • Trong VS 2010 mở giải pháp của bạn
    • mở solution explorer (View-> Solution Explorer)
    • Tìm một dự án mà đã tạo ra các lỗi liên kết này. (Trong ví dụ của tôi nó là một dự án được gọi là "cvblob" bên trong giải pháp gọi là "cvBlob" tạo ra bởi cmake.)
    • nhấn chuột phải về dự án mà
    • Từ menu ngữ cảnh chọn tính
    • Trên trái chọn properties Configuration -> General và tìm thấy một lĩnh vực được gọi "mở rộng mục tiêu"
    • Trong Thông tin chi tiết dự án tìm các cài đặt dự án của bạn cho "Loại Configuration"
    • phân tích chúng. Trong vấn đề cụ thể của tôi về biên dịch cvblob tôi đã phải đặt Mở rộng mục tiêu tới .libLoại cấu hình để Thư viện tĩnh. Đây cũng là giải pháp cho những người đang cố gắng biên dịch thư viện cvblob trong Visual Studio 2010. Làm tương tự cho phiên bản Gỡ lỗi và Phát hành nếu cần.

lỗi tôi là:

Error 24 error LNK2019: unresolved external symbol _cvSetImageROI referenced in function _cvSetImageROItoBlob C:\cvblob\build\lib\cvblob.obj cvblob

Error 25 error LNK2019: unresolved external symbol _cvSaveImage referenced in function _cvSaveImageBlob C:\cvblob\build\lib\cvblob.obj cvblob

Error 26 error LNK2019: unresolved external symbol _cvGetImageROI referenced in function _cvSaveImageBlob C:\cvblob\build\lib\cvblob.obj cvblob

Error 27 error LNK2001: unresolved external symbol _cvError C:\cvblob\build\lib\cvcolor.obj cvblob

Error 28 error LNK2019: unresolved external symbol _cvError referenced in function _cvRenderBlob C:\cvblob\build\lib\cvblob.obj cvblob

Error 29 error LNK2001: unresolved external symbol _cvError C:\cvblob\build\lib\cvlabel.obj cvblob

Error 30 error LNK2001: unresolved external symbol _cvError C:\cvblob\build\lib\cvcontour.obj cvblob

Error 31 error LNK2001: unresolved external symbol _cvError C:\cvblob\build\lib\cvtrack.obj cvblob

Error 32 error LNK2019: unresolved external symbol _cvLine referenced in function _cvRenderBlob C:\cvblob\build\lib\cvblob.obj cvblob

Error 33 error LNK2001: unresolved external symbol _cvLine C:\cvblob\build\lib\cvcontour.obj cvblob

Error 34 error LNK2019: unresolved external symbol _cvRectangle referenced in function _cvRenderBlob C:\cvblob\build\lib\cvblob.obj cvblob

Error 35 error LNK2001: unresolved external symbol _cvRectangle C:\cvblob\build\lib\cvtrack.obj cvblob

Error 36 error LNK2019: unresolved external symbol _cvSetZero referenced in function _cvLabel C:\cvblob\build\lib\cvlabel.obj cvblob

Error 37 error LNK2019: unresolved external symbol _cvPutText referenced in function _cvRenderTracks C:\cvblob\build\lib\cvtrack.obj cvblob

Error 38 error LNK2019: unresolved external symbol _cvInitFont referenced in function _cvRenderTracks C:\cvblob\build\lib\cvtrack.obj cvblob

Error 39 error LNK1120: 9 unresolved externals C:\cvblob\build\lib\libs\Release\cvblob.dll cvblob

Tôi hy vọng nó sẽ giúp một ai đó biên soạn thư viện cvblob trong visual studio 2010.

+0

Rất tốt! Đã xây dựng mỏ, nhưng bây giờ làm thế nào để tôi chạy nó? : P – JSideris

+0

Đồng ý, làm thế nào để bạn chạy nó ngay bây giờ? –

+0

đây chỉ là khi bạn xây dựng một lib không phải là một thực thi ..... – user1767754

1

Tôi đã gặp sự cố tương tự, trong vs10

tôi đã bỏ lỡ "opencv_core246d.lib" để thêm. thêm nó vào Linker-> Input-> Aditional Dependencies cố định lỗi.

1

Điều này có thể trợ giúp với phiên bản mới hơn.
Đối với phiên bản 2.4.8, thêm opencv_imgproc248.lib giải quyết các lỗi liên kết sau đây:

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 
2

Tôi có vấn đề tương tự trong VS10 và tôi đã quên để thêm cv210d.lib. Thêm vào đó các thuộc tính của project -> các thuộc tính cấu hình-> Linker-> Input-> Dependencies Aditional giúp tôi giải quyết vấn đề này. Tôi tìm thấy từ câu hỏi rằng opencv_cv230.lib không được bao gồm trong các phụ thuộc bổ sung thêm vào đó sẽ giúp giải quyết vấn đề.

0

đối với tôi, lỗi này đã được giải quyết bằng cách thêm hai tên lib một cách rõ ràng dưới đầu vào (thuộc tính cấu hình -> trình liên kết -> đầu vào -> phụ thuộc bổ sung).

khi bạn cài đặt opencv, dựa trên phiên bản, nó sẽ có số được nối thêm vào. Ví dụ tôi có opencv2.4.13 và nó có 2413 nối thêm vào tất cả các thư viện của nó, opencv_highgui2413.lib (opencv_highgui2413d.lib để gỡ lỗi xây dựng).

Bây giờ, hãy kiểm tra xem các thư viện nào có các chức năng được hiển thị do lỗi. highgui có chức năng cvshowimage -> bạn có thể làm điều này bằng cách xén nó trực tuyến. http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html

Sau đó, thêm lib đó để nhập và tạo giải pháp của bạn.

Các vấn đề liên quan