Sample to operate omron HVC-P2 on GR-PEACH.
Dependencies: AsciiFont
What is this ?
This is a sample that runs OMRON HVC-P2 with GR-PEACH. In this sample, you can try following among the functions of HVC-P2 : Human Body Detection, Face Detection, Age Estimation, Gender Estimation, Expression Estimation and Face Recognition.
Both GR-PEACH and HVC-P2 use Renesas RZ/A1H included ARM® Cortex™-A9 processor.
HVC-P2 (Human Vision Components B5T-007001) is a human-sensing component that recognizes people. It is an integrated module that is built into other device and provides both the OKAO Vision's ten types of image sensing and a camera module.
For details, please refer to the following link.
- SENSING EGG PROJECT > HVC-P2 (In Japanese)
https://plus-sensing.omron.co.jp/egg-project/product/hvc-p2/ - HVC-P2 (Human Vision Components B5T-007001)
http://www.omron.com/ecb/products/mobile/hvc_p2/ - OKAO Vision
https://plus-sensing.omron.com/technology/index.html
In the HVCApi folder of this sample, the code of the following link destination Sample Code "SampleCode_rev.2.0.2" is used. (You can download from "Product Information" -> "Sample Code" in the middle of the following page.)
http://www.omron.com/ecb/products/mobile/hvc_p2/
Constitution
- HVC-P2 x 1
- USBA-microUSB conversion cable x 2
- USBA-microUSB conversion adapter x 1
- GR-PEACH x 1
- 4.3inc LCD shield x 1
Please close JP3 of GR-PEACH.
How to use
It starts when connecting the power supply USB cable. At startup, all functions are turned off. By pressing the button on the right of the screen you can switch the function on / off.
- Function ON : orange or green
- Function OFF : blue or gray
Only the FACE button changes to "FACE (blue) -> FACE (orange) -> RECOGNITION (green)". When FACE (blue), following buttons are gray and can not be operated : AGE, GENDER and EXPRESSION.
"Response time" at the bottom left of the screen indicates "image processing + USB transfer time". It is not pure image processing time.
Register Data (Face Recognition)
Set the FACE button to RECOGNITION (green), and touch the screen with one person on the screen to register the face. In this sample, face registration will record up to 10 people. Delete the old registrant when registering after 11 people. Registration information is stored in the RAM on the HVC-P2 side. It is discarded by power off and reset.
Change parameters
When you press Config icon at the bottom right of the screen, the parameter setting screen is displayed. You can change threshold value, detection size and face angle parameters.
Change transfer image size
By pressing USER_BUTTON0 on the back of the board, the image transfer size switches in the order of "160 x 120 -> 320 x 240 -> no image".
HVC/STBLib/src/STB_Tracker/STBTrAPI.c@5:49a61433290a, 2017-09-05 (annotated)
- Committer:
- dkato
- Date:
- Tue Sep 05 10:01:51 2017 +0000
- Revision:
- 5:49a61433290a
Add HVC sensing result stabilizing library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dkato | 5:49a61433290a | 1 | /*---------------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 2 | /* Copyright(C) 2017 OMRON Corporation */ |
| dkato | 5:49a61433290a | 3 | /* */ |
| dkato | 5:49a61433290a | 4 | /* Licensed under the Apache License, Version 2.0 (the "License"); */ |
| dkato | 5:49a61433290a | 5 | /* you may not use this file except in compliance with the License. */ |
| dkato | 5:49a61433290a | 6 | /* You may obtain a copy of the License at */ |
| dkato | 5:49a61433290a | 7 | /* */ |
| dkato | 5:49a61433290a | 8 | /* http://www.apache.org/licenses/LICENSE-2.0 */ |
| dkato | 5:49a61433290a | 9 | /* */ |
| dkato | 5:49a61433290a | 10 | /* Unless required by applicable law or agreed to in writing, software */ |
| dkato | 5:49a61433290a | 11 | /* distributed under the License is distributed on an "AS IS" BASIS, */ |
| dkato | 5:49a61433290a | 12 | /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ |
| dkato | 5:49a61433290a | 13 | /* See the License for the specific language governing permissions and */ |
| dkato | 5:49a61433290a | 14 | /* limitations under the License. */ |
| dkato | 5:49a61433290a | 15 | /*---------------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 16 | |
| dkato | 5:49a61433290a | 17 | #include "STBTrAPI.h" |
| dkato | 5:49a61433290a | 18 | |
| dkato | 5:49a61433290a | 19 | #define STB_INT_MAX 2147483647 /* maximum (signed) int value */ |
| dkato | 5:49a61433290a | 20 | |
| dkato | 5:49a61433290a | 21 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 22 | // TrSlideRec |
| dkato | 5:49a61433290a | 23 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 24 | void TrSlideRec ( ROI_SYS *rec ) |
| dkato | 5:49a61433290a | 25 | { |
| dkato | 5:49a61433290a | 26 | STB_INT32 t , i ; |
| dkato | 5:49a61433290a | 27 | |
| dkato | 5:49a61433290a | 28 | for( t = STB_TR_BACK_MAX - 2 ; t >= 0 ; t-- ) |
| dkato | 5:49a61433290a | 29 | { |
| dkato | 5:49a61433290a | 30 | rec [ t + 1 ].cnt = rec[ t + 0 ].cnt; |
| dkato | 5:49a61433290a | 31 | for( i = 0 ; i < rec [ t + 1 ].cnt ; i++ ) |
| dkato | 5:49a61433290a | 32 | { |
| dkato | 5:49a61433290a | 33 | rec [ t + 1 ].nDetID [i] = rec [ t ].nDetID [i] ; |
| dkato | 5:49a61433290a | 34 | rec [ t + 1 ].nTraID [i] = rec [ t ].nTraID [i] ; |
| dkato | 5:49a61433290a | 35 | rec [ t + 1 ].posX [i] = rec [ t ].posX [i] ; |
| dkato | 5:49a61433290a | 36 | rec [ t + 1 ].posY [i] = rec [ t ].posY [i] ; |
| dkato | 5:49a61433290a | 37 | rec [ t + 1 ].size [i] = rec [ t ].size [i] ; |
| dkato | 5:49a61433290a | 38 | rec [ t + 1 ].conf [i] = rec [ t ].conf [i] ; |
| dkato | 5:49a61433290a | 39 | rec [ t + 1 ].retryN [i] = rec [ t ].retryN [i] ; |
| dkato | 5:49a61433290a | 40 | } |
| dkato | 5:49a61433290a | 41 | } |
| dkato | 5:49a61433290a | 42 | } |
| dkato | 5:49a61433290a | 43 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 44 | // TrCurRec |
| dkato | 5:49a61433290a | 45 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 46 | void TrCurRec ( ROI_SYS *rec , ROI_DET *det , STB_INT32 num) |
| dkato | 5:49a61433290a | 47 | { |
| dkato | 5:49a61433290a | 48 | STB_INT32 i ; |
| dkato | 5:49a61433290a | 49 | |
| dkato | 5:49a61433290a | 50 | |
| dkato | 5:49a61433290a | 51 | rec [ 0 ].cnt =num; |
| dkato | 5:49a61433290a | 52 | for( i = 0 ; i < rec [ 0 ].cnt ; i++ ) |
| dkato | 5:49a61433290a | 53 | { |
| dkato | 5:49a61433290a | 54 | rec [ 0 ].nDetID [i] = i ; |
| dkato | 5:49a61433290a | 55 | rec [ 0 ].nTraID [i] = -1 ; |
| dkato | 5:49a61433290a | 56 | rec [ 0 ].posX [i] = det[i].posX ; |
| dkato | 5:49a61433290a | 57 | rec [ 0 ].posY [i] = det[i].posY ; |
| dkato | 5:49a61433290a | 58 | rec [ 0 ].size [i] = det[i].size ; |
| dkato | 5:49a61433290a | 59 | rec [ 0 ].conf [i] = det[i].conf ; |
| dkato | 5:49a61433290a | 60 | rec [ 0 ].retryN [i] = 0 ; |
| dkato | 5:49a61433290a | 61 | } |
| dkato | 5:49a61433290a | 62 | |
| dkato | 5:49a61433290a | 63 | } |
| dkato | 5:49a61433290a | 64 | |
| dkato | 5:49a61433290a | 65 | |
| dkato | 5:49a61433290a | 66 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 67 | // TrDelRetry |
| dkato | 5:49a61433290a | 68 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 69 | void |
| dkato | 5:49a61433290a | 70 | TrDelRetry( ROI_SYS *preData , STB_INT32 thrRetryCnt ) |
| dkato | 5:49a61433290a | 71 | { |
| dkato | 5:49a61433290a | 72 | //delete data exceeding the number of retries |
| dkato | 5:49a61433290a | 73 | //If the face isn't find out during tracking, set until how many frames can look for it. |
| dkato | 5:49a61433290a | 74 | //If tracking fails for the specified number of consecutive frames, tracking is terminated assuming that face is lost. |
| dkato | 5:49a61433290a | 75 | STB_INT32 i, tmpCnt ; |
| dkato | 5:49a61433290a | 76 | |
| dkato | 5:49a61433290a | 77 | tmpCnt = 0; |
| dkato | 5:49a61433290a | 78 | for( i = 0 ; i < preData->cnt ; i++ ) |
| dkato | 5:49a61433290a | 79 | { |
| dkato | 5:49a61433290a | 80 | if( preData->retryN[i] <= thrRetryCnt ) |
| dkato | 5:49a61433290a | 81 | { |
| dkato | 5:49a61433290a | 82 | |
| dkato | 5:49a61433290a | 83 | preData->nDetID [tmpCnt ] = preData->nDetID [i] ; |
| dkato | 5:49a61433290a | 84 | preData->nTraID [tmpCnt ] = preData->nTraID [i] ; |
| dkato | 5:49a61433290a | 85 | preData->posX [tmpCnt ] = preData->posX [i] ; |
| dkato | 5:49a61433290a | 86 | preData->posY [tmpCnt ] = preData->posY [i] ; |
| dkato | 5:49a61433290a | 87 | preData->size [tmpCnt ] = preData->size [i] ; |
| dkato | 5:49a61433290a | 88 | preData->conf [tmpCnt ] = preData->conf [i] ; |
| dkato | 5:49a61433290a | 89 | preData->retryN [tmpCnt ] = preData->retryN [i] ; |
| dkato | 5:49a61433290a | 90 | tmpCnt++; |
| dkato | 5:49a61433290a | 91 | } |
| dkato | 5:49a61433290a | 92 | } |
| dkato | 5:49a61433290a | 93 | preData->cnt = tmpCnt ; |
| dkato | 5:49a61433290a | 94 | |
| dkato | 5:49a61433290a | 95 | |
| dkato | 5:49a61433290a | 96 | } |
| dkato | 5:49a61433290a | 97 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 98 | // TrCheckSameROI |
| dkato | 5:49a61433290a | 99 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 100 | STB_INT32 |
| dkato | 5:49a61433290a | 101 | TrCheckSameROI( STB_INT32 curX ,STB_INT32 curY ,STB_INT32 curS , |
| dkato | 5:49a61433290a | 102 | STB_INT32 preX ,STB_INT32 preY ,STB_INT32 preS |
| dkato | 5:49a61433290a | 103 | ) |
| dkato | 5:49a61433290a | 104 | { |
| dkato | 5:49a61433290a | 105 | |
| dkato | 5:49a61433290a | 106 | STB_INT32 difP ;//the percentage of detection position change |
| dkato | 5:49a61433290a | 107 | STB_INT32 difS ;//the percentage of detection size change |
| dkato | 5:49a61433290a | 108 | float tmpVal; |
| dkato | 5:49a61433290a | 109 | STB_INT32 retVal; |
| dkato | 5:49a61433290a | 110 | |
| dkato | 5:49a61433290a | 111 | if( preS < 1 ) |
| dkato | 5:49a61433290a | 112 | { |
| dkato | 5:49a61433290a | 113 | return STB_INT_MAX; |
| dkato | 5:49a61433290a | 114 | } |
| dkato | 5:49a61433290a | 115 | |
| dkato | 5:49a61433290a | 116 | //the percentage of detect position change |
| dkato | 5:49a61433290a | 117 | //It is "Absolute value of detected position change amount from previous frame / Detected size of previous frame * 100". |
| dkato | 5:49a61433290a | 118 | tmpVal = (float)sqrt( (float) (preX-curX)*(preX-curX) + (preY-curY)*(preY-curY) ); |
| dkato | 5:49a61433290a | 119 | difP = (STB_INT32)( tmpVal * 100 / preS ); |
| dkato | 5:49a61433290a | 120 | //the percentage of detect size change |
| dkato | 5:49a61433290a | 121 | //It is "Absolute value of detected size change amount from previous frame / Detected size of previous frame * 100". |
| dkato | 5:49a61433290a | 122 | tmpVal = (float)(preS-curS); |
| dkato | 5:49a61433290a | 123 | if( tmpVal < 0 ) |
| dkato | 5:49a61433290a | 124 | { |
| dkato | 5:49a61433290a | 125 | tmpVal *= (-1); |
| dkato | 5:49a61433290a | 126 | } |
| dkato | 5:49a61433290a | 127 | difS = (STB_INT32)( tmpVal * 100 / preS ); |
| dkato | 5:49a61433290a | 128 | retVal = (difP+1)*(difS+1); |
| dkato | 5:49a61433290a | 129 | |
| dkato | 5:49a61433290a | 130 | return retVal;//The return value is the similarity of the rectangle. Always a value more than or equal to zero. The closer to zero, the more similar they are. |
| dkato | 5:49a61433290a | 131 | |
| dkato | 5:49a61433290a | 132 | } |
| dkato | 5:49a61433290a | 133 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 134 | // TrSetDistTbl |
| dkato | 5:49a61433290a | 135 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 136 | void |
| dkato | 5:49a61433290a | 137 | TrSetDistTbl |
| dkato | 5:49a61433290a | 138 | ( |
| dkato | 5:49a61433290a | 139 | STB_INT32 *dst , |
| dkato | 5:49a61433290a | 140 | ROI_SYS *curData , |
| dkato | 5:49a61433290a | 141 | ROI_SYS *preData , |
| dkato | 5:49a61433290a | 142 | STB_INT32 traCntMax |
| dkato | 5:49a61433290a | 143 | ) |
| dkato | 5:49a61433290a | 144 | { |
| dkato | 5:49a61433290a | 145 | STB_INT32 ip ,ic ; |
| dkato | 5:49a61433290a | 146 | STB_INT32 distMax = STB_INT_MAX; |
| dkato | 5:49a61433290a | 147 | |
| dkato | 5:49a61433290a | 148 | // init |
| dkato | 5:49a61433290a | 149 | for( ip = 0 ; ip < traCntMax ; ip++ ) |
| dkato | 5:49a61433290a | 150 | { |
| dkato | 5:49a61433290a | 151 | for( ic = 0 ; ic < traCntMax ; ic++ ) |
| dkato | 5:49a61433290a | 152 | { |
| dkato | 5:49a61433290a | 153 | dst [ ip * traCntMax + ic ] = distMax; |
| dkato | 5:49a61433290a | 154 | } |
| dkato | 5:49a61433290a | 155 | } |
| dkato | 5:49a61433290a | 156 | |
| dkato | 5:49a61433290a | 157 | |
| dkato | 5:49a61433290a | 158 | for( ip = 0 ; ip < preData->cnt ; ip++ ) |
| dkato | 5:49a61433290a | 159 | { |
| dkato | 5:49a61433290a | 160 | for( ic = 0 ; ic < curData->cnt ; ic++ ) |
| dkato | 5:49a61433290a | 161 | { |
| dkato | 5:49a61433290a | 162 | dst [ ip * traCntMax + ic ] |
| dkato | 5:49a61433290a | 163 | = TrCheckSameROI//The return value is the similarity of the rectangle. Always a value more than or equal to zero. The closer to zero, the more similar they are. |
| dkato | 5:49a61433290a | 164 | ( |
| dkato | 5:49a61433290a | 165 | curData->posX[ic],curData->posY[ic],curData->size[ic], |
| dkato | 5:49a61433290a | 166 | preData->posX[ip],preData->posY[ip],preData->size[ip] |
| dkato | 5:49a61433290a | 167 | ); |
| dkato | 5:49a61433290a | 168 | } |
| dkato | 5:49a61433290a | 169 | } |
| dkato | 5:49a61433290a | 170 | |
| dkato | 5:49a61433290a | 171 | } |
| dkato | 5:49a61433290a | 172 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 173 | // TrSteadinessXYS |
| dkato | 5:49a61433290a | 174 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 175 | void |
| dkato | 5:49a61433290a | 176 | TrSteadinessXYS |
| dkato | 5:49a61433290a | 177 | ( |
| dkato | 5:49a61433290a | 178 | STB_INT32 curX ,STB_INT32 curY ,STB_INT32 curS , |
| dkato | 5:49a61433290a | 179 | STB_INT32 preX ,STB_INT32 preY ,STB_INT32 preS , |
| dkato | 5:49a61433290a | 180 | STB_INT32* dstX ,STB_INT32* dstY ,STB_INT32* dstS , |
| dkato | 5:49a61433290a | 181 | STB_INT32 thrP ,STB_INT32 thrS |
| dkato | 5:49a61433290a | 182 | ) |
| dkato | 5:49a61433290a | 183 | { |
| dkato | 5:49a61433290a | 184 | |
| dkato | 5:49a61433290a | 185 | STB_INT32 difP ;//the percentage of detection position change |
| dkato | 5:49a61433290a | 186 | STB_INT32 difS ;//the percentage of detection size change |
| dkato | 5:49a61433290a | 187 | float tmpVal; |
| dkato | 5:49a61433290a | 188 | |
| dkato | 5:49a61433290a | 189 | |
| dkato | 5:49a61433290a | 190 | if( preS < 1 ) |
| dkato | 5:49a61433290a | 191 | { |
| dkato | 5:49a61433290a | 192 | *dstX = curX ; *dstY = curY ; *dstS = curS ; |
| dkato | 5:49a61433290a | 193 | return ; |
| dkato | 5:49a61433290a | 194 | } |
| dkato | 5:49a61433290a | 195 | |
| dkato | 5:49a61433290a | 196 | //the percentage of detect position change |
| dkato | 5:49a61433290a | 197 | //It is "Absolute value of detected position change amount from previous frame / Detected size of previous frame * 100". |
| dkato | 5:49a61433290a | 198 | tmpVal = (float)sqrt( (float) (preX-curX)*(preX-curX) + (preY-curY)*(preY-curY) ); |
| dkato | 5:49a61433290a | 199 | difP = (STB_INT32)( tmpVal * 100 / preS ); |
| dkato | 5:49a61433290a | 200 | if( difP <= thrP ) |
| dkato | 5:49a61433290a | 201 | { |
| dkato | 5:49a61433290a | 202 | *dstX = preX ; *dstY = preY ; |
| dkato | 5:49a61433290a | 203 | }else |
| dkato | 5:49a61433290a | 204 | { |
| dkato | 5:49a61433290a | 205 | *dstX = curX ; *dstY = curY ; |
| dkato | 5:49a61433290a | 206 | } |
| dkato | 5:49a61433290a | 207 | |
| dkato | 5:49a61433290a | 208 | //the percentage of detect size change |
| dkato | 5:49a61433290a | 209 | //It is "Absolute value of detected size change amount from previous frame / Detected size of previous frame * 100". |
| dkato | 5:49a61433290a | 210 | tmpVal = (float)(preS-curS); |
| dkato | 5:49a61433290a | 211 | if( tmpVal < 0 ) |
| dkato | 5:49a61433290a | 212 | { |
| dkato | 5:49a61433290a | 213 | tmpVal *= (-1); |
| dkato | 5:49a61433290a | 214 | } |
| dkato | 5:49a61433290a | 215 | difS = (STB_INT32)( tmpVal * 100 / preS ); |
| dkato | 5:49a61433290a | 216 | if( difS <= thrS ) |
| dkato | 5:49a61433290a | 217 | { |
| dkato | 5:49a61433290a | 218 | *dstS = preS ; |
| dkato | 5:49a61433290a | 219 | }else |
| dkato | 5:49a61433290a | 220 | { |
| dkato | 5:49a61433290a | 221 | *dstS = curS ; |
| dkato | 5:49a61433290a | 222 | } |
| dkato | 5:49a61433290a | 223 | |
| dkato | 5:49a61433290a | 224 | } |
| dkato | 5:49a61433290a | 225 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 226 | // TrStabilizeTR |
| dkato | 5:49a61433290a | 227 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 228 | void TrStabilizeTR |
| dkato | 5:49a61433290a | 229 | ( |
| dkato | 5:49a61433290a | 230 | ROI_SYS *wData , //present data after the stabilization |
| dkato | 5:49a61433290a | 231 | STB_INT32 *wCnt , //a number of present data after the stabilization |
| dkato | 5:49a61433290a | 232 | ROI_SYS *rec , //past data |
| dkato | 5:49a61433290a | 233 | STB_INT32 *cntAcc , |
| dkato | 5:49a61433290a | 234 | TRHANDLE handle |
| dkato | 5:49a61433290a | 235 | ) |
| dkato | 5:49a61433290a | 236 | { |
| dkato | 5:49a61433290a | 237 | |
| dkato | 5:49a61433290a | 238 | STB_INT32 stedinessPos = handle->stedPos ; |
| dkato | 5:49a61433290a | 239 | STB_INT32 stedinessSize = handle->stedSize ; |
| dkato | 5:49a61433290a | 240 | STB_INT32 thrRetryCnt = handle->retryCnt ; |
| dkato | 5:49a61433290a | 241 | STB_INT32 traCntMax = handle->traCntMax ; |
| dkato | 5:49a61433290a | 242 | STB_INT32 *idPreCur = handle->wIdPreCur ; |
| dkato | 5:49a61433290a | 243 | STB_INT32 *idCurPre = handle->wIdCurPre ; |
| dkato | 5:49a61433290a | 244 | STB_INT32 *dstTbl = handle->wDstTbl ; |
| dkato | 5:49a61433290a | 245 | ROI_SYS *curData = &rec[0];//current frame data |
| dkato | 5:49a61433290a | 246 | ROI_SYS *preData = &rec[1];//previous frame data |
| dkato | 5:49a61433290a | 247 | STB_INT32 tmpAccCnt ; |
| dkato | 5:49a61433290a | 248 | STB_INT32 ip ,ic ; |
| dkato | 5:49a61433290a | 249 | STB_INT32 ipp ,icc ; |
| dkato | 5:49a61433290a | 250 | STB_INT32 tmpWCnt ; |
| dkato | 5:49a61433290a | 251 | STB_INT32 tmpVal ; |
| dkato | 5:49a61433290a | 252 | STB_INT32 tmpX,tmpY,tmpS ; |
| dkato | 5:49a61433290a | 253 | const STB_INT32 LinkNot = -1 ; |
| dkato | 5:49a61433290a | 254 | |
| dkato | 5:49a61433290a | 255 | |
| dkato | 5:49a61433290a | 256 | //------------------------------------------------------------------------------// |
| dkato | 5:49a61433290a | 257 | //Initialization |
| dkato | 5:49a61433290a | 258 | //------------------------------------------------------------------------------// |
| dkato | 5:49a61433290a | 259 | for( ip = 0 ; ip < traCntMax ; ip++ ) |
| dkato | 5:49a61433290a | 260 | { |
| dkato | 5:49a61433290a | 261 | idPreCur[ip] = LinkNot; |
| dkato | 5:49a61433290a | 262 | idCurPre[ip] = LinkNot; |
| dkato | 5:49a61433290a | 263 | } |
| dkato | 5:49a61433290a | 264 | |
| dkato | 5:49a61433290a | 265 | |
| dkato | 5:49a61433290a | 266 | //------------------------------------------------------------------------------// |
| dkato | 5:49a61433290a | 267 | //previous preparation |
| dkato | 5:49a61433290a | 268 | //------------------------------------------------------------------------------// |
| dkato | 5:49a61433290a | 269 | //Delete the data exceeding the retry count from the previous frame data. |
| dkato | 5:49a61433290a | 270 | TrDelRetry ( preData ,thrRetryCnt ); |
| dkato | 5:49a61433290a | 271 | |
| dkato | 5:49a61433290a | 272 | |
| dkato | 5:49a61433290a | 273 | //------------------------------------------------------------------------------// |
| dkato | 5:49a61433290a | 274 | //main processing |
| dkato | 5:49a61433290a | 275 | //------------------------------------------------------------------------------// |
| dkato | 5:49a61433290a | 276 | tmpWCnt = 0 ;//a number of present data after the stabilization |
| dkato | 5:49a61433290a | 277 | |
| dkato | 5:49a61433290a | 278 | // "It's reflected in the previous frame" and "It's reflected in the current frame". |
| dkato | 5:49a61433290a | 279 | //Create dstTbl. The value of dstTbl is the similarity of the rectangle. Always a value more than or equal to zero. The closer to zero, the more similar they are. |
| dkato | 5:49a61433290a | 280 | TrSetDistTbl( dstTbl,curData,preData, traCntMax); |
| dkato | 5:49a61433290a | 281 | for( ;; ) |
| dkato | 5:49a61433290a | 282 | { |
| dkato | 5:49a61433290a | 283 | //Get the combination (icc, ipp) that minimizes the value of dstTbl. |
| dkato | 5:49a61433290a | 284 | tmpVal = STB_INT_MAX; icc = -1; ipp = -1; |
| dkato | 5:49a61433290a | 285 | for( ic = 0 ; ic < curData->cnt ; ic++ ) |
| dkato | 5:49a61433290a | 286 | { |
| dkato | 5:49a61433290a | 287 | for( ip = 0 ; ip < preData->cnt ; ip++ ) |
| dkato | 5:49a61433290a | 288 | { |
| dkato | 5:49a61433290a | 289 | if( tmpVal > dstTbl [ ip * traCntMax + ic ] ) |
| dkato | 5:49a61433290a | 290 | { |
| dkato | 5:49a61433290a | 291 | tmpVal = dstTbl [ ip * traCntMax + ic ] ; icc = ic; ipp = ip; |
| dkato | 5:49a61433290a | 292 | } |
| dkato | 5:49a61433290a | 293 | } |
| dkato | 5:49a61433290a | 294 | } |
| dkato | 5:49a61433290a | 295 | if( tmpVal == STB_INT_MAX ) |
| dkato | 5:49a61433290a | 296 | { |
| dkato | 5:49a61433290a | 297 | break; |
| dkato | 5:49a61433290a | 298 | } |
| dkato | 5:49a61433290a | 299 | |
| dkato | 5:49a61433290a | 300 | //Link ipp and icc |
| dkato | 5:49a61433290a | 301 | idCurPre[ icc ] = ipp ; |
| dkato | 5:49a61433290a | 302 | idPreCur[ ipp ] = icc ; |
| dkato | 5:49a61433290a | 303 | // steadiness |
| dkato | 5:49a61433290a | 304 | TrSteadinessXYS |
| dkato | 5:49a61433290a | 305 | ( |
| dkato | 5:49a61433290a | 306 | curData->posX[icc] ,curData->posY[icc] ,curData->size[icc] , |
| dkato | 5:49a61433290a | 307 | preData->posX[ipp] ,preData->posY[ipp] ,preData->size[ipp] , |
| dkato | 5:49a61433290a | 308 | &tmpX ,&tmpY ,&tmpS , |
| dkato | 5:49a61433290a | 309 | stedinessPos ,stedinessSize |
| dkato | 5:49a61433290a | 310 | ); |
| dkato | 5:49a61433290a | 311 | // set |
| dkato | 5:49a61433290a | 312 | wData->nTraID[tmpWCnt] = preData->nTraID[ipp]; |
| dkato | 5:49a61433290a | 313 | wData->nDetID[tmpWCnt] = curData->nDetID[icc]; |
| dkato | 5:49a61433290a | 314 | wData->posX [tmpWCnt] = tmpX ; |
| dkato | 5:49a61433290a | 315 | wData->posY [tmpWCnt] = tmpY ; |
| dkato | 5:49a61433290a | 316 | wData->size [tmpWCnt] = tmpS ; |
| dkato | 5:49a61433290a | 317 | wData->conf [tmpWCnt] = ( ( curData->conf[icc] + preData->conf[ipp] ) /2 ); |
| dkato | 5:49a61433290a | 318 | wData->retryN[tmpWCnt] = 0 ;//"It's reflected(linked) in the current frame"so that 0. |
| dkato | 5:49a61433290a | 319 | tmpWCnt++; |
| dkato | 5:49a61433290a | 320 | //Renewal "dstTbl" not to refer the associated data. |
| dkato | 5:49a61433290a | 321 | for( ic = 0 ; ic < curData->cnt ; ic++ ) |
| dkato | 5:49a61433290a | 322 | { |
| dkato | 5:49a61433290a | 323 | dstTbl [ ipp * traCntMax + ic ] = STB_INT_MAX ; |
| dkato | 5:49a61433290a | 324 | } |
| dkato | 5:49a61433290a | 325 | for( ip = 0 ; ip < preData->cnt ; ip++ ) |
| dkato | 5:49a61433290a | 326 | { |
| dkato | 5:49a61433290a | 327 | dstTbl [ ip * traCntMax + icc ] = STB_INT_MAX ; |
| dkato | 5:49a61433290a | 328 | } |
| dkato | 5:49a61433290a | 329 | |
| dkato | 5:49a61433290a | 330 | if( tmpWCnt == traCntMax ) |
| dkato | 5:49a61433290a | 331 | { |
| dkato | 5:49a61433290a | 332 | *wCnt = tmpWCnt; |
| dkato | 5:49a61433290a | 333 | return; |
| dkato | 5:49a61433290a | 334 | } |
| dkato | 5:49a61433290a | 335 | } |
| dkato | 5:49a61433290a | 336 | |
| dkato | 5:49a61433290a | 337 | // "It is reflected in the previous frame" and "It is not reflected in the current frame". |
| dkato | 5:49a61433290a | 338 | for( ip = 0 ; ip < preData->cnt ; ip++ ) //"It's reflected in the previous frame" |
| dkato | 5:49a61433290a | 339 | { |
| dkato | 5:49a61433290a | 340 | if( idPreCur[ip] == LinkNot ) //"It's not reflected in the current frame" |
| dkato | 5:49a61433290a | 341 | { |
| dkato | 5:49a61433290a | 342 | // set |
| dkato | 5:49a61433290a | 343 | wData->nTraID[tmpWCnt] = preData->nTraID[ip]; |
| dkato | 5:49a61433290a | 344 | wData->nDetID[tmpWCnt] = -1;//"It's not reflected in the current frame so the detection number is -1" |
| dkato | 5:49a61433290a | 345 | wData->posX [tmpWCnt] = preData->posX [ip]; |
| dkato | 5:49a61433290a | 346 | wData->posY [tmpWCnt] = preData->posY [ip]; |
| dkato | 5:49a61433290a | 347 | wData->size [tmpWCnt] = preData->size [ip]; |
| dkato | 5:49a61433290a | 348 | wData->conf [tmpWCnt] = preData->conf[ip]; |
| dkato | 5:49a61433290a | 349 | wData->retryN[tmpWCnt] = preData->retryN[ip] + 1 ;//"It's not reflected in the current frame"so that +1. |
| dkato | 5:49a61433290a | 350 | tmpWCnt++; |
| dkato | 5:49a61433290a | 351 | } |
| dkato | 5:49a61433290a | 352 | if( tmpWCnt == traCntMax) |
| dkato | 5:49a61433290a | 353 | { |
| dkato | 5:49a61433290a | 354 | *wCnt = tmpWCnt ; |
| dkato | 5:49a61433290a | 355 | return; |
| dkato | 5:49a61433290a | 356 | } |
| dkato | 5:49a61433290a | 357 | } |
| dkato | 5:49a61433290a | 358 | |
| dkato | 5:49a61433290a | 359 | // "It is not reflected in the previous frame" and "It is reflected in the current frame". |
| dkato | 5:49a61433290a | 360 | tmpAccCnt = *cntAcc; |
| dkato | 5:49a61433290a | 361 | for( ic = 0 ; ic < curData->cnt ; ic++ ) //"It's reflected in the current frame" |
| dkato | 5:49a61433290a | 362 | { |
| dkato | 5:49a61433290a | 363 | if( idCurPre[ic] == LinkNot ) //"It's not reflected in the previous frame" |
| dkato | 5:49a61433290a | 364 | { |
| dkato | 5:49a61433290a | 365 | // set |
| dkato | 5:49a61433290a | 366 | wData->nTraID[tmpWCnt] = tmpAccCnt; |
| dkato | 5:49a61433290a | 367 | wData->nDetID[tmpWCnt] = curData->nDetID[ic]; |
| dkato | 5:49a61433290a | 368 | wData->posX [tmpWCnt] = curData->posX [ic]; |
| dkato | 5:49a61433290a | 369 | wData->posY [tmpWCnt] = curData->posY [ic]; |
| dkato | 5:49a61433290a | 370 | wData->size [tmpWCnt] = curData->size [ic]; |
| dkato | 5:49a61433290a | 371 | wData->conf [tmpWCnt] = curData->conf[ic]; |
| dkato | 5:49a61433290a | 372 | wData->retryN[tmpWCnt] = 0 ;//"It's reflected in the current frame" so that 0. |
| dkato | 5:49a61433290a | 373 | tmpWCnt++; |
| dkato | 5:49a61433290a | 374 | tmpAccCnt++; |
| dkato | 5:49a61433290a | 375 | } |
| dkato | 5:49a61433290a | 376 | if( tmpWCnt == traCntMax ) |
| dkato | 5:49a61433290a | 377 | { |
| dkato | 5:49a61433290a | 378 | *wCnt = tmpWCnt; |
| dkato | 5:49a61433290a | 379 | *cntAcc = tmpAccCnt; |
| dkato | 5:49a61433290a | 380 | return; |
| dkato | 5:49a61433290a | 381 | } |
| dkato | 5:49a61433290a | 382 | } |
| dkato | 5:49a61433290a | 383 | |
| dkato | 5:49a61433290a | 384 | |
| dkato | 5:49a61433290a | 385 | *wCnt = tmpWCnt ; |
| dkato | 5:49a61433290a | 386 | *cntAcc = tmpAccCnt; |
| dkato | 5:49a61433290a | 387 | |
| dkato | 5:49a61433290a | 388 | |
| dkato | 5:49a61433290a | 389 | } |
| dkato | 5:49a61433290a | 390 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 391 | // TrSetRes |
| dkato | 5:49a61433290a | 392 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 393 | void TrSetRes( ROI_SYS* wRoi,STB_TR_RES* resData , STB_INT32* resCnt ) |
| dkato | 5:49a61433290a | 394 | { |
| dkato | 5:49a61433290a | 395 | STB_INT32 i; |
| dkato | 5:49a61433290a | 396 | |
| dkato | 5:49a61433290a | 397 | *resCnt = wRoi->cnt; |
| dkato | 5:49a61433290a | 398 | for( i = 0 ; i < wRoi->cnt ; i++ ) |
| dkato | 5:49a61433290a | 399 | { |
| dkato | 5:49a61433290a | 400 | resData[i].nTraID = wRoi->nTraID[i]; |
| dkato | 5:49a61433290a | 401 | resData[i].nDetID = wRoi->nDetID[i]; |
| dkato | 5:49a61433290a | 402 | resData[i].pos.x = wRoi->posX [i]; |
| dkato | 5:49a61433290a | 403 | resData[i].pos.y = wRoi->posY [i]; |
| dkato | 5:49a61433290a | 404 | resData[i].size = wRoi->size [i]; |
| dkato | 5:49a61433290a | 405 | resData[i].conf = wRoi->conf[i]; |
| dkato | 5:49a61433290a | 406 | } |
| dkato | 5:49a61433290a | 407 | } |
| dkato | 5:49a61433290a | 408 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 409 | // TrEditCur |
| dkato | 5:49a61433290a | 410 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 411 | void TrEditCur( ROI_SYS* wRoi,ROI_SYS* curData ) |
| dkato | 5:49a61433290a | 412 | { |
| dkato | 5:49a61433290a | 413 | STB_INT32 i; |
| dkato | 5:49a61433290a | 414 | |
| dkato | 5:49a61433290a | 415 | curData->cnt = wRoi->cnt; |
| dkato | 5:49a61433290a | 416 | for( i = 0 ; i < wRoi->cnt ; i++ ) |
| dkato | 5:49a61433290a | 417 | { |
| dkato | 5:49a61433290a | 418 | curData->nTraID[i] = wRoi->nTraID[i]; |
| dkato | 5:49a61433290a | 419 | curData->nDetID[i] = wRoi->nDetID[i]; |
| dkato | 5:49a61433290a | 420 | curData->posX [i] = wRoi->posX [i]; |
| dkato | 5:49a61433290a | 421 | curData->posY [i] = wRoi->posY [i]; |
| dkato | 5:49a61433290a | 422 | curData->size [i] = wRoi->size [i]; |
| dkato | 5:49a61433290a | 423 | curData->conf [i] = wRoi->conf [i]; |
| dkato | 5:49a61433290a | 424 | curData->retryN[i] = wRoi->retryN[i]; |
| dkato | 5:49a61433290a | 425 | } |
| dkato | 5:49a61433290a | 426 | } |
| dkato | 5:49a61433290a | 427 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 428 | // StbTrExec |
| dkato | 5:49a61433290a | 429 | /*---------------------------------------------------------------------*/ |
| dkato | 5:49a61433290a | 430 | int StbTrExec ( TRHANDLE handle ) |
| dkato | 5:49a61433290a | 431 | { |
| dkato | 5:49a61433290a | 432 | |
| dkato | 5:49a61433290a | 433 | |
| dkato | 5:49a61433290a | 434 | /* Face --------------------------------------*/ |
| dkato | 5:49a61433290a | 435 | if( handle->execFlg->faceTr == STB_TRUE ) |
| dkato | 5:49a61433290a | 436 | { |
| dkato | 5:49a61433290a | 437 | //Move the time series of past data. |
| dkato | 5:49a61433290a | 438 | TrSlideRec( handle->fcRec ); |
| dkato | 5:49a61433290a | 439 | //"the present data" set to the past data |
| dkato | 5:49a61433290a | 440 | TrCurRec( handle->fcRec ,handle->stbTrDet->fcDet, handle->stbTrDet->fcNum ); |
| dkato | 5:49a61433290a | 441 | //Calculate "stabilized current data wRoi" from "past data". |
| dkato | 5:49a61433290a | 442 | TrStabilizeTR( handle->wRoi ,&(handle->wRoi->cnt) ,handle->fcRec ,&(handle->fcCntAcc) ,handle ); |
| dkato | 5:49a61433290a | 443 | //Set "wRoi" data to output data "resFaces". |
| dkato | 5:49a61433290a | 444 | TrSetRes( handle->wRoi, handle->resFaces->face, &(handle->resFaces->cnt) ); |
| dkato | 5:49a61433290a | 445 | //set "wRoi" data to accumulated data (current) "fcRec [0]". |
| dkato | 5:49a61433290a | 446 | TrEditCur( handle->wRoi, &(handle->fcRec[0]) ); |
| dkato | 5:49a61433290a | 447 | } |
| dkato | 5:49a61433290a | 448 | |
| dkato | 5:49a61433290a | 449 | /* Body --------------------------------------*/ |
| dkato | 5:49a61433290a | 450 | if( handle->execFlg->bodyTr == STB_TRUE ) |
| dkato | 5:49a61433290a | 451 | { |
| dkato | 5:49a61433290a | 452 | //Move the time series of past data. |
| dkato | 5:49a61433290a | 453 | TrSlideRec( handle->bdRec ); |
| dkato | 5:49a61433290a | 454 | //"the present data" set to the past data |
| dkato | 5:49a61433290a | 455 | TrCurRec( handle->bdRec ,handle->stbTrDet->bdDet ,handle->stbTrDet->bdNum ); |
| dkato | 5:49a61433290a | 456 | //Calculate "stabilized current data wRoi" from "past data". |
| dkato | 5:49a61433290a | 457 | TrStabilizeTR( handle->wRoi ,&(handle->wRoi->cnt) , handle->bdRec, &(handle->bdCntAcc) , handle ); |
| dkato | 5:49a61433290a | 458 | //Set "wRoi" data to output data "resFaces". |
| dkato | 5:49a61433290a | 459 | TrSetRes( handle->wRoi, handle->resBodys->body, &(handle->resBodys->cnt) ); |
| dkato | 5:49a61433290a | 460 | //set "wRoi" data to accumulated data (current) "bdRec [0]". |
| dkato | 5:49a61433290a | 461 | TrEditCur( handle->wRoi, &(handle->bdRec[0]) ); |
| dkato | 5:49a61433290a | 462 | } |
| dkato | 5:49a61433290a | 463 | |
| dkato | 5:49a61433290a | 464 | |
| dkato | 5:49a61433290a | 465 | return STB_NORMAL; |
| dkato | 5:49a61433290a | 466 | } |
| dkato | 5:49a61433290a | 467 | |
| dkato | 5:49a61433290a | 468 | |
| dkato | 5:49a61433290a | 469 |