Leap Motion 用EmguCV 显示图像并对齐手指

使用的为控制台应用程序。主要的代码都在重写的Listener类里,代码如下。
中间需要对坐标转换下。
我只显示了左边的那副图。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Leap;
using Emgu.CV;
using System.Drawing;
using Emgu.CV.Structure;
using Emgu.Util;
using System.Drawing.Imaging;

namespace ConsoleApplication14
{
    class asas : Listener
    {
        Object thislock = new Object();
        Image<Gray, byte> left = new Image<Gray, byte>(640, 240);
        void safewriteline(string line)
        {
            lock (thislock)
            {
                Console.WriteLine(line);
            }
        }
        public override void OnConnect(Controller arg0)
        {
            safewriteline("Conectted");
        }
        public override void OnFrame(Controller arg0)
        {
            Frame frame = arg0.Frame();
            ImageList images = frame.Images;
            //HandList hands = frame.Hands;
            FingerList fingers = frame.Fingers;

            Image<Gray, byte> left = new Image<Gray, byte>(640,240);
            left.Bytes = images[0].Data;
            foreach(var f1 in fingers)
            {
                Leap.Vector tip = f1.TipPosition;
                float h_slope = -(tip.x + 20 * (-1)) / tip.y;
                float v_slope = tip.z / tip.y;

                Leap.Vector pixel = images[0].Warp(new Leap.Vector(h_slope, v_slope, 0));
                CvInvoke.Circle(left, new Point((int)pixel.x, (int)pixel.y), (int)(1/tip.y*1000), new MCvScalar(255), (int)(1/tip.y*1000)*2);
            }
            CvInvoke.Imshow("asasa",left);
            CvInvoke.WaitKey(2);
        }
        public override void OnInit(Controller arg0)
        {
            safewriteline("inti");
        }

    }
}

然后这个是主函数的代码

namespace ConsoleApplication14
{
 class MyApplication { static void Main(string[] args) { Controller leap = new Controller(); leap.AddListener(new asas()); leap.SetPolicy(Controller.PolicyFlag.POLICY_IMAGES); Console.ReadKey(); } } }

运行图:
Leap Motion 用EmguCV 显示图像并对齐手指_第1张图片

你可能感兴趣的:(Leap,motion)