Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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; 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);<="" p="">

   Mat temp(image,roi);
   minMaxLoc(temp,0,&maxval,0,0);
      if (maxval >= 100)
        {
           cout << temp << " ";
           k++;
        }
   }
    cout << k <<endl;

return 0; }

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; 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);<="" p="">

   Mat temp(image,roi);
   minMaxLoc(temp,0,&maxval,0,0);
      if (maxval >= 100)
        {
           cout << temp << " ";
           k++;
        }
   }
    cout << k <<endl;

return 0; }(/upfiles/1369198828524581.png)

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.

(/upfiles/1369198828524581.png)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; 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);<="" p="">

   Mat temp(image,roi);
   minMaxLoc(temp,0,&maxval,0,0);
      if (maxval >= 100)
        {
           cout << temp << " ";
           k++;
        }
   }
    cout << k <<endl;

return 0; }

image description

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. 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; 
   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);<="" p="">

roi(m,n,5,5);="" <pre="">   Mat temp(image,roi);
   minMaxLoc(temp,0,&maxval,0,0);
      if (maxval >= 100)
        {
           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="" &lt;="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&lt;float">(radius,2)); if (radius <= max_radius && data[j] <= 4*mean) { data[j] = 0; }

      }

}

}

image description

click to hide/show revision 5
No.5 Revision

updated 2013-05-22 12:47:49 -0600

berak gravatar image

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; 
   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);="" <pre="">++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)
        {
    {
               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;

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="" &lt;="max_radius)" {="" rotation_sum.at<float="">(radius,0) ++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&lt;float">(radius,2)); ++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; }

 }

          }
   }

}

}

}

image description

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 ((maxval >= 100)
            {
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;
              }

          }
   }

}

image description