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); } } } }
private void DoTracking() { FacePipeline pp = new FacePipeline(1); pp.QueryCapture().SetFilter(DeviceName); //set modules pp.EnableFaceLocation(ModuleName); pp.EnableFaceLandmark(ModuleName); //initialize if (pp.Init()) { while (!stopped) { if (!pp.AcquireFrame(true)) { break; } if (!pp.IsDisconnected()) { PXCMFaceAnalysis ft = pp.QueryFace(); DisplayPicture(pp.QueryImage(PXCMImage.ImageType.IMAGE_TYPE_COLOR)); DisplayLocation(ft); } pp.ReleaseFrame(); } } else { MessageBox.Show("Init Failed"); } pp.Close(); pp.Dispose(); }
private static extern bool QueryFaceLocationDataC(IntPtr pp, Int32 face, out PXCMFaceAnalysis.Detection.Data data);
private static extern bool QueryFaceLandmarkPoseC(IntPtr pp, Int32 face, out PXCMFaceAnalysis.Landmark.PoseData data);
private static extern bool QueryFaceLandmarkDataC(IntPtr pp, Int32 face, PXCMFaceAnalysis.Landmark.Label label, int idx, out PXCMFaceAnalysis.Landmark.LandmarkData data);
public bool QueryFaceLocationData(Int32 face, out PXCMFaceAnalysis.Detection.Data data) { if (instance!=IntPtr.Zero) return QueryFaceLocationDataC(instance,face,out data); data=new PXCMFaceAnalysis.Detection.Data(); return false; }
public bool QueryFaceLandmarkPose(Int32 face, out PXCMFaceAnalysis.Landmark.PoseData data) { if (instance!=IntPtr.Zero) return QueryFaceLandmarkPoseC(instance,face,out data); data=new PXCMFaceAnalysis.Landmark.PoseData(); return false; }
public bool QueryFaceLandmarkData(Int32 face, PXCMFaceAnalysis.Landmark.Label label, ref PXCMFaceAnalysis.Landmark.LandmarkData[] data) { bool sts = false; for (int i=0;i<data.Length;i++) if (QueryFaceLandmarkData(face,label,i,out data[i])) sts=true; return sts; }
public bool QueryFaceLandmarkData(Int32 face, PXCMFaceAnalysis.Landmark.Label label, int idx, out PXCMFaceAnalysis.Landmark.LandmarkData data) { if (instance!=IntPtr.Zero) return QueryFaceLandmarkDataC(instance,face,label,idx,out data); data=new PXCMFaceAnalysis.Landmark.LandmarkData(); return false; }
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; }