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);
}
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?img_matisCV_8UC1-- i.e. a byte. And then you access it asimg_mat.at<int>, treating each element as a 32bit value. That's incorrect, it ought to be something likeimg_mat.at<uint8_t>.