Guest User

Untitled

a guest
May 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include "opencv2/opencv.hpp"
  4. #include "opencv2/objdetect/objdetect.hpp"
  5. #include "opencv2/highgui/highgui.hpp"
  6. #include "opencv2/imgproc/imgproc.hpp"
  7. #include "opencv2/cudaobjdetect.hpp"
  8. #include "opencv2/cudaimgproc.hpp"
  9. #include "opencv2/cudawarping.hpp"
  10.  
  11. using namespace std;
  12. using namespace cv;
  13.  
  14. void main()
  15. {
  16. Ptr<cuda::HOG> d_hog = cuda::HOG::create(Size(64, 128));
  17. d_hog->setSVMDetector(d_hog->getDefaultPeopleDetector());
  18. Mat img;
  19. VideoCapture cap("Source.mp4");
  20. cap >> img;
  21. if (img.empty())
  22. return;
  23. namedWindow("People motion tracking", 0);
  24. unsigned long AAtime = 0, BBtime = 0;
  25. double scale = float(1080) / img.cols;
  26. cuda::GpuMat GpuImg, rGpuImg;
  27. GpuImg.upload(img);
  28. cuda::resize(GpuImg, rGpuImg, Size(GpuImg.cols * scale, GpuImg.rows * scale));
  29. Mat rInimg;
  30. rGpuImg.download(rInimg);
  31. while (true)
  32. {
  33. AAtime = getTickCount();
  34. cap >> img;
  35. if (img.empty())
  36. break;
  37. GpuImg.upload(img);
  38. cuda::resize(GpuImg, rGpuImg, Size(GpuImg.cols * scale, GpuImg.rows * scale));
  39. rGpuImg.download(rInimg);
  40. cuda::cvtColor(rGpuImg, rGpuImg, CV_BGR2GRAY);
  41. vector<Point> found_locations;
  42. d_hog->detect(rGpuImg, found_locations);
  43. std::vector<Rect> found_locations_rect;
  44. d_hog->detectMultiScale(rGpuImg, found_locations_rect);
  45. for (int i = 0; i < found_locations_rect.size(); ++i)
  46. {
  47. rectangle(rInimg, found_locations_rect[i], CvScalar(0, 0, 255), 1);
  48. }
  49. imshow("People motion tracking", rInimg);
  50. waitKey(10);
  51. BBtime = getTickCount();
  52. double s_time = (BBtime - AAtime) / getTickFrequency();
  53. double fps_time = 1 / s_time;
  54. printf("%.2lf sec / %.2lf fps \n", s_time, fps_time);
  55. }
  56. }
Add Comment
Please, Sign In to add comment