How to fix ( release ) memory problem ? kernelbase.dll error
#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..
" 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
then,
image.at<uchar>(i, j)
// must be j,i , welcome to row,col world !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?
And thanks for j , i kkk
Are you sure your image has more than 100 cols/rows?
topsoil, your whole program could be written in a single line:
in other words, avoid per-pixel loops , they're error-prone, slow, and defeat the purpose of a high-level lib like opencv.