Kinect 开发系列之 获取捕捉点图像的横纵坐标并用来做图像剪切

仅是自己对kinect的理解,会有错漏。

 kinect的简单动作捕捉是通过 其RGB摄像头(3 个摄像头之一)捕捉的。目前beta2版本里至少可以追踪21个关节点(如头,左肩膀,肩膀中心,有肩膀,脊椎,左右肘,手腕,脚踝,左右中臀)。可以在这里找得到Microsoft.Research.Kinect.Nui.JointID

Kinect有3个摄像头,除了上面说到的那个,还有分别作3D深度识别和感知器。注意3D深度识别,用下面的代码你能大概理解深度识别的意义和用法。如下:

using Microsoft.Research.Kinect.Nui;  

public void GetCoordinates(Joint joint, out float x, out float y)
        {
            skeletonEngine.SkeletonToDepthImage(joint.Position, out x, out y);

            x = (float)(x * rootCanvas.ActualWidth);
            y = (float)(y * rootCanvas.ActualHeight);
        }

Tip: SkeletonEngine is a type/object of Microsoft.Research.Kinect.Nui namespace.

 

注意这个方法 "SkeletonToDepthImage" ,传入一个关节(或称为捕捉点),会返回其x,y坐标值。

这个坐标值做什么用呢?

可以根据其值用来计算你要截取从图像X,Y坐标位置处开始的图像。 代码示例如下:

public BitmapSource GetFrame()
        {
            ImageFrame imgFrame;

            try
            {
                imgFrame = kinectRuntime.VideoStream.GetNextFrame(3000);
            }
            catch (Exception)
            {
                return null;
            }

            PlanarImage Image = imgFrame.Image;

            if (this.lastHeadPoint != null)
            {
                float Xcenter = 0;
                float Ycenter = 0;

                skeletonDisplayManager.GetCoordinates((Joint)this.lastHeadPoint, out Xcenter, out  Ycenter);

                // calculate the Rectangle coordinates in whom to search for a match
                int width = 288;
                int height = 400;
                int X = (int)Xcenter - width / 2;
                int Y = (int)Ycenter - height / 2;

                // double check that we are not croping outside the image
                X = X < 0 ? 0 : X;
                Y = Y < 0 ? 0 : Y;
                X = X + width >= 1280 ? 1280 - width : X;
                Y = Y + height >= 1024 ? 1024 - height : Y;

               BitmapSource ColorBitmap = BitmapSource.Create(image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);

                // do the crop
               CroppedBitmap cb = new CroppedBitmap(ColorBitmap, new Int32Rect(x, y, width, height));
               ColorBitmap = cb;

                return ColorBitmap;
            }

          }

X,Y坐标跟图像细细相关,比如这个方法:

ColorBitmap = BitmapSource.Create(Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);

咋看起来参数有些复杂,其实只需关注2点:即图像本身和你要定位的X,Y坐标。

图像对象ImageFrame来自于Kinect自己的SDK:Microsoft.Research.Kinect.Nui.

.NET的命名空间System.Windows.Media.Imaging.BitmapSource和CroppedBitmap会被经常引用在Kinect开发中。就像上面的方法BitmapSource.Create需要BitmapSource来创建一个图形。

还有一个kinect的核心对象Runtime,通过它可以获得很多对象,比如camera和image,video对象。

 

to be continued.....
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值