Advertisement
kzbr93

new code

May 9th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. // Standard include files
  2.  
  3. #include <iostream>
  4. #include <opencv2/opencv.hpp>
  5. #include <opencv2/core.hpp>
  6. #include <opencv2/imgproc.hpp>
  7. #include <opencv2/highgui.hpp>
  8. #include <opencv2/tracking/tracking.hpp>
  9. #include <opencv2/videoio.hpp>
  10. #include <opencv2/video.hpp>
  11. #include <opencv2/imgcodecs.hpp>
  12.  
  13.  
  14. using namespace cv;
  15. using namespace std;
  16.  
  17. int main(int argc, char **argv)
  18. {
  19. // Set up tracker.
  20. // Instead of MIL, you can also use
  21. // BOOSTING, KCF, TLD, MEDIANFLOW or GOTURN
  22. Ptr<Tracker> tracker = Tracker::create( "MIL" );
  23.  
  24. VideoCapture cap(0); //capture the video from webcam
  25.  
  26. if ( !cap.isOpened() ) // if not success, exit program
  27. {
  28. cout << "Cannot open the web cam" << endl;
  29. return -1;
  30. }
  31.  
  32. Mat frame;
  33. cap>>frame;
  34. cap.read(frame);
  35.  
  36.  
  37. // Define an initial bounding box
  38. Rect2d bbox(287, 23, 86, 320);
  39.  
  40. // Uncomment the line below if you
  41. // want to choose the bounding box
  42. // bbox = selectROI(frame, false);
  43.  
  44. // Initialize tracker with first frame and bounding box
  45. tracker->init(frame, bbox);
  46.  
  47. while(cap.read(frame))
  48. {
  49. // Update tracking results
  50. tracker->update(frame, bbox);
  51.  
  52. // Draw bounding box
  53. rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 );
  54.  
  55. // Display result
  56. imshow("Tracking", frame);
  57. int k = waitKey(1);
  58. if(k == 27) break;
  59.  
  60. }
  61.  
  62. return 0;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement