Answered Problem move objetcs

  • Tuesday, May 01, 2012 7:25 PM
     
      Has Code

    I am starting in Kinect development, but I am finding difficulty.

    I am trying move objects in the screen. This is my code:

            void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
            {
                if (closing)
                    return;
    
                Skeleton skeleton = GetSkeleton(e);
    
                if (skeleton != null)
                {
                    MoveObject(imgHandLeft, lblLeft, skeleton.Joints[JointType.HandLeft]);
                    MoveObject(imgHandRight, lblRight, skeleton.Joints[JointType.HandRight]);
                    MoveObject(handRight, lblRight, skeleton.Joints[JointType.Head]);
                    
                    //GetCameraPoint(skeleton, e);
                }
            }
    
            public Skeleton GetSkeleton(AllFramesReadyEventArgs e)
            {
                using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
                {
                    if (skeletonFrame != null)
                    {
                        if ((skeletons == null) || (skeletons.Length != skeletonFrame.SkeletonArrayLength))
                        {
                            skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                        }
                        skeletonFrame.CopySkeletonDataTo(skeletons);
    
                    }
                }
    
                if (skeletons != null)
                {
                    Skeleton skeletonOne = (from s in skeletons
                                            where s.TrackingState == SkeletonTrackingState.Tracked
                                            select s).FirstOrDefault();
    
                    return skeletonOne;
                }
    
                return null;
            }
    
    
            void MoveObject(FrameworkElement obj, Label obj2, Joint joint)
            {
                var ScaledJoint = joint.ScaleTo(502, 512, .5f, .5f);
    
                Canvas.SetLeft(obj, ScaledJoint.Position.X);
                Canvas.SetTop(obj, ScaledJoint.Position.Y);
    
                Canvas.SetLeft(obj2, ScaledJoint.Position.X);
                Canvas.SetTop(obj2, ScaledJoint.Position.Y);
    
                obj2.Content = "X = " + ScaledJoint.Position.X + "\n" + "Y = " + ScaledJoint.Position.Y;
            }
    

    This code doesn't work, but I don't know what is happening.

    The method GetSkeleton() is returning the detected skeleton, but the method MoveObject doesn't work.

    Somebody have any ideia?


    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio

