Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/cpp/application_trace.cpp
16337 views
1
/* OpenCV Application Tracing support demo. */
2
#include <iostream>
3
4
#include <opencv2/core.hpp>
5
#include <opencv2/imgproc.hpp>
6
#include <opencv2/highgui.hpp>
7
#include <opencv2/core/utils/trace.hpp>
8
9
using namespace cv;
10
using namespace std;
11
12
static void process_frame(const cv::UMat& frame)
13
{
14
CV_TRACE_FUNCTION(); // OpenCV Trace macro for function
15
16
imshow("Live", frame);
17
18
UMat gray, processed;
19
cv::cvtColor(frame, gray, COLOR_BGR2GRAY);
20
Canny(gray, processed, 32, 64, 3);
21
imshow("Processed", processed);
22
}
23
24
int main(int argc, char** argv)
25
{
26
CV_TRACE_FUNCTION();
27
28
cv::CommandLineParser parser(argc, argv,
29
"{help h ? | | help message}"
30
"{n | 100 | number of frames to process }"
31
"{@video | 0 | video filename or cameraID }"
32
);
33
if (parser.has("help"))
34
{
35
parser.printMessage();
36
return 0;
37
}
38
39
VideoCapture capture;
40
std::string video = parser.get<string>("@video");
41
if (video.size() == 1 && isdigit(video[0]))
42
capture.open(parser.get<int>("@video"));
43
else
44
capture.open(video);
45
int nframes = 0;
46
if (capture.isOpened())
47
{
48
nframes = (int)capture.get(CAP_PROP_FRAME_COUNT);
49
cout << "Video " << video <<
50
": width=" << capture.get(CAP_PROP_FRAME_WIDTH) <<
51
", height=" << capture.get(CAP_PROP_FRAME_HEIGHT) <<
52
", nframes=" << nframes << endl;
53
}
54
else
55
{
56
cout << "Could not initialize video capturing...\n";
57
return -1;
58
}
59
60
int N = parser.get<int>("n");
61
if (nframes > 0 && N > nframes)
62
N = nframes;
63
64
cout << "Start processing..." << endl
65
<< "Press ESC key to terminate" << endl;
66
67
UMat frame;
68
for (int i = 0; N > 0 ? (i < N) : true; i++)
69
{
70
CV_TRACE_REGION("FRAME"); // OpenCV Trace macro for named "scope" region
71
{
72
CV_TRACE_REGION("read");
73
capture.read(frame);
74
75
if (frame.empty())
76
{
77
cerr << "Can't capture frame: " << i << std::endl;
78
break;
79
}
80
81
// OpenCV Trace macro for NEXT named region in the same C++ scope
82
// Previous "read" region will be marked complete on this line.
83
// Use this to eliminate unnecessary curly braces.
84
CV_TRACE_REGION_NEXT("process");
85
process_frame(frame);
86
87
CV_TRACE_REGION_NEXT("delay");
88
if (waitKey(1) == 27/*ESC*/)
89
break;
90
}
91
}
92
93
return 0;
94
}
95
96