2011-09-13 63 views
3

我在VS2010中安裝openCV2.3.1。我可以在openCV中讀取圖像而不會出現任何錯誤。但是當我從文件夾open/samples/cpp運行camshiftdemo時。它顯示這個錯誤。我無法在openCV中運行camshift演示

1> All outputs are up-to-date. 
1>main.obj : error LNK2019: unresolved external symbol "class cv::RotatedRect __cdecl cv::CamShift(class cv::_InputArray const &,class cv::Rect_<int> &,class cv::TermCriteria)" ([email protected]@@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) referenced in function _main 
1>c:\users\pkru\documents\visual studio 2010\Projects\TestCmean\Debug\TestCmean.exe : fatal error LNK1120: 1 unresolved externals 
1> 
1>Build FAILED 

當我註釋此行// RotatedRect trackBox = CamShift的(backproj,trackWindow, TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER,10,1));它沒有錯誤。

在我的另一個代碼它表明這樣的錯誤。這是我的代碼測試meanshift

int main() 
{ 
    // Read reference image 
    cv::Mat image= cv::imread("Desert.jpg"); 
    if (!image.data) 
     return 0; 

    // Define ROI 
    cv::Mat imageROI= image(cv::Rect(110,260,35,40)); 
    cv::rectangle(image, cv::Rect(110,260,35,40),cv::Scalar(0,0,255)); 

    // Display image 
    cv::namedWindow("Image"); 
    cv::imshow("Image",image); 

    // Get the Hue histogram 
    int minSat=65; 
    ColorHistogram hc; 
    //cv::MatND colorhist= hc.getHueHistogram(imageROI,minSat); 

    ObjectFinder finder; 
    //finder.setHistogram(colorhist); 
    finder.setThreshold(0.2f); 

    // Convert to HSV space 
    cv::Mat hsv; 
    cv::cvtColor(image, hsv, CV_BGR2HSV); 

    // Split the image 
    vector<cv::Mat> v; 
    cv::split(hsv,v); 

    // Eliminate pixels with low saturation 
    cv::threshold(v[1],v[1],minSat,255,cv::THRESH_BINARY); 
    cv::namedWindow("Saturation"); 
    cv::imshow("Saturation",v[1]); 

    // Get back-projection of hue histogram 
    int ch[1]={0}; 
    cv::Mat result= finder.find(hsv,0.0f,180.0f,ch,1); 

    cv::namedWindow("Result Hue"); 
    cv::imshow("Result Hue",result); 

    cv::bitwise_and(result,v[1],result); 
    cv::namedWindow("Result Hue and"); 
    cv::imshow("Result Hue and",result); 

    // Second image 
    image= cv::imread("Desert.jpg"); 

    // Display image 
    cv::namedWindow("Image 2"); 
    cv::imshow("Image 2",image); 

    // Convert to HSV space 
    cv::cvtColor(image, hsv, CV_BGR2HSV); 

    // Split the image 
    cv::split(hsv,v); 

    // Eliminate pixels with low saturation 
    cv::threshold(v[1],v[1],minSat,255,cv::THRESH_BINARY); 
    cv::namedWindow("Saturation"); 
    cv::imshow("Saturation",v[1]); 

    // Get back-projection of hue histogram 
    result= finder.find(hsv,0.0f,180.0f,ch,1); 

    cv::namedWindow("Result Hue"); 
    cv::imshow("Result Hue",result); 

    // Eliminate low stauration pixels 
    cv::bitwise_and(result,v[1],result); 
    cv::namedWindow("Result Hue and"); 
    cv::imshow("Result Hue and",result); 

    // Get back-projection of hue histogram 
    finder.setThreshold(-1.0f); 
    result= finder.find(hsv,0.0f,180.0f,ch,1); 
    cv::bitwise_and(result,v[1],result); 
    cv::namedWindow("Result Hue and raw"); 
    cv::imshow("Result Hue and raw",result); 

    cv::Rect rect(110,260,35,40); 
    cv::rectangle(image, rect, cv::Scalar(0,0,255)); 

    cv::TermCriteria criteria(cv::TermCriteria::MAX_ITER,10,0.01); 
// cout << "meanshift= " << cv::meanShift(result,rect,criteria) << endl; 

    cv::rectangle(image, rect, cv::Scalar(0,255,0)); 

    // Display image 
    cv::namedWindow("Image 2 result"); 
    cv::imshow("Image 2 result",image); 

    cv::waitKey(); 
    return 0; 
} 

當我運行此代碼時,它顯示此錯誤。

1> main.cpp 
1>ManifestResourceCompile: 
1> All outputs are up-to-date. 
1>main.obj : error LNK2001: unresolved external symbol "int __cdecl cv::meanShift(class cv::_InputArray const &,class cv::Rect_<int> &,class cv::TermCriteria)" ([email protected]@@[email protected]@[email protected]@[email protected]@[email protected]@Z) 
1>c:\users\pkru\documents\visual studio 2010\Projects\TestCmean\Debug\TestCmean.exe : fatal error LNK1120: 1 unresolved externals 
1> 
1>Build FAILE 
+0

在Linux :'-lopencv_video'。 –

回答

7

的CamShift的和均值漂移方法是視頻\跟蹤模塊的一部分,所以你可能忘記了opencv_videoXXX.lib

0

鏈接的OpenCV 3.2 的情況下,添加鏈接爲「-lopencv_video」