Pergunta

Então o que estou tentando fazer é pegar a amostra do esqueleto do Kinect e salvar uma quantidade x de fotos, apenas quando um humano passar.Eu consegui que funcionasse, exceto que quando ele detecta um humano, ele apenas registra uma quantidade x de fotos, mesmo quando a pessoa sai da visão do Kinect.Alguém sabe como fazer para que assim que uma pessoa entre ela comece a gravar e quando ela saia pare?

Variáveis

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

Entrando/Saindo do Quadro

 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
    }

Código real

    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;
            }
        }

    }
Foi útil?

Solução

Eu tentaria algo assim.Crie uma variável de classe bool chamada SkeletonInFrame e inicialize-a como falsa.Cada vez que o SkeletonFrameReady for acionado, defina esse bool como verdadeiro.Ao processar um quadro colorido, processe apenas se esta variável for verdadeira.Depois de processar um quadro colorido, defina a variável como falsa.Isso deve ajudá-lo a interromper o processamento do quadro quando não estiver mais recebendo eventos de esqueleto.

Outras dicas

Na maioria das configurações que usei na área de eventos de rastreamento de esqueleto, há uma verificação de if (skeleton! = null) tudo o que você precisa fazer é redefinir seu gatilho assim que um esqueleto nulo for recebido.

O SDK enviará um esqueleto sempre que o evento for disparado, então...

if(skeleton != null)
{
  \\do image taking here
}
else
{
  \\reset image counter
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top