Bus error (core dumped) while declaring cv::Mat
Hi, I have been dealing with very simple matrices. The code snippet is below
cv::Size sz, sz1, sz2;
sz2 = cv::Size(4,1);
cv::Mat M(sz2, CV_8U);
int color_array_size = (1/3) * (point_cloud->width * point_cloud->height);
uint32_t arr [point_cloud->width * point_cloud->height] = {0};
uint8_t red_array[color_array_size] ={}, blue_array[color_array_size] ={} , green_array[color_array_size] ={};
sz= cv::Size(point_cloud->width, point_cloud->height);
sz1= cv::Size( point_cloud->width, point_cloud->height);
cv::Mat_ <cv::Vec3f> image(sz, CV_32FC3);
cv::Mat image_color(sz, CV_32F, arr);
The trouble is caused due to cv::Mat M(sz2, CV_8U);
building the code is fine. While running the executable Bus error (core dumped)
occurs. Some other type of matrices are also causing this annoying trouble. Anyone could suggest something to get rid of this?
you're taking liberties with the type system, and your Mat constructors are broken ;(
cv::Mat image_color(sz, CV_32F, arr);
arr
is an int not a float array.cv::Mat_ <cv::Vec3f> image(sz, CV_32FC3);
no, it must be the array size, notCV_32FC3
as well forM
ok, I modified to
float arr
. Still same. I do not understand your second point.strike the 2nd part, i misread something. apologies.
what are you doing with
image_color
later ? isarr
valid all through it's lifetime ?how many bytes do you actually try to allocate in (limited) auto memory with constructs like:
?
imho, you should use std::vector (or at least new), not put all of your (dynamic) arrays in auto memory
Code:
this is the part that is modified in the above code. Now, it works fine. But still I am not happy. Why is it so that creating matrix
M
without assigning data to it, complaints where as, after assigning data to it, it works fine. If somebody please explain ?I want to allocate
(point_cloud->width , 3)
data in a 2Dfloat
matrix.why even use external arrays ?