I have the following code:
string filename = "frame_00003_depth.bin";
int16_t* depth_img = loadDepthImageCompressed(filename.c_str());
Mat depth_img_meters = Mat(480, 640, CV_16UC1);
for(int row = 0; row < 480; row++){
for(int col = 0; col < 640; col++){
depth_img_meters.at<int16_t>(row, col) = depth_img[(640*row + col)] * 0.001;
cout << depth_img_meters.at<int16_t>(row,col)<< "meters" << endl;
}
}
I have checked that the array int16_t* depth_img has values in it greater than 100, however when assigning to the Mat here it prints all zeros
Looks like a truncation problem to me.
You are multiplying the values in
depth_imgby 0.001, which means the numbers are getting converted to floating point and then back toint16_tin the assignment process. This means that any values less than 1000 indepth_imgwill be truncated to zero indepth_img_metersAny time you are dealing with different data types you have to watch out for errors associated with this sort of implicit conversion during assignment.