Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Standard include files
- #include <iostream>
- #include <opencv2/opencv.hpp>
- #include <opencv2/core.hpp>
- #include <opencv2/imgproc.hpp>
- #include <opencv2/highgui.hpp>
- #include <opencv2/tracking/tracking.hpp>
- #include <opencv2/videoio.hpp>
- #include <opencv2/video.hpp>
- #include <opencv2/imgcodecs.hpp>
- using namespace cv;
- using namespace std;
- int main(int argc, char **argv)
- {
- // Set up tracker.
- // Instead of MIL, you can also use
- // BOOSTING, KCF, TLD, MEDIANFLOW or GOTURN
- Ptr<Tracker> tracker = Tracker::create( "MIL" );
- VideoCapture cap(0); //capture the video from webcam
- if ( !cap.isOpened() ) // if not success, exit program
- {
- cout << "Cannot open the web cam" << endl;
- return -1;
- }
- Mat frame;
- cap>>frame;
- cap.read(frame);
- // Define an initial bounding box
- Rect2d bbox(287, 23, 86, 320);
- // Uncomment the line below if you
- // want to choose the bounding box
- // bbox = selectROI(frame, false);
- // Initialize tracker with first frame and bounding box
- tracker->init(frame, bbox);
- while(cap.read(frame))
- {
- // Update tracking results
- tracker->update(frame, bbox);
- // Draw bounding box
- rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 );
- // Display result
- imshow("Tracking", frame);
- int k = waitKey(1);
- if(k == 27) break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement