-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
39 lines (32 loc) · 1.29 KB
/
main.cpp
File metadata and controls
39 lines (32 loc) · 1.29 KB
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
#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
std::string pipeline = "nvarguscamerasrc ! nvvidconv ! appsink";
// Open the video source using the GStreamer pipeline
cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);
if (!cap.isOpened()) {
std::cerr << "Error: Could not open the video source." << std::endl;
return -1;
}
int frameCounter = 0;
std::cout << "Starting frame capture. Press 'ESC' to exit." << std::endl;
// Continuous loop for capturing frames
while (true) {
cv::Mat frame;
if (!cap.read(frame)) {
std::cerr << "Error: Could not read a frame." << std::endl;
break;
}
frameCounter++;
// Console output: frame number and image dimensions
std::cout << "Frame " << frameCounter
<< " captured (Size: " << frame.cols << " x " << frame.rows << ")"
<< std::endl;
// Check for 'ESC' key press (only works if a window is active)
if (cv::waitKey(1) == 27) { // 27 corresponds to the ESC key
break;
}
}
cap.release();
return 0;
}