forked from CihanTopal/ED_Lib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
video_test.cpp
96 lines (79 loc) · 3.25 KB
/
video_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "EDLib.h"
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/ximgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
using namespace cv::ximgproc;
int main(int argc, const char** argv)
{
cv::CommandLineParser parser(argc, argv,
"{scale|1|}"
"{counter|99999|}"
"{show|false|}"
"{@filename|vtest.avi|}"
);
String filename = parser.get<string>("@filename");
double scale = parser.get<double>("scale");
int test_counter = parser.get<int>("counter");
bool show = parser.get<bool>("show");
Mat src, gray;
TickMeter tm0, tm1;
int counter = 0;
VideoCapture capture(samples::findFileOrKeep(filename));
if (capture.isOpened())
{
cout << "Capture is opened, " << capture.get(CAP_PROP_FRAME_COUNT) << " frames" << endl;
cout << "Frame [width,height] : [" << capture.get(CAP_PROP_FRAME_WIDTH) << "," << capture.get(CAP_PROP_FRAME_HEIGHT) << "]" << endl;
cout << "Scaled[width,height] : [" << capture.get(CAP_PROP_FRAME_WIDTH) * scale << "," << capture.get(CAP_PROP_FRAME_HEIGHT) * scale << "]" << endl;;
Ptr<EdgeDrawing> ed = createEdgeDrawing();
ed->params.EdgeDetectionOperator = EdgeDrawing::SOBEL;
ed->params.GradientThresholdValue = 36;
ed->params.AnchorThresholdValue = 8;
ed->params.ScanInterval = 1;
vector<Vec6d> ellipses;
vector<Vec4f> lines;
for (;;)
{
capture >> src;
test_counter--;
if (src.empty() || test_counter < 0)
break;
resize(src, src, Size(), scale, scale);
cvtColor(src, gray, COLOR_BGR2GRAY);
tm0.start();
ed->detectEdges(gray);
ed->detectLines(lines);
ed->detectEllipses(ellipses);
tm0.stop();
counter++;
tm1.start();
ED testED = ED(gray, SOBEL_OPERATOR, 36, 8, 1, 10, 1.0, true);
EDLines testEDLines = EDLines(testED);
EDCircles testEDCircles = EDCircles(testEDLines);
tm1.stop();
if (show)
{
std::vector<LS> linesegments = testEDLines.getLines();
Mat lineImg0 = testEDLines.getLineImage(); //draws on an empty image
Mat lineImg1 = Mat(lineImg0.rows, lineImg0.cols, CV_8UC1, Scalar(255));
for (int i = 0; i < lines.size(); i++)
line(lineImg1, Point2d(lines[i][0], lines[i][1]), Point2d(lines[i][2], lines[i][3]), Scalar(0), 1, LINE_AA);
Mat diff;
absdiff(lineImg0, lineImg1, diff);
imshow("lineImg0", lineImg0);
imshow("lineImg1", lineImg1);
imshow("diff", diff);
imshow("gray", gray);
waitKey();
}
}
cout << "OpenCV processed " << counter << " frames in " << tm0.getTimeMilli() << " ms.";
cout << "\t\tfps : " << counter * 1000 / tm0.getTimeMilli() << endl;
cout << "EDCircles processed " << counter << " frames in " << tm1.getTimeMilli() << " ms.";
cout << "\t\tfps : " << counter * 1000 / tm1.getTimeMilli() << endl;
}
return 0;
}