2012-01-11 1 views
3

그래서 내가하려는 것은 인간이 지나갈 때만 Kinect Skeletal Sample을 가져 와서 x 개의 사진을 저장하는 것입니다. 나는 일단 인간이 그것을 발견하면 일단 사람이 Kinect의 시야를 떠난 후에도 x 개의 사진을 기록한다는 것을 제외하고는 작동하도록했습니다. 누구든지 일단 사람이 들어가면 녹음을 시작하고 일단 그것을 끝내려면 어떻게해야하는지 알고 있습니까?Kinect - 인간이 프레임을 벗어날 때 감지하기

변수

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

입력하기/

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 
    } 

실제 프레임을 종료 코드

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

    } 
+1

를 보내드립니다. 당신이 말한 것에서, 이미지의 실제 저장 (게시 한 것)은 정상적으로 작동합니다. – Jason

+0

네,하지만 누군가 kinect보기에 들어가면 사람이보기를 떠나더라도 stopFrameNumber에 도달 할 때까지 프레임 저장을 시작합니다 –

+0

누군가가보기를 떠날 때 어떻게 감지합니까? 아니면 당신이 뭘하고 싶은지 알고 싶습니까? – Jason

답변

2

내가 woul 이런 식으로 시도해보십시오. SkeletonInFrame이라는 이름의 bool 클래스 변수를 만들고이를 false로 초기화하십시오. SkeletonFrameReady가 실행될 때마다이 bool을 true로 설정하십시오. 색상 프레임을 처리 할 때이 변수가 true 인 경우에만 처리합니다. 그런 다음 색상 프레임을 처리 한 다음 변수를 false로 설정하십시오. 골격 이벤트를 더 이상 수신하지 않을 때 프레임 처리를 중지하는 데 도움이됩니다.

+0

알겠습니다. 시도해보십시오 –

+0

나는 이것을 시도한 다음 SkeletonFrameReady가 유효한 방법이 아니라고 말했습니다. 어떤 도움이 필요합니까? –

+0

의사 코드를 제공하고있었습니다. 귀하의 코드에서 그것을 호출 nui_SkeletonFrameReady() – Jason

3

대부분의 설정에서 골격 추적 이벤트 영역에 if (skeleton! = null)에 대한 검사가 있습니다. null skeleton이 수신되면 트리거를 재설정해야합니다.

SDK는 골격 프레임에게 나는 사람이/입력 프레임을 떠날 때 어떤 코드가 감지 보이지 않는 이벤트가 너무 발사 할 때마다 ...

if(skeleton != null) 
{ 
    \\do image taking here 
} 
else 
{ 
    \\reset image counter 
} 
관련 문제