2015-12-29 52 views
-1
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; 

}OpenCV的立體圖像C++

我試圖將分辨率調整爲1080,960左,右1080,960。

Unhandled exception at at 0x7781D8A8 in Playing_images2.exe: Microsoft C++ exception: cv::Exception at memory location 0x0017F628.

我會很感激,如果有人能指導我:如果我改變

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

否則,我得到的錯誤此代碼的工作。

+1

什麼錯誤? –

+0

請正確編輯您的代碼,並添加錯誤 – Miki

+0

並且您在哪裏更改值以更改分辨率? – agold

回答

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); 
+0

謝謝@morotspaj的答覆。顯然,我對openCV和編程非常陌生。如果你能告訴我,我將如何實現這一點到我的完整代碼,我將不勝感激。 – skyrocket

+0

更新的代碼建議 – morotspaj

+0

謝謝。我得到以下錯誤:智能感知:沒有重載函數的實例「hconcat」匹配參數列表參數類型是:()\t 智能感知:類型名稱是不允許的\t 智能感知:預期a')' – skyrocket