Question

Alors que je suis en train de faire est de prendre l'échantillon Skeletal Kinect et enregistrer quantité x de photos, que lorsqu'un homme passe par. Je l'ai eu à travailler, sauf une fois qu'il détecte un humain, il enregistre juste quantité x de photos, même une fois que la personne quitte la vision de Kinect. Est-ce que quelqu'un sait comment faire en sorte qu'une fois qu'une personne entre elle commence l'enregistrement, et une fois qu'ils quittent il arrête?

Variables

   Runtime nui;
    int totalFrames = 0;
    int totalFrames2 = 0;
    int lastFrames = 0;
    int lastFrameWithMotion = 0;
    int stopFrameNumber = 100;
    DateTime lastTime = DateTime.MaxValue;

Entrée / quitte l'image

 void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        SkeletonFrame skeletonFrame = e.SkeletonFrame;

        int iSkeleton = 0;
        ++totalFrames;
        string bb1 = Convert.ToString(totalFrames);
        //Uri uri1 = new Uri("C:\\Research\\Kinect\\Proposal_Skeleton\\Skeleton_Img" + bb1 + ".png");
        Uri uri1 = new Uri("C:\\temp\\Skeleton_Img" + bb1 + ".png");
        // string file_name_3 = "C:\\Research\\Kinect\\Proposal_Skeleton\\Skeleton_Img" + bb1 + ".png";    // xxx 
        Brush[] brushes = new Brush[6];
        brushes[0] = new SolidColorBrush(Color.FromRgb(255, 0, 0));
        brushes[1] = new SolidColorBrush(Color.FromRgb(0, 255, 0));
        brushes[2] = new SolidColorBrush(Color.FromRgb(64, 255, 255));
        brushes[3] = new SolidColorBrush(Color.FromRgb(255, 255, 64));
        brushes[4] = new SolidColorBrush(Color.FromRgb(255, 64, 255));
        brushes[5] = new SolidColorBrush(Color.FromRgb(128, 128, 255));

        skeleton.Children.Clear();
        //byte[] skeletonFrame32 = new byte[(int)(skeleton.Width) * (int)(skeleton.Height) * 4];
        foreach (SkeletonData data in skeletonFrame.Skeletons)
        {
            if (SkeletonTrackingState.Tracked == data.TrackingState)
            {
                // Draw bones
                Brush brush = brushes[iSkeleton % brushes.Length];
                skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.HipCenter, JointID.Spine, JointID.ShoulderCenter, JointID.Head));
                skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.ShoulderCenter, JointID.ShoulderLeft, JointID.ElbowLeft, JointID.WristLeft, JointID.HandLeft));
                skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.ShoulderCenter, JointID.ShoulderRight, JointID.ElbowRight, JointID.WristRight, JointID.HandRight));
                skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.HipCenter, JointID.HipLeft, JointID.KneeLeft, JointID.AnkleLeft, JointID.FootLeft));
                skeleton.Children.Add(getBodySegment(data.Joints, brush, JointID.HipCenter, JointID.HipRight, JointID.KneeRight, JointID.AnkleRight, JointID.FootRight));

                // Draw joints
                // try to add a comment, xxx
                foreach (Joint joint in data.Joints)
                {
                    Point jointPos = getDisplayPosition(joint);
                    Line jointLine = new Line();
                    jointLine.X1 = jointPos.X - 3;
                    jointLine.X2 = jointLine.X1 + 6;
                    jointLine.Y1 = jointLine.Y2 = jointPos.Y;
                    jointLine.Stroke = jointColors[joint.ID];
                    jointLine.StrokeThickness = 6;
                    skeleton.Children.Add(jointLine);
                }
                //       ExportToPng(uri1, skeleton);
               // SoundPlayerAction Source = "C:/LiamScienceFair/muhaha.wav";
                //SoundPlayer player1 = new SoundPlayer("muhaha.wav")
               //  player1.Play(); 
              // MediaPlayer.
               // axWindowsMediaPlayer1.currentPlaylist = axWindowsMediaPlayer1.mediaCollection.getByName("mediafile");


                nui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_ColorFrameReady2);



            }


            iSkeleton++;
        } // for each skeleton
    }

code réel

    void nui_ColorFrameReady2(object sender, ImageFrameReadyEventArgs e)
    {
        // 32-bit per pixel, RGBA image  xxx
        PlanarImage Image = e.ImageFrame.Image;
        int deltaFrames = totalFrames - lastFrameWithMotion;
        if (totalFrames2 <= stopFrameNumber & deltaFrames > 300)
        {
            ++totalFrames2;
            string bb1 = Convert.ToString(totalFrames2);
            // string file_name_3 = "C:\\Research\\Kinect\\Proposal\\Depth_Img" + bb1 + ".jpg"; xxx
            string file_name_4 = "C:\\temp\\Video2_Img" + bb1 + ".jpg";
            video.Source = BitmapSource.Create(
                Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);

            BitmapSource image4 = BitmapSource.Create(
                Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);
            image4.Save(file_name_4, Coding4Fun.Kinect.Wpf.ImageFormat.Jpeg);
            if (totalFrames2 == stopFrameNumber)
            {
                lastFrameWithMotion = totalFrames;
                stopFrameNumber += 100;
            }
        }

    }
Était-ce utile?

La solution

Je voudrais essayer quelque chose comme ça. Créer une variable de classe bool nommée SkeletonInFrame et l'initialiser à false. Chaque fois feux SkeletonFrameReady, réglez ce bool true. Lorsque vous traitez un cadre de couleur, traiter uniquement si cette variable est vrai. Ensuite, une fois que vous traitez un cadre de couleur, la variable à false. Cela devrait vous aider à arrêter le traitement cadre lorsque vous ne recevez plus skeleton.

Autres conseils

Dans la plupart des configurations, je l'ai utilisé dans la zone d'événement de suivi du squelette il y a un chèque si (squelette! = Null) tout ce que vous devez faire est de réinitialiser votre détente une fois un squelette nul est reçu.

Le SDK envoie un cadre squelette à chaque fois que l'événement est déclenché si ...

if(skeleton != null)
{
  \\do image taking here
}
else
{
  \\reset image counter
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top