public override void Work(Graphics g) { // Retrieve gesture data hand = senseManager.QueryHand(); face = senseManager.QueryFace(); // if (hand != null) { // Retrieve the most recent processed data handData = hand.CreateOutput(); handData.Update(); handWaving = handData.IsGestureFired("wave", out gestureData); } if (face != null) { faceData = face.CreateOutput(); faceData.Update(); //surching faces Int32 nfaces = faceData.QueryNumberOfDetectedFaces(); for (Int32 i = 0; i < nfaces; i++) { // Retrieve the data instance PXCMFaceData.Face faceI = faceData.QueryFaceByIndex(i); PXCMFaceData.ExpressionsData edata = faceI.QueryExpressions(); if (edata != null) { edata.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_SMILE, out score); if (score.intensity >= 25) { smiling = true; } else { smiling = false; } Console.WriteLine(i + ": " + score.intensity); } } faceData.Dispose(); } }
private void ProcessingThread() { // Start AcquireFrame/ReleaseFrame loop while (senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMCapture.Sample sample = senseManager.QuerySample(); Bitmap colorBitmap; PXCMImage.ImageData colorData; // Get color image data sample.color.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB24, out colorData); colorBitmap = colorData.ToBitmap(0, sample.color.info.width, sample.color.info.height); // Retrieve gesture data hand = senseManager.QueryHand(); if (hand != null) { // Retrieve the most recent processed data handData = hand.CreateOutput(); handData.Update(); handWaving = handData.IsGestureFired("v_sign", out gestureData); } // Update the user interface UpdateUI(colorBitmap); // Release the frame if (handData != null) { handData.Dispose(); } colorBitmap.Dispose(); sample.color.ReleaseAccess(colorData); senseManager.ReleaseFrame(); } }
pxcmStatus newHandFrame(PXCMHandModule hand) { if (hand != null) { PXCMHandData handData = hand.CreateOutput(); handData.Update(); PXCMHandData.IHand iHandDataLeft = null, iHandDataRight = null; PXCMHandData.JointData jointData = null; PXCMImage image = null; handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_LEFT_HANDS, 0, out iHandDataLeft); handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_RIGHT_HANDS, 0, out iHandDataRight); if (handForm != null && !handForm.IsDisposed) { this.handForm.HandCount = handData.QueryNumberOfHands(); if (iHandDataLeft != null) { iHandDataLeft.QuerySegmentationImage(out image); if (image != null) { PXCMImage.ImageData data = new PXCMImage.ImageData(); image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out data); handForm.LeftHand = data.ToBitmap(0, image.info.width, image.info.height); image.ReleaseAccess(data); } } if (iHandDataRight != null) { iHandDataRight.QuerySegmentationImage(out image); if (image != null) { PXCMImage.ImageData data = new PXCMImage.ImageData(); image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out data); handForm.RightHand = data.ToBitmap(0, image.info.width, image.info.height); image.ReleaseAccess(data); } } } if (iHandDataLeft != null) { if (jointData == null) { iHandDataLeft.QueryTrackedJoint(PXCMHandData.JointType.JOINT_INDEX_TIP, out jointData); } } if (iHandDataRight != null) { if (jointData == null) { iHandDataRight.QueryTrackedJoint(PXCMHandData.JointType.JOINT_INDEX_TIP, out jointData); } } if (jointData != null && canTrack.Checked) { Cursor.Position = new System.Drawing.Point( (int)((640.0f - jointData.positionImage.x) * Screen.PrimaryScreen.Bounds.Width / 640.0f), (int)(jointData.positionImage.y * Screen.PrimaryScreen.Bounds.Height / 480.0f)); PXCMHandData.GestureData gestureData = null; if (handData.IsGestureFired("two_fingers_pinch_open", out gestureData)) { Program.DoMouseClick(); } Console.WriteLine("Z Position: " + jointData.positionWorld.z); } handData.Dispose(); } return(pxcmStatus.PXCM_STATUS_NO_ERROR); }
public void ProcessingThread() { // Start AcquireFrame/ReleaseFrame loop while (senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { hand = senseManager.QueryHand(); if (hand != null) { // Retrieve the most recent processed data handData = hand.CreateOutput(); handData.Update(); // Get number of tracked hands nhands = handData.QueryNumberOfHands(); if (nhands > 0) { // Retrieve hand identifier handData.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, 0, out handId); // Retrieve hand data handData.QueryHandDataById(handId, out ihand); PXCMHandData.BodySideType bodySideType = ihand.QueryBodySide(); if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_LEFT) { leftHand = true; } else if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_RIGHT) { leftHand = false; } // Retrieve all hand joint data for (int i = 0; i < nhands; i++) { for (int j = 0; j < 0x20; j++) { PXCMHandData.JointData jointData; ihand.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData); nodes[i][j] = jointData; } } // Get world coordinates for tip of middle finger on the first hand in camera range handTipX = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.x; handTipY = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.y; handTipZ = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.z; swipehandTipX = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionImage.x; swipehandTipY = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionImage.y; swipehandTipZ = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionImage.z; //Console.Out.WriteLine("Before x={0}", swipehandTipX); //Console.Out.WriteLine("Before speed={0}", nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].speed.x); // Retrieve gesture data if (handData.IsGestureFired("spreadfingers", out gestureData)) { gesture = Gesture.FingerSpread; } else if (handData.IsGestureFired("two_fingers_pinch_open", out gestureData)) { gesture = Gesture.Pinch; } else if (handData.IsGestureFired("wave", out gestureData)) { gesture = Gesture.Wave; } else if (handData.IsGestureFired("swipe_left", out gestureData)) { gesture = Gesture.SwipeLeft; } else if (handData.IsGestureFired("swipe_right", out gestureData)) { gesture = Gesture.SwipeRight; } else if (handData.IsGestureFired("fist", out gestureData)) { gesture = Gesture.Fist; } else if (handData.IsGestureFired("thumb_up", out gestureData)) { gesture = Gesture.Thumb; } } else { gesture = Gesture.Undefined; } UpdateUI(); if (handData != null) { handData.Dispose(); } } senseManager.ReleaseFrame(); } }
private void ProcessingHandThread() { // Start AcquireFrame/ReleaseFrame loop while (senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { hand = senseManager.QueryHand(); if (hand != null) { // Retrieve the most recent processed data handData = hand.CreateOutput(); handData.Update(); // Get number of tracked hands nhands = handData.QueryNumberOfHands(); if (nhands > 0) { // Retrieve hand identifier handData.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, 0, out handId); // Retrieve hand data handData.QueryHandDataById(handId, out ihand); // Retrieve all hand joint data for (int i = 0; i < nhands; i++) { for (int j = 0; j < 0x20; j++) { PXCMHandData.JointData jointData; ihand.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData); nodes[i][j] = jointData; } } // Get world coordinates for tip of middle finger on the first hand in camera range handTipX = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.x; handTipY = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.y; handTipZ = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.z; // Retrieve gesture data if (handData.IsGestureFired("spreadfingers", out gestureData)) { gesture = Gesture.FingerSpread; } else if (handData.IsGestureFired("two_fingers_pinch_open", out gestureData)) { gesture = Gesture.Pinch; } else if (handData.IsGestureFired("wave", out gestureData)) { gesture = Gesture.Wave; } } else { gesture = Gesture.Undefined; } // Get alert status for (int i = 0; i < handData.QueryFiredAlertsNumber(); i++) { PXCMHandData.AlertData alertData; if (handData.QueryFiredAlertData(i, out alertData) != pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; } //Displaying last alert switch (alertData.label) { case PXCMHandData.AlertType.ALERT_HAND_DETECTED: detectionAlert = "Hand Detected"; detectionStatusOk = true; break; case PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED: detectionAlert = "Hand Not Detected"; detectionStatusOk = false; break; case PXCMHandData.AlertType.ALERT_HAND_CALIBRATED: calibrationAlert = "Hand Calibrated"; calibrationStatusOk = true; break; case PXCMHandData.AlertType.ALERT_HAND_NOT_CALIBRATED: calibrationAlert = "Hand Not Calibrated"; calibrationStatusOk = false; break; case PXCMHandData.AlertType.ALERT_HAND_INSIDE_BORDERS: bordersAlert = "Hand Inside Borders"; borderStatusOk = true; break; case PXCMHandData.AlertType.ALERT_HAND_OUT_OF_BORDERS: bordersAlert = "Hand Out Of Borders"; borderStatusOk = false; break; } } UpdateUI(); if (handData != null) handData.Dispose(); } senseManager.ReleaseFrame(); } }
private void ProcessingThread() { // Start AcquireFrame/ReleaseFrame loop - MAIN PROCESSING LOOP while (senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { if (firstFrame == true) { firstFrame = false; //pipeClient.SendMessage(CAMERA_CONNECTED_MESSAGE); } //Get sample from the sensemanager to convert to bitmap and show PXCMCapture.Sample sample = senseManager.QuerySample(); Bitmap colorBitmap; PXCMImage.ImageData colorData = null; // Get color/ir image data if (cameraMode == "Color") sample.color.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB24, out colorData); else if (cameraMode == "IR") sample.ir.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB24, out colorData); else if (cameraMode == "Depth") ;// -> broken! // sample.depth.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH, out colorData); else sample.color.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB24, out colorData); //convert it to bitmap colorBitmap = colorData.ToBitmap(0, sample.color.info.width, sample.color.info.height); // Retrieve hand and face data AND EMOTION DATA hand = senseManager.QueryHand(); face = senseManager.QueryFace(); emotion = senseManager.QueryEmotion(); //Process hand data if (hand != null) { // Retrieve the most recent processed data handData = hand.CreateOutput(); handData.Update(); handWaving = handData.IsGestureFired("wave", out gestureData); } //Process face data if (face != null) { // Retrieve the most recent processed data faceData = face.CreateOutput(); faceData.Update(); numFacesDetected = faceData.QueryNumberOfDetectedFaces(); if (numFacesDetected > 0) { // for (Int32 i = 0; i < numFacesDetected; i++) --> MULTIPLE FACE DETECTION DISABLED, UNCOMMENT TO INCLUDE // { // PXCMFaceData.Face singleFace = faceData.QueryFaceByIndex(i); --> FOR MULTIPLE FACE DETECTION //get all possible data from frame PXCMFaceData.Face singleFaceData = faceData.QueryFaceByIndex(0); //only getting first face! PXCMFaceData.ExpressionsData singleExprData = singleFaceData.QueryExpressions(); PXCMFaceData.DetectionData detectionData = singleFaceData.QueryDetection(); PXCMFaceData.LandmarksData landmarksData = singleFaceData.QueryLandmarks(); PXCMFaceData.PoseData poseData = singleFaceData.QueryPose(); //Work on face location data from detectionData if (detectionData != null) { // vars are defined globally detectionData.QueryBoundingRect(out boundingRect); detectionData.QueryFaceAverageDepth(out averageDepth); } //Work on getting landmark data if (landmarksData != null) { //var is defined globally landmarksData.QueryPoints(out landmarkPoints); } //Work on getting euler angles for face pose data if (poseData != null) { //var is defined globally poseData.QueryPoseAngles(out eulerAngles); poseData.QueryPoseQuaternion(out quaternionAngles); } //Do work on all face location data from singleExprData if (singleExprData != null) { //get scores and intensities for right and left eye closing - 22 possible expressions --> put into hashtable PXCMFaceData.ExpressionsData.FaceExpressionResult score; //this gets a list of enum names as strings var enumNames = Enum.GetNames(typeof(PXCMFaceData.ExpressionsData.FaceExpression)); //for all enumnames, calculate the for (int j = 0; j < enumNames.Length; j++) { PXCMFaceData.ExpressionsData.FaceExpressionResult innerScore; singleExprData.QueryExpression((PXCMFaceData.ExpressionsData.FaceExpression)(j), out innerScore); //Console.WriteLine((PXCMFaceData.ExpressionsData.FaceExpression)(j)); exprTable[enumNames[j]] = innerScore.intensity; } //Attempt to write to file if there are any significant events /* //check if everything is 0 bool significantEntry = false; foreach (DictionaryEntry entry in exprTable) { if (Convert.ToInt32(entry.Value.ToString()) != 0) { significantEntry = true; break; } } if (significantEntry) */ writeSignificantToFile(exprTable, boundingRect, averageDepth, landmarkPoints, eulerAngles, quaternionAngles); singleExprData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_CLOSED_LEFT, out score); lEyeClosedIntensity = score.intensity; singleExprData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_CLOSED_RIGHT, out score); rEyeClosedIntensity = score.intensity; //eye closed logic -> will be reset in UI thread after some number of frames if (lEyeClosedIntensity >= EYE_CLOSED_DETECT_THRESHOLD) lEyeClosed = true; if (rEyeClosedIntensity >= EYE_CLOSED_DETECT_THRESHOLD) rEyeClosed = true; } // } } } if (emotion != null) { int numFaces = emotion.QueryNumFaces(); for (int fid = 0; fid < numFaces; fid++) { //TODO - MULTIPLE FACE IMPLEMENTATION? //retrieve all est data PXCMEmotion.EmotionData[] arrData = new PXCMEmotion.EmotionData[10]; emotion.QueryAllEmotionData(fid, out arrData); //find emotion with maximum evidence int idx_outstanding_emotion = 0; int max_evidence = arrData[0].evidence; for (int k = 1; k < 7; k++) { if (arrData[k].evidence < max_evidence) { } else { max_evidence = arrData[k].evidence; idx_outstanding_emotion = k; } } currentEmotion = arrData[idx_outstanding_emotion].eid; //Console.WriteLine(currentEmotion.ToString()); emotionEvidence = max_evidence; // Console.WriteLine(currentEmotion.ToString() + ":" + emotionEvidence.ToString()); } } // Update the user interface UpdateUI(colorBitmap); // Release the frame if (handData != null) handData.Dispose(); // colorBitmap.Dispose(); sample.color.ReleaseAccess(colorData); senseManager.ReleaseFrame(); } }
public bool IsGestureFired(string Gesture) { PXCMHandData.GestureData data; return(HandData.IsGestureFired(Gesture, out data)); }