public void TestFaceExpression() { var faceExpression = new FaceExpression("Smile", 0.1f, "face test"); Assert.AreEqual("Smile", faceExpression.Name); Assert.AreEqual(0.1f, faceExpression.Duration); Assert.AreEqual("face test", faceExpression.Description); }
public static float GetFaceExpression(FaceExpression expressionID) { if (faceAlignment == null) { return(0); } return(faceAlignment.AnimationUnits[(Microsoft.Kinect.Face.FaceShapeAnimations)expressionID]); }
public static float GetFaceExpression(FaceExpression expressionID) { if (expressionData == null) { return(0); } PXCMFaceData.ExpressionsData.FaceExpressionResult score; expressionData.QueryExpression((PXCMFaceData.ExpressionsData.FaceExpression)expressionID, out score); return(((float)score.intensity) / 100); }
internal static Boolean QueryExpressionINT(IntPtr instance, FaceExpression au, out FaceExpressionResult auResult) { auResult = new FaceExpressionResult(); return(PXCMFaceData_ExpressionsData_QueryExpression(instance, au, auResult)); }
internal static extern Boolean PXCMFaceData_ExpressionsData_QueryExpression(IntPtr instance, FaceExpression au, [Out] FaceExpressionResult auResult);
async Task subscription() { try { byte[] buffer = new byte[recieveChunckSize]; var mstream = new MemoryStream(); if (wsc.State != WebSocketState.Open) { connect("wss://emotivcortex.com:54321"); } ClientWebSocket webSocket = wsc; while (webSocket.State == WebSocketState.Open && stop != true) { Console.WriteLine("Recieve:"); WebSocketReceiveResult result = await webSocket.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None); if (result.EndOfMessage) { if (result.MessageType == WebSocketMessageType.Close) { await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, String.Empty, CancellationToken.None); } else if (result.MessageType == WebSocketMessageType.Text) { String resString = Encoding.UTF8.GetString(buffer, 0, result.Count); if (result.EndOfMessage) { JObject rj = JObject.Parse(resString); Console.WriteLine("Recieved:" + resString); if (rj["error"] != null) { Console.WriteLine("Error in request"); break; //Probably nothing interesting in this response } else { if (rj["fac"] != null) { JProperty jpres = null; foreach (JProperty jpr in rj.Properties()) { if (jpr.Name == "result") { jpres = jpr; break; } if (jpr.Name == "fac") { if (jpr.HasValues) { JArray jaa = (JArray)jpr.Value; FaceExpression expression = new FaceExpression(); expression.eyeExpression = (String)jaa[0]; expression.upperFaceExpression = (String)jaa[1]; expression.upperFaceExpressionPower = (float)jaa[2]; expression.lowerFaceExpression = (String)jaa[3]; expression.lowerFaceExpressionPower = (float)jaa[4]; faceAnimationUpdate.updateFaceExpression(expression); } } } } } } else { Debug.LogError("Recieved: " + result.ToString()); Console.WriteLine("Status: Recieved..:" + result.ToString()); } } } Task.Delay(100); } } catch (Exception e) { Debug.Log("Subscribe error: " + e.ToString()); } }
private void UpdateUI(Bitmap bitmap, FaceExpression expression) { this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { // Display the color image if (bitmap != null) { imgColorStream.Source = ConvertBitmap.BitmapToBitmapSource(bitmap); } if (_persistentDict.ContainsKey(userId.ToString())) { userName = _persistentDict[userId.ToString()].ToString(); } else { userName = ""; } if (userName == "") { lblName.Content = userId; } else { lblName.Content = userName; } // Update UI elements //lblNumFacesDetected.Content = String.Format("Faces Detected: {0}", numFacesDetected); //lblUserId.Content = String.Format("User ID: {0}", userId); //lblDatabaseState.Content = String.Format("Database: {0}", dbState); // Change picture border color depending on if user is in camera view if (numFacesDetected > 0) { //bdrPictureBorder.BorderBrush = System.Windows.Media.Brushes.LightGreen; switch (expression) { case FaceExpression.None: imgFace.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/shame.png")); break; case FaceExpression.Kiss: imgFace.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/kissy.png")); break; case FaceExpression.Open: imgFace.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/surprise.png")); break; case FaceExpression.Smile: imgFace.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/happy.png")); break; case FaceExpression.Tongue: imgFace.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/tongue.png")); break; default: imgFace.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/shame.png")); break; } // Make the BlockHead visible imgFace.Visibility = Visibility.Visible; //// Scale the BlockHead //imgFace.Width = faceRectangleWidth; //imgFace.Height = faceRectangleHeight; //// Rotate the BlockHead based on Roll orientation data //RotateTransform headRotateTransform = new RotateTransform(headRoll); //headRotateTransform.CenterX = imgFace.Width / 2; //headRotateTransform.CenterY = imgFace.Height / 2; //imgFace.RenderTransform = headRotateTransform; //// Display the BlockHead on the canvas //Canvas.SetRight(imgFace, faceRectangleX - 15); //Canvas.SetTop(imgFace, faceRectangleY); } else { imgFace.Visibility = Visibility.Hidden; //bdrPictureBorder.BorderBrush = System.Windows.Media.Brushes.Red; } // Show or hide face marker if (numFacesDetected > 0) { // Show face marker rectFaceMarker.Height = faceRectangleHeight; rectFaceMarker.Width = faceRectangleWidth; Canvas.SetLeft(rectFaceMarker, faceRectangleX); Canvas.SetTop(rectFaceMarker, faceRectangleY); rectFaceMarker.Visibility = Visibility.Visible; //// Show floating ID label //lblFloatingId.Content = String.Format("User ID: {0}", userId); //Canvas.SetLeft(lblFloatingId, faceRectangleX); //Canvas.SetTop(lblFloatingId, faceRectangleY - 20); //lblFloatingId.Visibility = Visibility.Visible; } else { // Hide the face marker and floating ID label rectFaceMarker.Visibility = Visibility.Hidden; //lblFloatingId.Visibility = Visibility.Hidden; } //Console.Out.WriteLine("Swipe X" + swipehandTipX); //if ((swipehandTipX < 200) && (swipehandTipX > 0) && (leftHand == false)) //{ // startLeftTracking = true; //} //else // if ((swipehandTipX > 400) && (leftHand == true)) // { // startRightTracking = true; // } //if ((startLeftTracking) || (startRightTracking)) //{ // framecount++; //} //if ((swipehandTipX > 450) && (startLeftTracking)) //{ // Console.Out.WriteLine("FrameCount " + framecount); // startLeftTracking = false; // framecount = 0; // window2.GoBack(); //} //if ((swipehandTipX < 100) && (startRightTracking) && (swipehandTipX != 0)) //{ // Console.Out.WriteLine("FrameCount " + framecount); // startRightTracking = false; // framecount = 0; // window2.GoNext(); //} //if (framecount > 100) //{ // startLeftTracking = false; // startRightTracking = false; // framecount = 0; //} //if ((gesture == Gesture.Fist) && (FirstWindow)) //{ // //senseManager.PauseHand(true); // SecondWindow = true; // _disp.BeginInvoke((Action)(() => // { // ShowProducts(); // })); //} //if ((gesture == Gesture.Thumb) && (SecondWindow)) //{ // window2.Buy(); //} // Show or hide face marker //if ((numFacesDetected > 0) && (chkShowFaceMarker.IsChecked == true)) //{ // // Show face marker // rectFaceMarker.Height = faceRectangleHeight; // rectFaceMarker.Width = faceRectangleWidth; // Canvas.SetLeft(rectFaceMarker, faceRectangleX); // Canvas.SetTop(rectFaceMarker, faceRectangleY); // rectFaceMarker.Visibility = Visibility.Visible; // // Show floating ID label // lblFloatingId.Content = String.Format("User ID: {0}", userId); // Canvas.SetLeft(lblFloatingId, faceRectangleX); // Canvas.SetTop(lblFloatingId, faceRectangleY - 20); // lblFloatingId.Visibility = Visibility.Visible; //} //else //{ // // Hide the face marker and floating ID label // rectFaceMarker.Visibility = Visibility.Hidden; // lblFloatingId.Visibility = Visibility.Hidden; //} })); // Release resources bitmap.Dispose(); }
private void ProcessingThread() { // Start AcquireFrame/ReleaseFrame loop while (senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { // Acquire the color image data PXCMCapture.Sample sample = senseManager.QuerySample(); Bitmap colorBitmap; PXCMImage.ImageData colorData; int topScore = 0; FaceExpression expression = FaceExpression.None; 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); try { IBarcodeReader reader = new BarcodeReader(); // load a bitmap //var barcodeBitmap = (Bitmap)Bitmap.LoadFrom("C:\\sample-barcode-image.png"); // detect and decode the barcode inside the bitmap var result = reader.Decode(colorBitmap); // do something with the result if (result != null) { MessageBox.Show(result.BarcodeFormat.ToString()); MessageBox.Show(result.Text); } } catch (Exception ex) { } // Get face data if (faceData != null) { faceData.Update(); numFacesDetected = faceData.QueryNumberOfDetectedFaces(); if (numFacesDetected > 0) { // Get the first face detected (index 0) PXCMFaceData.Face face = faceData.QueryFaceByIndex(0); // Retrieve face location data PXCMFaceData.DetectionData faceDetectionData = face.QueryDetection(); if (faceDetectionData != null) { PXCMRectI32 faceRectangle; faceDetectionData.QueryBoundingRect(out faceRectangle); if ((faceRectangle.h > 90) || (faceRectangle.w > 90)) { faceRectangleHeight = faceRectangle.h * 3 / 2; faceRectangleWidth = faceRectangle.w * 3 / 2; } else if (((faceRectangle.h < 90) || (faceRectangle.w < 90)) && ((faceRectangle.h > 70) || (faceRectangle.w > 70))) { faceRectangleHeight = faceRectangle.h * 2; faceRectangleWidth = faceRectangle.w * 2; } else { faceRectangleHeight = faceRectangle.h * 5 / 2; faceRectangleWidth = faceRectangle.w * 5 / 2; } faceRectangleX = faceRectangle.x; faceRectangleY = faceRectangle.y; } // Retrieve pose estimation data PXCMFaceData.PoseData facePoseData = face.QueryPose(); if (facePoseData != null) { PXCMFaceData.PoseEulerAngles headAngles; facePoseData.QueryPoseAngles(out headAngles); headRoll = headAngles.roll; headPitch = headAngles.pitch; headYaw = headAngles.yaw; } // Retrieve expression data PXCMFaceData.ExpressionsData expressionData = face.QueryExpressions(); if (expressionData != null) { PXCMFaceData.ExpressionsData.FaceExpressionResult score; expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_KISS, out score); expressionScore[Convert.ToInt32(FaceExpression.Kiss)] = score.intensity; expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_MOUTH_OPEN, out score); expressionScore[Convert.ToInt32(FaceExpression.Open)] = score.intensity; expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_SMILE, out score); expressionScore[Convert.ToInt32(FaceExpression.Smile)] = score.intensity; expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_TONGUE_OUT, out score); expressionScore[Convert.ToInt32(FaceExpression.Tongue)] = score.intensity; // Determine the highest scoring expression for (int i = 1; i < TotalExpressions; i++) { if (expressionScore[i] > topScore) { expression = (FaceExpression)i; } } } // Process face recognition data if (face != null) { // Retrieve the recognition data instance recognitionData = face.QueryRecognition(); // Set the user ID and process register/unregister logic if (recognitionData.IsRegistered()) { userId = Convert.ToString(recognitionData.QueryUserID()); if (doUnregister) { recognitionData.UnregisterUser(); SaveDatabaseToFile(); doUnregister = false; if (_persistentDict.ContainsKey(userId) == true) { _persistentDict.Remove(userId); } } } else { if (doRegister) { int uId = recognitionData.RegisterUser(); SaveDatabaseToFile(); if (newUserName != "") { if (_persistentDict.ContainsKey(uId.ToString()) == false) { _persistentDict.Add(uId.ToString(), newUserName); _persistentDict.Flush(); newUserName = ""; } } // Capture a jpg image of registered user colorBitmap.Save("image.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); doRegister = false; } else { userId = "New User"; } } } } else { userId = "No users in view"; } } //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(); //} // Display the color stream and other UI elements //UpdateUI(colorBitmap, expression, gesture); UpdateUI(colorBitmap, expression); // Release resources colorBitmap.Dispose(); sample.color.ReleaseAccess(colorData); sample.color.Dispose(); // Release the frame senseManager.ReleaseFrame(); } }
/// <summary> /// Queries single expression result /// </summary> /// <param name="expression">Single expression</param> /// <param name="expressionResult">Expression result - such as intensity</param> /// <returns>Returns true if expression was calculated successfully, false otherwise.</returns> public Boolean QueryExpression(FaceExpression expression, out FaceExpressionResult expressionResult) { return QueryExpressionINT(instance, expression, out expressionResult); }
/// <summary> /// Queries single expression result /// </summary> /// <param name="expression">Single expression</param> /// <param name="expressionResult">Expression result - such as intensity</param> /// <returns>Returns true if expression was calculated successfully, false otherwise.</returns> public Boolean QueryExpression(FaceExpression expression, out FaceExpressionResult expressionResult) { return(QueryExpressionINT(instance, expression, out expressionResult)); }
public void updateFaceExpression(FaceExpression newFaceialExpression) { faceNextExpression = newFaceialExpression; nextExpress = true; }
internal static Boolean QueryExpressionINT(IntPtr instance, FaceExpression au, out FaceExpressionResult auResult) { auResult = new FaceExpressionResult(); return PXCMFaceData_ExpressionsData_QueryExpression(instance, au, auResult); }