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_img by 0.001, which means the numbers are getting converted to floating point and then back to int16_t in the assignment process. This means that any values less than 1000 in depth_img will be truncated to zero in depth_img_meters

Any time you are dealing with different data types you have to watch out for errors associated with this sort of implicit conversion during assignment.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top