2
我目前正在玩360°相機,並希望使用OpenCV的球形整經器。但是,每次嘗試運行使用拼接器功能的簡單程序時,都無法返回拼接圖像。我基本上只是拍攝360°照片,將它分成兩個獨立的照片(前後鏡頭)並將它們拼接在一起。OpenCV(C++)stitcher不寫入OutputArray
下面的代碼:
Mat srcImage = imread("assets/360_0043.JPG");
Mat frontLensImage(srcImage, Rect(0, 0, srcImage.cols/2, srcImage.rows));
Mat rearLensImage(srcImage, Rect(srcImage.rows, 0, srcImage.cols/2, srcImage.rows));
vector<Mat> imagesToStitch;
imagesToStitch.push_back(frontLensImage);
imagesToStitch.push_back(rearLensImage);
Mat panorama;
Stitcher stitcher = Stitcher::createDefault();
if(!imagesToStitch.empty()){
stitcher.stitch(imagesToStitch, panorama);
imshow("test", panorama);
waitKey(0);
}
else{
cout << "ERROR: Image array empty" << endl;
}
return 0;
當試圖運行,它返回此錯誤:
OpenCV Error: Assertion failed (ssize.area() > 0) in resize, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/imgproc/src/imgwarp.cpp, line 1834
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/imgproc/src/imgwarp.cpp:1834: error: (-215) ssize.area() > 0 in function resize
調試時,panorama
是即使我將它作爲OutputArray
到stitcher.stitch
一個空對象。我徹底搜索了網頁,找不到解決方案,所以任何幫助將不勝感激!
不應該是:'mat rearLensImage(srcImage,Rect(srcImage.cols/2,0,srcImage.cols/2,srcImage.rows));'?然而,你需要圖像重疊...所以你可以嘗試:Mat frontLensImage(srcImage,Rect(0,0,3 * srcImage.cols/4,srcImage.rows)); Mat rearLensImage(srcImage,Rect(srcImage.cols/4,0,3 * srcImage.cols/4,srcImage.rows));' – Miki
感謝您的快速回復!我不知道重疊,所以很好知道。儘管如此,它仍然無法使用你的代碼。我得到這個錯誤:'imshow'中斷言失敗(size.width> 0 && size.height> 0) – neobanshee