corrupted double-linked list
I have a problem which probably is the memory problem, but I do not where is error and how to solve it. the code is followed.
when removed the two lines code
mv_background_average(image); mv_background_rotation(image);
it can work, I still can not find the bug.
please help me to check it and tell me what happened. Thanks a lot.
int main (int argc, char * argv[])
{
string filename = string(argv[1]);
Mat image = imread(filename.c_str(),0);
mv_background_average(image);
mv_background_rotation(image);
int r = image.rows;
int c = image.cols;
int k=0;
Mat_<uchar> dst(r,c);
for (int i=3; i<r-3; ++i)
for (int j=3; j<c-3; ++j)
{
int m = i-2;
int n = j-2;
double maxval;
Rect roi(m,n,5,5);
Mat temp(image,roi);
minMaxLoc(temp,0,&maxval,0,0);
if ((maxval >= 100) && (image.at<uchar>(i,j) == maxval))
{
dst(i,j) == 255;
cout << temp << " ";
k++;
}
}
cout << k <<endl;
return 0;
}
void mv_background_average(Mat & img)
{
int r = img.rows;
int c = img.cols;
int length = r/4;
int r2 = 3*r/8;
int c2 = 3*c/8;
Scalar mean, stddev;
Mat RoiA(img,Rect(r2,c2,length,length));
meanStdDev(RoiA,mean,stddev);
float m = mean.val[0];
float std = stddev.val[0];
int threshold = ceil(m + 2 * std);
for (int i = 0; i<r ; ++i)
{
ushort * data = img.ptr<ushort>(i);
for (int j = 0; j<c; ++j)
{
if(data[j] <= threshold) { data[j] = 0;}
}
}
}
void mv_background_rotation(Mat & img)
{
int r = img.rows;
int c = img.cols;
int max_radius = 0;
int radius = 0;
r > c ? max_radius = c/2 : max_radius = r/2;
Mat rotation_sum(max_radius,3,CV_32FC1,Scalar::all(0));
for (int i = 0; i< r; ++i)
{
ushort * data = img.ptr<ushort>(i);
for (int j = 0; j<c; ++j)
{
radius = round(sqrt((i-r/2)*(i-c/2) + (j-r/2)*(j-c/2)));
if (radius <= max_radius)
{
rotation_sum.at<float>(radius,0) += data[j];
rotation_sum.at<float>(radius,1) += 1;
}
}
}
for (int i=0; i<=max_radius; ++i)
{
rotation_sum.at<float>(i,2) = rotation_sum.at<float>(i,0) / rotation_sum.at<float>(i,1);
}
for (int i = 0; i< r; ++i)
{
ushort * data = img.ptr<ushort>(i);
for (int j = 0; j<c; ++j)
{
radius = round(sqrt((i-r/2)*(i-c/2) + (j-r/2)*(j-c/2)));
int mean = ceil(rotation_sum.at<float>(radius,2));
if (radius <= max_radius && data[j] <= 4*mean)
{
data[j] = 0;
}
}
}
}
unfortunately, you don't tell us, what
mv_background_average
ormv_background_rotation
do ;(they are try to remove the background of image. their definitions show as follow: void mv_background_aveage(Mat & img) void mv_background_rotation(Mat & img)
again, since something seems to go wrong there, noone can help you without looking at the code.
where's the "double linked list", your title refers to ?
( also, you can use the "01101" button to format code properly )
I have uploaded my code, and hope this can help you find the bug. Thanks