segmentation fault with a vector<point2f>

asked 2015-04-25 10:01:22 -0500

215 gravatar image

updated 2015-04-25 11:16:44 -0500

Hi guys.. For some reason i have this issue with a vector becoming bigger and bigger creating a segmentation error which i don't understand occur at all.. could someone clarify the reason why this appearing? If i look for the size within the last for loop, i just get a size value which keep increasing.

Mat gray, prevGray, image,test;
image = cv_ptr->image;
Mat mask(image.size(),CV_8UC1,Scalar(0));
static uint64_t c;
if (c++ == 0 || reinit == true)
         cout << "automatic initialization" << endl;
         goodFeaturesToTrack(gray, points[1], MAX_COUNT, 0.01, 10, mask, 3, 0, 0.04);
         cornerSubPix(gray, points[1], subPixWinSize, Size(-1,-1), termcrit);
         cout << "Recalc" << endl; 
         reinit = false;

if( !points[0].empty() )
    // cout << "i am here" << endl;
        vector<uchar> status;
        vector<float> err;
        calcOpticalFlowPyrLK(prevGray, gray, points[0], points[1], status, err, winSize,3, termcrit, 0, qualitylevel);
        calcOpticalFlowPyrLK(gray, prevGray, points[1], finalpoints, status2, err2, winSize,3, termcrit, 0, qualitylevel);                    size_t i;
        for( i = 0; i < points[1].size(); i++ )
                 if( status[i] && status2[i])
                            cout << "Good Features" << endl;

        for(int i = 0;i < goodFeatures.size(); i++)
             circle(image,goodFeatures[i],4,scalar(255,0,0),-1,8,0) // segmentation Error occurence... :(:(

edit retag flag offensive close merge delete



please cut down that wall of code to something reasonable

also: vector<Rect> faces(1); please leave it empty, else you got a bogus item.

berak gravatar imageberak ( 2015-04-25 10:13:57 -0500 )edit

The wall has been cut down to where the problem occurs. I am not sure on what you mean by leaving it empty.. No size? or empty it after a face has been found?

215 gravatar image215 ( 2015-04-25 10:34:22 -0500 )edit

I narrowed down the problem being the for loop and the limit it said to run.. It doesn't like to run within the size of the vector.. i changed to only run up to 500. i don't why it becomes so big..

215 gravatar image215 ( 2015-04-25 13:04:23 -0500 )edit