Ask Your Question

TonyRo's profile - activity

2017-08-22 18:24:20 -0600 received badge  Student (source)
2013-06-07 09:35:01 -0600 commented question OpenCV Buffer Overflow Issue...

I've narrowed it down a bit if this helps:

The entire program runs fine (i.e. the stitching works, I can see "pano", and if I imshow the foreground mask "fGround" it looks fine as well) if I just comment out drawBoundingBoxes in main.cpp until I hit spacebar, or whatever, and then I get a runtime error (as mentioned in my original post) from triggering waitKey. So there's some problem with waitKey (I don't understand how this is possible at all) and another from drawBoundingBoxes().

2013-06-06 13:31:26 -0600 commented question OpenCV Buffer Overflow Issue...

Sorry, was unsure of any other way to properly portray my problem with all of the relevant information.

2013-06-06 13:13:53 -0600 asked a question OpenCV Buffer Overflow Issue...

I've got myself in a pickle on this project I'm working on. My main objective is to stitch two webcam feeds together and do object detection on them - bounding boxes, etc...the standard stuff.

I can't rid myself of buffer overflows though - the somewhat simplified code below (for readability) compiles x64 and soon after I get a buffer overflow error and this in the console:

OpenCV Error: Assertion Failed (contour.checkVector(2) >= 0 && (contour.depth() == CV_32F || contour.depth() == CV_32S)) in unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 1904

If comment out all of the lines that have to do with contours (from findContours to drawBoundingBoxes in main) it compiles and runs fine until I hit the spacebar to stop the program, and then I get another buffer overflow error. I get the same errors when I compile x32 as well, for the record.

Any help? Relevant code/pseudo-code pasted below:

// **defines.h**
//Definitions for anything in all caps, like WIDTH, HEIGHT, ERODEIT, etc...

// **protos.h**
// All function prototypes, nothing else

// **detection.cpp**

/* This is the code that related to background subtraction operations*/

#include <opencv2/opencv.hpp>
#include <iostream>
#include "defines.h"

using namespace std;
using namespace cv;

void initBackgroundSubtractor(BackgroundSubtractorMOG2 &bSub)
{
    bSub.set("detectShadows", 1);
}

Mat doBackgroundSubtract(BackgroundSubtractorMOG2 &bSub, Mat panorama)
{
    Mat foreground;

    bSub.operator()(panorama, foreground);
    erode(foreground, foreground, Mat(), Point(-1, -1), ERODEIT, BORDER_DEFAULT);
    dilate(foreground, foreground, Mat(), Point(-1, -1), DILATEIT, BORDER_DEFAULT);

    return foreground;
}

// **contourOps.cpp**

/* Functions that operate on, filter, or relate to OpenCV contours vectors */

#include <opencv2/opencv.hpp>
#include <vector>
#include <fstream>
#include "defines.h"

using namespace std;
using namespace cv;

/* Returns the centroid of a contour */

Point getCentroid(vector<Point> contour)
{
    Point centroid;
    Moments m;

    m = moments(contour, false);
    centroid.x = int(m.m10/m.m00);
    centroid.y = int(m.m01/m.m00);

    return centroid;
}

/* Draws a rectangle around a contour */

void drawBoundingBoxes(vector<vector<Point>> contours, Mat &img)
{
    vector<Rect> boundRect(contours.size());

    for(unsigned int j = 0; j < contours.size(); j++)
    {
        boundRect[j] = boundingRect(contours[j]);
        rectangle(img, boundRect[j], Scalar(153,0,76), 2, 8, 0);
    }
}

/* Removes contours from a vector if they're smaller than the argument "area" */

void contourSizeTrim (vector<vector<Point>> &contours, int area)
{
    vector<vector<Point>>::iterator i = contours.begin();
    while(i != contours.end())
    {
        if(contourArea(*i, false) < area)
            i = contours.erase(i);
        else
            i++;
    }
}

/* Removes contours from a vector if they're X % smaller than largest contour in vector */

void contourRelSizeTrim(vector<vector<Point>> &contours, int percent)
{
    double maxArea = 0.0;

    for(unsigned int i=0; i<contours.size(); i++)
    {
        if (contourArea(contours[i], false) > maxArea)
                maxArea = contourArea(contours[i], false);
    }

    vector<vector<Point>>::iterator j = contours.begin();
    while(j != contours.end())
    {
        if (contourArea(*j, false) < (double)(percent/100.0)*maxArea)
            j = contours.erase(j);
        else
            j++;
    }
}

// **realtimestitch.cpp**

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

using namespace std;
using namespace cv;

void initStitcher(VideoCapture &capture1, VideoCapture &capture2, Stitcher ...
(more)
2013-04-18 13:46:44 -0600 received badge  Supporter (source)
2013-04-04 09:38:17 -0600 commented answer Stitching Two Webcam Feeds

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

2013-04-03 15:58:24 -0600 commented answer Stitching Two Webcam Feeds

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!

2013-04-03 15:32:29 -0600 received badge  Editor (source)
2013-04-03 15:20:47 -0600 asked a question Stitching Two Webcam Feeds

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?