Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cmath>
- #include <opencv2/core.hpp>
- #include <opencv2/highgui.hpp>
- #include <opencv2/imgproc.hpp>
- #include <opencv2/imgcodecs.hpp>
- #include <opencv2/core/cuda.hpp>
- #include <opencv2/cudaimgproc.hpp>
- #include <opencv2/cudawarping.hpp>
- #include <opencv2/cudaarithm.hpp>
- std::string gstreamer_pipeline (int capture_width, int capture_height, int display_width, int display_height, int framerate, int flip_method) {
- return "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)" + std::to_string(capture_width) + ", height=(int)" +
- std::to_string(capture_height) + ", format=(string)NV12, framerate=(fraction)" + std::to_string(framerate) +
- "/1 ! nvvidconv flip-method=" + std::to_string(flip_method) + " ! video/x-raw, width=(int)" + std::to_string(display_width) + ", height=(int)" +
- std::to_string(display_height) + ", format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink";
- }
- int main()
- {
- cv::cuda::printCudaDeviceInfo(cv::cuda::getDevice());
- int capture_width = 1280 ;
- int capture_height = 720 ;
- int display_width = 1280 ;
- int display_height = 720 ;
- int framerate = 60 ;
- int flip_method = 2 ;
- std::string pipeline = gstreamer_pipeline(capture_width,
- capture_height,
- display_width,
- display_height,
- framerate,
- flip_method);
- std::cout << "Using pipeline: \n\t" << pipeline << "\n";
- cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);
- if(!cap.isOpened()) {
- std::cout<<"Failed to open camera."<<std::endl;
- return (-1);
- }
- cv::namedWindow("CSI Camera", cv::WINDOW_AUTOSIZE);
- cv::Mat img;
- std::cout << "Hit ESC to exit" << "\n" ;
- while(true)
- {
- if (!cap.read(img)) {
- std::cout<<"Capture read error"<<std::endl;
- break;
- }
- cv::cuda::GpuMat display, smaller;
- display.upload(img);
- cv::cuda::resize(display, smaller, cv::Size(1920,1080));
- display.download(img);
- cv::imshow("CSI Camera",img);
- int keycode = cv::waitKey(5) & 0xff ;
- if (keycode == 27) break ;
- }
- cap.release();
- cv::destroyAllWindows() ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement