<|start_filename|>nvar/include/nvAR.h<|end_filename|>
/*###############################################################################
#
# Copyright 2020 NVIDIA Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
###############################################################################*/

#ifndef NvAR_H
#define NvAR_H

#include "nvAR_defs.h"

#ifdef __cplusplus
extern "C" {
#endif  // __cplusplus

// Forward declaration for CUDA API
// CUstream and cudaStream_t are CUstream_st*
struct CUstream_st;
typedef struct CUstream_st *CUstream;

typedef struct nvAR_Feature nvAR_Feature;
typedef struct nvAR_Feature *NvAR_FeatureHandle;

//! Get the SDK version
//! \param[in,out]  version    Pointer to an unsigned int set to 
//!                            (major << 24) | (minor << 16) | (build << 8) | 0
//! \return         NVCV_SUCCESS  if the version was set
//! \return         NVCV_ERR_PARAMETER  if version was NULL
NvCV_Status NvAR_API NvAR_GetVersion(unsigned int *version);

//! Create a new feature instantiation.
//! \param[in]  InFeatureID The selector code for the desired feature.
//! \param[out] handle      Handle to the feature instance.
NvCV_Status NvAR_API NvAR_Create(NvAR_FeatureID featureID, NvAR_FeatureHandle *handle);

//! Load the model based on the set params.
//! \param[in] handle Handle to the feature instance.
NvCV_Status NvAR_API NvAR_Load(NvAR_FeatureHandle handle);

//! Run the selected feature instance.
//! \param[in] handle Handle to the feature instance.
NvCV_Status NvAR_API NvAR_Run(NvAR_FeatureHandle handle);

//! Delete a previously created feature instance.
//! \param[in] handle Handle to the feature instance.
NvCV_Status NvAR_API NvAR_Destroy(NvAR_FeatureHandle handle);

//! Wrapper for cudaStreamCreate(), if it is desired to avoid linking with the cuda lib.
//! \param[out] stream  A place to store the newly allocated stream.
NvCV_Status NvAR_API NvAR_CudaStreamCreate(CUstream *stream);

//! Wrapper for cudaStreamDestroy(), if it is desired to avoid linking with the cuda lib.
//! \param[in]  stream  The stream to destroy.
NvCV_Status NvAR_API NvAR_CudaStreamDestroy(CUstream stream);

//! Set the value of the selected parameter.
//! \param[in] handle Handle to the feature instance.
//! \param[in] name   The selector of the feature parameter to configure.
//! \param[in] val    The value to be assigned to the selected feature parameter.
NvCV_Status NvAR_API NvAR_SetU32(NvAR_FeatureHandle handle, const char *name, unsigned int val);
NvCV_Status NvAR_API NvAR_SetS32(NvAR_FeatureHandle handle, const char *name, int val);
NvCV_Status NvAR_API NvAR_SetF32(NvAR_FeatureHandle handle, const char *name, float val);
NvCV_Status NvAR_API NvAR_SetF64(NvAR_FeatureHandle handle, const char *name, double val);
NvCV_Status NvAR_API NvAR_SetU64(NvAR_FeatureHandle handle, const char *name, unsigned long long val);
NvCV_Status NvAR_API NvAR_SetObject(NvAR_FeatureHandle handle, const char *name, void *ptr, unsigned long typeSize);
NvCV_Status NvAR_API NvAR_SetString(NvAR_FeatureHandle handle, const char *name, const char *str);
NvCV_Status NvAR_API NvAR_SetCudaStream(NvAR_FeatureHandle handle, const char *name, CUstream stream);
NvCV_Status NvAR_API NvAR_SetF32Array(NvAR_FeatureHandle handle, const char *name, float *vals, int /*count*/);

//! Get the value of the selected parameter.
//! \param[in]  handle Handle to the feature instance.
//! \param[in]  name   The selector of the feature parameter to retrieve.
//! \param[out] val    Place to store the retrieved parameter.
NvCV_Status NvAR_API NvAR_GetU32(NvAR_FeatureHandle handle, const char *name, unsigned int *val);
NvCV_Status NvAR_API NvAR_GetS32(NvAR_FeatureHandle handle, const char *name, int *val);
NvCV_Status NvAR_API NvAR_GetF32(NvAR_FeatureHandle handle, const char *name, float *val);
NvCV_Status NvAR_API NvAR_GetF64(NvAR_FeatureHandle handle, const char *name, double *val);
NvCV_Status NvAR_API NvAR_GetU64(NvAR_FeatureHandle handle, const char *name, unsigned long long *val);
NvCV_Status NvAR_API NvAR_GetObject(NvAR_FeatureHandle handle, const char *name, const void **ptr,
                                    unsigned long typeSize);
NvCV_Status NvAR_API NvAR_GetString(NvAR_FeatureHandle handle, const char *name, const char **str);
NvCV_Status NvAR_API NvAR_GetCudaStream(NvAR_FeatureHandle handle, const char *name, const CUstream *stream);
NvCV_Status NvAR_API NvAR_GetF32Array(NvAR_FeatureHandle handle, const char *name, const float **vals, int* /*count*/);

#ifdef __cplusplus
}
#endif  // __cplusplus

