版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ktigerhero3/article/details/83039964
买了个usb接口的双目摄像头,首先读出图像,发现读出来的图像是合并的,将整个图像分割为左右图像,并且实时显示.
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include<unistd.h>
using namespace cv;
using namespace std;
#define WIDTH 2560
#define HEIGHT 720
int main() {
VideoCapture capture(0);
if (!capture.isOpened())
{
cout<<"can not open the camera"<<endl; cin.get(); exit(1);
}
capture.set(CV_CAP_PROP_FRAME_WIDTH, WIDTH);
capture.set(CV_CAP_PROP_FRAME_HEIGHT, HEIGHT);
int count=0;
Rect leftRect(0, 0, WIDTH/2, HEIGHT); //创建一个Rect框,属于cv中的类,四个参数代表x,y,width,height
Rect rightRect(WIDTH/2-1, 0, WIDTH/2, HEIGHT);
while (1) {
Mat frame; capture>>frame; //载入图像
if (frame.empty())
{
//判断图像是否载入 cout<<"can not load the frame"<<endl;
} else {
count++;
if (count == 1) {
cout<<frame.cols<<" "<<frame.rows<<endl;
}
Mat leftImg,rightImg;
frame(leftRect).copyTo(leftImg);
frame(rightRect).copyTo(rightImg);
imshow("left",leftImg);
imshow("right",rightImg);
imshow("oriImage", frame);
char c=waitKey(30); //延时30毫秒 if (c == 27) //按ESC键退出 break;
}
}
}