Issue with finding homography between two images

asked 2015-07-23 14:42:09 -0600

morphogencc gravatar image

I have two cameras that are looking overhead at a square object, and I'd like to take the two images and combine them to get one image that is (approximately) representative of the overall area.

The views from my two cameras look like so:

Two camera images.

The left edge of the left image should stitch with the right edge of the right image, with the dotted black line being the point where they overlap.

My first attempt is to stitch the images together using the stitcher class:

if (mObservers[0]->isImageBufferReady() && mObservers[1]->isImageBufferReady()) {
            try {
                cv::Mat leftImage = cv::Mat(mObservers[0]->getImageHeight(), mObservers[0]->getImageWidth(), CV_8UC1, mObservers[0]->getImageBuffer());
                cv::transpose(leftImage, leftImage);
                cv::flip(leftImage, leftImage, -1);

                cv::Mat rightImage = cv::Mat(mObservers[1]->getImageHeight(), mObservers[1]->getImageWidth(), CV_8UC1, mObservers[1]->getImageBuffer());
                cv::transpose(rightImage, rightImage);

                std::vector<cv::Mat> images;
                images.push_back(leftImage);
                images.push_back(rightImage);

                cv::Mat result;
                cv::Stitcher stitcher = cv::Stitcher::createDefault(true);

                stitcher.setRegistrationResol(-1); /// 0.6
                stitcher.setSeamEstimationResol(-1);   /// 0.1
                stitcher.setCompositingResol(-1);   //1
                stitcher.setPanoConfidenceThresh(-1);   //1
                stitcher.setWaveCorrection(true);
                stitcher.setWaveCorrectKind(cv::detail::WAVE_CORRECT_HORIZ);

                cv::Stitcher::Status status = stitcher.stitch(images, result);

                if (status != cv::Stitcher::OK) {
                    sdfLog::logFormat("Stitching failed! Error code = %i", int(status));
                    return cv::Mat::zeros(500, 500, CV_8UC1);
                }

                return result;


            }

Here, Observer is an external class that wraps around my camera, and exposes the data buffer (of type unsigned char*).

Unfortunately, this fails (consistently) with the error:

Debug Assertion Failed! Program: ....\VC\include\xmemory0 Line 106 Expression "(_Ptr_user & (_BIG_ALLOCATION_ALIGNMENT -1)) == 0" && 0

The call stack indicates that this happens during the call to std::_Deallocate<cv::KeyPoint> -- presumably when the keypoints vectors are deallocated.

Needless to say, the image stitching fails.

I've tried using the cv::Stitcher class, but I get the same error.

How can I attempt to stitch images together and get information about how or why this is failing?

thanks!

edit retag flag offensive close merge delete

Comments

I tried this code with these test images, and I get the same error in the destructor for cv::DMatch -- imgur.com/a/u34NJ

morphogencc gravatar imagemorphogencc ( 2015-07-23 15:24:26 -0600 )edit

on which line does this happen?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-24 04:33:34 -0600 )edit

It crashes right on return result;, at the end of the function when it is presumably deallocating local variables.

morphogencc gravatar imagemorphogencc ( 2015-07-24 12:58:27 -0600 )edit