Software Archive
Read-only legacy content
17060 Discussions

QueryFaceAverageDepth

Brennon_W_
Beginner
251 Views

Hi,

In C# parsing a float as the out param of QueryFaceAverageDepth never return a value.

Is this a known issue?

 

Cheers

0 Kudos
5 Replies
Colleen_C_Intel
Employee
251 Views

We tested this and had no issue.  Here's the relevant snips of code....let me know if you'd like the whole code by pm.

expressionConfiguration;
        private float faceAverageDepth;

......   // Retrieve face related data
          
 PXCMFaceData.DetectionData
faceDetectionData = faceDataFace.QueryDetection();
         
  if (faceDetectionData != null)
           
{
        
        PXCMRectI32 faceRectangle;
        
       faceDetectionData.QueryFaceAverageDepth(out faceAverageDepth);
           }
.................................................
  
this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
       {
                lblFaceDepth.Content = string.Format("Face Average Depth: {0}", faceAverageDepth);

 

 

0 Kudos
Brennon_W_
Beginner
251 Views

Hi Colleen,

Thanks for your reply.

In one of the samples (DF_FaceTracking) you have a class called "FaceTextOrganiser" where work is being done to create a detection window I believe. In the last method "ChangeFace", you have this:

PXCMFaceData.DetectionData fdetectionData = face.QueryDetection();

So at the end of the method after verifying that fdetectionData is not null, I am calling the QueryFaceAverageDepth method with a float param just as your snippet shows - I get no errors, but this value is always 0.

 

Cheers

0 Kudos
Colleen_C_Intel
Employee
251 Views
MainWindow.xaml.cs

//--------------------------------------------------------------------------------------
// Copyright 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.Threading;

namespace FaceTrackingSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Thread processingThread;
        private PXCMSenseManager senseManager;
        private PXCMSession session;
        private PXCMFaceModule face;
        private PXCMFaceConfiguration faceConfiguration;
        private PXCMFaceConfiguration.ExpressionsConfiguration expressionConfiguration;
        private Int32 numberTrackedFaces;
        private int faceRectangleHeight;
        private int faceRectangleWidth;
        private int faceRectangleX;
        private int faceRectangleY;
        private float faceAverageDepth;
        private float headRoll;
        private float headPitch;
        private float headYaw;
        private int smileScore;

        public MainWindow()
        {
            InitializeComponent();
            senseManager = PXCMSenseManager.CreateInstance();
            session = senseManager.QuerySession();
            senseManager.EnableFace();
            senseManager.Init();
            ConfigureFaceTracking();
            processingThread = new Thread(new ThreadStart(ProcessingThread));
            processingThread.Start();
        }

        private void ConfigureFaceTracking()
        {
            face = senseManager.QueryFace();
            faceConfiguration = face.CreateActiveConfiguration();
            faceConfiguration.detection.isEnabled = true;

            expressionConfiguration = faceConfiguration.QueryExpressions();
            expressionConfiguration.Enable();
            expressionConfiguration.EnableAllExpressions();

            faceConfiguration.EnableAllAlerts();
            faceConfiguration.ApplyChanges();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            processingThread.Abort();
            faceConfiguration.Dispose();
            senseManager.Dispose();
        }

        private void ProcessingThread()
        {
            // Start AcquireFrame/ReleaseFrame loop
            while (senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                // Get a face instance
                face = senseManager.QueryFace();

                if (face != null)
              {
                    // Get face tracking processed data
                    PXCMFaceData faceData = face.CreateOutput();
                    faceData.Update();
                    numberTrackedFaces = faceData.QueryNumberOfDetectedFaces();

                    // Retrive the face location data instance
                    PXCMFaceData.Face faceDataFace = faceData.QueryFaceByIndex(0);
                    
                    if (faceDataFace != null)
                    {
                        // Retrieve face location data
                        PXCMFaceData.DetectionData faceDetectionData = faceDataFace.QueryDetection();
                        if (faceDetectionData != null)
                        {
                            PXCMRectI32 faceRectangle;
                            faceDetectionData.QueryFaceAverageDepth(out faceAverageDepth);
                            faceDetectionData.QueryBoundingRect(out faceRectangle);
                            faceRectangleHeight = faceRectangle.h;
                            faceRectangleWidth = faceRectangle.w;
                            faceRectangleX = faceRectangle.x;
                            faceRectangleY = faceRectangle.y;
                        }

                        // Retrive pose estimation data
                        PXCMFaceData.PoseData facePoseData = faceDataFace.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 = faceDataFace.QueryExpressions();
                        if (expressionData != null)
                        {
                            PXCMFaceData.ExpressionsData.FaceExpressionResult score;
                            expressionData.QueryExpression(PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_SMILE, out score);
                            smileScore = score.intensity;
                        }
                    }

                    UpdateUI();
                    faceData.Dispose();
                }

                senseManager.ReleaseFrame();
            }
        }

        private void UpdateUI()
        {
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                lblNumberFaces.Content = string.Format("Detected Faces: {0}", numberTrackedFaces);
                lblFaceH.Content = string.Format("Face Height: {0}", faceRectangleHeight);
                lblFaceW.Content = string.Format("Face Width: {0}", faceRectangleWidth);
                lblFaceX.Content = string.Format("Face X: {0}", faceRectangleX);
                lblFaceY.Content = string.Format("Face Y: {0}", faceRectangleY);
                lblFaceDepth.Content = string.Format("Face Average Depth: {0}", faceAverageDepth);
                lblHeadRoll.Content = string.Format("Head Roll: {0}", headRoll);
                lblHeadPitch.Content = string.Format("Head Pitch: {0}", headPitch);
                lblHeadYaw.Content = string.Format("Head Yaw: {0}", headYaw);
                lblExpression.Content = string.Format("Smile Score: {0}", smileScore);
            }));
        }
    }
}

