qq_27468993 2015-09-28 06:08 采纳率: 50%
浏览 1714
已采纳

新人求助!!!代码纠错

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Kinect;
using System.IO;
using System.Windows.Forms;
namespace GetPointCloudFromKinectV2
{
class Program
{

//************************ 初始化相关对象 *********************************
public static KinectSensor sensor0 = null;

    static DepthFrameSource depthFrameSource0 = null;

    static DepthFrameReader depthFrameReader0 = null;

    static DepthFrame depthFrame = null;
    static ushort[] frameData_Shoot = new ushort[217088];

    static CoordinateMapper coordinateMapper0 = null;

    static int depthFrameWidth=512;
    static int depthFrameHeight = 424;
    static CameraSpacePoint[] OriginalPointCloud0 = new CameraSpacePoint[depthFrameWidth*depthFrameHeight];
    static void Main(string[] args)
    {
        sensor0 = KinectSensor.GetDefault();
        sensor0.Open(); //打开传感器


        depthFrameSource0 = sensor0.DepthFrameSource;//初始化depthFrameSource0
        coordinateMapper0 = sensor0.CoordinateMapper;//初始化coordinateMapper0

        depthFrameReader0 = sensor0.DepthFrameSource.OpenReader();//打开深度数据流

        DepthFrame depthFrame = null;
        depthFrame = depthFrameReader0.AcquireLatestFrame();
        if (depthFrame != null)
        {
            depthFrame.CopyFrameDataToArray(frameData_Shoot);

            coordinateMapper0.MapDepthFrameToCameraSpace(frameData_Shoot, OriginalPointCloud0);}}



        }

/// 将摄像机坐标系下的点云写入到文件

static void WritePointCloud(CameraSpacePoint[] cameraSpacePoints, string FilePath, string FileName)
{
//确保路径存在
//如果不存在,则创建文件夹
if (!Directory.Exists(FilePath))
{
Directory.CreateDirectory(FilePath);
}

        FilePath = Path.Combine(FilePath + FileName);
        try
        {
            FileStream aFile = new FileStream(FilePath, FileMode.Create);
            StreamWriter sw = new StreamWriter(aFile);
            float x, y, z;
            int frameWidth = depthFrameWidth;//深度帧的宽度
            int frameHeight = depthFrameHeight;//深度帧的高度
            for (int row = 0; row < frameHeight; row++)
            {
                for (int col = 0; col < frameWidth; col++)
                {
                    x = cameraSpacePoints[row * frameWidth + col].X;
                    y = cameraSpacePoints[row * frameWidth + col].Y;
                    z = cameraSpacePoints[row * frameWidth + col].Z;
                    sw.WriteLine("{0} {1} {2}", x, y, z);
                }
            }
            sw.Close();
        }
        catch (IOException ex)
        {
            System.Windows.Forms.MessageBox.Show("An IO exception has been thrown!\n{0}",
                ex.ToString());
            return;
        }
    }


            新手拼凑的代码,用于提取KINECT点云数据,生成文件部分出现许多(应输入 class、delegate、enum、interface 或 struct)的错误  求前辈更正指点,没接触过C#又有些急于应用。
  • 写回答

3条回答 默认 最新

  • Go 旅城通票 2015-09-28 08:35
    关注

    类型定义错误之类的就不先不说了,就你发的这个代码好多语法错误,反大括号有些地方没闭合,楼主就没有个ide开发工具吗。。。

     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Kinect;
    using System.IO;
    using System.Windows.Forms;
    namespace GetPointCloudFromKinectV2
    {
        class Program
        {
    
            //************************ 初始化相关对象 *********************************
            public static KinectSensor sensor0 = null;
    
            static DepthFrameSource depthFrameSource0 = null;
    
            static DepthFrameReader depthFrameReader0 = null;
    
            static DepthFrame depthFrame = null;
            static ushort[] frameData_Shoot = new ushort[217088];
    
            static CoordinateMapper coordinateMapper0 = null;
    
            static int depthFrameWidth = 512;
            static int depthFrameHeight = 424;
            static CameraSpacePoint[] OriginalPointCloud0 = new CameraSpacePoint[depthFrameWidth * depthFrameHeight];
            static void Main(string[] args)
            {
                sensor0 = KinectSensor.GetDefault();
                sensor0.Open(); //打开传感器
    
    
                depthFrameSource0 = sensor0.DepthFrameSource;//初始化depthFrameSource0
                coordinateMapper0 = sensor0.CoordinateMapper;//初始化coordinateMapper0
    
                depthFrameReader0 = sensor0.DepthFrameSource.OpenReader();//打开深度数据流
    
                DepthFrame depthFrame = null;
                depthFrame = depthFrameReader0.AcquireLatestFrame();
                if (depthFrame != null)
                {
                    depthFrame.CopyFrameDataToArray(frameData_Shoot);
    
                    coordinateMapper0.MapDepthFrameToCameraSpace(frameData_Shoot, OriginalPointCloud0);////////}}////////这里多2个闭合按钮
    
    
    
                }
            }//main没有闭合
    
            /// 将摄像机坐标系下的点云写入到文件
    
            static void WritePointCloud(CameraSpacePoint[] cameraSpacePoints, string FilePath, string FileName)
            {
                //确保路径存在
                //如果不存在,则创建文件夹
                if (!Directory.Exists(FilePath))
                {
                    Directory.CreateDirectory(FilePath);
                }
    
                FilePath = Path.Combine(FilePath + FileName);
                try
                {
                    FileStream aFile = new FileStream(FilePath, FileMode.Create);
                    StreamWriter sw = new StreamWriter(aFile);
                    float x, y, z;
                    int frameWidth = depthFrameWidth;//深度帧的宽度
                    int frameHeight = depthFrameHeight;//深度帧的高度
                    for (int row = 0; row < frameHeight; row++)
                    {
                        for (int col = 0; col < frameWidth; col++)
                        {
                            x = cameraSpacePoints[row * frameWidth + col].X;
                            y = cameraSpacePoints[row * frameWidth + col].Y;
                            z = cameraSpacePoints[row * frameWidth + col].Z;
                            sw.WriteLine("{0} {1} {2}", x, y, z);
                        }
                    }
                    sw.Close();
                }
                catch (IOException ex)
                {
                    System.Windows.Forms.MessageBox.Show("An IO exception has been thrown!\n{0}",
                        ex.ToString());
                    return;
                }
            }
        }//class没有闭合
    }//namespace没有闭合
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型