示例#1
0
            public static PointsPair GetPoints(Point A, Point B)
            {
                Random random = new Random();

                PointsPair AnB = new PointsPair();

                Thread.Sleep(20);
                A.X = random.Next(0, width - 1);
                Thread.Sleep(20);
                B.X = random.Next(A.X, width);
                Thread.Sleep(20);

                Thread.Sleep(20);
                A.Y = random.Next(0, height - 1);
                Thread.Sleep(20);
                B.Y = random.Next(A.Y, height);
                Thread.Sleep(20);

                AnB.A = A;
                AnB.B = B;

                if (PointsPair.count > 1)
                {
                    if (IsBetween(A, count - 1))
                    {
                        return(GetPoints(A, B));
                    }
                    if (IsBetween(B, count - 1))
                    {
                        return(GetPoints(A, B));
                    }
                }
                return(AnB);
            }
示例#2
0
        private void GenRand(int min, int max)
        {
            Random random = new Random();
            int    color  = random.Next(min, max);

            Bitmap timage = new Bitmap(originalImageBox.Image);

            Point A = new Point();
            Point B = new Point();

            PointsPair AnB = PointsPair.GetPoints(A, B);

            pointsList.Add(AnB);

            Thread.Sleep(20);
            for (int x = AnB.A.X; x < AnB.B.X; x++)
            {
                for (int y = AnB.A.Y; y < AnB.B.Y; y++)
                {
                    timage.SetPixel(x, y, System.Drawing.Color.FromArgb(color, color, color));
                }
            }
            originalImageBox.Image = timage;
        }
示例#3
0
        /// <summary>
        /// Handles the body frame data arriving from the sensor
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_FrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            int depthWidth      = 0;
            int depthHeight     = 0;
            int colorWidth      = 0;
            int colorHeight     = 0;
            int bodyIndexWidth  = 0;
            int bodyIndexHeight = 0;

            bool multiSourceFrameProcessed = false;
            bool colorFrameProcessed       = false;
            bool depthFrameProcessed       = false;
            bool bodyFrameProcessed        = false;
            bool bodyIndexFrameProcessed   = false;

            // coordinatemapperのルックアップテーブルがどのタイミングで生成されるのかよくわからんので、とりあえずここ
            if (this.motionDataHandler.DepthLUT == null)
            {
                this.motionDataHandler.DepthLUT = this.coordinateMapper.GetDepthFrameToCameraSpaceTable();
                //TODO: world to colorの式を予想する
            }

            MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame();

            if (multiSourceFrame != null)
            {
                using (DepthFrame depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame())
                    using (ColorFrame colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame())
                        using (BodyFrame bodyFrame = multiSourceFrame.BodyFrameReference.AcquireFrame())
                            using (BodyIndexFrame bodyIndexFrame = multiSourceFrame.BodyIndexFrameReference.AcquireFrame())
                            {
                                if (depthFrame != null)
                                {
                                    FrameDescription depthFrameDescription = depthFrame.FrameDescription;
                                    depthWidth  = depthFrameDescription.Width;
                                    depthHeight = depthFrameDescription.Height;
                                    if ((depthWidth * depthHeight) == this.depthBuffer.Length)
                                    {
                                        depthFrame.CopyFrameDataToArray(this.depthBuffer);
                                        depthFrameProcessed = true;
                                    }
                                }
                                if (bodyIndexFrame != null)
                                {
                                    FrameDescription bodyFrameDescription = bodyIndexFrame.FrameDescription;
                                    bodyIndexWidth  = bodyFrameDescription.Width;
                                    bodyIndexHeight = bodyFrameDescription.Height;
                                    if ((bodyIndexWidth * bodyIndexHeight) == this.bodyIndexBuffer.Length)
                                    {
                                        bodyIndexFrame.CopyFrameDataToArray(this.bodyIndexBuffer);
                                        bodyIndexFrameProcessed = true;
                                    }
                                }
                                if (colorFrame != null)
                                {
                                    FrameDescription colorFrameDescription = colorFrame.FrameDescription;
                                    colorWidth  = colorFrameDescription.Width;
                                    colorHeight = colorFrameDescription.Height;
                                    if ((colorWidth == this.colorBitmap.PixelWidth) && (colorHeight == this.colorBitmap.PixelHeight))
                                    {
                                        if (colorFrame.RawColorImageFormat == ColorImageFormat.Bgra)
                                        {
                                            colorFrame.CopyRawFrameDataToArray(this.colorPixels);
                                        }
                                        else
                                        {
                                            colorFrame.CopyConvertedFrameDataToArray(this.colorPixels, ColorImageFormat.Bgra);
                                        }
                                        colorFrameProcessed = true;
                                    }
                                }
                                if (bodyFrame != null)
                                {
                                    if (this.bodies == null)
                                    {
                                        this.bodies = new Body[bodyFrame.BodyCount];
                                    }
                                    bodyFrame.GetAndRefreshBodyData(this.bodies);
                                    bodyFrameProcessed = true;
                                }
                                multiSourceFrameProcessed = true;
                            }
            }

            // we got all frames
            if (multiSourceFrameProcessed && depthFrameProcessed && colorFrameProcessed && bodyFrameProcessed && bodyIndexFrameProcessed)
            {
                Dictionary <ulong, PointsPair> pointPairs = new Dictionary <ulong, PointsPair>();
                this.RenderColorPixels();
                using (DrawingContext dc = this.drawingGroup.Open())
                {
                    dc.DrawRectangle(Brushes.Transparent, null, new Rect(0.0, 0.0, this.colorWidth, this.colorHeight));
                    int penIndex = 0;

                    foreach (Body body in this.bodies)
                    {
                        Pen drawPen = this.bodyColors[penIndex++];
                        if (body.IsTracked)
                        {
                            Dictionary <JointType, Joint> joints = (Dictionary <JointType, Joint>)body.Joints;
                            PointsPair pointsPair = this.ConvertCameraPoint(joints);
                            pointPairs[body.TrackingId] = pointsPair;

                            Dictionary <JointType, Point> colorPoints = pointsPair.Item1;
                            this.DrawBody(joints, colorPoints, dc, drawPen);
                        }
                    }
                    this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.colorWidth, this.colorHeight));
                }
                // TODO : ロケールのチェック
                if (this.isRecording)
                {
                    Task.Run(() => this.motionDataHandler.AddData(this.counter++, DateTime.Now, this.bodies, ref this.colorPixels, ref this.depthBuffer, ref this.bodyIndexBuffer, pointPairs));
                }
            }
        }