Ask Your Question
0

std::vector of cv::Mat causing memory corruption

asked 2015-06-18 20:59:18 -0600

Devansh Dalal gravatar image

updated 2015-07-07 21:31:54 -0600

I am using opencv_contrib's ximgproc moule's structural edge detector's code in my visual studio project . But it giving _CrtIsValidHeapPointer(pUserData) error expression . With some debugging I realized that Actually the error is caused when a function getFeatures defined in structured_edge_detector.cpp tries to push cv::Mat in a std::vector as shown below

virtual void getFeatures(const Mat &src, Mat &features, const int gnrmRad, const int gsmthRad,
                         const int shrink, const int outNum, const int gradNum) const
{
    cv::Mat luvImg = rgb2luv(src);

    std::vector <cv::Mat> featureArray;

    cv::Size nSize = src.size() / float(shrink);
    split( imresize(luvImg, nSize), featureArray );

    CV_INIT_VECTOR(scales, float, {1.0f, 0.5f});

    for (size_t i = 0; i < scales.size(); ++i)
    {
        int pSize = std::max( 1, int(shrink*scales[i]) );
    }
    mixChannels(featureArray, features, fromTo);
}

Please tell me what is the reason of such fault in program and any possible solution. My Opencv version is 2.4.10 so I am actually using the ximgproc's structured edge detector's code within my project.

Thanks

edit retag flag offensive close merge delete

Comments

1

ohh, you again ;9

can you add some lines of test code ? (might be another buffer overrun due to weird image size or such)

also check, if you strictly use opencv debug libs in debug build, and release ones in release (since mixing them produces similar errors)

berak gravatar imageberak ( 2015-06-18 23:56:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-06-19 03:47:36 -0600

mshabunin gravatar image

Probably the problem is in gradientHist, see opencv_contrib#195: https://github.com/Itseez/opencv_cont...

I proposed the solution, but can not reproduce the issue myself. You can try to fix it and provide patches to opencv2.4 and opencv_contrib.

edit flag offensive delete link more

Comments

oh, i missed the gradientHist call. this problem was encountered before , and cvCeil() seemed to fix it.

i'll try to come up with a better test case.

berak gravatar imageberak ( 2015-06-19 04:03:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-18 20:59:18 -0600

Seen: 698 times

Last updated: Jul 07 '15