当前位置:网站首页>Unity display Kinect depth data
Unity display Kinect depth data
2022-07-27 19:04:00 【Miracle Fan】
Unity Show Kinect Depth data
1. Create display graphic objects
1.1 establish RawImage object

1.2 Create materials
Set to the following parameters , Set it to unlit-transparent Make transparent display

![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-XAa6AsOI-1650011391827)(../ picture /image-20220415160945797.png)]](/img/60/48cde59502bc90db9d0d76149c6c81.png)
2. Create fields
public MultiSourceManager mMultiSource;
public Texture2D mDepthTexture;// Depth texture
// Depth data
private ushort[] mDepthData = null;//MultiSource Manager Output depth data content
private CameraSpacePoint[] mCameraSpacePoint = null;
private ColorSpacePoint[] mColorSpacePoints = null;
//Kinect
private KinectSensor mSensor = null;
private CoordinateMapper mMapper = null;// Mapper
// The resolution of depth data is 512*424
private readonly Vector2 mDepthResolution = new Vector2(512, 424);
3. Awake
private void Awake()
{
mSensor = KinectSensor.GetDefault();// obtain Kinect sensor
mMapper = mSensor.CoordinateMapper;// Get coordinate mapper
int arraySize = (int)(mDepthResolution.x * mDepthResolution.y);// Depth data resolution
// Create new spatial points according to the resolution of the depth data
mCameraSpacePoint = new CameraSpacePoint[arraySize];
mColorSpacePoints = new ColorSpacePoint[arraySize];
}
4. Update
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))// Determine whether to press the space
{
// Press the space to map the depth image to the color space
DepthToColor();
mDepthTexture = CreateTexture();// Get new texture
}
}
5. Create a new texture
/// <summary>
/// Create a new texture
/// </summary>
/// <returns></returns>
private Texture2D CreateTexture()
{
Texture2D newTexture = new Texture2D(1920, 1080, TextureFormat.Alpha8, false);//RGB Camera output 1920*1080 Pixel image ,alpha8 So that we can see transparent pictures
// Traverse all pixels to clear the initial texture
for (int x = 0; x < 1920; x++)
{
for (int y = 0; y < 1080; y++)
{
newTexture.SetPixel(x, y, Color.clear);
}
}
// Traverse all pixels and set new colors for them
foreach (ColorSpacePoint point in mColorSpacePoints)// Traverse all pixels and set new colors for them
{
newTexture.SetPixel((int)point.X, (int)point.Y, Color.black);
}
newTexture.Apply();// Apply a new texture
return newTexture;
}
6. Depth data is mapped to color space
/// <summary>
/// Get camera space points and color space points
/// </summary>
private void DepthToColor()
{
// Acquire depth image data , A set of data streams
mDepthData = mMultiSource.GetDepthData();
// Map the image
mMapper.MapDepthFrameToCameraSpace(mDepthData, mCameraSpacePoint);// Map depth frames to camera space points
mMapper.MapDepthFrameToColorSpace(mDepthData, mColorSpacePoints);// Depth frames are mapped to color space points
}
After clearing the color image, the following depth data can be displayed .

Reference material :https://youtu.be/ukN3Aq7oYro
边栏推荐
猜你喜欢

自控原理学习笔记-系统稳定性分析(1)-BIBO稳定及Routh判据

Unity显示Kinect捕获的镜头

NPM's ID card and dependence

Product recommendation and classified product recommendation

MySQL 01 关系型数据库设计

Intelligent insomnia therapeutic instrument product dlt8p68sa Jericho

Extension of regular expression

连接查询和子查询

SSM integration

JMeter interface automation - how to solve the content type conflict of request headers
随机推荐
Docker - docker installation, MySQL installation on docker, and project deployment on docker
`this.$ Emit ` the child component passes multiple parameters to the parent component
JDBC-MySql 02 数据访问和DAO模式
IDEA连接数据库时区问题,报红Server returns invalid timezone. Need to set ‘serverTimezone‘ property.
MySQL 01 relational database design
"Testing novice encyclopedia" 5-minute quick start pytest automated testing framework
MySQL 05 stored procedure
Useful resources for ns2
MySQL 01 关系型数据库设计
ridis命令笔记
【微信小程序】项目实战—抽签应用
汇编语言入门基础(1)
Music rhythm colorful gradient lamp chip -- dlt8s04a- Jericho
Overview of Baidu map technology, and application development of basic API and webapi
CMD 命令
express get/post/delete...请求
微信支付及支付回调
Here are all the MySQL interview questions you can't expect (the latest version of 2022)
MongoDB
npm、cnpm 淘宝镜像