#endif  // #define NvAR_H


<|start_filename|>samples/FaceTrack/run.bat<|end_filename|>
SETLOCAL
SET PATH=%PATH%;..\..\samples\external\opencv\bin;..\..\bin;
FaceTrack.exe

<|start_filename|>samples/utils/FeatureVertexName.cpp<|end_filename|>
/*###############################################################################
#
# Copyright(c) 2019 NVIDIA CORPORATION.All Rights Reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
###############################################################################*/

#include "FeatureVertexName.h"
#include <stdlib.h>
#include <string.h>


// TODO: We should read this from a file
const LandmarkEOSMap LandmarkMapEOS[] = {
    {   33, "chin bottom" },
    {  225, "right eyebrow outer-corner" },
    {  229, "right eyebrow between middle and outer corner" },
    {  233, "right eyebrow middle, vertical middle" },
    { 2086, "right eyebrow between middle and inner corner" },
    {  157, "right eyebrow inner-corner" },
    {  590, "left eyebrow inner-corner" },
    { 2091, "left eyebrow between inner corner and middle" },
    {  666, "left eyebrow middle" },
    {  662, "left eyebrow between middle and outer corner" },
    {  658, "left eyebrow outer-corner" },
    { 2842, "bridge of the nose (parallel to upper eye lids)" },
    {  379, "middle of the nose, a bit below the lower eye lids" },
    {  272, "above nose-tip (1cm or so)" },
    {  114, "nose-tip" },
    {  100, "right nostril, below nose, nose-lip junction" },
    { 2794, "nose-lip junction" },
    {  270, "nose-lip junction" },
    { 2797, "nose-lip junction" },
    {  537, "left nostril, below nose, nose-lip junction" },
    {  177, "right eye outer-corner" },
    {  172, "right eye pupil top right (from subject's perspective)" },
    {  191, "right eye pupil top left" },
    {  181, "right eye inner-corner" },
    {  173, "right eye pupil bottom left" },
    {  174, "right eye pupil bottom right" },
    {  614, "left eye inner-corner" },
    {  624, "left eye pupil top right" },
    {  605, "left eye pupil top left" },
    {  610, "left eye outer-corner" },
    {  607, "left eye pupil bottom left" },
    {  606, "left eye pupil bottom right" },
    {  398, "right mouth corner" },
    {  315, "upper lip right top outer" },
    {  413, "upper lip middle top right" },
    {  329, "upper lip middle top" },
    {  825, "upper lip middle top left" },
    {  736, "upper lip left top outer" },
    {  812, "left mouth corner" },
    {  841, "lower lip left bottom outer" },
    {  693, "lower lip middle bottom left" },
    {  411, "lower lip middle bottom" },
    {  264, "lower lip middle bottom right" },
    {  431, "lower lip right bottom outer" },
    {  416, "upper lip right bottom outer" },
    {  423, "upper lip middle bottom" },
    {  828, "upper lip left bottom outer" },
    {  817, "lower lip left top outer" },
    {  442, "lower lip middle top" },
    {  404, "lower lip right top outer" },
    {  0xFFFF,  nullptr }
};

