OpenCV立体图像c ++

时间:2015-12-29 23:51:45

标签: opencv

VideoCapture capleft(0);     
VideoCapture capright(1);
//int width=640, height = 480;
Mat frameLeft,frameRight,both;
both= Mat(1080,1920,CV_MAKETYPE(8,3),CV_RGB(255,255,255));


if(!capleft.isOpened() || !capright.isOpened())
{
    cout<<"Please check your connection!"<<endl;
    system ("pause");
    return -1;
}

while(true)
{                  
    capleft>>frameLeft; 
    capright>>frameRight;

    if(frameLeft.data==NULL|| frameRight.data==NULL)
        break;

    frameLeft.copyTo(Mat(both,Rect(50,50,960,1080)));  
    frameRight.copyTo(Mat(both,Rect(693,50,960,1080)));
    imshow("images", both);
    waitKey(30);

    switch(waitKey(30))
    {
        case 27:
        return 0;
    }           
} 
return 0;

}

我正在尝试将分辨率调整为1080,960左右,1080,960分辨率。如果我改变

,此代码有效
frameLeft.copyTo(Mat(both,Rect(50,50,960,1080))); // 960->640 and 1080->480 
frameRight.copyTo(Mat(both,Rect(693,50,960,1080))); 

否则,我收到错误:

  

在Playing_images2.exe中的0x7781D8A8处未处理的异常:Microsoft C ++异常:cv ::内存位置0x0017F628的异常。

如果有人可以指导我,我将非常感激。

1 个答案:

答案 0 :(得分:0)

看起来你正在访问图像之外的内存。尝试使用hconcat以更安全的方式连接图像。

删除行

both= Mat(1080,1920,CV_MAKETYPE(8,3),CV_RGB(255,255,255));

并替换

frameLeft.copyTo(Mat(both,Rect(50,50,960,1080)));  
frameRight.copyTo(Mat(both,Rect(693,50,960,1080)));

hconcat(std::vector<Mat>{frameLeft, frameRight}, both);