heap corruption compiling an opencv project

0
void trackFilteredObject(int &x, int &y, Mat threshold, Mat &cameraFeed) {
Mat temp;
threshold.copyTo(temp);
//these two vectors needed for output of findContours
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
//find contours of filtered image using openCV findContours function
findContours(temp, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
//use moments method to find our filtered object
double refArea = 0;
int largestIndex = 0;
bool objectFound = false;
if (hierarchy.size() > 0) {
    int numObjects = hierarchy.size();
    //if number of objects greater than MAX_NUM_OBJECTS we have a noisy filter
    if (numObjects<MAX_NUM_OBJECTS) {
        for (int index = 0; index >= 0; index = hierarchy[index][0]) {

            Moments moment = moments((cv::Mat)contours[index]);
            double area = moment.m00;

            //if the area is less than 20 px by 20px then it is probably just noise
            //if the area is the same as the 3/2 of the image size, probably just a bad filter
            //we only want the object with the largest area so we save a reference area each
            //iteration and compare it to the area in the next iteration.
            if (area>MIN_OBJECT_AREA && area<MAX_OBJECT_AREA && area>refArea) {
                x = moment.m10 / area;
                y = moment.m01 / area;
                objectFound = true;
                refArea = area;
                //save index of largest contour to use with drawContours
                largestIndex = index;
            }
            else objectFound = false;


        }
        //let user know you found an object
        if (objectFound == true) {
            putText(cameraFeed, "Tracking Object", Point(0, 50), 2, 1, Scalar(0, 255, 0), 2);
            //draw object location on screen
            drawObject(x, y, cameraFeed);
            //draw largest contour
            //drawContours(cameraFeed, contours, largestIndex, Scalar(0, 255, 255), 2);
        }

    }
    else putText(cameraFeed, "TOO MUCH NOISE! ADJUST FILTER", Point(0, 50), 1, 2, Scalar(0, 0, 255), 2);
}

Whenever I compile my code with this function, this problem appears, heap corruption. I want to trace an object and draw a geometric figure in it

Then this error appears at runtime, only when I use this function. debugging the code, the error occurs the moment I leave the function. From what I've seen, something is happening with the use of the vectors I use as a parameter ...

    
asked by anonymous 06.04.2016 / 03:50

0 answers