Пример #1
0
 private void cameraCanvas_MouseClick(object sender, MouseEventArgs e)
 {
     int depth = depthPixels[e.Y * 640 + e.X].Depth;
     SkeletonPoint sp = SkeletonDepthPointToSkeltonPoint(e.X, e.Y, depth);
     if (e.Button == System.Windows.Forms.MouseButtons.Left)
     {
         planePixels.Add(sp);
         stagePoints.Add(sp);
         if (planePixels.Count == 5)
         {
             planePixels.RemoveAt(3);
             stagePoints.RemoveAt(3);
         }
         else if (planePixels.Count == 3) plane = new Plane(planePixels[0], planePixels[1], planePixels[2]);
     }
 }
Пример #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                this.sensor.SkeletonStream.Enable();
                this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;
                this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength];
                this.depthPixels = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength];
                this.planePixels = new List<SkeletonPoint>();
                this.plane = null;
                this.colorBitmap = new Bitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                this.sensor.ColorFrameReady += this.SensorColorFrameReady;
                this.sensor.DepthFrameReady += this.SensorDepthFrameReady;
                try
                {
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    this.sensor = null;
                }
            }
            cameraCanvas.Image = new Bitmap(640, 480);

            // Processingと接続
            try
            {
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    // サーバーを作る
                    server = new TcpListener(IPAddress.Parse(Host), Port);

                    // サーバーを接続待機させる
                    server.Start();
                    Console.WriteLine("connecting...");
                    // サーバーから見たクライアントがclient、AcceptTcpClientで接続を待つ
                    client = server.AcceptTcpClient();
                    Console.WriteLine("connected!");

                    while (client.Connected)
                    {
                        System.Threading.Thread.Sleep(16);
                        if (IsSendText)
                        {
                            IsSendText = false;
                            SendQuery(SendText);
                        }
                        else
                        {
                            SendQuery("-100 -100");
                        }
                    }
                });
            }
            catch (SocketException ee)
            {
                Console.WriteLine(ee.Message);
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee.Message);
            }
        }