public override bool OnNewFrame() { faceAnalysis = QueryFace(); faceAnalysis.QueryFace(fidx, out faceId, out timeStamp); //Get face location faceLocation = (PXCMFaceAnalysis.Detection)faceAnalysis.DynamicCast(PXCMFaceAnalysis.Detection.CUID); locationStatus = faceLocation.QueryData(faceId, out faceLocationData); detectionConfidence = faceLocationData.confidence.ToString(); //Get face attributes (smile, age group, gender, eye blink, etc) faceAttributes = (PXCMFaceAnalysis.Attribute)faceAnalysis.DynamicCast(PXCMFaceAnalysis.Attribute.CUID); faceAttributes.QueryProfile(PXCMFaceAnalysis.Attribute.Label.LABEL_EYE_CLOSED, 0, out attributeProfile); attributeProfile.threshold = 50; //Must be here! faceAttributes.SetProfile(PXCMFaceAnalysis.Attribute.Label.LABEL_EYE_CLOSED, ref attributeProfile); attributeStatus = faceAttributes.QueryData(PXCMFaceAnalysis.Attribute.Label.LABEL_EYE_CLOSED, faceId, out blink); ShowAttributesOnForm(); //Do the application events try { Application.DoEvents(); //TODO: This should be avoided using a different thread, but how? } catch (AccessViolationException e) { //TODO: Handle exception! } return(true); }
private void DisplayLocation(PXCMFaceAnalysis ft) { for (uint i = 0; ; i++) { int fid; ulong ts; if (ft.QueryFace(i, out fid, out ts) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } //retrieve face location data PXCMFaceAnalysis.Detection.Data rData; var ftd = ft.DynamicCast <PXCMFaceAnalysis.Detection>(PXCMFaceAnalysis.Detection.CUID); var rStatus = ftd.QueryData(fid, out rData); //Retrieve face landmark data PXCMFaceAnalysis.Landmark.ProfileInfo pinfo; var ftl = ft.DynamicCast <PXCMFaceAnalysis.Landmark>(PXCMFaceAnalysis.Landmark.CUID); ftl.QueryProfile(out pinfo); var lData = new PXCMFaceAnalysis.Landmark.LandmarkData[(int)(pinfo.labels & PXCMFaceAnalysis.Landmark.Label.LABEL_SIZE_MASK)]; var lStatus = ftl.QueryLandmarkData(fid, pinfo.labels, lData); //if (rStatus >= pxcmStatus.PXCM_STATUS_NO_ERROR && lStatus >= pxcmStatus.PXCM_STATUS_NO_ERROR) if (rStatus < pxcmStatus.PXCM_STATUS_NO_ERROR || lStatus < pxcmStatus.PXCM_STATUS_NO_ERROR) { if (FaceNotAvailable != null) { FaceNotAvailable(); } } else { //build facedata FaceData faceData = new FaceData(); faceData.Rect = new Rect(rData.rectangle.x, rData.rectangle.y, rData.rectangle.w, rData.rectangle.h); faceData.Points = lData.Select(p => new System.Windows.Point(p.position.x, p.position.y)).ToList(); if (FaceAvailable != null) { FaceAvailable(faceData); } } } }
public override bool OnNewFrame() { faceAnalysis = QueryFace(); faceAnalysis.QueryFace(fidx, out faceId, out timeStamp); //Get face location faceLocation = (PXCMFaceAnalysis.Detection)faceAnalysis.DynamicCast(PXCMFaceAnalysis.Detection.CUID); locationStatus = faceLocation.QueryData(faceId, out faceLocationData); detectionConfidence = faceLocationData.confidence.ToString(); //Get face attributes (smile, age group, gender, eye blink, etc) faceAttributes = (PXCMFaceAnalysis.Attribute)faceAnalysis.DynamicCast(PXCMFaceAnalysis.Attribute.CUID); faceAttributes.QueryProfile(PXCMFaceAnalysis.Attribute.Label.LABEL_EYE_CLOSED, 0, out attributeProfile); attributeProfile.threshold = 50; //Must be here! faceAttributes.SetProfile(PXCMFaceAnalysis.Attribute.Label.LABEL_EYE_CLOSED, ref attributeProfile); attributeStatus = faceAttributes.QueryData(PXCMFaceAnalysis.Attribute.Label.LABEL_EYE_CLOSED, faceId, out blink); //Get face landmarks (eye, mouth, nose position) faceLandmark = (PXCMFaceAnalysis.Landmark)faceAnalysis.DynamicCast(PXCMFaceAnalysis.Landmark.CUID); faceLandmark.QueryProfile(1, out landmarkProfile); faceLandmark.SetProfile(ref landmarkProfile); landmarkStatus = faceLandmark.QueryLandmarkData(faceId, PXCMFaceAnalysis.Landmark.Label.LABEL_7POINTS, faceLandmarkData); ShowAttributesOnForm(); //Do the application events try { Application.DoEvents(); //TODO: This should be avoided using a different thread, but how? } catch (AccessViolationException e) { //TODO: Handle exception! } return true; }