- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to run this code but I receive null reference from faceData.QueryFaceByIndex(i) or f.QueryPose(). Can you please help me figure out what's wrong? I have attached the whole project in zip format so you can be able to reproduce it.
//-------------------------------------------------------------------------------------- // Copyright 2014-2015 Intel Corporation // All Rights Reserved // // Permission is granted to use, copy, distribute and prepare derivative works of this // software for any purpose and without fee, provided, that the above copyright notice // and this statement appear in all copies. Intel makes no representations about the // suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS." // INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY, // INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, // INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not // assume any responsibility for any errors which may appear in this software nor any // responsibility to update it. //-------------------------------------------------------------------------------------- using System; using System.Windows; using System.Windows.Media; using System.Threading; using System.Drawing; using System.ComponentModel; namespace HelloWorld { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private Thread processingThread; private PXCMSenseManager senseManager; private PXCMHandModule hand; private PXCMHandConfiguration handConfig; private PXCMHandData handData; private PXCMHandData.GestureData gestureData; private bool handWaving; private bool handTrigger; private int msgTimer; public MainWindow() { InitializeComponent(); handWaving = false; handTrigger = false; msgTimer = 0; // Instantiate and initialize the SenseManager senseManager = PXCMSenseManager.CreateInstance(); senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 30); senseManager.EnableHand(); senseManager.Init(); // Configure the Hand Module hand = senseManager.QueryHand(); handConfig = hand.CreateActiveConfiguration(); handConfig.EnableGesture("wave"); handConfig.EnableAllAlerts(); handConfig.ApplyChanges(); // Start the worker thread processingThread = new Thread(new ThreadStart(ProcessingThread)); processingThread.Start(); } private void Window_Loaded(object sender, RoutedEventArgs e) { lblMessage.Content = "(Wave Your Hand)"; Console.WriteLine("Waving and all"); } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { processingThread.Abort(); if (handData != null) handData.Dispose(); handConfig.Dispose(); senseManager.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(); // Update the user interface UpdateUI(colorBitmap); senseManager.EnableFace(); PXCMFaceModule faceModule = senseManager.QueryFace(); PXCMFaceConfiguration faceConfig = faceModule.CreateActiveConfiguration(); faceConfig.detection.isEnabled = true; faceConfig.detection.maxTrackedFaces = 2; faceConfig.landmarks.isEnabled = true; faceConfig.ApplyChanges(); faceConfig.Dispose(); Console.WriteLine("We got here!"); PXCMFaceData faceData = faceModule.CreateOutput(); faceData.Update(); int numFaces = faceData.QueryNumberOfDetectedFaces(); Console.WriteLine(numFaces); //PXCMFaceData.Face face = faceData.QueryFaceByIndex(0); for (int i = 0; i < numFaces; i++) { PXCMFaceData.Face f = faceData.QueryFaceByIndex(i); PXCMFaceData.PoseData p = f.QueryPose(); PXCMPoint3DF32 outHeadPosition = new PXCMPoint3DF32(); // Boolean headout= p.QueryHeadPosition(out outHeadPosition); // p.QueryHeadPosition(out outHeadPosition); //System.out.println("Out: " + outHeadPosition); PXCMFaceData.PoseEulerAngles outPoseEulerAngles = new PXCMFaceData.PoseEulerAngles(); p.QueryPoseAngles(out outPoseEulerAngles); Console.WriteLine("Rotation: " + outPoseEulerAngles.roll + " " + outPoseEulerAngles.pitch + " " + outPoseEulerAngles.yaw); } // PXCMFaceData.PoseData poseData = face.QueryPose(); colorBitmap.Dispose(); sample.color.ReleaseAccess(colorData); senseManager.ReleaseFrame(); } } private void UpdateUI(Bitmap bitmap) { this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { if (bitmap != null) { // Mirror the color stream Image control imgColorStream.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5); ScaleTransform mainTransform = new ScaleTransform(); mainTransform.ScaleX = -1; mainTransform.ScaleY = 1; imgColorStream.RenderTransform = mainTransform; // Display the color stream imgColorStream.Source = ConvertBitmap.BitmapToBitmapSource(bitmap); // Update the screen message if (handWaving) { lblMessage.Content = "Hello World!"; handTrigger = true; } // Reset the screen message after ~50 frames if (handTrigger) { msgTimer++; if (msgTimer >= 50) { lblMessage.Content = "(Wave Your Hand)"; msgTimer = 0; handTrigger = false; } } } })); } } }
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For some weird reason numFaces is always zero. So I don't know why is like so, I think that is why it can't query the face data. Any idea what's wrong with my code or say how to fix it? Because it gives null reference at this line
PXCMFaceData.PoseData p = f.QueryPose();
PXCMFaceData faceData = faceModule.CreateOutput(); faceData.Update(); int numFaces = faceData.QueryNumberOfDetectedFaces(); Console.WriteLine(numFaces); //PXCMFaceData.Face face = faceData.QueryFaceByIndex(0); //for (int i = 0; i < numFaces; i++) { Console.WriteLine("We got here!"); PXCMFaceData.Face f = faceData.QueryFaceByIndex(0); Console.WriteLine("We got here too!"); PXCMFaceData.PoseData p = f.QueryPose(); PXCMPoint3DF32 outHeadPosition = new PXCMPoint3DF32(); // Boolean headout= p.QueryHeadPosition(out outHeadPosition); // p.QueryHeadPosition(out outHeadPosition); //System.out.println("Out: " + outHeadPosition);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Mona,
Did you try calling "senseManager.EnableFace();" before calling "senseManager.Init();
"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey Mona, the issue I see here is that configuration should not be done every frame – preferably only once and before acquire frame processing loop
- Init & Configuration
- Enable face module -> senseManager.EnableFace();
- Configure face module -> config.ApplyChanges();
- Init -> senseManager.Init();
- Processing
- faceData->update();
- Query faceData.
Let me know if you have any other problems.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page