Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.
Ask Your Question

Miny's profile - activity

2015-04-15 02:00:34 -0500 received badge  Student (source)
2015-04-14 23:29:09 -0500 asked a question obvious bug in structured edge_detection.cpp , ximgproc,opencv_contrib,opencv 3.0beta

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.