光流开路错误

时间:2013-11-29 15:15:42

标签: c++ opencv

我试图在2张图像中找到光流。我的代码提供了以下2个错误:

error LNK1120: 1 unresolved externals

error LNK2019: unresolved external symbol "void __cdecl cv::calcOpticalFlowPyrLK(
class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputArray 
const &,class cv::_OutputArray const &,class cv::_OutputArray const &,class 
cv::_OutputArray const &,class cv::Size_<int>,int,class cv::TermCriteria,double,
int)"(?calcOpticalFlowPyrLK@cv@@YAXABV_InputArray@1@00ABV_OutputArray@1@11V?$Size_
@H@1@HVTermCriteria@1@NH@Z) referenced in function "public: void __thiscall 
optical_flow::optical(void)" (?optical@optical_flow@@QAEXXZ)

代码如下所示。请帮我解决这个错误。如果我评论调用calcOpticalFlowPyrLK函数的行,我无法找到原因。它停止发出此错误。

void optical()
    {   
    // Load two images and allocate other structures

        Mat imgA = imread("a.jpg", CV_LOAD_IMAGE_GRAYSCALE);
        Mat imgB = imread("c.jpg", CV_LOAD_IMAGE_GRAYSCALE);
        Size img_sz = imgA.size();
        Mat imgC(img_sz,1);
        int win_size = 15;

        int maxCorners = 20;
        double qualityLevel = 0.05;
        double minDistance = 5.0;
        int blockSize = 3;

        double k = 0.04;
        std::vector<cv::Point2f> cornersA;
        cornersA.reserve(maxCorners);
        std::vector<cv::Point2f> cornersB;
        cornersB.reserve(maxCorners);

        goodFeaturesToTrack( imgA,cornersA,maxCorners,qualityLevel,minDistance,cv::Mat());

        goodFeaturesToTrack( imgB,cornersB,maxCorners,qualityLevel,minDistance,cv::Mat());
        cout<<"Runniung"<<endl;
        cornerSubPix( imgA, cornersA, Size( win_size, win_size ), Size( -1, -1 ),

        TermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03 ) );
        cornerSubPix( imgB, cornersB, Size( win_size, win_size ), Size( -1, -1 ),

        TermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03 ) );

        // Call Lucas Kanade algorithm
        CvSize pyr_sz = Size( img_sz.width+8, img_sz.height/3 );
        std::vector<uchar> features_found;
        features_found.reserve(maxCorners);

        std::vector<float> feature_errors;
        feature_errors.reserve(maxCorners);

        calcOpticalFlowPyrLK( imgA, imgB, cornersA, cornersB, features_found, feature_errors ,Size( win_size, win_size ), 5,cvTermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.3 ), 0 );

        // Make an image of the results


        for( int i=0; i < features_found.size(); i++ ){

         cout<<"Error is "<<feature_errors[i]<<endl;

         //continue;
         cout<<"Got it"<<endl;

         Point p0( ceil( cornersA[i].x ), ceil( cornersA[i].y ) );

         Point p1( ceil( cornersB[i].x ), ceil( cornersB[i].y ) );

         line( imgC, p0, p1, CV_RGB(255,255,255), 2 );

         }



         namedWindow( "ImageA", 0 );

         namedWindow( "ImageB", 0 );

         namedWindow( "LKpyr_OpticalFlow", 0 );



         imshow( "ImageA", imgA );

         imshow( "ImageB", imgB );

         imshow( "LKpyr_OpticalFlow", imgC );
         cvWaitKey(0);
        // return 0;

        //return 0;
    }

int _tmain(int argc, _TCHAR* argv[])
{
//  video obj("video.avi");
    optical_flow obj2;
    obj2.optical();
}

1 个答案:

答案 0 :(得分:1)

  

忘了链接opencv_video247.lib

这是@break的评论,它解决了我的问题,还有其他人,因为upvotes,这应该作为任何人试图找出哪个可能是链接问题的答案。

对于正在阅读此内容的任何人,请注意版本号可能与 247 不同,并且最后可以在 d 标记为调试版本所以它可能是:

opencv_video<version number>[d].lib
相关问题