简体   繁体   中英

error in optical flow opencv

I am trying to find the optical flow in 2 images . My code gives 2 following errors :

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)

code is shown below . please help me resolving this error . I am unable to find the reason if i comment the line calling calcOpticalFlowPyrLK function. It stops giving this error.

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();
}

forgot to link against opencv_video247.lib

This is the comment of @break which solved my problem, and others too, because of the upvotes, and this should be posted as answer for anybody trying to figure out which may be the link problem.

To anyone who is reading this, keep in mind that version number may be different than 247 and that it can have a d at the end to mark that is for debug version so it could be:

opencv_video<version number>[d].lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM