2017-06-20 203 views
1

我正在研究涉及跟踪对象的项目,并试图让OpenCV contrib repo的TrackerKCF工作。这是示例代码,我在网上得到:OpenCV:无法从contrib存储库中找到模块(跟踪器,selectROI)

#include <opencv2/core/utility.hpp> 
#include <opencv2/video/tracking.hpp> 
#include <opencv2/videoio.hpp> 
#include <opencv2/highgui.hpp> 
#include <iostream> 
#include <cstring> 

using namespace std; 
using namespace cv; 

int main(int argc, char** argv){ 
    // show help 
    if(argc<2){ 
    cout<< 
     " Usage: example_tracking_kcf <video_name>\n" 
     " examples:\n" 
     " example_tracking_kcf Bolt/img/%04.jpg\n" 
     " example_tracking_kcf faceocc2.webm\n" 
     << endl; 
    return 0; 
    } 

    // create the tracker 
    Ptr<Tracker> tracker = TrackerKCF::create(); 

    // set input video 
    std::string video = argv[1]; 
    VideoCapture cap(video); 

    Mat frame; 

    // get bounding box 
    cap >> frame; 
    Rect2d roi= selectROI("tracker", frame, true, false); 

    //quit if ROI was not selected 
    if(roi.width==0 || roi.height==0) 
    return 0; 

    // initialize the tracker 
    tracker->init(frame,roi); 

    // do the tracking 
    printf("Start the tracking process, press ESC to quit.\n"); 
    for (;;){ 
    // get frame from the video 
    cap >> frame; 

    // stop the program if no more images 
    if(frame.rows==0 || frame.cols==0) 
     break; 

    // update the tracking result 
    bool isfound = tracker->update(frame,roi); 
    if(!isfound) 
    { 
     cout << "The target has been lost...\n"; 
     waitKey(0); 
     return 0; 
    } 

    // draw the tracked object 
    rectangle(frame, roi, Scalar(255, 0, 0), 2, 1); 

    // show image with the tracked object 
    imshow("tracker",frame); 

    //quit on ESC button 
    if(waitKey(1)==27)break; 
    } 
} 

但是,我得到了以下错误:

tracktest.cpp: In function ‘int main(int, char**)’: 
tracktest.cpp:33:7: error: ‘Tracker’ was not declared in this scope 
    Ptr<Tracker> tracker = TrackerKCF::create(); 
    ^
tracktest.cpp:33:14: error: template argument 1 is invalid 
    Ptr<Tracker> tracker = TrackerKCF::create(); 
      ^
tracktest.cpp:33:26: error: ‘TrackerKCF’ has not been declared 
    Ptr<Tracker> tracker = TrackerKCF::create(); 
         ^
tracktest.cpp:43:54: error: ‘selectROI’ was not declared in this scope 
    Rect2d roi= selectROI("tracker", frame, true, false); 
                ^
tracktest.cpp:50:10: error: base operand of ‘->’ is not a pointer 
    tracker->init(frame,roi); 
     ^
tracktest.cpp:63:27: error: base operand of ‘->’ is not a pointer 
    bool isfound = tracker->update(frame,roi); 
         ^
./tracktest.sh: line 5: ./tracktest: No such file or directory 

我试图重新安装OpenCV的3.1.0和相应的contrib回购,这似乎make完成得很好。我还试图找到tracker.cpp在我的OpenCV源目录中,但没有弹出。

我认为这是因为我错误地安装了contrib模块,但我不确定。任何人都可以弄清楚什么是错的?提前致谢。

+0

我想跟踪头文件是''。包括这个文件,看看它是否有效。 – sgarizvi

+0

没有'tracking.hpp' :( 'tracktest.cpp:16:32:致命错误:opencv2/tracking.hpp:没有这样的文件或目录 编译已终止 ./tracktest.sh:第5行:./ tracktest:没有这样的文件或目录 ' – zeklewa

+0

也我认为这已经包含在'#include ' – zeklewa

回答

0

由于我莫名的愚蠢,我忘了跑make install。 现在都很好!

+0

我仍然收到错误::错误:'selectROI'未在此范围内声明 –

+0

有没有办法可以检查我是否安装了opencv_contrib? –