Exception in stitching object (Bug #2744)
Description
I'm trying to perform stitching of three images from cam:
vector<Mat> imgs; Mat pano; int width = 1280; int height = 960; Mat image1(height, width, CV_8UC1, (unsigned char*) captureClient->bList.at(0).data()); imgs.push_back(image1); imshow("Stitshed1", image1); //for test Mat image2(height, width, CV_8UC1, (unsigned char*) captureClient->bList.at(1).data()); imgs.push_back(image2); imshow("Stitshed2", image2); //for test Mat image3(height, width, CV_8UC1, (unsigned char*) captureClient->bList.at(2).data()); imgs.push_back(image3); imshow("Stitshed3", image3); //for test [...] Stitcher stitcher = Stitcher::createDefault(false); Stitcher::Status status = stitcher.stitch(imgs, pano); /// <--- exception HERE
imshow - in my code works fine, and I can see the right images, and also if I'll use imread instead for copy constructor for Mat (image1, image2, image2) all work good.
Associated revisions
Merge pull request #2744 from jet47:kmeans-fix
History
Updated by Nikolay Rogoshchenkov about 12 years ago
Updated by Alexey Spizhevoy about 12 years ago
Hi Nikolay,
What is the exception message? Please, take into account that only 8UC3 images are fully supported by the stitching module.
Regards, Alexey
- Priority changed from High to Normal
Updated by Nikolay Rogoshchenkov about 12 years ago
Hi Alexey,
I mean crashing application:
About CV_8UC3. I think this is another case, because I case no problem with the same images with this code:
int main(int argc, char* argv[]) { int retval = parseCmdArgs(argc, argv); if (retval) return -1; Mat pano; cv::Rect rect1 = cvRect(3*imgs[0].cols/4, imgs[0].rows/3, imgs[0].cols/4, imgs[0].rows/2); //second half of the first image cv::vector<cv::Rect> roi1; roi1.push_back(rect1); cv::Rect rect12 = cvRect(0, imgs[1].rows/3, imgs[1].cols/4, 2*imgs[1].rows/3); //first half of the second image cv::Rect rect23 = cvRect(3*imgs[1].cols/4, imgs[1].rows/3, imgs[1].cols/4, imgs[1].rows/2); //second half of the first image cv::vector<cv::Rect> roi2; roi2.push_back(rect12); roi2.push_back(rect23); cv::Rect rect3 = cvRect(0, imgs[2].rows/3, imgs[2].cols/4, imgs[2].rows/2); //first half of the third image cv::vector<cv::Rect> roi3; roi3.push_back(rect3); cv::vector<cv::vector<cv::Rect>> rois; rois.resize(3); rois[0] = roi1; rois[1] = roi2; rois[2] = roi3; Stitcher stitcher = Stitcher::createDefault(true); Stitcher::Status status = stitcher.stitch(imgs, rois, pano); //Stitcher::Status status = stitcher.composePanorama(imgs, pano); if (status != Stitcher::OK) { cout << "Can't stitch images, error code = " << status << endl; return -1; } return 0; }
Updated by Nikolay Rogoshchenkov about 12 years ago
Hm, looks like you are right. Should I convert Mats from CV_8UC1 to CV_8UC3 before stitching?
Mat image11, image22, image33; Mat image1(height, width, CV_8UC1, (unsigned char*) captureClient->bList.at(0).data()); image1.convertTo(image11, CV_8UC3); imgs.push_back(image11);
is it correct way?
Updated by Alexey Spizhevoy about 12 years ago
Converting images to 8UC3 should resolve the issue. Here is a way to do it:
Mat img(height, width, CV_8U, (uchar*)captureClient->bList.at(0).data()); cvtColor(img, img, CV_GRAY2BGR); imgs.push_back(img);
OpenCV functions throw exceptions when something is wrong, usually it helps to understand the cause of issue:
try { /*OpenCV calls*/ } catch (const cv::Exception &e) { cout << e.what() << endl; }
Updated by Nikolay Rogoshchenkov about 12 years ago
Thank you for you help Alexey! Now it works.
Do you planing to update stitching module for 8-bit images?
Now it looks like not very wise to convert 8-bit to 24-bit images only for stitching purposes,
for large images I'll loose more memory and CPU/GPU time.
Updated by Alexey Spizhevoy about 12 years ago
You can create a task for adding 8UC1 images support into the stitching module. We'll add the task into our plans. Also you can implement 8UC1 support by yourself, and contribute the patch into OpenCV.
- Status changed from Open to Done
Updated by Alexey Spizhevoy about 12 years ago
- Target version deleted ()
Updated by Nikolay Rogoshchenkov about 12 years ago
Done. Feature #2752
Updated by Kirill Kornyakov about 12 years ago
- Target version set to 2.4.4