1 | #include <iostream>
|
2 | #include <time.h>
|
3 | #include <cstdlib>
|
4 | #include <numeric>
|
5 | #include <fstream>
|
6 |
|
7 | #include <sys/time.h>
|
8 |
|
9 | #include <opencv2/core/core.hpp>
|
10 | #include <opencv2/highgui/highgui.hpp>
|
11 | #include <opencv2/imgproc/imgproc.hpp>
|
12 | #include <opencv2/gpu/gpu.hpp>
|
13 |
|
14 | using namespace std;
|
15 |
|
16 | int main()
|
17 | {
|
18 | int num_bottle=0;
|
19 |
|
20 | cv::Mat frame;
|
21 | cv::VideoCapture capture;
|
22 | cv::Mat image,main_image;
|
23 | cv::gpu::GpuMat gpu_image, gpu_main_image, gpu_circles;
|
24 | cv::vector<cv::Vec3f> circles;
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | string video="/home/marco/Videos/video1.mp4";
|
30 |
|
31 |
|
32 | int ROI_video[4]={86, 650, 1070, 70};
|
33 |
|
34 |
|
35 | int hough_param[6]={1, 100, 24, 18, 25, 28};
|
36 |
|
37 |
|
38 | try {
|
39 |
|
40 | capture.open(video);
|
41 | do
|
42 | {
|
43 |
|
44 | if (!capture.read(frame)) break;
|
45 |
|
46 | image=frame(cv::Rect(ROI_video[0], ROI_video[1], ROI_video[2], ROI_video[3]));
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | cv::cvtColor(image,main_image,CV_BGR2GRAY);
|
56 | cv::GaussianBlur(main_image, main_image, cv::Size(5, 5), 1, 1);
|
57 |
|
58 | gpu_main_image.upload(main_image);
|
59 | cv::gpu::HoughCircles(gpu_main_image, gpu_circles, CV_HOUGH_GRADIENT,hough_param[0], hough_param[1], hough_param[2],hough_param[3], hough_param[4], hough_param[5]);
|
60 | cv::gpu::HoughCirclesDownload(gpu_circles, circles);
|
61 | num_bottle += circles.size();
|
62 |
|
63 | } while(true);
|
64 |
|
65 | cout << "\nNumero Bottiglie totale: " << num_bottle << endl;
|
66 |
|
67 | return 0;
|
68 |
|
69 | } catch (cv::Exception& e){
|
70 | const char* err_msg = e.what();
|
71 | cout<<err_msg<< endl;
|
72 | return 1;
|
73 | }
|
74 | }
|