Neeraj's Blog

There is always an open source solution..

Retrieving Facial Landmarks using Intel RealSense SDK

I am trying to print the x and y position of the facial landmarks retrieving through realsense camera.

#include<iostream>
#include "pxccapturemanager.h"
#include "pxcsensemanager.h"
#include "pxcstatus.h"
#include "pxcfacemodule.h"
#include "pxcfacedata.h"
#include "pxcfaceconfiguration.h"

using namespace std;

int MAX_FACES = 4;
pxcI32 m_numLandmarks;
PXCFaceData::LandmarkPoint* m_landmarkPoints;
static const int LANDMARK_ALIGNMENT = -3;

void main(int argc, char** argv)
{
    PXCSenseManager *sm = PXCSenseManager::CreateInstance();
    pxcStatus sts;


    if(!sm){
        printf("Unable to create sense manager\n");
        return;
    }

    sts = sm->EnableFace();
    if(sts<PXC_STATUS_NO_ERROR) {
        printf("Unable to enable face Analysis\n");
    }

    sm->Init();

    PXCFaceModule *face=sm->QueryFace();
    PXCFaceData *fdata = face->CreateOutput();

    PXCFaceConfiguration* config = face->CreateActiveConfiguration();
    config->detection.isEnabled = true;
    config->detection.maxTrackedFaces = MAX_FACES;
    config->landmarks.isEnabled = true;
    m_numLandmarks = config->landmarks.numLandmarks;
    config->ApplyChanges();

    m_landmarkPoints = new PXCFaceData::LandmarkPoint[m_numLandmarks];
    
    for(;;)
    {
        sts=sm->AcquireFrame(true);
//        if(sts<PXC_STATUS_NO_ERROR) break;

        fdata->Update();
        pxcI32 numFaces =  fdata->QueryNumberOfDetectedFaces();

        for(pxcI32 i =0; i< numFaces; i++)
        {
            PXCFaceData::Face *singleFdata =  fdata->QueryFaceByIndex(i);
            const PXCFaceData::LandmarksData* landmarkData = singleFdata->QueryLandmarks();
            if (landmarkData == NULL)
                break;

            pxcI32 numPoints = landmarkData->QueryNumPoints();
            if (numPoints != m_numLandmarks) {
                break;
            }

            landmarkData->QueryPoints(m_landmarkPoints);

            for (int j = 0; j < numPoints; ++j)
            {
                int x = (int)m_landmarkPoints[j].image.x + LANDMARK_ALIGNMENT;
                int y = (int)m_landmarkPoints[j].image.y + LANDMARK_ALIGNMENT;
                
                if (m_landmarkPoints[j].confidenceImage)
                {
                    cout<< "point : "<< j << "\t x : " << x << "\t y : " << y <<endl; 
                }
            }
        }
        sm->ReleaseFrame();
    }
    return;
}

 

Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: