1 | initial version |
"But When i view the newly created mat, it is solid black. "
ah, this is now easy to answer. idk. , in which range your z values are, but most likely, your conversion to u8 needs a scale factor, like:
depth_image.convertTo(depth_image, CV_8U, 255.0); // offset, too ?
to be sure, check min/max vals before the conversion. (maybe you even got negative values ? requiring an offset ?)
double m,M;
minMaxLoc(depth_image, &m, &M, 0, 0);
alternatively, you could normalize your image (and change type on the way):
normalize(depth_image, depth_image, 0, 255, NORM_MINMAX, CV_8U);
2 | No.2 Revision |
"But When i view the newly created mat, it is solid black. "
ah, this is now easy to answer. idk. , in which range your z values are, but most likely, your conversion to u8 needs a scale factor, like:and maybe an offset (remember, you need [0..255] for u8).
depth_image.convertTo(depth_image, CV_8U, 255.0); // offset, too ?
to be sure, check min/max vals before the conversion. (maybe you even got negative values ? requiring an offset ?)
double m,M;
minMaxLoc(depth_image, &m, &M, 0, 0);
then use that information like:
depth_image.convertTo(depth_image, CV_8U, 255.0/(M-m), -m);
alternatively, you could normalize your image (and change type on the way):
normalize(depth_image, depth_image, 0, 255, NORM_MINMAX, CV_8U);