I'm creating a new Mat
by jumping pixels of the original image, but I get this error:
PRM algorithm: malloc.c:2451: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
My code is:
int width = round(img.cols / M);
int height = round(img.rows / M);
cv::Mat res(height, width, CV_8U);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
res.at<cv::Vec3b>(i, j)[0] = img.at<cv::Vec3b>(i * M, j * M)[0];
res.at<cv::Vec3b>(i, j)[1] = img.at<cv::Vec3b>(i * M, j * M)[1];
res.at<cv::Vec3b>(i, j)[2] = img.at<cv::Vec3b>(i * M, j * M)[2];
}
}
return res;
I also tried using uchar* ptr = img.ptr<uchar>(i)
and ptr[j]
so it's possible to access the data directly, but I receive the same error.
I was searching, and tried some "solution" such as sYSMALLOc: Assertion Failed error in opencv, but the trouble keeps appearing.