EdgeBoard采集图片
基于opencv可以通过EdgeBoard采集图片
#include <fstream>
#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char *argv[]) {
std::string writePath = "/root/workspace/SmartCarToolKits/c++/temp";//这里是绝对路径
/*注意:
使用 0 和 /dev/video0 的分辨率不同:
0 : opencv 内部的采集,可能是基于 V4L2, 分辨率:1280 * 960
/dev/video0 : 基于Gstreamer , 分辨率:640 * 480
*/
VideoCapture capture(0);
capture.open(0, cv::CAP_V4L);
if (!capture.isOpened()) {
std::cout << "can not open video device " << std::endl;
return 1;
}
capture.set(cv::CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
capture.set(cv::CAP_PROP_FPS, 60);
capture.set(cv::CAP_PROP_FRAME_WIDTH, 640);
capture.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
double rate = capture.get(CAP_PROP_FPS);
double width = capture.get(CAP_PROP_FRAME_WIDTH);
double height = capture.get(CAP_PROP_FRAME_HEIGHT);
std::cout << "Camera Param: frame rate = " << rate << " width = " << width
<< " height = " << height << std::endl;
std::string window_name = "usbcamera";
namedWindow(window_name, WINDOW_NORMAL);
std::string name;
int i=0;
int width_ = 640;
int height_ = 480;
//Mat frame;
while (1) {
//if (!capture.read(frame)) {
//std::cout << "no video frame" << std::endl;
//continue;
//}
Mat frame;
capture >> frame;
if (32 == waitKey(20)) { //空格拍照
name = writePath + to_string(i)+".jpg";
imwrite(name, frame);
cout << name << endl;
i++;
}
if (97 == waitKey(10)) { //'a'退出
break;
}
imshow(window_name, frame);
//waitKey(1);
}
//capture.release();
}
浙公网安备 33010602011771号