コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: user-mfp/IMI
        private void initJointsToTrack(FubiUtils.SkeletonJoint center_joint)
        {
            this.TRACKED_JOINTS = new Dictionary<FubiUtils.SkeletonJoint, Point3D>();

            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.FACE_CHIN, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.FACE_FOREHEAD, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.FACE_RIGHT_EAR, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.FACE_LEFT_EAR, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.FACE_NOSE, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.RIGHT_FOOT, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.RIGHT_ANKLE, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.RIGHT_KNEE, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.RIGHT_HIP, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.LEFT_FOOT, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.LEFT_ANKLE, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.LEFT_KNEE, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.LEFT_HIP, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.RIGHT_HAND, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.RIGHT_WRIST, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.RIGHT_ELBOW, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.RIGHT_SHOULDER, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.LEFT_HAND, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.LEFT_WRIST, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.LEFT_ELBOW, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.LEFT_SHOULDER, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.WAIST, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.TORSO, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.NECK, new Point3D());
            this.TRACKED_JOINTS.Add(FubiUtils.SkeletonJoint.HEAD, new Point3D());

            this.TRACKED_CENTER_JOINT = center_joint;
        }
コード例 #2
0
    // Called for rendering the gui
    void OnGUI()
    {
        // AA: Position the depth image so the user can see the kinect output
        if (!m_disableTrackingImage && (!m_disableTrackingImageWithSwipeMenu || !m_swipeMenuDisplayedLastFrame))
        {
            // Debug image
            GUI.depth = -4;
            GUI.DrawTexture(new Rect(25, Screen.height - m_yRes / m_factor - 25, m_xRes / m_factor, m_yRes / m_factor), m_depthMapTexture);
            //GUI.DrawTexture(new Rect(Screen.width-m_xRes/m_factor, Screen.height-m_yRes/m_factor, m_xRes / m_factor, m_yRes / m_factor), m_depthMapTexture);
        }



        //AA: add the GUI elements
        int shift = 42;

        GUI.Box(new Rect(5 + shift, 25, Screen.width / 3 - 130, Screen.height - 50), "FILTERS");

        m_bUseSimpleAverage = GUI.Toggle(new Rect(45 + shift, 50, 200, 30), m_bUseSimpleAverage, " SIMPLE AVERAGE 10");

        m_bUseMovingAverage = GUI.Toggle(new Rect(45 + shift, 90, 200, 30), m_bUseMovingAverage, " MOVING AVERAGE");

        m_bUseSimpleAverage5 = GUI.Toggle(new Rect(45 + shift, 130, 200, 30), m_bUseSimpleAverage5, " SIMPLE AVERAGE 5");

        m_bDblMovingAverage = GUI.Toggle(new Rect(45 + shift, 170, 200, 30), m_bDblMovingAverage, " DOUBLE MOV AVERAGE");

        m_bUseExpSmoothing = GUI.Toggle(new Rect(45 + shift, 210, 200, 30), m_bUseExpSmoothing, " EXP SMOOTHING");

        m_bUseDblExpSmoothing = GUI.Toggle(new Rect(45 + shift, 250, 200, 30), m_bUseDblExpSmoothing, " DOUBLE EXP SMOOTHING");

        m_bUseAdaptive = GUI.Toggle(new Rect(45 + shift, 290, 200, 30), m_bUseAdaptive, " ADAPTIVE DBL EXP");

        m_bUseMedian = GUI.Toggle(new Rect(45 + shift, 330, 200, 30), m_bUseMedian, " MEDIAN");

        m_bUseCombination1 = GUI.Toggle(new Rect(45 + shift, 370, 200, 30), m_bUseCombination1, " SIMPLE AVG + Median");

        m_bUseCombination2 = GUI.Toggle(new Rect(45 + shift, 410, 200, 30), m_bUseCombination2, " DBL MOV AVG + Median");

        m_bUseNone = GUI.Toggle(new Rect(45 + shift, 450, 200, 30), m_bUseNone, " NONE");


        if (GUI.Button(new Rect(50 + shift, Screen.height - 75, 150, 30), "Clear"))
        {
            WriteableAreaResize();
            fv.DrawCircle();
        }

        // If some button has been pressed OR this is the first exection
        if (GUI.changed)
        {
            LoadFilters();

            if (fm.filters.Count == 1)
            {
                m_principalCursor = 0;
            }
        }

        int count = 0;

        if (m_bUseSimpleAverage)
        {
            GUI.Label(new Rect(15 + shift, 45, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bUseMovingAverage)
        {
            GUI.Label(new Rect(15 + shift, 85, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bUseSimpleAverage5)
        {
            GUI.Label(new Rect(15 + shift, 125, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bDblMovingAverage)
        {
            GUI.Label(new Rect(15 + shift, 165, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bUseExpSmoothing)
        {
            GUI.Label(new Rect(15 + shift, 205, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bUseDblExpSmoothing)
        {
            GUI.Label(new Rect(15 + shift, 245, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bUseAdaptive)
        {
            GUI.Label(new Rect(15 + shift, 285, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bUseMedian)
        {
            GUI.Label(new Rect(15 + shift, 325, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bUseCombination1)
        {
            GUI.Label(new Rect(15 + shift, 365, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bUseCombination2)
        {
            GUI.Label(new Rect(15 + shift, 405, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (m_bUseNone)
        {
            GUI.Label(new Rect(15 + shift, 445, 30, 30), m_colorTextureDictionary[fm.colors[count].ToString()]);
            count++;
        }

        if (prevScreenWidth != Screen.width || prevScreenHeight != Screen.height)
        {
            // Resize writeable area, redraw the circle
            WriteableAreaResize();
            prevScreenWidth  = Screen.width;
            prevScreenHeight = Screen.height;
            fv.DrawCircle();
        }

        //AA: Draw the writeable area
        fv.Apply();
        for (int i = 0; i < fv.m_filterOutputTexture.Count; i++)
        {
            GUI.DrawTexture(new Rect(fv.filterOutputLocX, fv.filterOutputLocY, fv.filterOutputWidth, fv.filterOutputHeight), fv.m_filterOutputTexture[i]);
        }


        // Cursor
        m_gotNewFubiCoordinates = false;
        if (Fubi.isInitialized())
        {
            // Take closest user
            uint userID = Fubi.getClosestUserID();
            if (userID != m_currentUser)
            {
                m_currentUser             = userID;
                m_lastCalibrationSucceded = false;
            }
            if (userID > 0)
            {
                if (!m_lastCalibrationSucceded)
                {
                    m_lastCalibrationSucceded = calibrateCursorMapping(m_currentUser);
                }
                FubiUtils.SkeletonJoint joint    = FubiUtils.SkeletonJoint.RIGHT_HAND;
                FubiUtils.SkeletonJoint relJoint = FubiUtils.SkeletonJoint.RIGHT_SHOULDER;

                // Get hand and shoulder position and check their confidence
                double timeStamp;
                float  handX, handY, handZ, confidence;
                Fubi.getCurrentSkeletonJointPosition(userID, joint, out handX, out handY, out handZ, out confidence, out timeStamp);
                if (confidence > 0.5f)
                {
                    float relX, relY, relZ;
                    Fubi.getCurrentSkeletonJointPosition(userID, relJoint, out relX, out relY, out relZ, out confidence, out timeStamp);
                    if (confidence > 0.5f)
                    {
                        // AA: Filtering should happen here for the hand and relative joints separately
                        // If true, use the smoothed joints for calculating screen coordinates
                        fm.UpdateJointFilters(new Vector3(handX, handY, handZ), new Vector3(relX, relY, relZ));

                        for (int i = 0; i < fm.filters.Count; i++)
                        {
                            if (m_bUseJointFiltering)
                            {
                                //Debug.Log ("Prehand " + new Vector3(handX, handY, handZ) + " relJoint " + new Vector3(relX, relY, relZ));
                                Vector3 handPos     = fm.joints[i];                             // filter.Update(new Vector3(handX, handY, handZ), Filter.JOINT_TYPE.JOINT);
                                Vector3 relJointPos = fm.relativeJoints[i];                     //filter.Update(new Vector3(relX, relY, relZ), Filter.JOINT_TYPE.RELATIVEJOINT);
                                //Debug.Log ("hand " + handPos + " relJoint " + relJointPos);
                                handZ = handPos.z;
                                handY = handPos.y;
                                handX = handPos.x;

                                relZ = relJointPos.z;
                                relY = relJointPos.y;
                                relX = relJointPos.x;
                                m_relativeCursorPosition = fm.relativeCursorPosition[i];
                            }
                            // AA: End

                            // Take relative coordinates
                            float zDiff = handZ - relZ;
                            float yDiff = handY - relY;
                            float xDiff = handX - relX;
                            // Check if hand is enough in front of shoulder
                            if ((yDiff > 0 && zDiff < -150.0f) || (Mathf.Abs(xDiff) > 150.0f && zDiff < -175.0f) || zDiff < -225.0f)
                            {
                                // Now get the possible cursor position
                                // Convert to screen coordinates
                                float newX, newY;
                                float mapX = m_mapping.x;
                                newX = (xDiff - mapX) / m_mapping.width;
                                newY = (m_mapping.y - yDiff) / m_mapping.height;         // Flip y for the screen coordinates

                                // Filtering
                                // New coordinate is weighted more if it represents a longer distance change
                                // This should reduce the lagging of the cursor on higher distances, but still filter out small jittering
                                float changeX = newX - m_relativeCursorPosition.x;
                                float changeY = newY - m_relativeCursorPosition.y;

                                if (changeX != 0 || changeY != 0 && timeStamp != m_timeStamp)
                                {
                                    float changeLength = Mathf.Sqrt(changeX * changeX + changeY * changeY);
                                    float filterFactor = changeLength;         //Mathf.Sqrt(changeLength);
                                    if (filterFactor > 1.0f)
                                    {
                                        filterFactor = 1.0f;
                                    }

                                    // Apply the tracking to the current position with the given filter factor
                                    // AA: Filtering should happen here for joint-to-relativejoint (VECTOR) filtering
                                    // AA: filtering code

                                    Vector2 tempNew = new Vector2(newX, newY);

                                    fm.UpdateVectorFilters(m_relativeCursorPosition, tempNew, filterFactor);
                                    // If true, use the calculated factor for smoothing, else just use the new
                                    if (m_bUseVectorFiltering)
                                    {
                                        m_relativeCursorPosition = fm.vectors[i]; //filter.Update(m_relativeCursorPosition, tempNew, filterFactor);
                                    }
                                    else                                          // Just give equal weight to both
                                    {
                                        m_relativeCursorPosition = filter.Update(m_relativeCursorPosition, tempNew, 0.5f);
                                    }

                                    // AA: Calculate all filters
                                    // fm.UpdateVectorFilters(m_relativeCursorPosition, tempNew, filterFactor);

                                    m_timeStamp = timeStamp;

                                    // Send it, but only if it is more or less within the screen
                                    if (m_relativeCursorPosition.x > -0.1f && m_relativeCursorPosition.x < 1.1f &&
                                        m_relativeCursorPosition.y > -0.1f && m_relativeCursorPosition.y < 1.1f)
                                    {
                                        MoveMouse(m_relativeCursorPosition.x, m_relativeCursorPosition.y, i);

                                        // Each filter must store it's own value of relative position, absolute and previous absolute positions
                                        fm.relativeCursorPosition[i] = m_relativeCursorPosition;
                                        fm.absPixelPosition[i]       = m_absPixelPosition;
                                        fm.prevAbsPixelPosition[i]   = m_previousAbsPixelPosition;

                                        DrawFilterOutputs(i);
                                        m_gotNewFubiCoordinates      = true;
                                        m_lastCursorChangeDoneByFubi = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // AA: FUBI does not move mouse if the confidence value is too low

        if (!m_gotNewFubiCoordinates)           // AA: this only executes when input is coming from mouse
        {
            // Got no mouse coordinates from fubi this frame
            Vector2 mousePos = Input.mousePosition;
            // Only move mouse if it wasn't changed by fubi the last time or or it really has changed
            if (!m_lastCursorChangeDoneByFubi || mousePos != m_lastMousePos)
            {
                //AA: Old code for cursor placement
                m_relativeCursorPosition.x = mousePos.x / (float)Screen.width;
                m_relativeCursorPosition.y = 1.0f - (mousePos.y / (float)Screen.height);
                // Get mouse X and Y position as a percentage of screen width and height
                MoveActualMouse(m_relativeCursorPosition.x, m_relativeCursorPosition.y, true);
                m_lastMousePos = mousePos;
                m_lastCursorChangeDoneByFubi = false;
            }
        }
    }
コード例 #3
0
 protected string getJointName(FubiUtils.SkeletonJoint jointID)
 {
     return(UseHand ? FubiUtils.getHandJointName((FubiUtils.SkeletonHandJoint)jointID) : FubiUtils.getJointName(jointID));
 }
コード例 #4
0
        public void applyHandPositionToMouse(uint userID, out float x, out float y, bool leftHand = false)
        {
            x = float.NaN;
            y = float.NaN;

            float handX, handY, handZ, confidence;

            FubiUtils.SkeletonJoint joint    = FubiUtils.SkeletonJoint.RIGHT_HAND;
            FubiUtils.SkeletonJoint relJoint = FubiUtils.SkeletonJoint.RIGHT_SHOULDER;
            if (leftHand)
            {
                joint    = FubiUtils.SkeletonJoint.LEFT_HAND;
                relJoint = FubiUtils.SkeletonJoint.LEFT_SHOULDER;
            }

            double timeStamp;

            Fubi.getCurrentSkeletonJointPosition(userID, joint, out handX, out handY, out handZ, out confidence, out timeStamp);

            if (confidence > 0.5f)
            {
                float relX, relY, relZ;
                Fubi.getCurrentSkeletonJointPosition(userID, relJoint, out relX, out relY, out relZ, out confidence, out timeStamp);

                if (confidence > 0.5f)
                {
                    // Take relative coordinates
                    float rawX = handX - relX;
                    float rawY = handY - relY;

                    // Convert to screen coordinates
                    float newX, newY;
                    float mapX = m_mapX;
                    if (leftHand)
                    {
                        // Mirror x  area for left hand
                        mapX = -m_mapX - m_mapW;
                    }
                    newX = (rawX - mapX) / m_mapW;
                    newY = (m_mapY - rawY) / m_mapH; // Flip y for the screen coordinates

                    // Filtering
                    // New coordinate is weighted more if it represents a longer distance change
                    // This should reduce the lagging of the cursor on higher distances, but still filter out small jittering
                    float changeX = newX - m_x;
                    float changeY = newY - m_y;

                    if (changeX != 0 || changeY != 0 && timeStamp != m_timeStamp)
                    {
                        double changeLength = Math.Sqrt(changeX * changeX + changeY * changeY);
                        double changeDur    = timeStamp - m_timeStamp;
                        float  filterFactor = (float)Math.Sqrt(changeLength) * m_smoothingFactor;
                        if (filterFactor > 1.0f)
                        {
                            filterFactor = 1.0f;
                        }

                        // Apply the tracking to the current position with the given filter factor
                        m_x         = (1.0f - filterFactor) * m_x + filterFactor * newX;
                        m_y         = (1.0f - filterFactor) * m_y + filterFactor * newY;
                        m_timeStamp = timeStamp;

                        // Send it
                        MouseSimulator.sendMousePos(m_x, m_y);
                        x = m_x;
                        y = m_x;
                    }

                    // Check for mouse click
                    if (Fubi.recognizeGestureOn("mouseClick", userID) == FubiUtils.RecognitionResult.RECOGNIZED ||
                        Fubi.recognizeGestureOn("mouseClick1", userID) == FubiUtils.RecognitionResult.RECOGNIZED)
                    {
                        if (m_timeStamp - m_lastMouseClick > 1)
                        {
                            MouseSimulator.sendMouseButton(true, true);
                            MouseSimulator.sendMouseButton(true, false);
                            m_lastMouseClick = m_timeStamp;
                        }
                    }
                }
            }
        }
コード例 #5
0
 public RelativeJoint(FubiUtils.SkeletonJoint main, FubiUtils.SkeletonJoint relative = FubiUtils.SkeletonJoint.NUM_JOINTS)
 {
     Main     = main;
     Relative = relative;
 }
コード例 #6
0
ファイル: FubiInternal.cs プロジェクト: thelegend831/FUBIOSC
 internal static extern void getSkeletonJointPosition(IntPtr trackingData, FubiUtils.SkeletonJoint joint, out float x, out float y, out float z,
                                                      out float confidence, out double timeStamp, [MarshalAs(UnmanagedType.U1)] bool useLocalPositions = false);
コード例 #7
0
ファイル: FubiInternal.cs プロジェクト: thelegend831/FUBIOSC
 internal static extern void getSkeletonJointOrientation(IntPtr trackingData, FubiUtils.SkeletonJoint joint, [MarshalAs(UnmanagedType.LPArray)] float[] mat,
                                                         out float confidence, out double timeStamp, [MarshalAs(UnmanagedType.U1)] bool useLocalOrientations = true);
コード例 #8
0
ファイル: FubiInternal.cs プロジェクト: thelegend831/FUBIOSC
 internal static extern UInt32 addFingerCountRecognizer(FubiUtils.SkeletonJoint handJoint,
                                                        UInt32 minFingers, UInt32 maxFingers,
                                                        Int32 atIndex,
                                                        IntPtr name,
                                                        float minConfidence,
                                                        bool useMedianCalculation);
コード例 #9
0
ファイル: FubiInternal.cs プロジェクト: thelegend831/FUBIOSC
 internal static extern UInt32 addLinearMovementRecognizer(FubiUtils.SkeletonJoint joint, FubiUtils.SkeletonJoint relJoint,
                                                           float dirX, float dirY, float dirZ, float minVel, float maxVel,
                                                           [MarshalAs(UnmanagedType.U1)] bool useLocalPositions,
                                                           int atIndex, IntPtr name, float maxAngleDifference, [MarshalAs(UnmanagedType.U1)] bool useOnlyCorrectDirectionComponent);
コード例 #10
0
ファイル: FubiInternal.cs プロジェクト: thelegend831/FUBIOSC
 internal static extern UInt32 addJointRelationRecognizer(FubiUtils.SkeletonJoint joint, FubiUtils.SkeletonJoint relJoint,
                                                          float minX, float minY, float minZ,
                                                          float maxX, float maxY, float maxZ,
                                                          float minDistance, float maxDistance,
                                                          [MarshalAs(UnmanagedType.U1)] bool useLocalPositions,
                                                          Int32 atIndex, IntPtr name,
                                                          float minConfidence, FubiUtils.BodyMeasurement measuringUnit);
コード例 #11
0
ファイル: FubiInternal.cs プロジェクト: thelegend831/FUBIOSC
 internal static extern bool saveImage(IntPtr fileName, int jpegQuality /*0-100*/,
                                       FubiUtils.ImageType type, FubiUtils.ImageNumChannels numChannels, FubiUtils.ImageDepth depth,
                                       uint renderOptions = (uint)FubiUtils.RenderOptions.Default,
                                       FubiUtils.DepthImageModification depthModifications = FubiUtils.DepthImageModification.UseHistogram,
                                       UInt32 userId = 0, FubiUtils.SkeletonJoint jointOfInterest = FubiUtils.SkeletonJoint.NUM_JOINTS);
コード例 #12
0
ファイル: FubiInternal.cs プロジェクト: thelegend831/FUBIOSC
 internal static extern void getImage(IntPtr outputImage, FubiUtils.ImageType type, FubiUtils.ImageNumChannels numChannels, FubiUtils.ImageDepth depth,
                                      uint renderOptions = (uint)FubiUtils.RenderOptions.Default,
                                      FubiUtils.DepthImageModification depthModifications = FubiUtils.DepthImageModification.UseHistogram,
                                      UInt32 userId = 0, FubiUtils.SkeletonJoint jointOfInterest = FubiUtils.SkeletonJoint.NUM_JOINTS);