Download samples/cpp/application_trace.cpp from tgollogly/test: direct link, hf CLI and curl.
- Browser
- Download file 2.63 kB
-
https://huggingface.co/tgollogly/test/resolve/main/samples/cpp/application_trace.cpp
- Command line
-
hf download hf://tgollogly/test/samples/cpp/application_trace.cpp
-
curl -L -o application_trace.cpp https://huggingface.co/tgollogly/test/resolve/main/samples/cpp/application_trace.cpp
2.63 kB
| /* OpenCV Application Tracing support demo. */ | |
| using namespace cv; | |
| using namespace std; | |
| static void process_frame(const cv::UMat& frame) | |
| { | |
| CV_TRACE_FUNCTION(); // OpenCV Trace macro for function | |
| imshow("Live", frame); | |
| UMat gray, processed; | |
| cv::cvtColor(frame, gray, COLOR_BGR2GRAY); | |
| Canny(gray, processed, 32, 64, 3); | |
| imshow("Processed", processed); | |
| } | |
| int main(int argc, char** argv) | |
| { | |
| CV_TRACE_FUNCTION(); | |
| cv::CommandLineParser parser(argc, argv, | |
| "{help h ? | | help message}" | |
| "{n | 100 | number of frames to process }" | |
| "{@video | 0 | video filename or cameraID }" | |
| ); | |
| if (parser.has("help")) | |
| { | |
| parser.printMessage(); | |
| return 0; | |
| } | |
| VideoCapture capture; | |
| std::string video = parser.get<string>("@video"); | |
| if (video.size() == 1 && isdigit(video[0])) | |
| capture.open(parser.get<int>("@video")); | |
| else | |
| capture.open(samples::findFileOrKeep(video)); // keep GStreamer pipelines | |
| int nframes = 0; | |
| if (capture.isOpened()) | |
| { | |
| nframes = (int)capture.get(CAP_PROP_FRAME_COUNT); | |
| cout << "Video " << video << | |
| ": width=" << capture.get(CAP_PROP_FRAME_WIDTH) << | |
| ", height=" << capture.get(CAP_PROP_FRAME_HEIGHT) << | |
| ", nframes=" << nframes << endl; | |
| } | |
| else | |
| { | |
| cout << "Could not initialize video capturing...\n"; | |
| return -1; | |
| } | |
| int N = parser.get<int>("n"); | |
| if (nframes > 0 && N > nframes) | |
| N = nframes; | |
| cout << "Start processing..." << endl | |
| << "Press ESC key to terminate" << endl; | |
| UMat frame; | |
| for (int i = 0; N > 0 ? (i < N) : true; i++) | |
| { | |
| CV_TRACE_REGION("FRAME"); // OpenCV Trace macro for named "scope" region | |
| { | |
| CV_TRACE_REGION("read"); | |
| capture.read(frame); | |
| if (frame.empty()) | |
| { | |
| cerr << "Can't capture frame: " << i << std::endl; | |
| break; | |
| } | |
| // OpenCV Trace macro for NEXT named region in the same C++ scope | |
| // Previous "read" region will be marked complete on this line. | |
| // Use this to eliminate unnecessary curly braces. | |
| CV_TRACE_REGION_NEXT("process"); | |
| process_frame(frame); | |
| CV_TRACE_REGION_NEXT("delay"); | |
| if (waitKey(1) == 27/*ESC*/) | |
| break; | |
| } | |
| } | |
| return 0; | |
| } | |