Sample to operate omron HVC-P2 on GR-PEACH.
Dependencies: AsciiFont
STBFrAPI.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 "STBFrAPI.h" 00018 00019 /*---------------------------------------------------------------------*/ 00020 // FrSlideFacesRec 00021 /*---------------------------------------------------------------------*/ 00022 void FrSlideFacesRec ( STB_FR_DET *facesRec ) 00023 { 00024 STB_INT32 t , i ; 00025 00026 for( t = STB_FR_BACK_MAX - 2 ; t >= 0 ; t-- ) 00027 { 00028 facesRec [ t + 1 ].num = facesRec[ t + 0 ].num; 00029 for( i = 0 ; i < facesRec [ t + 1 ].num ; i++ ) 00030 { 00031 facesRec [ t + 1 ].fcDet[i].nDetID = facesRec [ t ].fcDet[i].nDetID ; 00032 facesRec [ t + 1 ].fcDet[i].nTraID = facesRec [ t ].fcDet[i].nTraID ; 00033 00034 facesRec [ t + 1 ].fcDet[i].dirDetPitch = facesRec [ t ].fcDet[i].dirDetPitch ; 00035 facesRec [ t + 1 ].fcDet[i].dirDetRoll = facesRec [ t ].fcDet[i].dirDetRoll ; 00036 facesRec [ t + 1 ].fcDet[i].dirDetYaw = facesRec [ t ].fcDet[i].dirDetYaw ; 00037 facesRec [ t + 1 ].fcDet[i].dirDetConf = facesRec [ t ].fcDet[i].dirDetConf ; 00038 facesRec [ t + 1 ].fcDet[i].frDetID = facesRec [ t ].fcDet[i].frDetID ; 00039 facesRec [ t + 1 ].fcDet[i].frDetConf = facesRec [ t ].fcDet[i].frDetConf ; 00040 facesRec [ t + 1 ].fcDet[i].frStatus = facesRec [ t ].fcDet[i].frStatus ; 00041 00042 } 00043 } 00044 } 00045 /*---------------------------------------------------------------------*/ 00046 // FrCurFaces 00047 /*---------------------------------------------------------------------*/ 00048 void FrCurFaces ( STB_FR_DET *facesRec , STB_FR_DET *srcFace ) 00049 { 00050 STB_INT32 i ; 00051 00052 00053 facesRec [ 0 ].num = srcFace->num; 00054 for( i = 0 ; i < facesRec [ 0 ].num ; i++ ) 00055 { 00056 facesRec [ 0 ].fcDet[i].nDetID = srcFace->fcDet[i].nDetID ; 00057 facesRec [ 0 ].fcDet[i].nTraID = srcFace->fcDet[i].nTraID ; 00058 facesRec [ 0 ].fcDet[i].dirDetPitch = srcFace->fcDet[i].dirDetPitch ; 00059 facesRec [ 0 ].fcDet[i].dirDetRoll = srcFace->fcDet[i].dirDetRoll ; 00060 facesRec [ 0 ].fcDet[i].dirDetYaw = srcFace->fcDet[i].dirDetYaw ; 00061 facesRec [ 0 ].fcDet[i].dirDetConf = srcFace->fcDet[i].dirDetConf ; 00062 facesRec [ 0 ].fcDet[i].frDetID = srcFace->fcDet[i].frDetID ; 00063 facesRec [ 0 ].fcDet[i].frDetConf = srcFace->fcDet[i].frDetConf ; 00064 facesRec [ 0 ].fcDet[i].frStatus = STB_STATUS_NO_DATA ; 00065 00066 } 00067 00068 } 00069 00070 00071 /*---------------------------------------------------------------------*/ 00072 // FrStbFaceEasy 00073 /*---------------------------------------------------------------------*/ 00074 void 00075 FrStbFaceEasy 00076 ( 00077 STB_FR_RES* peRes , 00078 STB_FR_DET* peRec , 00079 STB_INT32 dirThr , 00080 STB_INT32 dirUDMax , 00081 STB_INT32 dirUDMin , 00082 STB_INT32 dirLRMax , 00083 STB_INT32 dirLRMin , 00084 STB_INT32 frmCnt , 00085 STB_INT32 frmRatio 00086 00087 00088 ) 00089 { 00090 STB_INT32 i, t, k; 00091 STB_INT32 trID; 00092 STB_INT32 recCnt; 00093 STB_INT32 recUID [STB_FR_BACK_MAX]; 00094 STB_INT32 recConf [STB_FR_BACK_MAX]; 00095 00096 STB_INT32 accUID [STB_FR_BACK_MAX]; 00097 STB_INT32 accCnt [STB_FR_BACK_MAX]; 00098 STB_INT32 accKind; 00099 STB_INT32 tmpUID; 00100 STB_INT32 tmpCnt; 00101 STB_INT32 tmpConf; 00102 STB_INT32 topUID; 00103 STB_INT32 topCnt; 00104 STB_STATUS preStatus ; 00105 STB_INT32 preUID ; 00106 STB_INT32 preConf ; 00107 00108 00109 for( t = 0; t < STB_FR_BACK_MAX ; t++) 00110 { 00111 recUID [t] = STB_FR_INVALID_UID; 00112 recConf [t] = 0; 00113 accUID [t] = STB_FR_INVALID_UID; 00114 accCnt [t] = 0; 00115 } 00116 00117 00118 /*Checking the past data here, fill in all peRes.*/ 00119 /*do stabilization processing each tracking person*/ 00120 00121 peRes->frCnt = peRec[0].num; 00122 for( k = 0; k < peRes->frCnt; k++) 00123 { 00124 /*Tracking person number in the through frame*/ 00125 trID = peRec[0].fcDet[k].nTraID; 00126 00127 // peRes Add ------------------------------------------------------------------------------------------------- 00128 peRes->frFace[k].nTraID = trID; 00129 00130 00131 //in case of unregistered album for present UID(no album files) 00132 if( peRec[0].fcDet[k].frDetID == STB_ERR_FR_NOALBUM ) 00133 { 00134 peRes->frFace[k].frRecog.value = STB_ERR_FR_NOALBUM ; 00135 peRes->frFace[k].frRecog.status = STB_STATUS_NO_DATA ; 00136 peRes->frFace[k].frRecog.conf = STB_CONF_NO_DATA ; 00137 peRec[0].fcDet[k].frDetID = STB_ERR_FR_NOALBUM ; 00138 peRec[0].fcDet[k].frStatus = STB_STATUS_NO_DATA ; 00139 peRec[0].fcDet[k].frDetConf = STB_CONF_NO_DATA ; 00140 continue; 00141 } 00142 00143 // preStatus ------------------------------------------------------------------------------------------------- 00144 preStatus = STB_STATUS_NO_DATA ; 00145 preUID = STB_FR_INVALID_UID ; 00146 preConf = 0 ; 00147 for( i = 0; i < peRec[1].num ; i++) 00148 { 00149 if( peRec[1].fcDet[i].nTraID == trID ) 00150 { 00151 preUID = peRec[1].fcDet[i].frDetID ; 00152 preStatus = peRec[1].fcDet[i].frStatus ; 00153 preConf = peRec[1].fcDet[i].frDetConf ; 00154 break; 00155 } 00156 } 00157 00158 00159 // ------------------------------------------------------------------------------------------------- 00160 // ------------------------------------------------------------------------------------------------- 00161 if ( preStatus == STB_STATUS_NO_DATA //stabilization impossible: no data of the relevant people 00162 || preStatus == STB_STATUS_CALCULATING //during stabilization : a number of data for relevant people aren't enough(a number of frames that relevant people are taken) 00163 ) 00164 { 00165 // ------------------------------------------------------------------------------------------------- 00166 //Setting "recUID" to past data of Tracking ID(trID) : (Up to "frmCnt") 00167 // ------------------------------------------------------------------------------------------------- 00168 recCnt = 0; 00169 for( t = 0; t < STB_FR_BACK_MAX ; t++) //previous t frame 00170 { 00171 for( i = 0; i < peRec[t].num ; i++) //a number of tracking people(previous t frame) 00172 { 00173 if( 00174 peRec [ t ].fcDet[i].nTraID == trID //the same tracking number 00175 && peRec [ t ].fcDet[i].nDetID >= 0 //not lost 00176 && peRec [ t ].fcDet[i].dirDetConf >= dirThr // Face angle : confidence 00177 && peRec [ t ].fcDet[i].dirDetPitch >= dirUDMin // Face angle : pitch 00178 && peRec [ t ].fcDet[i].dirDetPitch <= dirUDMax // Face angle : pitch 00179 && peRec [ t ].fcDet[i].dirDetYaw >= dirLRMin // Face angle : yaw 00180 && peRec [ t ].fcDet[i].dirDetYaw <= dirLRMax // Face angle : yaw 00181 && peRec [ t ].fcDet[i].frDetID != STB_ERR_FR_CANNOT //Recognition impossible 00182 && peRec [ t ].fcDet[i].frDetID != STB_ERR_FR_NOALBUM // Not-registered in Album 00183 ) 00184 { 00185 recUID [ recCnt ] = peRec [ t ].fcDet[ i ].frDetID ; 00186 recConf[ recCnt ] = peRec [ t ].fcDet[ i ].frDetConf; 00187 recCnt++; 00188 break; 00189 } 00190 } 00191 if( recCnt == frmCnt ) 00192 { 00193 break ;//Maximum number is frmCnt 00194 } 00195 } 00196 // ------------------------------------------------------------------------------------------------- 00197 // tmpConf 00198 // ------------------------------------------------------------------------------------------------- 00199 tmpConf = 0; 00200 for( i = 0 ; i < recCnt ; i++) 00201 { 00202 tmpConf += recConf[ i ]; 00203 } 00204 if( recCnt > 0 ) 00205 { 00206 tmpConf /= recCnt; 00207 }else 00208 { 00209 tmpConf = 0 ; 00210 } 00211 // ------------------------------------------------------------------------------------------------- 00212 //Create a cumulative frequency distribution of recUID and set it to accUID [accKind] accCnt [accKind]. 00213 //AccCnt [i] pieces of data (in the past) determined to be "accUID [i]". 00214 // ------------------------------------------------------------------------------------------------- 00215 accKind = 0; 00216 for(;;) 00217 { 00218 tmpUID = STB_FR_INVALID_UID; 00219 for( i = 0 ; i < recCnt ; i++) 00220 { 00221 if( recUID[ i ] != STB_FR_INVALID_UID ) 00222 { 00223 tmpUID = recUID[ i ]; 00224 break; 00225 } 00226 } 00227 if( tmpUID == STB_FR_INVALID_UID ) 00228 { 00229 break; 00230 } 00231 tmpCnt = 0; 00232 for( i = 0 ; i < recCnt ; i++) 00233 { 00234 if( recUID[ i ] == tmpUID ) 00235 { 00236 recUID[ i ] = STB_FR_INVALID_UID ; 00237 tmpCnt++; 00238 } 00239 } 00240 accUID[accKind] = tmpUID; 00241 accCnt[accKind] = tmpCnt; 00242 accKind++; 00243 } 00244 // ------------------------------------------------------------------------------------------------- 00245 //Find the ID whose frequency is the maximum from the cumulative frequency distribution and set it to topUID. 00246 // ------------------------------------------------------------------------------------------------- 00247 topUID = STB_FR_INVALID_UID ; 00248 topCnt = 0 ; 00249 for( i = 0 ; i < accKind ; i++) 00250 { 00251 if( topCnt < accCnt[i] ) 00252 { 00253 topCnt = accCnt[i] ; 00254 topUID = accUID[i] ; 00255 } 00256 } 00257 if( topUID == STB_FR_INVALID_UID ) 00258 { 00259 peRes->frFace[k].frRecog.value = STB_STATUS_NO_DATA ; 00260 peRes->frFace[k].frRecog.conf = STB_CONF_NO_DATA ; 00261 peRes->frFace[k].frRecog.status = STB_STATUS_NO_DATA;//during stabilization : a number of data for relevant people aren't enough(a number of frames that relevant people are taken) 00262 peRec[0].fcDet[k].frStatus = STB_STATUS_NO_DATA; 00263 }else 00264 { 00265 if( topCnt < frmCnt * frmRatio / 100 ) 00266 { 00267 peRes->frFace[k].frRecog.value = topUID ; 00268 peRes->frFace[k].frRecog.conf = STB_CONF_NO_DATA ; 00269 peRes->frFace[k].frRecog.status = STB_STATUS_CALCULATING;//during stabilization : a number of data for relevant people aren't enough(a number of frames that relevant people are taken) 00270 peRec[0].fcDet[k].frStatus = STB_STATUS_CALCULATING; 00271 }else 00272 { 00273 peRes->frFace[k].frRecog.value = topUID ; 00274 peRes->frFace[k].frRecog.conf = tmpConf ; 00275 peRes->frFace[k].frRecog.status = STB_STATUS_COMPLETE ;//Just after stabilization : The state immediately after the number of data of the relevant person is sufficient and fixed. When creating an entry log, it is better to log data immediately after stabilization. 00276 peRec[0].fcDet[k].frDetID = topUID ; 00277 peRec[0].fcDet[k].frStatus = STB_STATUS_COMPLETE ; 00278 peRec[0].fcDet[k].frDetConf = tmpConf ; 00279 } 00280 } 00281 }else if ( preStatus == STB_STATUS_COMPLETE //Just after stabilization 00282 || preStatus == STB_STATUS_FIXED //already stabilized 00283 ) 00284 { 00285 peRes->frFace[k].frRecog.value = preUID ; 00286 peRes->frFace[k].frRecog.status = STB_STATUS_FIXED ; 00287 peRes->frFace[k].frRecog.conf = preConf; 00288 peRec[0].fcDet[k].frDetID = preUID ; 00289 peRec[0].fcDet[k].frStatus = STB_STATUS_FIXED ; 00290 peRec[0].fcDet[k].frDetConf = preConf; 00291 00292 } 00293 00294 00295 } 00296 } 00297 /*---------------------------------------------------------------------*/ 00298 // StbFrExec 00299 /*---------------------------------------------------------------------*/ 00300 int StbFrExec ( FRHANDLE handle ) 00301 { 00302 00303 int retVal = 0 ; 00304 00305 /* Face --------------------------------------*/ 00306 FrSlideFacesRec ( handle->frDetRec );//Shift the time series of past data before stabilization. 00307 FrCurFaces ( handle->frDetRec , 00308 &(handle->frDet) );//Setting "present data before the stabilization" to past data before the stabilization. 00309 00310 FrStbFaceEasy ( &(handle->frRes) , 00311 handle->frDetRec , 00312 handle->frFaceDirThr , 00313 handle->frFaceDirUDMax , 00314 handle->frFaceDirUDMin , 00315 handle->frFaceDirLRMax , 00316 handle->frFaceDirLRMin , 00317 handle->frFrameCount , 00318 handle->frFrameRatio );//Calculate "current data after stabilization" from "past data before stabilization". 00319 00320 00321 00322 return retVal; 00323 } 00324 00325 00326
Generated on Fri Jul 15 2022 01:15:47 by 1.7.2