static const LandmarksMap LandmarkMap[] = {
    {  0,  0, "right contour point 1"  },
    {  1,  2, "right contour point 2"  },
    {  2,  4, "right contour point 3"  },
    {  3,  6, "right contour point 4"  },
    {  4,  8, "right contour point 5"  },
    {  5,  10, "right contour point 6"  },
    {  6,  12, "right contour point 7"  },
    {  7,  14, "right contour point 8"  },
    {  8,  16, "chin bottom"  },
    {  9,  18, "left contour point 1"  },
    {  10,  20, "left contour point 2"  },
    {  11,  22, "left contour point 3"  },
    {  12,  24, "left contour point 4"  },
    {  13,  26, "left contour point 5"  },
    {  14,  28, "left contour point 6"  },
    {  15,  30, "left contour point 7"  },
    {  16,  32, "left contour point 8"  },
    {  17,  33, "right eyebrow outer-corner"  },
    {  18,  34, "right eyebrow between middle and outer corner"  },
    {  19,  35, "right eyebrow middle, vertical middle"  },
    {  20,  36, "right eyebrow between middle and inner corner"  },
    {  21,  37, "right eyebrow inner-corner"  },
    {  22,  42, "left eyebrow inner-corner"  },
    {  23,  43, "left eyebrow between inner corner and middle"  },
    {  24,  44, "left eyebrow middle"  },
    {  25,  45, "left eyebrow between middle and outer corner"  },
    {  26,  46, "left eyebrow outer-corner"  },
    {  27,  51, "bridge of the nose (parallel to upper eye lids)"  },
    {  28,  52, "middle of the nose, a bit below the lower eye lids"  },
    {  29,  53, "above nose-tip (1cm or so)"  },
    {  30,  54, "nose-tip"  },
    {  31,  57, "right nostril, below nose, nose-lip junction"  },
    {  32,  58, "nose-lip junction"  },
    {  33,  59, "nose-lip junction"  },
    {  34,  60, "nose-lip junction"  },
    {  35,  61, "left nostril, below nose, nose-lip junction"  },
    {  36,  64, "right eye outer-corner"  },
    {  37,  65, "right eye pupil top right (from subject's perspective)"  },
    {  38,  67, "right eye pupil top left"  },
    {  39,  68, "right eye inner-corner"  },
    {  40,  69, "right eye pupil bottom left"  },
    {  41,  71, "right eye pupil bottom right"  },
    {  42,  81, "left eye inner-corner"  },
    {  43,  82, "left eye pupil top right"  },
    {  44,  84, "left eye pupil top left"  },
    {  45,  85, "left eye outer-corner"  },
    {  46,  86, "left eye pupil bottom left"  },
    {  47,  88, "left eye pupil bottom right"  },
    {  48,  98, "right mouth corner"  },
    {  49,  99, "upper lip right top outer"  },
    {  50,  100, "upper lip middle top right"  },
    {  51,  101, "upper lip middle top"  },
    {  52,  102, "upper lip middle top left"  },
    {  53,  103, "upper lip left top outer"  },
    {  54,  104, "left mouth corner"  },
    {  55,  105, "lower lip left bottom outer"  },
    {  56,  106, "lower lip middle bottom left"  },
    {  57,  107, "lower lip middle bottom"  },
    {  58,  108, "lower lip middle bottom right"  },
    {  59,  109, "lower lip right bottom outer"  },
    {  60,  110, "right inner mouth corner "},
    {  61,  111, "upper lip right bottom outer"  },
    {  62,  112, "upper lip middle bottom"  },
    {  63,  113, "upper lip left bottom outer"  },
    {  64,  114, "left inner mouth corner"},
    {  65,  115, "lower lip left top outer"  },
    {  66,  116, "lower lip middle top"  },
    {  67,  117, "lower lip right top outer"  },
    { 0xFFFF, 0xFFFF,  nullptr }
};


unsigned short FindEOSLandmarkIndexFromName(const char* name)
{
  if (!name)
    return 0xFFFF;
  switch (name[0]) {
  case '#':                                                       // 1-based index ...
    return (unsigned short)(strtol(name + 1, nullptr, 10) - 1); // ... gets converted into a 0-based index
  case '@':                                                       // 0-based index
    return (unsigned short)strtol(name + 1, nullptr, 10);
  default:
    break;
  }
  const LandmarkEOSMap* lmList = LandmarkMapEOS;
  for (; lmList->name != nullptr; ++lmList)
    if (!strcmp(name, lmList->name))
      break;
  return lmList->index;
}

unsigned short FindLandmarkIndexFromName(const unsigned int numLandmarks, const char* name) {
  if (!name)
    return 0xFFFF;
  switch (name[0]) {
  case '#':                                                       // 1-based index ...
    return (unsigned short)(strtol(name + 1, nullptr, 10) - 1); // ... gets converted into a 0-based index
  case '@':                                                       // 0-based index
    return (unsigned short)strtol(name + 1, nullptr, 10);
  default:
    break;
  }
  const LandmarksMap* lmList = LandmarkMap;
  for (; lmList->name != nullptr; ++lmList)
    if (!strcmp(name, lmList->name))
      break;
  if (numLandmarks == 68) {
    return lmList->index_68;
  } else if (numLandmarks == 126) {
    return lmList->index_126;
  } else {
    return 0xFFFF;
  }
}


<|start_filename|>samples/utils/FeatureVertexName.h<|end_filename|>
/*###############################################################################
#
# Copyright(c) 2019 NVIDIA CORPORATION.All Rights Reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
###############################################################################*/

#ifndef __FEATURE_VERTEX_NAME__
#define __FEATURE_VERTEX_NAME__


struct LandmarkEOSMap  { unsigned short index; const char *name; };
struct LandmarksMap { unsigned short index_68; unsigned short index_126; const char* name; };

unsigned short FindEOSLandmarkIndexFromName(const char *name);
unsigned short FindLandmarkIndexFromName(const unsigned int numLandmarks, const char* name);

#endif /* __FEATURE_VERTEX_NAME__ */