MainWindow.xaml

<Window x:Class="FaceTrackingSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Face Tracking Sample" Height="452.287" Width="452.219" Icon="icon.ico" Closing="Window_Closing" WindowStartupLocation="CenterScreen">

    <StackPanel>
        <Label x:Name="lblNumberFaces" Content="-" FontSize="16" Margin="30,4,0,4"/>
        <Label x:Name="lblFaceH" Content="-" FontSize="16" Margin="30,4,0,4"/>
        <Label x:Name="lblFaceW" Content="-" FontSize="16" Margin="30,4,0,4"/>
        <Label x:Name="lblFaceX" Content="-" FontSize="16" Margin="30,4,0,4"/>
        <Label x:Name="lblFaceY" Content="-" FontSize="16" Margin="30,4,0,4"/>
        <Label x:Name="lblFaceDepth" Content="-" FontSize="16" Margin="30,4,0,4"/>
        <Label x:Name="lblHeadRoll" Content="-" FontSize="16" Margin="30,4,0,4"/>
        <Label x:Name="lblHeadPitch" Content="-" FontSize="16" Margin="30,4,0,4"/>
        <Label x:Name="lblHeadYaw" Content="-" FontSize="16" Margin="30,4,0,4"/>
        <Label x:Name="lblExpression" Content="-" FontSize="16" Margin="30,4,0,4"/>
    </StackPanel>
</Window>

 

0 Kudos
Brennon_W_
Beginner
251 Views

Hi Colleen,

Thanks for the sample.

I'm still no clearer as to why the implementation that is in the Sample SDK does not work, when really it should.

Will keep messing around and update if I figure it out.

Thanks again for the help.

 

Best,

0 Kudos
Zenny_T_
Beginner
251 Views

I was running into this same issue for a bit, but managed to figure it out the reason why I was seeing the problem.

The QueryFaceAverageDepth is a boolean function that will return False if it doesn't set your out parameter, so that's the first thing to check.

I was seeing the function itself return false, and my out parameter stayed at whatever I set it to initially.

Eventually I stumbled upon this line of code:

PXCMFaceConfiguration.TrackingModeType mode = PXCMFaceConfiguration.TrackingModeType.FACE_MODE_COLOR;

From looking at some sample code, I noticed they had this:

PXCMFaceConfiguration.TrackingModeType mode = PXCMFaceConfiguration.TrackingModeType.FACE_MODE_COLOR_PLUS_DEPTH;

Changing it to PLUS_DEPTH seemed to fix the issue for me.

Hopefully this helps anyone else that might run into the same issue in the future, or at least eliminate a potential cause of this problem.

0 Kudos
Reply