コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Gibolt/Kinivacy
 private void ResetGame()
 {
     savedBackground = null;
     GoodJob.Visibility = System.Windows.Visibility.Hidden;
     switchImage();
 }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: Gibolt/Kinivacy
        private void BackgroundRemovedFrameReadyHandler(object sender, BackgroundRemovedColorFrameReadyEventArgs e)
        {
            using (var backgroundRemovedFrame = e.OpenBackgroundRemovedColorFrame())
            {
                if (backgroundRemovedFrame != null)
                {
                    if (null == this.foregroundBitmap || this.foregroundBitmap.PixelWidth != backgroundRemovedFrame.Width 
                        || this.foregroundBitmap.PixelHeight != backgroundRemovedFrame.Height)
                    {
                    //    WriteableBitmap bit = WriteableBitmap(Happy.Source);
                        this.foregroundBitmap = new WriteableBitmap(backgroundRemovedFrame.Width, backgroundRemovedFrame.Height, 96.0, 96.0, PixelFormats.Bgra32, null);
                        // Set the image we display to point to the bitmap where we'll put the image data
                        this.MaskedColor.Source = this.foregroundBitmap;
                    }
                    if (original == 0)
                    {
                        original = image.Width;
                    }
                    if (stage == 0)
                    {
                        if (s != null && currentlyTrackedSkeletonId >= 0)
                        {
                            stage = 1;
                        }
                    }
                    else if (stage == 1) {
                        counter++;
                        Matching.FontSize = 30;
                        Matching.Text = "Initializing";
                        if (counter == 20) { stage = 2; counter = 0; }
                    }
                    else if (stage == 2)
                    {
                        counter++;
                        Matching.FontSize = 60;
                        Matching.Text = ((105 - counter) / 35 + 1).ToString();
                        if (counter == 105) { stage = 3; counter = 0; }
                    }
                    else if (stage == 3 || stage == 4)
                    {
                        if (stage == 3 && counter < 40)
                        {
                            counter++;
                            Matching.FontSize = 60 - counter;
                            Matching.Text = "Go";
                            if (counter == 40) { stage = 4; counter = 0; }
                        }
                        if (stage == 4)
                        {
                            image.Width = sizeIm;
                            if (sizeIm < foregroundBitmap.PixelWidth + 100)
                            {
                                sizeIm += rate;
                                var total = 0;
                                if (s != null)
                                {
                                    foreach (Joint joint in s.Joints)
                                    {
                                        ColorImagePoint point = ks.CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30);
                                        if (point.X > -1000000 && point.X < 1000000 && point.Y > -1000000 && point.Y < 1000000)
                                        {
                                            Joint j = joint;
                                            int pos = point.Y * stride + 4 * point.X;
                                            if (pos >= 0 && pos < sil.Length && sil[pos] == 255 && sil[pos + 1] == 255 && sil[pos + 2] == 255)
                                            {
                                                total += 1;
                                            }
                                        }
                                    }
                                    Matching.Text = "Matching: " + (total * 100 / s.Joints.Count).ToString() + "%";
                                }
                                else
                                {
                                    Matching.Text = "Matching: 0%";
                                }
                                Matching.FontSize = 30;
                            }
                            else
                            {
                                stage = 5;
                                savedBackground = backgroundRemovedFrame;
                                savedForeground = foregroundBitmap;
                            //    UpdateImage("Images//Bent.png");
                            //    image.Width = sizeIm;
                            //    image.UpdateLayout();
                                
                            }
                        }

                    }
                    else if (stage == 5)
                    {
                        counter++;
                        GoodJob.Visibility = System.Windows.Visibility.Visible;
                        if (image == Dog)
                        {
                            GoodJob.Text = "Woof! Bark!";
                        }
                        else
                        {
                            GoodJob.Text = "Good Job";
                        }
                        if (counter == 100) { stage = 6; counter = 0; GoodJob.Visibility = System.Windows.Visibility.Hidden; }
                      //  Happy.Visibility = System.Windows.Visibility.Hidden;
                      //  HappyEnd.Visibility = System.Windows.Visibility.Visible;
                      //  HappyEnd.Width = Happy.Width;
                     //   this.MaskedColor.Source = wb;
                     //   backgroundRemovedFrame = br;
                     /*   foreach (Joint joint in jc)
                        {
                            ColorImagePoint point = ks.CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30);
                            if (point.X > -1000000 && point.X < 1000000 && point.Y > -1000000 && point.Y < 1000000)
                            {
                                Joint j = joint;
                                int pos = point.Y * stride + 4 * point.X;
                                if (pos >= 0 && pos < sil.Length && sil[pos] == 255 && sil[pos + 1] == 255 && sil[pos + 2] == 255)
                                {
                                   // MaskedColor.
                                }
                            }
                        }*/
                    }
                    else if (stage == 6)
                    {
                        sizeIm -= 4;
                        if (sizeIm > startingSize)
                        {
                            image.Width = sizeIm;
                        }
                        else
                        {
                            stage = 1;
                            counter = 0;
                            rate += 1;
                            ResetGame();
                        }
                    }
                    if (savedBackground == null)
                    {
                        // Write the pixel data into our bitmap
                        this.foregroundBitmap.WritePixels(
                            new Int32Rect(0, 0, this.foregroundBitmap.PixelWidth, this.foregroundBitmap.PixelHeight),
                            backgroundRemovedFrame.GetRawPixelData(),
                            this.foregroundBitmap.PixelWidth * sizeof(int),
                            0);
                    }
                    else
                    {
                        // Write the pixel data into our bitmap
                      /*  this.foregroundBitmap.WritePixels(
                            new Int32Rect(0, 0, this.savedForeground.PixelWidth, this.savedForeground.PixelHeight),
                            savedBackground.GetRawPixelData(),
                            this.savedForeground.PixelWidth * sizeof(int),
                            0);*/
                    }
                }
            }
        }