obvious bug in structured edge_detection.cpp , ximgproc,opencv_contrib,opencv 3.0beta

asked 2015-04-14 22:43:19 -0600

Miny gravatar image

Hello,

There is a access violation bug in gradientHist function of structured edge_detection.cpp in line 184.The specify issue appears when the input Mat src.rows is odd and the specify access violation triggers in line 243. Detai in soure code link:link text

//funtion entry. default pSize =2
static void gradientHist(const cv::Mat &src, cv::Mat &magnitude, cv::Mat &histogram,
                     const int nBins, const int pSize, const int gnrmRad)
//leave out some code.
//allocate memory.note the potential bug here when the input Mat src.rows is  odd.
phase.create( src.size(), cv::DataType<float>::type );
histogram.create( cv::Size( cvRound(src.size().width/float(pSize)),
                            cvRound(src.size().height/float(pSize)) ),
    CV_MAKETYPE(cv::DataType<float>::type, nBins) );

//leave out some code.....

for (int i = 0; i < phase.rows; ++i)
{
    const float *pPhase = phase.ptr<float>(i);
    const float *pMagn  = magnitude.ptr<float>(i);

    float *pHist = histogram.ptr<float>(i/pSize);//specify  position of access violation 

    for (int j = 0; j < phase.cols; ++j)
        pHist[cvRound((j/pSize + pPhase[j])*nBins)] += pMagn[j] / CV_SQR(pSize);
}

As to my case.I fixed the bug by modifying the step of allocate memory as follow.

phase.create( src.size(), cv::DataType<float>::type );
histogram.create( cv::Size( cvCeil(src.size().width/float(pSize)),
                            cvCeil(src.size().height/float(pSize)) ),
    CV_MAKETYPE(cv::DataType<float>::type, nBins) );

Hope it helps.

edit retag flag offensive close merge delete

Comments

1
berak gravatar imageberak ( 2015-04-15 02:03:58 -0600 )edit