All Replies

  • Wednesday, May 02, 2012 7:01 AM
     
     

    First of all put to the MoveObject some debug functions.

    Does the function is invoked ? If it is invoked what is not working

  • Wednesday, May 02, 2012 9:10 AM
     
      Has Code

    Try this code to draw ellipse if it work fine update it to include the object you want to move

    private void SetEllipsePosition(Ellipse ellipse, Joint joint)
    {
                Point p = GetJointPoint(joint);
    
                ellipse.Width = 10;
                ellipse.Height = 10;
                ellipse.Fill = new SolidColorBrush(Colors.Red);
    
                ellipse.Visibility = Visibility.Visible;
    
                Canvas.SetLeft(ellipse, (p.X - _videoGrid.ActualWidth / 3) / 2.5);
                Canvas.SetTop(ellipse, (p.Y - _videoGrid.ActualHeight / 3) / 2.5);
    
    // _videoGrid is the space you want to move the ellipse in
            
    }

    Also add the following ellipse in the xaml

    <Ellipse Fill="Red" Name="ellipseHead" Stroke="White" />

    After that call the SetEllipsePosition method in the sensor_AllFramesReady event like this
    void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
            {
                if (closing)
                    return;
    
                Skeleton skeleton = GetSkeleton(e);
    
                if (skeleton != null)
                {
                    SetEllipsePosition(ellipseHead, skeleton.Joints[JointType.Head]);
                }
            }


    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members. Also try to Vote as Helpful


    • Edited by MohamedSakr Wednesday, May 02, 2012 9:14 AM
    •  
  • Wednesday, May 02, 2012 12:22 PM
     
      Has Code

    First of all put to the MoveObject some debug functions.

    Does the function is invoked ? If it is invoked what is not working

    Yes! The function is invoked! The JointType is detected but in the function MoveObject the images don't move.

    var ScaledJoint = joint.ScaleTo(502, 512, .5f, .5f);
    
    //This doesn't work!!!
    Canvas.SetLeft(obj, ScaledJoint.Position.X);
    Canvas.SetTop(obj, ScaledJoint.Position.Y);

    Thanks!


    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio

  • Wednesday, May 02, 2012 12:27 PM
     
      Has Code

    Try this code to draw ellipse if it work fine update it to include the object you want to move

    private void SetEllipsePosition(Ellipse ellipse, Joint joint)
    {
                Point p = GetJointPoint(joint);
    
                ellipse.Width = 10;
                ellipse.Height = 10;
                ellipse.Fill = new SolidColorBrush(Colors.Red);
    
                ellipse.Visibility = Visibility.Visible;
    
                Canvas.SetLeft(ellipse, (p.X - _videoGrid.ActualWidth / 3) / 2.5);
                Canvas.SetTop(ellipse, (p.Y - _videoGrid.ActualHeight / 3) / 2.5);
    
    // _videoGrid is the space you want to move the ellipse in
            
    }

    Also add the following ellipse in the xaml

    <Ellipse Fill="Red" Name="ellipseHead" Stroke="White" />

    After that call the SetEllipsePosition method in the sensor_AllFramesReady event like this
    void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
            {
                if (closing)
                    return;
    
                Skeleton skeleton = GetSkeleton(e);
    
                if (skeleton != null)
                {
                    SetEllipsePosition(ellipseHead, skeleton.Joints[JointType.Head]);
                }
            }


    Thanks,
    MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
    Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members. Also try to Vote as Helpful


    I will to try this way. After, I will to post the result here.
    Thanks!

    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio

  • Thursday, May 03, 2012 12:21 AM
     
     Answered Has Code

    I did it!!!
    The problem was the layout of my screen.
    The correct form is:

    <Grid>
           <Ellipse Height="62" HorizontalAlignment="Left" Margin="429,99,0,0" Name="headEllipse" Stroke="Black" VerticalAlignment="Top" Width="67" OpacityMask="#FFC42D2D" Fill="#FFE55555" />
    </Grid>

    But was:

    <Grid>
        <Canvas>
           <Ellipse Height="62" HorizontalAlignment="Left" Margin="429,99,0,0" Name="headEllipse" Stroke="Black" VerticalAlignment="Top" Width="67" OpacityMask="#FFC42D2D" Fill="#FFE55555" />
        </Canvas>
    </Grid>

    So, thank you for help!!!


    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio

    • Marked As Answer by Deise Vicentin Thursday, May 03, 2012 12:21 AM
    •  
  • Thursday, May 10, 2012 7:23 AM
     
     

    I am also starting Kinect development and looking for existing code to work with. I tried to use the code tonight that you entered here, including your fix, but got a series of errors--this has been true for all the code I've found posted online.

    You said you got this to work and i wondered if you could send me a complete copy of the working code? It's along the lines of what I'm trying to do--i know if i can get just one thing to work i'll be able to extend out from there with no problem.

    Could you send the entire listing, including the list of assemblies? Your help would be much appreciated!

    Ed

  • Thursday, May 10, 2012 12:08 PM
     
     

    I am also starting Kinect development and looking for existing code to work with. I tried to use the code tonight that you entered here, including your fix, but got a series of errors--this has been true for all the code I've found posted online.

    You said you got this to work and i wondered if you could send me a complete copy of the working code? It's along the lines of what I'm trying to do--i know if i can get just one thing to work i'll be able to extend out from there with no problem.

    Could you send the entire listing, including the list of assemblies? Your help would be much appreciated!

    Ed

    Yes Ed!

    Tonight I'll send my project for you, because I saved him in my personal computer and now, I'm at work.


    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio

  • Friday, May 11, 2012 1:02 AM
     
     

    Hi Ed;

    Take a look here. I uploaded my sample project.


    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio

  • Friday, May 11, 2012 4:19 AM
     
     

    Thanks! I'll look at it tonight or tomorrow morning.

    Ed

  • Friday, May 11, 2012 4:36 AM
     
     

    I looked at the files, but there are a lot of them, including multiple versions and there are no dates; could you give me guidance on which file(s) to download? Thanks,

    Ed

  • Friday, May 11, 2012 12:19 PM
     
     

    I looked at the files, but there are a lot of them, including multiple versions and there are no dates; could you give me guidance on which file(s) to download? Thanks,

    Ed

    Hi Ed!

    All files are part of project, but are much confused.

    Open that link, select "File" > "Download". After the end of download extract all files in a new folder.


    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio