使用C#在.bin中写入深度图像 [英] Writing depth image in .bin using C#

查看:74
本文介绍了使用C#在.bin中写入深度图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存使用Kinect v2捕获的深度图像。我可以将图像保存在(.png,.tif,.gif等)中,但是保存数据需要花费很多时间,并且在保存时会遗漏一些帧。所以我想以.bin格式保存图像。这是我的深度图像代码:


< g class =" gr_ gr_19 gr-alert gr_gramm标点符号replaceWithoutSep"数据-GR-ID =" 19 QUOT; id =" 19">请任何人< / g>告诉我如何写出深度图像< g class =" gr_ gr_36 gr-alert gr_gramm标点符号multiReplace"
data-gr-id =" 36" id =" 36"> in。< / g> bin文件。

 

 IplImage depth = new IplImage(512,424,BitDepth.U16,1); 
CvVideoWriter DepthWriter;
Width = sensor.DepthFrameSource.FrameDescription.Width;
DHeight = sensor.DepthFrameSource.FrameDescription.Height;
WbDepth = new WriteableBitmap(DWidth,DHeight,96,96,PixelFormats.Gray16,null);
int depthshft =(int)SliderDepth.Value;
使用(DepthFrame depthframe = frame.DepthFrameReference.AcquireFrame())
ushort * depthdata =(ushort *)depth.ImageData;
if(depthframe!= null)
{
Depthdata = new ushort [DWidth * DHeight];
ushort [] Depthloc = new ushort [DWidth * DHeight];
depthframe.CopyFrameDataToArray(Depthdata);
for(int i = 0; i< DWidth * DHeight; i ++)
{
Depthloc [i] = 0x1000;
}
colorspacePoint = new ColorSpacePoint [DWidth * DHeight];
depthspacePoint = new DepthSpacePoint [CWidth * CHeight];
sensor.CoordinateMapper.MapDepthFrameToColorSpace(Depthloc,colorspacePoint);
for(int y = 0; y< DHeight; y ++)
{
for(int x = 0; x< DWidth; x ++)
{
if(depthshft!= 0)
{
Depthdata [y * DWidth + x] =(ushort)((Depthdata [y * DWidth + x])<< depthshft);
}

}
}
depth.CopyPixelData(Depthdata);
}
WbDepth.WritePixels(new Int32Rect(0,0,DWidth,DHeight),Depthdata,strideDep,0);
ImageDepth.Source = WbDepth;
if(depth!= null)
{
string s = string.Format(" {0}",count_depth);
Cv.SaveImage(" G:\\Kinect V2 Recording\\\\\\\\\\\\\\\\\\\\\\\\\;


count_depth ++;
}
Cv.ReleaseVideoWriter(DepthWriter);
CheckBox_saveD.IsEnabled = false;
if(CheckBox_saveD.IsChecked == true)Cv.ReleaseVideoWriter(DepthWriter);


解决方案

这不是同一个问题:


https://social.msdn .microsoft.com /论坛/ EN-US / 51283b24-4844-4dfa-aed6-72bad6b0a1ea /视频编解码器,用于节能深入流?论坛= kinectv2sdk


I want to save depth images captured using Kinect v2. I can save the images in (.png, .tif, .gif etc) but it took much time in saving data and it miss some frames while saving. So I want to save the images in .bin format. Here is my code for the depth image:

<g class="gr_ gr_19 gr-alert gr_gramm Punctuation replaceWithoutSep" data-gr-id="19" id="19">Please anyone</g> tell me how can write the depth image <g class="gr_ gr_36 gr-alert gr_gramm Punctuation multiReplace" data-gr-id="36" id="36">in .</g>bin file.

IplImage depth = new IplImage(512, 424, BitDepth.U16, 1);
CvVideoWriter DepthWriter;
Width = sensor.DepthFrameSource.FrameDescription.Width;
DHeight = sensor.DepthFrameSource.FrameDescription.Height;
WbDepth = new WriteableBitmap(DWidth, DHeight, 96, 96, PixelFormats.Gray16, null);
int depthshft = (int)SliderDepth.Value;
using (DepthFrame depthframe = frame.DepthFrameReference.AcquireFrame())
ushort* depthdata = (ushort*)depth.ImageData;
if (depthframe != null)
   {
    Depthdata = new ushort[DWidth * DHeight];
    ushort[] Depthloc = new ushort[DWidth * DHeight];
    depthframe.CopyFrameDataToArray(Depthdata);
    for (int i = 0; i < DWidth * DHeight; i++)
        {
          Depthloc[i] = 0x1000;
        }
        colorspacePoint = new ColorSpacePoint[DWidth * DHeight];
        depthspacePoint = new DepthSpacePoint[CWidth * CHeight];
        sensor.CoordinateMapper.MapDepthFrameToColorSpace(Depthloc, colorspacePoint);
        for (int y = 0; y < DHeight; y++)
            {
            for (int x = 0; x < DWidth; x++)
                {
                if (depthshft != 0)
                   {
                    Depthdata[y * DWidth + x] = (ushort)((Depthdata[y * DWidth + x]) << depthshft);
                   }

                 }
             }
         depth.CopyPixelData(Depthdata);
 }
WbDepth.WritePixels(new Int32Rect(0, 0, DWidth, DHeight), Depthdata, strideDep, 0);
ImageDepth.Source = WbDepth;
if (depth != null )
            {
                string s = string.Format("{0}", count_depth);
                Cv.SaveImage("G:\\Kinect V2 Recording\\depth\\depth" + s + ".png", depth);


                count_depth++;
            }
Cv.ReleaseVideoWriter(DepthWriter);
    CheckBox_saveD.IsEnabled = false;
if (CheckBox_saveD.IsChecked == true) Cv.ReleaseVideoWriter(DepthWriter);


解决方案

Isn't this the same question:

https://social.msdn.microsoft.com/Forums/en-US/51283b24-4844-4dfa-aed6-72bad6b0a1ea/video-codec-for-saving-depth-stream?forum=kinectv2sdk


这篇关于使用C#在.bin中写入深度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