Ask Your Question
0

Mat::at <Double> give Unhandled exception

asked 2017-09-26 02:11:15 -0600

jjabaram gravatar image
im = imread(image1, IMREAD_GRAYSCALE);
Mat PdivS = Mat(im.rows, im.cols, CV_32F);
double val1 = 0;

divide(P, S, PdivS);
minMaxLoc(PdivS, &min, &max);
double tempmax = max;

for (int x = 0; x < im.rows; x++)//To loop through all the pixels 
    {
        for (int y = 0; y < im.cols; y++)
        {
            val1 = PdivS.at<double>(x, y); //<<<Give Unhandled exception
            res = (val1 / tempmax) * 255;
            PdivS.at<double>(x, y) = res;
        }
    }

When I tried using float on val1 and Mat::at, it doesn't have a problem. but when I change to double it give me.

Unhandled exception at 0x00007FFE727695FC in lineconnect.exe: Microsoft C++ exception: cv::Exception at memory location 0x0000007BA83DB690.

what shoud i do ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-09-26 02:21:45 -0600

berak gravatar image

updated 2017-09-26 02:23:18 -0600

"what should i do ?"

you probably should NOT write loops like that !

you have to be exact with the type in Mat::at(), if it's CV_32F, you have to use mat.at<float>().

so, please delete the whole loop, it is not nessecary at all, since you can (and better should !) write it as:

divide(P, S, PdivS);
minMaxLoc(PdivS, &min, &max);
double tempmax = max;

PdivS *= 255.0/tempmax;  // all you need !
edit flag offensive delete link more

Comments

Thank you for your answer. If I use it, is the result will same as i loop it ?

jjabaram gravatar imagejjabaram ( 2017-09-26 02:50:36 -0600 )edit

sure ! it will also be faster !

berak gravatar imageberak ( 2017-09-26 02:57:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-09-26 02:11:15 -0600

Seen: 491 times

Last updated: Sep 26 '17