#include //#include #include #include cv::Mat dst_frame; cv::Mat src_frame; void read_cam(int width, int height, int fps) { std::string v4l2_cmd = "media-ctl -d /dev/video0 --set-v4l2 '\"m00_b_mvcam 7-003b\":0[fmt:Y8_1X8/" + std::to_string(width) + "x" + std::to_string(height) + "@1/" + std::to_string(fps) + " field:none]'"; system(v4l2_cmd.c_str()); cv::VideoCapture cap("v4l2src io-mode=dmabuf device=/dev/video0 ! video/x-raw, format=(string)GRAY8, width=(int)" + std::to_string(width) + ", height=(int)" + std::to_string(height) + " ! appsink"); if (cap.isOpened()) { cv::namedWindow("demo", cv::WINDOW_AUTOSIZE); while (true) { bool ret_val = cap.read(src_frame); if (ret_val) { cv::medianBlur(src_frame, dst_frame, 5); cv::imshow("demo", dst_frame); cv::waitKey(1); } else { std::cout << "camera open failed" << std::endl; break; } } } else { std::cout << "camera open failed" << std::endl; } cv::destroyAllWindows(); } int main(int argc, char** argv) { int width = 1080; int height = 1080; int fps = 30; if (argc > 1) { width = std::stoi(argv[1]); } if (argc > 2) { height = std::stoi(argv[2]); } if (argc > 3) { fps = std::stoi(argv[3]); } read_cam(width, height, fps); return 0; }