Ask Your Question
1

Stitching Two Webcam Feeds

asked 2013-04-03 15:20:47 -0600

TonyRo gravatar image

updated 2013-04-03 15:43:34 -0600

Hello,

I'm new to OpenCV 2.4.4 and the Stitcher Module, and am struggling to get this test to work. The code is below:

#include <opencv2/opencv.hpp>
#include <opencv2/stitching/stitcher.hpp>
#include <iostream>
#include <vector>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
    Mat frame1, frame2, pano;
    bool try_use_gpu = false;
    vector<Mat> imgs;
    VideoCapture cap(0), cap2(1);

    while (true)
    {
        cap >> frame1;
        cap2 >> frame2;
        imgs.push_back(frame1);
        imgs.push_back(frame2);

        Stitcher test = Stitcher::createDefault(try_use_gpu);
        Stitcher::Status status = test.stitch(imgs, pano);

        if (status != Stitcher::OK)
        {
            cout << "Error stitching - Code: " <<int(status)<<endl;
            return -1;
        }

        imshow("Frame 1", frame1);
        imshow("Frame 2", frame2);
        imshow("Stitched Image", pano);

        if(waitKey(30) >= 0) 
            break;
    }
    return 0;
}

I get the errors:

First-chance exception at 0x0f3c7fe7 in StitchingTest.exe: 0xC0000005: Access violation writing location 0x00000038. First-chance exception at 0x0f3c8331 in StitchingTest.exe: 0xC0000005: Access violation reading location 0x00000014. Unhandled exception at 0x0f3c8331 in StitchingTest.exe: 0xC0000005: Access violation reading location 0x00000014. The program '[8416] StitchingTest.exe: Native' has exited with code 0 (0x0)

What did I do wrong? Thanks!

-Tony

EDIT: Solved the initial error - I was missing the "d" in the stitching Linker dependency.

SECOND ERROR: The stitcher status returns 1 - what does that mean?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-04-03 15:44:12 -0600

berak gravatar image

here's the problem:

cap >> frame1;
imgs.push_back(frame1);

the images you get from the capture, are pointing to video-driver space, you can't store a flat copy in a vector like this, the memory will go out of scope. instead, do like this:

cap >> frame1;
imgs.push_back(frame1.clone());

you'll want to copy the pixel memory too, if you want to store them in a vector

edit flag offensive delete link more

Comments

I changed the above statements according to your suggestion, but I'm not sure what you mean by "copy the pixel memory too" - could you elaborate? The code still throws the same error, so I assume it's because of this last bit that I'm not doing. Thanks!

TonyRo gravatar imageTonyRo ( 2013-04-03 15:58:24 -0600 )edit

No help on this? I'm pretty desperate to get this stitcher working!

TonyRo gravatar imageTonyRo ( 2013-04-04 09:38:17 -0600 )edit

Question Tools

Stats

Asked: 2013-04-03 15:20:47 -0600

Seen: 834 times

Last updated: Apr 03 '13