Sample to operate omron HVC-P2 on GR-PEACH.

Dependencies:   AsciiFont

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FrInterface.c Source File

FrInterface.c

00001 /*---------------------------------------------------------------------------*/
00002 /* Copyright(C)  2017  OMRON Corporation                                     */
00003 /*                                                                           */
00004 /* Licensed under the Apache License, Version 2.0 (the "License");           */
00005 /* you may not use this file except in compliance with the License.          */
00006 /* You may obtain a copy of the License at                                   */
00007 /*                                                                           */
00008 /*     http://www.apache.org/licenses/LICENSE-2.0                            */
00009 /*                                                                           */
00010 /* Unless required by applicable law or agreed to in writing, software       */
00011 /* distributed under the License is distributed on an "AS IS" BASIS,         */
00012 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  */
00013 /* See the License for the specific language governing permissions and       */
00014 /* limitations under the License.                                            */
00015 /*---------------------------------------------------------------------------*/
00016 
00017 #include "FrInterface.h"
00018 #include "STBFrAPI.h"
00019 
00020 /*Value range check*/
00021 #define ISVALID_RANGE( val , min , max )    ( ( (min) <= (val) ) && ( (val) <= (max) ) )
00022 
00023 /*---------------------------------------------------------------------
00024 ---------------------------------------------------------------------*/
00025 /*error check*/
00026 /*---------------------------------------------------------------------
00027 ---------------------------------------------------------------------*/
00028 static STB_INT32 FrIsValidValue(
00029     const STB_INT32 nValue ,
00030     const STB_INT32 nLimitMin ,
00031     const STB_INT32 nLimitMax )
00032 {
00033     STB_INT32 nRet;
00034     for( nRet = STB_ERR_INVALIDPARAM; nRet != STB_NORMAL; nRet = STB_NORMAL ){
00035         if( ! ISVALID_RANGE( nValue , nLimitMin , nLimitMax ) ){ break; }
00036     }
00037     return nRet;
00038 }
00039 /*---------------------------------------------------------------------
00040 ---------------------------------------------------------------------*/
00041 static STB_INT32 FrIsValidPointer( const VOID* pPointer )    
00042 {
00043     STB_INT32 nRet;
00044     for( nRet = STB_ERR_INVALIDPARAM; nRet != STB_NORMAL; nRet = STB_NORMAL ){
00045         if( NULL == pPointer ){ break; }
00046     }
00047     return nRet;
00048 }
00049 
00050 /*------------------------------------------------------------------------------------------------------------------*/
00051 /*    CalcFrSize                                                                                                        */
00052 /*------------------------------------------------------------------------------------------------------------------*/
00053 STB_UINT32 CalcFrSize ( STB_UINT32 nTraCntMax )
00054 {
00055     STB_UINT32 retVal ;
00056 
00057     retVal = 0 ;
00058 
00059     retVal += 100 ;///Margin  : alignment
00060 
00061 
00062 
00063     retVal    +=    sizeof( FR_DET        ) * nTraCntMax                ;    // frDet.fcDet
00064     retVal    +=    sizeof( STB_FR_DET    ) * STB_FR_BACK_MAX            ;    // frDetRec
00065     retVal    +=    sizeof( FR_DET        ) * nTraCntMax * nTraCntMax    ;    // frDetRec[t].fcDet
00066     retVal    +=    sizeof( FR_RES        ) * nTraCntMax                ;    // frRes.frFace
00067 
00068     return retVal;
00069 }
00070 /*------------------------------------------------------------------------------------------------------------------*/
00071 /*    ShareFrSize                                                                                                        */
00072 /*------------------------------------------------------------------------------------------------------------------*/
00073 void ShareFrSize ( FRHANDLE    handle )
00074 {
00075 
00076     STB_UINT32    t;
00077     STB_INT8    *stbPtr        = handle->frPtr        ;
00078     STB_UINT32    nTraCntMax    = handle->frCntMax    ;
00079 
00080     handle->frDet.fcDet        =    ( FR_DET*        ) stbPtr;        stbPtr    += ( sizeof( FR_DET        ) * nTraCntMax    );
00081     handle->frDetRec        =    ( STB_FR_DET*    ) stbPtr;        stbPtr    += ( sizeof( STB_FR_DET    ) * STB_FR_BACK_MAX);
00082     for( t = 0 ; t < STB_FR_BACK_MAX ; t++ )
00083     {
00084         handle->frDetRec[t].fcDet = ( FR_DET*    ) stbPtr;        stbPtr    += ( sizeof( FR_DET        ) * nTraCntMax    );
00085     }
00086     handle->frRes.frFace    =    ( FR_RES    *    ) stbPtr;        stbPtr    += ( sizeof( FR_RES        ) * nTraCntMax    );
00087 
00088 }
00089 /*---------------------------------------------------------------------
00090 ---------------------------------------------------------------------*/
00091 /*Create handle*/
00092 FRHANDLE FrCreateHandle(  const STB_INT32 nTraCntMax    )
00093 
00094 {
00095 
00096     FRHANDLE    handle;
00097     STB_INT32    t , i ;
00098     STB_INT32    tmpVal;
00099 
00100 
00101 
00102     if( nTraCntMax < 1 || STB_FR_TRA_CNT_MAX < nTraCntMax )
00103     {
00104         return NULL;
00105     }
00106 
00107     /*do handle's Malloc here*/
00108     handle = (FRHANDLE)malloc(sizeof(*handle));
00109     if(handle == NULL)
00110     {
00111         return NULL;
00112     }
00113 
00114 
00115     /*initial value---------------------------------------------------------------------*/
00116     handle->frFaceDirUDMax     = STB_FR_DIR_MAX_UD_INI        ;
00117     handle->frFaceDirUDMin    = STB_FR_DIR_MIN_UD_INI        ;
00118     handle->frFaceDirLRMax     = STB_FR_DIR_MAX_LR_INI        ;
00119     handle->frFaceDirLRMin    = STB_FR_DIR_MIN_LR_INI        ;
00120     handle->frCntMax        = nTraCntMax                ;//Maximum number of tracking people
00121     handle->frFaceDirThr    = STB_FR_DIR_THR_INI            ;//If the confidence of Face direction estimation doesn't exceed the reference value, the recognition result isn't trusted.
00122     handle->frFrameCount    = STB_FR_FRAME_CNT_INI            ;
00123     handle->frFrameRatio    = STB_FR_FRAME_RATIO_INI        ;
00124     handle->frPtr            = NULL;
00125     handle->frDet.num        = 0;
00126     handle->frDet.fcDet        = NULL;
00127     handle->frDetRec        = NULL;
00128     handle->frRes.frCnt        = 0;
00129     handle->frRes.frFace    = NULL;
00130 
00131     tmpVal            = CalcFrSize (    nTraCntMax        );    /*calculate necessary amount in the Fr handle*/
00132     handle->frPtr    = NULL;
00133     handle->frPtr    = ( STB_INT8 * )malloc( tmpVal    );    /*keeping necessary amount in the Fr handle*/
00134     if( handle->frPtr == NULL )
00135     {
00136         free ( handle->frPtr    );
00137         free ( handle            );
00138         return NULL;
00139     }
00140 
00141     /* Malloc-area is allocated to things that need Malloc in FR handle */
00142     ShareFrSize ( handle     );
00143 
00144 
00145 
00146 
00147     for( t = 0 ; t < STB_FR_BACK_MAX  ;  t++ ) 
00148     {
00149         handle->frDetRec [ t ].num = 0;
00150         for( i = 0 ; i < handle->frCntMax ;  i++ ) 
00151         {
00152             handle->frDetRec [ t ].fcDet[i].nDetID        = STB_STATUS_NO_DATA ;
00153             handle->frDetRec [ t ].fcDet[i].nTraID        = STB_STATUS_NO_DATA ;
00154             handle->frDetRec [ t ].fcDet[i].dirDetPitch    = STB_STATUS_NO_DATA ;
00155             handle->frDetRec [ t ].fcDet[i].dirDetRoll    = STB_STATUS_NO_DATA ;
00156             handle->frDetRec [ t ].fcDet[i].dirDetYaw    = STB_STATUS_NO_DATA ;
00157             handle->frDetRec [ t ].fcDet[i].frDetConf    = STB_STATUS_NO_DATA ;
00158             handle->frDetRec [ t ].fcDet[i].frDetID        = STB_STATUS_NO_DATA ;
00159             handle->frDetRec [ t ].fcDet[i].frDetConf    = STB_STATUS_NO_DATA ;
00160             handle->frDetRec [ t ].fcDet[i].frStatus    = STB_STATUS_NO_DATA ;
00161 
00162         }
00163     }
00164 
00165     return handle;
00166 }
00167 
00168 /*---------------------------------------------------------------------
00169 ---------------------------------------------------------------------*/
00170 /*Delete handle*/
00171 STB_INT32 FrDeleteHandle(FRHANDLE handle){
00172     STB_INT32 nRet;
00173 
00174     /*NULL check*/
00175     nRet = FrIsValidPointer(handle);
00176     if(nRet != STB_ERR_NOHANDLE){
00177         return nRet;
00178     }
00179 
00180     free ( handle->frPtr    );
00181     free ( handle            );
00182 
00183     return STB_NORMAL;
00184 }
00185 
00186 
00187 /*---------------------------------------------------------------------
00188 ---------------------------------------------------------------------*/
00189 /*Set the result*/
00190 STB_INT32 FrSetDetect(FRHANDLE handle,const STB_FR_DET *stbFrDet){
00191 
00192     STB_INT32 nRet;
00193     STB_INT32 i;
00194 
00195     /*NULL check*/
00196     nRet = FrIsValidPointer(handle);
00197     if(nRet != STB_NORMAL){
00198         return STB_ERR_NOHANDLE;
00199     }
00200 
00201     nRet = FrIsValidPointer(stbFrDet);
00202     if(nRet != STB_NORMAL){
00203         return nRet;
00204     }
00205 
00206     /*Input value check*/
00207     nRet = STB_FrIsValidValue ( stbFrDet );
00208     if(nRet != STB_TRUE)
00209     {
00210         return STB_ERR_INVALIDPARAM;
00211     }
00212 
00213 
00214     /*Set the received result to the handle*/
00215     /* Face */
00216     if( stbFrDet->num > handle->frCntMax )
00217     {
00218         return STB_ERR_PROCESSCONDITION;
00219     }
00220     handle->frDet.num = stbFrDet->num;
00221     for( i = 0 ; i < handle->frDet.num ; i++ )
00222     {
00223 
00224         handle->frDet.fcDet[i].nDetID        = stbFrDet->fcDet[i].nDetID        ;
00225         handle->frDet.fcDet[i].nTraID        = stbFrDet->fcDet[i].nTraID        ;
00226         handle->frDet.fcDet[i].dirDetPitch    = stbFrDet->fcDet[i].dirDetPitch;
00227         handle->frDet.fcDet[i].dirDetRoll    = stbFrDet->fcDet[i].dirDetRoll    ;
00228         handle->frDet.fcDet[i].dirDetYaw    = stbFrDet->fcDet[i].dirDetYaw    ;
00229         handle->frDet.fcDet[i].dirDetConf    = stbFrDet->fcDet[i].dirDetConf    ;
00230         handle->frDet.fcDet[i].frDetID        = stbFrDet->fcDet[i].frDetID    ;
00231         handle->frDet.fcDet[i].frDetConf    = stbFrDet->fcDet[i].frDetConf    ;
00232 
00233     }
00234 
00235 
00236 
00237     return STB_NORMAL;
00238 }
00239 /*---------------------------------------------------------------------
00240 ---------------------------------------------------------------------*/
00241 /*Main process execution*/
00242 STB_INT32 FrExecute(FRHANDLE handle){
00243     STB_INT32 nRet;
00244     /*NULL check*/
00245     nRet = FrIsValidPointer(handle);
00246     if(nRet != STB_NORMAL){
00247         return STB_ERR_NOHANDLE;
00248     }
00249 
00250     /*Main processing here*/
00251     nRet = StbFrExec ( handle );
00252 
00253     return STB_NORMAL;
00254 }
00255 /*---------------------------------------------------------------------
00256 ---------------------------------------------------------------------*/
00257 /*Get-Function of results*/
00258 STB_INT32 FrGetResult(FRHANDLE handle,STB_FR_RES* frResult){
00259     STB_INT32 nRet;
00260     int i;
00261 
00262     /*NULL check*/
00263     nRet = FrIsValidPointer(handle);
00264     if(nRet != STB_NORMAL){
00265         return STB_ERR_NOHANDLE;
00266     }
00267 
00268     nRet = FrIsValidPointer(frResult);
00269     if(nRet != STB_NORMAL){
00270         return nRet;
00271     }
00272 
00273     /*Get result from handle*/
00274     frResult->frCnt = handle->frRes.frCnt ;
00275     for( i = 0 ; i < frResult->frCnt ; i++ ){
00276         frResult->frFace[i].nTraID                = handle->frRes.frFace[i].nTraID            ;
00277         frResult->frFace[i].frRecog.value        = handle->frRes.frFace[i].frRecog.value        ;
00278         frResult->frFace[i].frRecog.status        = handle->frRes.frFace[i].frRecog.status    ;
00279         frResult->frFace[i].frRecog.conf        = handle->frRes.frFace[i].frRecog.conf        ;
00280     }
00281 
00282     return STB_NORMAL;
00283 }
00284 /*---------------------------------------------------------------------
00285 ---------------------------------------------------------------------*/
00286 STB_INT32 FrSetFaceDirMinMax(FRHANDLE handle , STB_INT32 nMinUDAngle    , STB_INT32 nMaxUDAngle        ,STB_INT32 nMinLRAngle    , STB_INT32 nMaxLRAngle)
00287 {
00288     
00289     STB_INT32 nRet;
00290     /*NULL check*/
00291     nRet = FrIsValidPointer(handle);
00292     if(nRet != STB_NORMAL){
00293         return STB_ERR_NOHANDLE;
00294     }
00295     
00296     if( nMinUDAngle < STB_FR_DIR_MIN_UD_MIN || STB_FR_DIR_MIN_UD_MAX < nMinUDAngle)
00297     {
00298         return STB_ERR_INVALIDPARAM;
00299     }
00300     if( nMaxUDAngle < STB_FR_DIR_MAX_UD_MIN || STB_FR_DIR_MAX_UD_MAX < nMaxUDAngle)
00301     {
00302         return STB_ERR_INVALIDPARAM;
00303     }
00304     if( nMaxUDAngle < nMinUDAngle)
00305     {
00306         return STB_ERR_INVALIDPARAM;
00307     }
00308 
00309 
00310     if( nMinLRAngle < STB_FR_DIR_MIN_LR_MIN || STB_FR_DIR_MIN_LR_MAX < nMinLRAngle)
00311     {
00312         return STB_ERR_INVALIDPARAM;
00313     }
00314     if( nMaxLRAngle < STB_FR_DIR_MAX_LR_MIN || STB_FR_DIR_MAX_LR_MAX < nMaxLRAngle)
00315     {
00316         return STB_ERR_INVALIDPARAM;
00317     }
00318     if( nMaxLRAngle < nMinLRAngle)
00319     {
00320         return STB_ERR_INVALIDPARAM;
00321     }
00322 
00323 
00324     handle->frFaceDirUDMin = nMinUDAngle;
00325     handle->frFaceDirUDMax = nMaxUDAngle;
00326     handle->frFaceDirLRMin = nMinLRAngle;
00327     handle->frFaceDirLRMax = nMaxLRAngle;
00328     return STB_NORMAL;
00329 }
00330 /*---------------------------------------------------------------------
00331 ---------------------------------------------------------------------*/
00332 STB_INT32 FrGetFaceDirMinMax(FRHANDLE handle , STB_INT32 *pnMinUDAngle    , STB_INT32 *pnMaxUDAngle    ,STB_INT32 *pnMinLRAngle, STB_INT32 *pnMaxLRAngle )
00333 {
00334     STB_INT32 nRet;
00335     /*NULL check*/
00336     nRet = FrIsValidPointer(handle);
00337     if(nRet != STB_NORMAL){
00338         return STB_ERR_NOHANDLE;
00339     }
00340     nRet = FrIsValidPointer(pnMinUDAngle);
00341     if(nRet != STB_NORMAL){
00342         return STB_ERR_INVALIDPARAM;
00343     }
00344     nRet = FrIsValidPointer(pnMaxUDAngle);
00345     if(nRet != STB_NORMAL){
00346         return STB_ERR_INVALIDPARAM;
00347     }
00348     nRet = FrIsValidPointer(pnMinLRAngle);
00349     if(nRet != STB_NORMAL){
00350         return STB_ERR_INVALIDPARAM;
00351     }
00352     nRet = FrIsValidPointer(pnMaxLRAngle);
00353     if(nRet != STB_NORMAL){
00354         return STB_ERR_INVALIDPARAM;
00355     }
00356     
00357     
00358     *pnMinUDAngle = handle->frFaceDirUDMin ;
00359     *pnMaxUDAngle = handle->frFaceDirUDMax ;
00360     *pnMinLRAngle = handle->frFaceDirLRMin ;
00361     *pnMaxLRAngle = handle->frFaceDirLRMax ;
00362     return STB_NORMAL;
00363 }
00364 /*---------------------------------------------------------------------
00365 ---------------------------------------------------------------------*/
00366 STB_INT32    FrClear            ( FRHANDLE handle  )
00367 {
00368     //clear processing
00369 
00370     STB_INT32 t , i ;
00371     STB_INT32 nRet;
00372 
00373     /*NULL check*/
00374     nRet = FrIsValidPointer(handle);
00375     if(nRet != STB_NORMAL){
00376         return STB_ERR_NOHANDLE;
00377     }
00378 
00379     for( t = 0 ; t < STB_FR_BACK_MAX  ;  t++ ) 
00380     {
00381         handle->frDetRec [ t ].num = 0;
00382         for( i = 0 ; i < handle->frCntMax ;  i++ ) 
00383         {
00384             handle->frDetRec [ t ].fcDet[i].nDetID        = STB_STATUS_NO_DATA ;
00385             handle->frDetRec [ t ].fcDet[i].nTraID        = STB_STATUS_NO_DATA ;
00386             handle->frDetRec [ t ].fcDet[i].dirDetPitch    = STB_STATUS_NO_DATA ;
00387             handle->frDetRec [ t ].fcDet[i].dirDetRoll    = STB_STATUS_NO_DATA ;
00388             handle->frDetRec [ t ].fcDet[i].dirDetYaw    = STB_STATUS_NO_DATA ;
00389             handle->frDetRec [ t ].fcDet[i].dirDetConf    = STB_STATUS_NO_DATA ;
00390             handle->frDetRec [ t ].fcDet[i].frDetID        = STB_STATUS_NO_DATA ;
00391             handle->frDetRec [ t ].fcDet[i].frDetConf    = STB_STATUS_NO_DATA ;
00392             handle->frDetRec [ t ].fcDet[i].frStatus    = STB_STATUS_NO_DATA ;
00393 
00394         }
00395     }
00396     return STB_NORMAL;
00397 
00398 
00399 }
00400 /*---------------------------------------------------------------------
00401 ---------------------------------------------------------------------*/
00402 /*---------------------------------------------------------------------
00403 ---------------------------------------------------------------------*/
00404 STB_INT32 FrSetFaceDirThreshold(FRHANDLE handle , STB_INT32 threshold )
00405 {
00406     STB_INT32 nRet;
00407     /*NULL check*/
00408     nRet = FrIsValidPointer(handle);
00409     if(nRet != STB_NORMAL){
00410         return STB_ERR_NOHANDLE;
00411     }
00412     
00413     if( threshold < STB_FR_DIR_THR_MIN || STB_FR_DIR_THR_MAX < threshold)
00414     {
00415         return STB_ERR_INVALIDPARAM;
00416     }
00417     handle->frFaceDirThr = threshold;
00418     return STB_NORMAL;
00419 }
00420 /*---------------------------------------------------------------------
00421 ---------------------------------------------------------------------*/
00422 STB_INT32 FrGetFaceDirThreshold(FRHANDLE handle , STB_INT32* threshold )
00423 {
00424     STB_INT32 nRet;
00425 
00426     /*NULL check*/
00427     nRet = FrIsValidPointer(handle);
00428     if(nRet != STB_NORMAL){
00429         return STB_ERR_NOHANDLE;
00430     }
00431     nRet = FrIsValidPointer(threshold);
00432     if(nRet != STB_NORMAL){
00433         return STB_ERR_INVALIDPARAM;
00434     }
00435     
00436     *threshold = handle->frFaceDirThr ;
00437     return STB_NORMAL;
00438 }
00439 /*---------------------------------------------------------------------
00440 ---------------------------------------------------------------------*/
00441 STB_INT32 FrSetFrameCount(FRHANDLE handle , STB_INT32 nFrameCount )
00442 {
00443 
00444     STB_INT32 nRet;
00445     /*NULL check*/
00446     nRet = FrIsValidPointer(handle);
00447     if(nRet != STB_NORMAL){
00448         return STB_ERR_NOHANDLE;
00449     }
00450     if( nFrameCount < STB_FR_FRAME_CNT_MIN || STB_FR_FRAME_CNT_MAX < nFrameCount)
00451     {
00452         return STB_ERR_INVALIDPARAM;
00453     }
00454     handle->frFrameCount = nFrameCount;
00455     return STB_NORMAL;
00456 }
00457 /*---------------------------------------------------------------------
00458 ---------------------------------------------------------------------*/
00459 STB_INT32 FrGetFrameCount(FRHANDLE handle , STB_INT32* nFrameCount )
00460 {
00461     STB_INT32 nRet;
00462     /*NULL check*/
00463     nRet = FrIsValidPointer(handle);
00464     if(nRet != STB_NORMAL){
00465         return STB_ERR_NOHANDLE;
00466     }
00467     nRet = FrIsValidPointer(nFrameCount);
00468     if(nRet != STB_NORMAL){
00469         return STB_ERR_INVALIDPARAM;
00470     }
00471     
00472     *nFrameCount = handle->frFrameCount ;
00473     return STB_NORMAL;
00474 }
00475 /*---------------------------------------------------------------------
00476 ---------------------------------------------------------------------*/
00477 STB_INT32 FrSetMinRatio(FRHANDLE handle , STB_INT32 nMinRatio )
00478 {
00479     STB_INT32 nRet;
00480     /*NULL check*/
00481     nRet = FrIsValidPointer(handle);
00482     if(nRet != STB_NORMAL){
00483         return STB_ERR_NOHANDLE;
00484     }    
00485     if( nMinRatio < STB_FR_FRAME_RATIO_MIN || STB_FR_FRAME_RATIO_MAX < nMinRatio)
00486     {
00487         return STB_ERR_INVALIDPARAM;
00488     }
00489     handle->frFrameRatio = nMinRatio;
00490     return STB_NORMAL;
00491 }
00492 /*---------------------------------------------------------------------
00493 ---------------------------------------------------------------------*/
00494 STB_INT32 FrGetMinRatio(FRHANDLE handle , STB_INT32* nMinRatio )
00495 {
00496     STB_INT32 nRet;
00497     /*NULL check*/
00498     nRet = FrIsValidPointer(handle);
00499     if(nRet != STB_NORMAL){
00500         return STB_ERR_NOHANDLE;
00501     }    
00502     nRet = FrIsValidPointer(nMinRatio);
00503     if(nRet != STB_NORMAL){
00504         return STB_ERR_INVALIDPARAM;
00505     }
00506     
00507     *nMinRatio = handle->frFrameRatio ;
00508     return STB_NORMAL;
00509 }