Ask Your Question
0

segmentation fault

asked 2016-01-17 10:45:02 -0600

lyw8120 gravatar image

updated 2016-01-17 12:07:25 -0600

this code can work the image size 256x256, but not work on 4096x4096. I really confuse where get problem. the img.at<float>(i,j) should not access invalid memory address.

    void dustHighValue(Mat & img, float & sigma)
{
    int m = img.rows;
    int n = img.cols;
    copyMakeBorder(img, img,2, 2, 2, 2, BORDER_CONSTANT, Scalar::all(0));
    Mat tmp;
    Scalar meanValue, stdValue;
    for ( int i=2; i<img.rows-2; ++i)
        for( int j=2; j<img.cols-2; ++j)
        {
            tmp=img(Rect(i-1,j-1,3,3));
            meanStdDev(tmp, meanValue, stdValue);
            if( img.at<float>(i,j) > (sigma * stdValue[0] + meanValue[0]))  
            {   
                img.at<float>(i,j) = meanValue[0];
            }
        }

    img=img(Rect(2,2,n,m));

}
edit retag flag offensive close merge delete

Comments

first, let's clarify the type . how do you acquire the image, and why do you access it as float ?

berak gravatar imageberak ( 2016-01-17 10:58:40 -0600 )edit

again, please highlite, why you think, your image has actually float type. ( if it is not so, (usually images loaded are uchar(nchannels), not float , this might explain your failure.)

the most plausible explanation of your segfault is : you're accessing your image using the wrong type

berak gravatar imageberak ( 2016-01-17 12:13:43 -0600 )edit

cerr << img.type() << endl; // returns what ?

berak gravatar imageberak ( 2016-01-17 12:21:52 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-01-17 13:56:47 -0600

lyw8120 gravatar image

you are right the return value is 0, means it is CV_8U. I will check the input image, it is strange, becuase I thought I already have converted it to CV_32FC1.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-01-17 10:45:02 -0600

Seen: 700 times

Last updated: Jan 17 '16