-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
59 lines (48 loc) · 1.72 KB
/
main.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
#include <opencv2/opencv.hpp>
/// For the Raspberry Pi 64-bit Bullseye OS
std::string gstreamer_pipeline(int capture_width, int capture_height, int framerate, int display_width, int display_height) {
return
" libcamerasrc ! video/x-raw, "
" width=(int)" + std::to_string(capture_width) + ","
" height=(int)" + std::to_string(capture_height) + ","
" framerate=(fraction)" + std::to_string(framerate) +"/1 !"
" videoconvert ! videoscale !"
" video/x-raw,"
" width=(int)" + std::to_string(display_width) + ","
" height=(int)" + std::to_string(display_height) + " ! appsink";
}
int main()
{
//pipeline parameters
int capture_width = 640; //1280 ;
int capture_height = 480; //720 ;
int framerate = 15 ;
int display_width = 640; //1280 ;
int display_height = 480; //720 ;
//reset frame average
std::string pipeline = gstreamer_pipeline(capture_width, capture_height, framerate,
display_width, display_height);
std::cout << "Using pipeline: \n\t" << pipeline << "\n\n\n";
cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);
if(!cap.isOpened()) {
std::cout<<"Failed to open camera."<<std::endl;
return (-1);
}
cv::namedWindow("Camera", cv::WINDOW_AUTOSIZE);
cv::Mat frame;
std::cout << "Hit ESC to exit" << "\n" ;
while(true)
{
if (!cap.read(frame)) {
std::cout<<"Capture read error"<<std::endl;
break;
}
//show frame
cv::imshow("Camera",frame);
char esc = cv::waitKey(5);
if(esc == 27) break;
}
cap.release();
cv::destroyAllWindows() ;
return 0;
}