How to fix ( release ) memory problem ? kernelbase.dll error

asked 2015-10-23 01:01:29 -0600

topsoil gravatar image

updated 2015-10-23 01:33:21 -0600

#include <iostream>
#include <fstream>
#include <iomanip>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<opencv\cv.h>
#include<opencv\highgui.h>

using namespace cv;
using namespace std;
int c;
int main(int argc, char* argv[])
{
    ofstream fout("output.txt");
    Mat image = imread("toilet.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    Mat B = image;
    if (image.empty()){
        fout << "Image open fail" << endl;
        exit(1);
    }
        for (int i = 0; i < 320; ++i){
        for (int j = 0; j < 240; ++j){
            //3)
            if ((int)image.at<uchar>(i, j) > 120)
            {c=c+1;}
                fout << setw(3) << " " << (int)image.at<uchar>(i, j);
        }
        fout << endl;
    }
    if (c>3000)
 printf("bright pixel : %d \n AAA", c);
    else
 printf("bright pixel : %d \n BBB", c);
    //4)
    imshow("ML", B);
    //5)
    waitKey(0);
image.release();        // isn't it releasing memory?
B.release();              //
    return 0;

}

please give me some bright answers it's killing me :( because it worked right before a day The error is like figure under.

The error says

Unhandled exception at 0x75915b68 (KernelBase.dll) in opencvtest.exe: Microsoft C++ exception: cv::Exception at memory location 0x0024f558..

image description

edit retag flag offensive close merge delete

Comments

1

" because it worked right before a day " - well, i highly doubt that. ;)

please start with replacing the unreadable screenshot with a text version of the exception thrown (so folks can grep msgs, etc.)

also please never use outdated c-headers like cv.h and highgui.h

berak gravatar imageberak ( 2015-10-23 01:11:02 -0600 )edit
1

then, image.at<uchar>(i, j) // must be j,i , welcome to row,col world !

berak gravatar imageberak ( 2015-10-23 01:12:11 -0600 )edit

I tried again and it worked just as it was The only difference was the size of i and j in 'for' bracket If i and j are getting over 100 each, the error occurs. How can it be fixed?

topsoil gravatar imagetopsoil ( 2015-10-23 01:32:32 -0600 )edit

And thanks for j , i kkk

topsoil gravatar imagetopsoil ( 2015-10-23 01:36:31 -0600 )edit

Are you sure your image has more than 100 cols/rows?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-10-23 07:05:47 -0600 )edit
2

topsoil, your whole program could be written in a single line:

cout << countNonZero(imread("toilet.jpg", 0) > 120);

in other words, avoid per-pixel loops , they're error-prone, slow, and defeat the purpose of a high-level lib like opencv.

berak gravatar imageberak ( 2015-10-23 07:37:39 -0600 )edit