当前位置:网站首页>ToF相机从Camera2 API中获取DEPTH16格式深度图
ToF相机从Camera2 API中获取DEPTH16格式深度图
2022-08-02 14:02:00 【程序猫 猫小白】
ToF相机工作原理:
ToF相机给目标连续发送光脉冲,然后用传感器接收从物体返回的光,通过探测光脉冲往回的飞行时间来得到目标距离。ToF相机可以同时得到整幅图像的深度(距离)信息。
深度图通常是灰度图,其中的每个值代表光反射表面和相机的距离。灰度图水平垂直坐标对应像素点位置,该位置的灰度值对应的是该像素距离摄像头的距离。所以深度图中的每个像素可以表示空间中一个点的三维坐标。如果光源被吸收或者未收到反射信号则呈现黑色。
从Camera2API中获取DEPTH16格式的深度信息
ImageFormat.DEPTH16: Android密集深度图像格式。每个深度值是16位。16位由置信度值和实际测距测量组成。置信度是该样本正确性的估计值。它被编码在样本的3个最高效有效位中,其值0表示100%置信度,值1表示0%置信度,值2表示1/7,值3表示2/7. 剩下的13位就是表示每个像素的深度值。
获取深度信息流程:打开深度ToF相机---->给ImageReader设置长宽和格式ImageFormat.DEPTH16。在回调接口onImageAvailabe中拿到image数据。
private int[] getDepth(Image image){
ShortBuffer shortDepthBuffer=image.gePlanes()[0].getBuffer().asShortBuffer();
int[] arr=new int[WIDTH*HEIGHT];
for(int y=0;y<HEIGHT;y++){
for(int x=0;x<WIDTH;x++){
int index=y*WIDTH+x;
short depth=shortDepthBuffer.get(indxe);
int newValue=extractRange(depthSample,0.1);
arr[index]=newVaule;
}
}
}
private int extractRange(short sample,float confidenceFilter){
//2字节后13位保存深度信息
int depthRange=(short)(sample&0x1FFF);
//2字节的前3位保存置信度值
int depthConfidence=(short)((sample>>13) & 0x7);
//其值0表示100%置信度,值1表示0%置信度,值2表示1/7,值3表示2/7.
//转换成我们熟悉点的表示方式 0~~1
float depthPercentage=depthConfidence==0?1.f:(depthConfidence-1)/7.f;
return depthPercentage>confidenceFilter?depthRange:0;
}
获取到的距离信息归一化位0~255的像素值,最后转为RGB Bitmap,然后显示出来,基本可以看到物体的轮廓。
写在最后的话
今天是五一,放假,有时间可以写写博客,刚好可以对自己学习的东西有个整理~~~
边栏推荐
猜你喜欢
![[ROS] The software package of the industrial computer does not compile](/img/a8/a1347568170821e8f186091b93e52a.png)
[ROS] The software package of the industrial computer does not compile

第十一单元 序列化器

网络剪枝(1)

Cloin 控制台乱码

深度学习框架pytorch快速开发与实战chapter3

The future of financial services will never stop, and the bull market will continue 2021-05-28
![[ROS]roscd和cd的区别](/img/a8/a1347568170821e8f186091b93e52a.png)
[ROS]roscd和cd的区别

How to solve mysql service cannot start 1069

The world's largest Apache open source foundation is how it works?

浅浅写一下PPOCRLabel的使用及体验
随机推荐
【Tensorflow】AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'
瑞吉外卖笔记——第05讲Redis入门
Sentinel源码(四)(滑动窗口流量统计)
Deep learning framework pytorch rapid development and actual combat chapter4
第十单元 前后连调
drf源码分析与全局捕获异常
The language of initial
Unit 11 Serializers
Supervision strikes again, what about the market outlook?2021-05-22
What are the file encryption software?Keep your files safe
ping命令的使用及代码_通过命令查看ping路径
The bad policy has no long-term impact on the market, and the bull market will continue 2021-05-19
Flask项目的完整创建 七牛云与容联云
Minio文件上传
Chapter6 visualization (don't want to see the version)
redis分布式锁和看门狗的实现
Sentinel源码(六)ParamFlowSlot热点参数限流
Briefly write about the use and experience of PPOCRLabel
8580 Merge linked list
Programming Specifications - LiteOS