Ask Your Question
0

Unhandled exception at 0x000007FEFD87A06D in ConsoleApplication1.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000013F000. occurred

asked 2018-10-30 09:40:51 -0500

rv98 gravatar image

hey

i was trying to play with the openCV 4.0.0 and visual studio 2017 after trying to run realy basic program on a 200X200 pixel picture

#include<opencv2\opencv.hpp>
#include<iostream>
#include<stdint.h>
using namespace std;
using namespace cv;
int main()
{
    Mat bwimg;
    Mat img = imread("C:/CV/lena.jpg");
    namedWindow("image", WINDOW_NORMAL);
    cvtColor(img, bwimg, cv::COLOR_RGB2GRAY);

    for (int r = 0; r <= bwimg.rows; r++) {
        for (int c = 0; c <= bwimg.cols; c++) {
            bwimg.at<uint8_t>(r, c) = bwimg.at<uint8_t>(r, c)*0.5f;
        }
    }

    imshow("image", bwimg);


    waitKey(0);
        return 0;
}

after running this program i got

"Unhandled exception at 0x000007FEFDA06D in ConsoleApplication1.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000013F000."

can anyone help fix that?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-10-30 09:53:57 -0500

berak gravatar image

please AVOID using Mat::at and for loops. it's slow, error prone, and you're defeating the purpose of using opencv as a high-level matrix library.

you're "one-off" here: r <= bwimg.rows (out-of-bounds)

again, DON'T write any loops, and rather write it as:

 bwimg *= 0.5;
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-10-30 09:39:49 -0500

Seen: 877 times

Last updated: Oct 30 '18