在将RealSense提取的深度图片进行显示时,由于是16位图片,想将图片转化成为8位图形进行显示
Opencv中有一个函数convertScaleAbs可以实现这种功能
C++: void convertScaleAbs(InputArray src, OutputArray dst, double alpha=1, double beta=0)
Parameters:
src: input array
dst: output array
alpha: optional scale factor
beta: optional delta added to the scaled values
the governmental definition for the function is :
On each element of the input array, the function covertScaleAbs performs three operations sequentially: scaling, taking an absolute value, conversion to an unsigned 8-bit type:
接下来示例代码:
cv::Mat map = cv::imread("C:/Users/Lee_gc/Desktop/try.png", CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);//read a 16bits depth pictures
double min;
double max;
cv::minMaxIdx(map, &min, &max);
cv::Mat adjMap();
cv::convertScaleAbs(map, adjMap, 255 / max);
imshow("8bitPic", adjMap);//the picture can be showed and converted to 8bits pic
waitKey();
为了提取有效的信息并且显示,需要将有效区域用其他颜色画出来
使用opencv circle函数
首先将单通道灰度图转化成3通道的彩色图像
实例如下:
// read image
cv::Mat img_gray = imread(path,0);
// create 8bit color image. IMPORTANT: initialize image otherwise it will result in 32F
cv::Mat img_rgb(img_gray.size(), CV_8UC3);
// convert grayscale to color image
cv::cvtColor(img_gray, img_rgb, CV_GRAY2RGB);
circle(img_rgb, Point(100,100), 30, Scalar(100, 250, 100), -1);//Point圆心中心点,30,半斤,Scalar画笔的参数,-1表示画成实心状态
imshow("test", img_rgb);
接下来我们如何能让画的圈为透明的,不遮挡重点显示的区域呢
接下来我们要使用addWeighted函数来实现这个功能,通过实现两张图片进行叠加
Mat overlay;
rgb_img.copyTo(overlay);
circle(overlay, p, 50, Scalar(100, 250, 100), -1);
addWeighted(overlay, 0.3, img_rgb, 0.7, 0, img_rgb);
imshow("test", img_rgb);
waitKey();
最后实现的效果如下:

本文介绍了如何使用OpenCV的convertScaleAbs函数将16位深度图片转换为8位图像,并展示了在灰度图上进行透明彩色绘制的方法。通过示例代码,解释了如何利用circle函数在图像上画出彩色圆圈,并借助addWeighted函数实现透明效果,以避免遮挡关键显示区域。

3145

被折叠的 条评论
为什么被折叠?



