opencv開啟雙目攝像頭、影象切割儲存
阿新 • • 發佈:2019-01-27
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
void main()
{
Mat input_image;
VideoCapture cam(0);
Rect left_rect(0, 0, 1279, 960); //建立一個Rect框,屬於cv中的類,四個引數代表x,y,width,height
Rect right_rect(1280, 0, 1279, 960);
Mat image_left, image_right;
String left_road ;
String right_road ;
int num = 0;
if (!cam.isOpened())
exit(0);
cam.set(CV_CAP_PROP_FRAME_WIDTH, 2560);
cam.set(CV_CAP_PROP_FRAME_HEIGHT, 960);
namedWindow("攝像頭");
vector<int> compression_params;
compression_params.push_back(IMWRITE_PNG_COMPRESSION);
compression_params.push_back(9);
while (true) {
cam >> input_image;
image_left = Mat(input_image, left_rect).clone();
image_right = Mat(input_image, right_rect).clone();
imshow("input image1", image_left);
imshow("input image2", image_right);
//imwrite("alpha.png", mat, compression_params);
//if ('q' == waitKey(30))
//break;
if ('q' == waitKey(30))
{
num++;
cout << num;
left_road = "F:\\opencv3.1\\雙目標定\\左\\" + to_string(num) + ".bmp";
right_road = "F:\\opencv3.1\\雙目標定\\右\\" + to_string(num) + ".bmp";
imwrite(left_road, image_left, compression_params);
imwrite(right_road, image_right, compression_params);
}
}
}
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
void main()
{
Mat input_image;
VideoCapture cam(0);
Rect left_rect(0, 0, 1279, 960); //建立一個Rect框,屬於cv中的類,四個引數代表x,y,width,height
Rect right_rect(1280, 0, 1279, 960);
Mat image_left, image_right;
String left_road ;
String right_road ;
int num = 0;
if (!cam.isOpened())
exit(0);
cam.set(CV_CAP_PROP_FRAME_WIDTH, 2560);
cam.set(CV_CAP_PROP_FRAME_HEIGHT, 960);
namedWindow("攝像頭");
vector<int> compression_params;
compression_params.push_back(IMWRITE_PNG_COMPRESSION);
compression_params.push_back(9);
while (true) {
cam >> input_image;
image_left = Mat(input_image, left_rect).clone();
image_right = Mat(input_image, right_rect).clone();
imshow("input image1", image_left);
imshow("input image2", image_right);
//imwrite("alpha.png", mat, compression_params);
//if ('q' == waitKey(30))
//break;
if ('q' == waitKey(30))
{
num++;
cout << num;
left_road = "F:\\opencv3.1\\雙目標定\\左\\" + to_string(num) + ".bmp";
right_road = "F:\\opencv3.1\\雙目標定\\右\\" + to_string(num) + ".bmp";
imwrite(left_road, image_left, compression_params);
imwrite(right_road, image_right, compression_params);
}
}
}