3

My code :

  cv::Mat img_mat = cv::Mat(hough_acc.size(), hough_acc[0].size(), CV_8UC1, cv::Scalar(0));
  std::cout << hough_acc.size(  ) << "  " << hough_acc[0].size() << std::endl;

  for (size_t i = 0; i < hough_acc.size(); i++) {
    for (size_t j = 0; j < hough_acc[0].size(); j++) {
      std::cout << hough_acc[i][j] << std::endl;
      img_mat.at<int> (i,j) = hough_acc[i][j];
    }
  }

The error is in the line img_mat.at<int> (i,j) = hough_acc[i][j];. Error is :

ps1: malloc.c:2392: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
Aborted (core dumped)

I have checked size of Mat img_mat and hough_acc[][] and both are equal. The values in hough_acc are also all integers. Don't understand why the error is there.

Full code :

void hough_lines_acc(cv::Mat img_a_edges, std::vector<std::vector<int> > &hough_acc) {
  int img_w = img_a_edges.cols;
  int img_h = img_a_edges.rows;

  int max_votes = 0;
  int min_votes = INT_MAX;

  for (size_t r = 0; r < img_h; r++) {
    for (size_t c = 0; c < img_w; c++) {
      if(true) {
        for (size_t angle = 0; angle < 180; angle++) {
          double theta = (angle * M_PI / 180);
          double rho = ( (c * cos(theta)) + (r * sin(theta)) );
          int buff = ++hough_acc[static_cast<int>(abs(rho))][static_cast<int>(theta)];

          if (buff > max_votes) {
            max_votes = buff;
          }
          if (buff < min_votes) {
            min_votes = buff;
          }
        }
      }
    }
  }

  double div = static_cast<double>(max_votes) / 255;
  int threshold = 10;
  int possible_edge = round(static_cast<double>(max_votes) / div) - threshold;

  cv::Mat img_mat = cv::Mat(hough_acc.size(), hough_acc[0].size(), CV_8UC1, cv::Scalar(0));
  std::cout << hough_acc.size(  ) << "  " << hough_acc[0].size() << std::endl;

  for (size_t i = 0; i < hough_acc.size(); i++) {
    for (size_t j = 0; j < hough_acc[0].size(); j++) {
      std::cout << hough_acc[i][j] << std::endl;
      img_mat.at<int> (i,j) = hough_acc[i][j];
    }
  }

  imwrite("../output/ps1-­2-­b-­1.png", img_mat);
}
6
  • Looks like you got a serious system error... Or your toolchain's broken... Maybe you're trying to allocate too much memory? Commented Jan 6, 2017 at 17:26
  • The matrices are of size 362 x 180. I don't think I have done so, but is there a way to check the total allocation of memory and what's using how much? Commented Jan 6, 2017 at 17:27
  • Also, the error doesn't show up if I remove the line I mentioned as the suspect. Since the memory is still allocated, I am not sure if overallocation is the cause. Commented Jan 6, 2017 at 17:31
  • that should only be around 261 KB (given that the standard size of an integer is 4 bytes), not so much... Commented Jan 6, 2017 at 17:32
  • 3
    Data type of img_mat is CV_8UC1 -- i.e. a byte. And then you access it as img_mat.at<int>, treating each element as a 32bit value. That's incorrect, it ought to be something like img_mat.at<uint8_t>. Commented Jan 6, 2017 at 17:51

1 Answer 1

1

The malloc error you are getting can be caused by writing out of bounds before the suspected line. Is it possible that

    int buff = ++hough_acc[static_cast<int>(abs(rho))][static_cast<int>(theta)];

writes outside the bounds of hough_acc? Something is "fishy" since the array is of size 180 but you calculate the angles in radians so it should (probably?) go up to 6.

Sign up to request clarification or add additional context in comments.

2 Comments

No, I checked the max value of rho which is 360 and theta's max value is hardcoded. The array size is 362x180
about the 180 sized array, thats the algorithmic detail and its meant to be that way. I need to run the code for 180 different angles(in degrees) but sin and cos take values in radians, which is why conversion is being done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.