Maxim Integrated / OWGridEye

Dependents:   MAXREFDES131_Qt_Demo MAXREFDES130_131_Demo

Committer:
j3
Date:
Tue Jun 14 20:32:49 2016 +0000
Revision:
3:5b025369ad96
Parent:
1:9e457e35e2e3
Child:
8:fa89d4cd41cd
updated library to use RomIterator for OW slaves

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 1:9e457e35e2e3 1 /*******************************************************************************
j3 1:9e457e35e2e3 2 include file
j3 1:9e457e35e2e3 3 *******************************************************************************/
j3 1:9e457e35e2e3 4 #include "grideye_api_common.h"
j3 1:9e457e35e2e3 5 #include "grideye_api_lv1.h"
j3 3:5b025369ad96 6 #include "grideye_api_lv2.h"
j3 1:9e457e35e2e3 7
j3 1:9e457e35e2e3 8
j3 1:9e457e35e2e3 9 /*******************************************************************************
j3 1:9e457e35e2e3 10 macro definition
j3 1:9e457e35e2e3 11 *******************************************************************************/
j3 1:9e457e35e2e3 12 #define TRUE (1)
j3 1:9e457e35e2e3 13 #define FALSE (0)
j3 1:9e457e35e2e3 14
j3 1:9e457e35e2e3 15 #define SHORT_MAX_VAL ( 32767) /* 0x7FFF */
j3 1:9e457e35e2e3 16 #define SHORT_MIN_VAL (-32768) /* 0x8000 */
j3 1:9e457e35e2e3 17 #define ULONG_MAX_VAL ( 4294967295) /* 0xFFFFFFFF */
j3 1:9e457e35e2e3 18
j3 1:9e457e35e2e3 19 /* Grid-EYE's number of pixels */
j3 1:9e457e35e2e3 20 #define SNR_SZ_X (8)
j3 1:9e457e35e2e3 21 #define SNR_SZ_Y (8)
j3 1:9e457e35e2e3 22 #define SNR_SZ (SNR_SZ_X * SNR_SZ_Y)
j3 1:9e457e35e2e3 23
j3 1:9e457e35e2e3 24
j3 1:9e457e35e2e3 25 /*******************************************************************************
j3 1:9e457e35e2e3 26 public method
j3 1:9e457e35e2e3 27 ******************************************************************************/
j3 1:9e457e35e2e3 28
j3 1:9e457e35e2e3 29 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 30 Calculate average.
j3 1:9e457e35e2e3 31 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 32 short shAMG_PUB_CMN_CalcAve( short* pshArray, USHORT usSize, UCHAR ucSkip, UCHAR ucMedian, BOOL* pbMedianWork )
j3 1:9e457e35e2e3 33 {
j3 1:9e457e35e2e3 34 short shAve = 0;
j3 1:9e457e35e2e3 35
j3 1:9e457e35e2e3 36 if( 1 >= usSize )
j3 1:9e457e35e2e3 37 {
j3 1:9e457e35e2e3 38 return( *pshArray );
j3 1:9e457e35e2e3 39 }
j3 1:9e457e35e2e3 40
j3 1:9e457e35e2e3 41 /* Adjust parameter. */
j3 1:9e457e35e2e3 42 if( 1 > ucSkip )
j3 1:9e457e35e2e3 43 {
j3 1:9e457e35e2e3 44 ucSkip = 1;
j3 1:9e457e35e2e3 45 }
j3 1:9e457e35e2e3 46 if( ucMedian > ((usSize - 1) / 2) )
j3 1:9e457e35e2e3 47 {
j3 1:9e457e35e2e3 48 ucMedian = ((usSize - 1) / 2);
j3 1:9e457e35e2e3 49 }
j3 1:9e457e35e2e3 50
j3 1:9e457e35e2e3 51 /* Calculate average. */
j3 1:9e457e35e2e3 52 if( 0 == ucMedian )
j3 1:9e457e35e2e3 53 {
j3 1:9e457e35e2e3 54 USHORT usCnt = 0;
j3 1:9e457e35e2e3 55 long loSum = 0;
j3 1:9e457e35e2e3 56
j3 1:9e457e35e2e3 57 for( usCnt = 0; usCnt < usSize; usCnt++ )
j3 1:9e457e35e2e3 58 {
j3 1:9e457e35e2e3 59 short shCurData = pshArray[usCnt * ucSkip];
j3 1:9e457e35e2e3 60 loSum += shCurData;
j3 1:9e457e35e2e3 61 }
j3 1:9e457e35e2e3 62 shAve = (short)(loSum / usSize);
j3 1:9e457e35e2e3 63 }
j3 1:9e457e35e2e3 64 else
j3 1:9e457e35e2e3 65 {
j3 1:9e457e35e2e3 66 USHORT usCnt = 0;
j3 1:9e457e35e2e3 67 long loSum = 0;
j3 1:9e457e35e2e3 68 UCHAR ucMedianCnt = 0;
j3 1:9e457e35e2e3 69
j3 1:9e457e35e2e3 70 for( usCnt = 0; usCnt < usSize; usCnt++ )
j3 1:9e457e35e2e3 71 {
j3 1:9e457e35e2e3 72 pbMedianWork[usCnt] = TRUE;
j3 1:9e457e35e2e3 73 }
j3 1:9e457e35e2e3 74
j3 1:9e457e35e2e3 75 for( ucMedianCnt = 0; ucMedianCnt < ucMedian; ucMedianCnt++ )
j3 1:9e457e35e2e3 76 {
j3 1:9e457e35e2e3 77 short shMaxData = SHORT_MIN_VAL;
j3 1:9e457e35e2e3 78 short shMinData = SHORT_MAX_VAL;
j3 1:9e457e35e2e3 79 UCHAR ucIndex = 0;
j3 1:9e457e35e2e3 80
j3 1:9e457e35e2e3 81 for( usCnt = 0; usCnt < usSize; usCnt++ )
j3 1:9e457e35e2e3 82 {
j3 1:9e457e35e2e3 83 if( FALSE != pbMedianWork[usCnt] )
j3 1:9e457e35e2e3 84 {
j3 1:9e457e35e2e3 85 short shCurData = pshArray[usCnt * ucSkip];
j3 1:9e457e35e2e3 86 if( shMaxData < shCurData )
j3 1:9e457e35e2e3 87 {
j3 1:9e457e35e2e3 88 shMaxData = shCurData;
j3 1:9e457e35e2e3 89 ucIndex = usCnt;
j3 1:9e457e35e2e3 90 }
j3 1:9e457e35e2e3 91 }
j3 1:9e457e35e2e3 92 }
j3 1:9e457e35e2e3 93 pbMedianWork[ucIndex] = FALSE;
j3 1:9e457e35e2e3 94
j3 1:9e457e35e2e3 95 for( usCnt = 0; usCnt < usSize; usCnt++ )
j3 1:9e457e35e2e3 96 {
j3 1:9e457e35e2e3 97 if( FALSE != pbMedianWork[usCnt] )
j3 1:9e457e35e2e3 98 {
j3 1:9e457e35e2e3 99 short shCurData = pshArray[usCnt * ucSkip];
j3 1:9e457e35e2e3 100 if( shMinData > shCurData )
j3 1:9e457e35e2e3 101 {
j3 1:9e457e35e2e3 102 shMinData = shCurData;
j3 1:9e457e35e2e3 103 ucIndex = usCnt;
j3 1:9e457e35e2e3 104 }
j3 1:9e457e35e2e3 105 }
j3 1:9e457e35e2e3 106 }
j3 1:9e457e35e2e3 107 pbMedianWork[ucIndex] = FALSE;
j3 1:9e457e35e2e3 108 }
j3 1:9e457e35e2e3 109
j3 1:9e457e35e2e3 110 for( usCnt = 0; usCnt < usSize; usCnt++ )
j3 1:9e457e35e2e3 111 {
j3 1:9e457e35e2e3 112 short shCurData = pshArray[usCnt * ucSkip];
j3 1:9e457e35e2e3 113 if( FALSE != pbMedianWork[usCnt] )
j3 1:9e457e35e2e3 114 {
j3 1:9e457e35e2e3 115 loSum += shCurData;
j3 1:9e457e35e2e3 116 }
j3 1:9e457e35e2e3 117 }
j3 1:9e457e35e2e3 118 shAve = (short)(loSum / ( usSize - ucMedian * 2 ));
j3 1:9e457e35e2e3 119 }
j3 1:9e457e35e2e3 120
j3 1:9e457e35e2e3 121 return( shAve );
j3 1:9e457e35e2e3 122 }
j3 1:9e457e35e2e3 123
j3 1:9e457e35e2e3 124 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 125 Calculate average.
j3 1:9e457e35e2e3 126 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 127 short shAMG_PUB_CMN_CalcIIR( short shVal1, short shVal2, short shTh )
j3 1:9e457e35e2e3 128 {
j3 1:9e457e35e2e3 129 const short c_shMinTh = 0;
j3 1:9e457e35e2e3 130 const short c_shMaxTh = 256;
j3 1:9e457e35e2e3 131 long loAddVal = 0;
j3 1:9e457e35e2e3 132
j3 1:9e457e35e2e3 133 /* Adjust parameter. */
j3 1:9e457e35e2e3 134 if( c_shMinTh > shTh )
j3 1:9e457e35e2e3 135 {
j3 1:9e457e35e2e3 136 shTh = c_shMinTh;
j3 1:9e457e35e2e3 137 }
j3 1:9e457e35e2e3 138 if( c_shMaxTh < shTh )
j3 1:9e457e35e2e3 139 {
j3 1:9e457e35e2e3 140 shTh = c_shMaxTh;
j3 1:9e457e35e2e3 141 }
j3 1:9e457e35e2e3 142
j3 1:9e457e35e2e3 143 /* Calculate average. */
j3 1:9e457e35e2e3 144 loAddVal = (long)shTh * ( shVal2 - shVal1 );
j3 1:9e457e35e2e3 145 return( shVal1 + (short)(loAddVal / c_shMaxTh) );
j3 1:9e457e35e2e3 146 }
j3 1:9e457e35e2e3 147
j3 1:9e457e35e2e3 148 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 149 Calculate average.
j3 1:9e457e35e2e3 150 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 151 short shAMG_PUB_CMN_CalcIIR_f( short shVal1, short shVal2, float fTh )
j3 1:9e457e35e2e3 152 {
j3 1:9e457e35e2e3 153 const float c_fMinTh = 0;
j3 1:9e457e35e2e3 154 const float c_fMaxTh = 1;
j3 1:9e457e35e2e3 155 float fAddVal = 0;
j3 1:9e457e35e2e3 156
j3 1:9e457e35e2e3 157 /* Adjust parameter. */
j3 1:9e457e35e2e3 158 if( c_fMinTh > fTh )
j3 1:9e457e35e2e3 159 {
j3 1:9e457e35e2e3 160 fTh = c_fMinTh;
j3 1:9e457e35e2e3 161 }
j3 1:9e457e35e2e3 162 if( c_fMaxTh < fTh )
j3 1:9e457e35e2e3 163 {
j3 1:9e457e35e2e3 164 fTh = c_fMaxTh;
j3 1:9e457e35e2e3 165 }
j3 1:9e457e35e2e3 166 /* Calculate average. */
j3 1:9e457e35e2e3 167 fAddVal = fTh * ( shVal2 - shVal1 );
j3 1:9e457e35e2e3 168 return( shVal1 + (short)fAddVal );
j3 1:9e457e35e2e3 169 }
j3 1:9e457e35e2e3 170
j3 1:9e457e35e2e3 171 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 172 Convert image : ( x, y ) -> ( ucWidth-1-x , y )
j3 1:9e457e35e2e3 173 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 174 void vAMG_PUB_IMG_ConvertFlipX( UCHAR ucWidth, UCHAR ucHeight, short* pshInImg, short* pshOutImg )
j3 1:9e457e35e2e3 175 {
j3 1:9e457e35e2e3 176 {
j3 1:9e457e35e2e3 177 UCHAR ucX = 0;
j3 1:9e457e35e2e3 178 UCHAR ucY = 0;
j3 1:9e457e35e2e3 179 for( ucY = 0; ucY < ucHeight; ucY++ )
j3 1:9e457e35e2e3 180 {
j3 1:9e457e35e2e3 181 for( ucX = 0; ucX < (ucWidth+1)/2; ucX++ )
j3 1:9e457e35e2e3 182 {
j3 1:9e457e35e2e3 183 USHORT usIndex1 = (USHORT)( ucX) + ucY * ucWidth;
j3 1:9e457e35e2e3 184 USHORT usIndex2 = (USHORT)(ucWidth - 1 - ucX) + ucY * ucWidth;
j3 1:9e457e35e2e3 185 short shVal = pshInImg[usIndex1];
j3 1:9e457e35e2e3 186 pshOutImg[usIndex1] = pshInImg[usIndex2];
j3 1:9e457e35e2e3 187 pshOutImg[usIndex2] = shVal;
j3 1:9e457e35e2e3 188 }
j3 1:9e457e35e2e3 189 }
j3 1:9e457e35e2e3 190 }
j3 1:9e457e35e2e3 191 }
j3 1:9e457e35e2e3 192
j3 1:9e457e35e2e3 193 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 194 Convert image : ( x, y ) -> ( x, ucHeight-1-y )
j3 1:9e457e35e2e3 195 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 196 void vAMG_PUB_IMG_ConvertFlipY( UCHAR ucWidth, UCHAR ucHeight, short* pshInImg, short* pshOutImg )
j3 1:9e457e35e2e3 197 {
j3 1:9e457e35e2e3 198 {
j3 1:9e457e35e2e3 199 UCHAR ucX = 0;
j3 1:9e457e35e2e3 200 UCHAR ucY = 0;
j3 1:9e457e35e2e3 201 for( ucY = 0; ucY < (ucHeight+1)/2; ucY++ )
j3 1:9e457e35e2e3 202 {
j3 1:9e457e35e2e3 203 for( ucX = 0; ucX < ucWidth; ucX++ )
j3 1:9e457e35e2e3 204 {
j3 1:9e457e35e2e3 205 USHORT usIndex1 = (USHORT)ucX + ( ucY) * ucWidth;
j3 1:9e457e35e2e3 206 USHORT usIndex2 = (USHORT)ucX + (ucHeight - 1 - ucY) * ucWidth;
j3 1:9e457e35e2e3 207 short shVal = pshInImg[usIndex1];
j3 1:9e457e35e2e3 208 pshOutImg[usIndex1] = pshInImg[usIndex2];
j3 1:9e457e35e2e3 209 pshOutImg[usIndex2] = shVal;
j3 1:9e457e35e2e3 210 }
j3 1:9e457e35e2e3 211 }
j3 1:9e457e35e2e3 212 }
j3 1:9e457e35e2e3 213 }
j3 1:9e457e35e2e3 214
j3 1:9e457e35e2e3 215 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 216 Convert image : ( x, y ) -> ( y, x )
j3 1:9e457e35e2e3 217 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 218 BOOL bAMG_PUB_IMG_ConvertFlipXY( UCHAR ucWidth, UCHAR ucHeight, short* pshInImg, short* pshOutImg )
j3 1:9e457e35e2e3 219 {
j3 1:9e457e35e2e3 220 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 221
j3 1:9e457e35e2e3 222 if( ucWidth == ucHeight )
j3 1:9e457e35e2e3 223 {
j3 1:9e457e35e2e3 224 UCHAR ucX = 0;
j3 1:9e457e35e2e3 225 UCHAR ucY = 0;
j3 1:9e457e35e2e3 226 for( ucY = 0; ucY < ucHeight; ucY++ )
j3 1:9e457e35e2e3 227 {
j3 1:9e457e35e2e3 228 for( ucX = ucY; ucX < ucWidth; ucX++ )
j3 1:9e457e35e2e3 229 {
j3 1:9e457e35e2e3 230 USHORT usIndex1 = (USHORT)ucX + ucY * ucWidth;
j3 1:9e457e35e2e3 231 USHORT usIndex2 = (USHORT)ucY + ucX * ucWidth;
j3 1:9e457e35e2e3 232 short shVal = pshInImg[usIndex1];
j3 1:9e457e35e2e3 233 pshOutImg[usIndex1] = pshInImg[usIndex2];
j3 1:9e457e35e2e3 234 pshOutImg[usIndex2] = shVal;
j3 1:9e457e35e2e3 235 }
j3 1:9e457e35e2e3 236 }
j3 1:9e457e35e2e3 237 bRet = TRUE;
j3 1:9e457e35e2e3 238 }
j3 1:9e457e35e2e3 239
j3 1:9e457e35e2e3 240 return( bRet );
j3 1:9e457e35e2e3 241 }
j3 1:9e457e35e2e3 242
j3 1:9e457e35e2e3 243 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 244 Convert image : ( x, y ) -> ( ucHeight-1-y, x )
j3 1:9e457e35e2e3 245 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 246 BOOL bAMG_PUB_IMG_ConvertRotate90( UCHAR ucWidth, UCHAR ucHeight, short* pshInImg, short* pshOutImg )
j3 1:9e457e35e2e3 247 {
j3 1:9e457e35e2e3 248 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 249
j3 1:9e457e35e2e3 250 if( ucWidth == ucHeight )
j3 1:9e457e35e2e3 251 {
j3 1:9e457e35e2e3 252 UCHAR ucX = 0;
j3 1:9e457e35e2e3 253 UCHAR ucY = 0;
j3 1:9e457e35e2e3 254 for( ucY = 0; ucY < (ucHeight+1)/2; ucY++ )
j3 1:9e457e35e2e3 255 {
j3 1:9e457e35e2e3 256 for( ucX = ucY; ucX < ucWidth - ucY - 1; ucX++ )
j3 1:9e457e35e2e3 257 {
j3 1:9e457e35e2e3 258 USHORT usIndex1 = (USHORT)( ucX) + ( ucY) * ucWidth;
j3 1:9e457e35e2e3 259 USHORT usIndex2 = (USHORT)( ucY) + (ucWidth - 1 - ucX) * ucWidth;
j3 1:9e457e35e2e3 260 USHORT usIndex3 = (USHORT)(ucWidth - 1 - ucX) + (ucWidth - 1 - ucY) * ucWidth;
j3 1:9e457e35e2e3 261 USHORT usIndex4 = (USHORT)(ucWidth - 1 - ucY) + ( ucX) * ucWidth;
j3 1:9e457e35e2e3 262 short shVal = pshInImg[usIndex1];
j3 1:9e457e35e2e3 263 pshOutImg[usIndex1] = pshInImg[usIndex2];
j3 1:9e457e35e2e3 264 pshOutImg[usIndex2] = pshInImg[usIndex3];
j3 1:9e457e35e2e3 265 pshOutImg[usIndex3] = pshInImg[usIndex4];
j3 1:9e457e35e2e3 266 pshOutImg[usIndex4] = shVal;
j3 1:9e457e35e2e3 267 }
j3 1:9e457e35e2e3 268 if( ucX == ucY )
j3 1:9e457e35e2e3 269 {
j3 1:9e457e35e2e3 270 USHORT usIndex = (USHORT)ucX + ucY * ucWidth;
j3 1:9e457e35e2e3 271 pshOutImg[usIndex] = pshInImg[usIndex];
j3 1:9e457e35e2e3 272 }
j3 1:9e457e35e2e3 273 }
j3 1:9e457e35e2e3 274
j3 1:9e457e35e2e3 275 bRet = TRUE;
j3 1:9e457e35e2e3 276 }
j3 1:9e457e35e2e3 277
j3 1:9e457e35e2e3 278 return( bRet );
j3 1:9e457e35e2e3 279 }
j3 1:9e457e35e2e3 280
j3 1:9e457e35e2e3 281 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 282 Convert image : ( x, y ) -> ( ucWidth-1-x, ucHeight-1-y )
j3 1:9e457e35e2e3 283 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 284 void vAMG_PUB_IMG_ConvertRotate180( UCHAR ucWidth, UCHAR ucHeight, short* pshInImg, short* pshOutImg )
j3 1:9e457e35e2e3 285 {
j3 1:9e457e35e2e3 286 USHORT usSize = ucWidth * ucHeight;
j3 1:9e457e35e2e3 287 USHORT usIndex1 = 0;
j3 1:9e457e35e2e3 288
j3 1:9e457e35e2e3 289 for( usIndex1 = 0; usIndex1 < (usSize+1)/2; usIndex1++ )
j3 1:9e457e35e2e3 290 {
j3 1:9e457e35e2e3 291 USHORT usIndex2 = usSize - 1 - usIndex1;
j3 1:9e457e35e2e3 292 short shVal = pshInImg[usIndex1];
j3 1:9e457e35e2e3 293 pshOutImg[usIndex1] = pshInImg[usIndex2];
j3 1:9e457e35e2e3 294 pshOutImg[usIndex2] = shVal;
j3 1:9e457e35e2e3 295 }
j3 1:9e457e35e2e3 296 }
j3 1:9e457e35e2e3 297
j3 1:9e457e35e2e3 298 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 299 Convert image : ( x, y ) -> ( y, ucWidth-1-x )
j3 1:9e457e35e2e3 300 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 301 BOOL bAMG_PUB_IMG_ConvertRotate270( UCHAR ucWidth, UCHAR ucHeight, short* pshInImg, short* pshOutImg )
j3 1:9e457e35e2e3 302 {
j3 1:9e457e35e2e3 303 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 304
j3 1:9e457e35e2e3 305 if( ucWidth == ucHeight )
j3 1:9e457e35e2e3 306 {
j3 1:9e457e35e2e3 307 UCHAR ucX = 0;
j3 1:9e457e35e2e3 308 UCHAR ucY = 0;
j3 1:9e457e35e2e3 309 for( ucY = 0; ucY < (ucHeight+1)/2; ucY++ )
j3 1:9e457e35e2e3 310 {
j3 1:9e457e35e2e3 311 for( ucX = ucY; ucX < ucWidth - ucY - 1; ucX++ )
j3 1:9e457e35e2e3 312 {
j3 1:9e457e35e2e3 313 USHORT usIndex1 = (USHORT)( ucX) + ( ucY) * ucWidth;
j3 1:9e457e35e2e3 314 USHORT usIndex2 = (USHORT)(ucWidth - 1 - ucY) + ( ucX) * ucWidth;
j3 1:9e457e35e2e3 315 USHORT usIndex3 = (USHORT)(ucWidth - 1 - ucX) + (ucWidth - 1 - ucY) * ucWidth;
j3 1:9e457e35e2e3 316 USHORT usIndex4 = (USHORT)( ucY) + (ucWidth - 1 - ucX) * ucWidth;
j3 1:9e457e35e2e3 317 short shVal = pshInImg[usIndex1];
j3 1:9e457e35e2e3 318 pshOutImg[usIndex1] = pshInImg[usIndex2];
j3 1:9e457e35e2e3 319 pshOutImg[usIndex2] = pshInImg[usIndex3];
j3 1:9e457e35e2e3 320 pshOutImg[usIndex3] = pshInImg[usIndex4];
j3 1:9e457e35e2e3 321 pshOutImg[usIndex4] = shVal;
j3 1:9e457e35e2e3 322 }
j3 1:9e457e35e2e3 323 if( ucX == ucY )
j3 1:9e457e35e2e3 324 {
j3 1:9e457e35e2e3 325 USHORT usIndex = (USHORT)ucX + ucY * ucWidth;
j3 1:9e457e35e2e3 326 pshOutImg[usIndex] = pshInImg[usIndex];
j3 1:9e457e35e2e3 327 }
j3 1:9e457e35e2e3 328 }
j3 1:9e457e35e2e3 329
j3 1:9e457e35e2e3 330 bRet = TRUE;
j3 1:9e457e35e2e3 331 }
j3 1:9e457e35e2e3 332
j3 1:9e457e35e2e3 333 return( bRet );
j3 1:9e457e35e2e3 334 }
j3 1:9e457e35e2e3 335
j3 1:9e457e35e2e3 336 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 337 Linear interpolation : 8 x 8 -> 15 x 15
j3 1:9e457e35e2e3 338 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 339 BOOL bAMG_PUB_IMG_LinearInterpolationSQ15( short* pshInImg, short* pshOutImg )
j3 1:9e457e35e2e3 340 {
j3 1:9e457e35e2e3 341 const UCHAR c_ucImgWidth = 15;
j3 1:9e457e35e2e3 342 const UCHAR c_ucImgHeight = 15;
j3 1:9e457e35e2e3 343 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 344
j3 1:9e457e35e2e3 345 if( pshInImg != pshOutImg )
j3 1:9e457e35e2e3 346 {
j3 1:9e457e35e2e3 347 UCHAR ucX = 0;
j3 1:9e457e35e2e3 348 UCHAR ucY = 0;
j3 1:9e457e35e2e3 349 for( ucY = 0; ucY < c_ucImgHeight; ucY += 2 )
j3 1:9e457e35e2e3 350 {
j3 1:9e457e35e2e3 351 for( ucX = 0; ucX < c_ucImgWidth; ucX += 2 )
j3 1:9e457e35e2e3 352 {
j3 1:9e457e35e2e3 353 UCHAR ucSnr = ucX / 2 + ucY / 2 * SNR_SZ_X;
j3 1:9e457e35e2e3 354 UCHAR ucImg = ucX + ucY * c_ucImgWidth;
j3 1:9e457e35e2e3 355 pshOutImg[ucImg] = pshInImg[ucSnr];
j3 1:9e457e35e2e3 356 }
j3 1:9e457e35e2e3 357 for( ucX = 1; ucX < c_ucImgWidth; ucX += 2 )
j3 1:9e457e35e2e3 358 {
j3 1:9e457e35e2e3 359 UCHAR ucImg = ucX + ucY * c_ucImgWidth;
j3 1:9e457e35e2e3 360 pshOutImg[ucImg] = ( pshOutImg[ucImg-1] + pshOutImg[ucImg+1] ) / 2;
j3 1:9e457e35e2e3 361 }
j3 1:9e457e35e2e3 362 }
j3 1:9e457e35e2e3 363 for( ucY = 1; ucY < c_ucImgHeight; ucY += 2 )
j3 1:9e457e35e2e3 364 {
j3 1:9e457e35e2e3 365 for( ucX = 0; ucX < c_ucImgWidth; ucX++ )
j3 1:9e457e35e2e3 366 {
j3 1:9e457e35e2e3 367 UCHAR ucImg = ucX + ucY * c_ucImgWidth;
j3 1:9e457e35e2e3 368 pshOutImg[ucImg] = ( pshOutImg[ucImg-c_ucImgWidth] + pshOutImg[ucImg+c_ucImgWidth] ) / 2;
j3 1:9e457e35e2e3 369 }
j3 1:9e457e35e2e3 370 }
j3 1:9e457e35e2e3 371
j3 1:9e457e35e2e3 372 bRet = TRUE;
j3 1:9e457e35e2e3 373 }
j3 1:9e457e35e2e3 374
j3 1:9e457e35e2e3 375 return( bRet );
j3 1:9e457e35e2e3 376 }
j3 1:9e457e35e2e3 377
j3 1:9e457e35e2e3 378 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 379 Linear interpolation : 8 x 8 -> ucWidth x ucHeight
j3 1:9e457e35e2e3 380 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 381 BOOL bAMG_PUB_IMG_LinearInterpolation( UCHAR ucWidth, UCHAR ucHeight, short* pshInImg, short* pshOutImg )
j3 1:9e457e35e2e3 382 {
j3 1:9e457e35e2e3 383 const UCHAR c_ucRes = 16;
j3 1:9e457e35e2e3 384 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 385
j3 1:9e457e35e2e3 386 if( pshInImg != pshOutImg )
j3 1:9e457e35e2e3 387 {
j3 1:9e457e35e2e3 388 USHORT usImg = 0;
j3 1:9e457e35e2e3 389
j3 1:9e457e35e2e3 390 for( usImg = 0; usImg < ucWidth * ucHeight; usImg++ )
j3 1:9e457e35e2e3 391 {
j3 1:9e457e35e2e3 392 UCHAR ucImgX = usImg % ucWidth;
j3 1:9e457e35e2e3 393 UCHAR ucImgY = usImg / ucWidth;
j3 1:9e457e35e2e3 394 USHORT usSnrXn = (USHORT)( c_ucRes * ucImgX * (SNR_SZ_X-1) / (ucWidth -1) );
j3 1:9e457e35e2e3 395 USHORT usSnrYn = (USHORT)( c_ucRes * ucImgY * (SNR_SZ_Y-1) / (ucHeight-1) );
j3 1:9e457e35e2e3 396 UCHAR ucSnrX = (UCHAR)( usSnrXn / c_ucRes );
j3 1:9e457e35e2e3 397 UCHAR ucSnrY = (UCHAR)( usSnrYn / c_ucRes );
j3 1:9e457e35e2e3 398 UCHAR ucRateX1 = (UCHAR)( usSnrXn % c_ucRes );
j3 1:9e457e35e2e3 399 UCHAR ucRateY1 = (UCHAR)( usSnrYn % c_ucRes );
j3 1:9e457e35e2e3 400 UCHAR ucRateX0 = c_ucRes - ucRateX1;
j3 1:9e457e35e2e3 401 UCHAR ucRateY0 = c_ucRes - ucRateY1;
j3 1:9e457e35e2e3 402 UCHAR ucSnr = ucSnrX + ucSnrY * SNR_SZ_X;
j3 1:9e457e35e2e3 403 long loWork = 0;
j3 1:9e457e35e2e3 404
j3 1:9e457e35e2e3 405 if( ucImgX == (ucWidth - 1) )
j3 1:9e457e35e2e3 406 {
j3 1:9e457e35e2e3 407 if( ucImgY == (ucHeight - 1) )
j3 1:9e457e35e2e3 408 {
j3 1:9e457e35e2e3 409 loWork += (long)pshInImg[ucSnr ];
j3 1:9e457e35e2e3 410 }
j3 1:9e457e35e2e3 411 else
j3 1:9e457e35e2e3 412 {
j3 1:9e457e35e2e3 413 loWork += (long)pshInImg[ucSnr ] * ucRateY0;
j3 1:9e457e35e2e3 414 loWork += (long)pshInImg[ucSnr + SNR_SZ_X] * ucRateY1;
j3 1:9e457e35e2e3 415 loWork /= c_ucRes;
j3 1:9e457e35e2e3 416 }
j3 1:9e457e35e2e3 417 }
j3 1:9e457e35e2e3 418 else
j3 1:9e457e35e2e3 419 {
j3 1:9e457e35e2e3 420 if( ucImgY == (ucHeight - 1) )
j3 1:9e457e35e2e3 421 {
j3 1:9e457e35e2e3 422 loWork += (long)pshInImg[ucSnr ] * ucRateX0;
j3 1:9e457e35e2e3 423 loWork += (long)pshInImg[ucSnr + 1 ] * ucRateX1;
j3 1:9e457e35e2e3 424 loWork /= c_ucRes;
j3 1:9e457e35e2e3 425 }
j3 1:9e457e35e2e3 426 else
j3 1:9e457e35e2e3 427 {
j3 1:9e457e35e2e3 428 loWork += (long)pshInImg[ucSnr ] * ucRateX0 * ucRateY0;
j3 1:9e457e35e2e3 429 loWork += (long)pshInImg[ucSnr + 1 ] * ucRateX1 * ucRateY0;
j3 1:9e457e35e2e3 430 loWork += (long)pshInImg[ucSnr + SNR_SZ_X] * ucRateX0 * ucRateY1;
j3 1:9e457e35e2e3 431 loWork += (long)pshInImg[ucSnr + 1 + SNR_SZ_X] * ucRateX1 * ucRateY1;
j3 1:9e457e35e2e3 432 loWork /= c_ucRes * c_ucRes;
j3 1:9e457e35e2e3 433 }
j3 1:9e457e35e2e3 434 }
j3 1:9e457e35e2e3 435 pshOutImg[usImg] = (short)loWork;
j3 1:9e457e35e2e3 436 }
j3 1:9e457e35e2e3 437
j3 1:9e457e35e2e3 438 bRet = TRUE;
j3 1:9e457e35e2e3 439 }
j3 1:9e457e35e2e3 440
j3 1:9e457e35e2e3 441 return( bRet );
j3 1:9e457e35e2e3 442 }
j3 1:9e457e35e2e3 443
j3 1:9e457e35e2e3 444 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 445 Image dilation.
j3 1:9e457e35e2e3 446 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 447 BOOL bAMG_PUB_IMG_ImageDilation1( UCHAR ucWidth, UCHAR ucHeight, UCHAR* pucInImg, UCHAR* pucOutImg )
j3 1:9e457e35e2e3 448 {
j3 1:9e457e35e2e3 449 USHORT usImg = 0;
j3 1:9e457e35e2e3 450 USHORT usSize = ucWidth * ucHeight;
j3 1:9e457e35e2e3 451 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 452
j3 1:9e457e35e2e3 453 if( pucInImg != pucOutImg )
j3 1:9e457e35e2e3 454 {
j3 1:9e457e35e2e3 455 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 456 {
j3 1:9e457e35e2e3 457 pucOutImg[usImg] = 0;
j3 1:9e457e35e2e3 458 }
j3 1:9e457e35e2e3 459 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 460 {
j3 1:9e457e35e2e3 461 UCHAR ucImgX = usImg % ucWidth;
j3 1:9e457e35e2e3 462 UCHAR ucImgY = usImg / ucWidth;
j3 1:9e457e35e2e3 463
j3 1:9e457e35e2e3 464 if( 0 != pucInImg[usImg] )
j3 1:9e457e35e2e3 465 {
j3 1:9e457e35e2e3 466 pucOutImg[usImg] = 1;
j3 1:9e457e35e2e3 467 if( 0 != ucImgX )
j3 1:9e457e35e2e3 468 {
j3 1:9e457e35e2e3 469 pucOutImg[usImg - 1] = 1;
j3 1:9e457e35e2e3 470 }
j3 1:9e457e35e2e3 471 if( (ucWidth - 1) != ucImgX )
j3 1:9e457e35e2e3 472 {
j3 1:9e457e35e2e3 473 pucOutImg[usImg + 1] = 1;
j3 1:9e457e35e2e3 474 }
j3 1:9e457e35e2e3 475 if( 0 != ucImgY )
j3 1:9e457e35e2e3 476 {
j3 1:9e457e35e2e3 477 pucOutImg[usImg - ucWidth] = 1;
j3 1:9e457e35e2e3 478 }
j3 1:9e457e35e2e3 479 if( (ucHeight - 1) != ucImgY )
j3 1:9e457e35e2e3 480 {
j3 1:9e457e35e2e3 481 pucOutImg[usImg + ucWidth] = 1;
j3 1:9e457e35e2e3 482 }
j3 1:9e457e35e2e3 483 }
j3 1:9e457e35e2e3 484 }
j3 1:9e457e35e2e3 485
j3 1:9e457e35e2e3 486 bRet = TRUE;
j3 1:9e457e35e2e3 487 }
j3 1:9e457e35e2e3 488
j3 1:9e457e35e2e3 489 return( bRet );
j3 1:9e457e35e2e3 490 }
j3 1:9e457e35e2e3 491
j3 1:9e457e35e2e3 492 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 493 Image dilation.
j3 1:9e457e35e2e3 494 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 495 BOOL bAMG_PUB_IMG_ImageDilation2( UCHAR ucWidth, UCHAR ucHeight, UCHAR ucLabelNo, UCHAR* pucInImg, UCHAR* pucOutImg )
j3 1:9e457e35e2e3 496 {
j3 1:9e457e35e2e3 497 USHORT usImg = 0;
j3 1:9e457e35e2e3 498 USHORT usSize = ucWidth * ucHeight;
j3 1:9e457e35e2e3 499 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 500
j3 1:9e457e35e2e3 501 if( pucInImg != pucOutImg )
j3 1:9e457e35e2e3 502 {
j3 1:9e457e35e2e3 503 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 504 {
j3 1:9e457e35e2e3 505 pucOutImg[usImg] = 0;
j3 1:9e457e35e2e3 506 }
j3 1:9e457e35e2e3 507 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 508 {
j3 1:9e457e35e2e3 509 UCHAR ucImgX = usImg % ucWidth;
j3 1:9e457e35e2e3 510 UCHAR ucImgY = usImg / ucWidth;
j3 1:9e457e35e2e3 511
j3 1:9e457e35e2e3 512 if( ucLabelNo == pucInImg[usImg] )
j3 1:9e457e35e2e3 513 {
j3 1:9e457e35e2e3 514 pucOutImg[usImg] = 1;
j3 1:9e457e35e2e3 515 if( 0 != ucImgX )
j3 1:9e457e35e2e3 516 {
j3 1:9e457e35e2e3 517 pucOutImg[usImg - 1] = 1;
j3 1:9e457e35e2e3 518 }
j3 1:9e457e35e2e3 519 if( (ucWidth - 1) != ucImgX )
j3 1:9e457e35e2e3 520 {
j3 1:9e457e35e2e3 521 pucOutImg[usImg + 1] = 1;
j3 1:9e457e35e2e3 522 }
j3 1:9e457e35e2e3 523 if( 0 != ucImgY )
j3 1:9e457e35e2e3 524 {
j3 1:9e457e35e2e3 525 pucOutImg[usImg - ucWidth] = 1;
j3 1:9e457e35e2e3 526 }
j3 1:9e457e35e2e3 527 if( (ucHeight - 1) != ucImgY )
j3 1:9e457e35e2e3 528 {
j3 1:9e457e35e2e3 529 pucOutImg[usImg + ucWidth] = 1;
j3 1:9e457e35e2e3 530 }
j3 1:9e457e35e2e3 531 }
j3 1:9e457e35e2e3 532 }
j3 1:9e457e35e2e3 533
j3 1:9e457e35e2e3 534 bRet = TRUE;
j3 1:9e457e35e2e3 535 }
j3 1:9e457e35e2e3 536
j3 1:9e457e35e2e3 537 return( bRet );
j3 1:9e457e35e2e3 538 }
j3 1:9e457e35e2e3 539
j3 1:9e457e35e2e3 540 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 541 Object detection.
j3 1:9e457e35e2e3 542 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 543 void vAMG_PUB_ODT_CalcDiffImage( USHORT usSize, short* pshInImg1, short* pshInImg2, short* pshOutImg )
j3 1:9e457e35e2e3 544 {
j3 1:9e457e35e2e3 545 USHORT usImg = 0;
j3 1:9e457e35e2e3 546
j3 1:9e457e35e2e3 547 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 548 {
j3 1:9e457e35e2e3 549 pshOutImg[usImg] = pshInImg1[usImg] - pshInImg2[usImg];
j3 1:9e457e35e2e3 550 }
j3 1:9e457e35e2e3 551 }
j3 1:9e457e35e2e3 552
j3 1:9e457e35e2e3 553 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 554 Object detection.
j3 1:9e457e35e2e3 555 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 556 void vAMG_PUB_ODT_CalcDetectImage1( USHORT usSize, short* pshInImg, short shTh, UCHAR ucMark, UCHAR* pucOutImg )
j3 1:9e457e35e2e3 557 {
j3 1:9e457e35e2e3 558 USHORT usImg = 0;
j3 1:9e457e35e2e3 559
j3 1:9e457e35e2e3 560 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 561 {
j3 1:9e457e35e2e3 562 pucOutImg[usImg] = ( shTh <= pshInImg[usImg] ) ? ucMark : 0;
j3 1:9e457e35e2e3 563 }
j3 1:9e457e35e2e3 564 }
j3 1:9e457e35e2e3 565
j3 1:9e457e35e2e3 566 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 567 Object detection.
j3 1:9e457e35e2e3 568 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 569 void vAMG_PUB_ODT_CalcDetectImage2( USHORT usSize, short* pshInImg, short* pshTh, UCHAR ucMark, UCHAR* pucOutImg )
j3 1:9e457e35e2e3 570 {
j3 1:9e457e35e2e3 571 USHORT usImg = 0;
j3 1:9e457e35e2e3 572
j3 1:9e457e35e2e3 573 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 574 {
j3 1:9e457e35e2e3 575 pucOutImg[usImg] = ( pshTh[usImg] <= pshInImg[usImg] ) ? ucMark : 0;
j3 1:9e457e35e2e3 576 }
j3 1:9e457e35e2e3 577 }
j3 1:9e457e35e2e3 578
j3 1:9e457e35e2e3 579 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 580 Labeling.
j3 1:9e457e35e2e3 581 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 582 UCHAR ucAMG_PUB_ODT_CalcDataLabeling8( UCHAR ucWidth, UCHAR ucHeight, UCHAR ucMark, USHORT usArea, UCHAR* pucImg, USHORT* pusSearchList )
j3 1:9e457e35e2e3 583 {
j3 1:9e457e35e2e3 584 USHORT usImg = 0;
j3 1:9e457e35e2e3 585 USHORT usSize = ucWidth * ucHeight;
j3 1:9e457e35e2e3 586 UCHAR ucDetectNum = 0;
j3 1:9e457e35e2e3 587
j3 1:9e457e35e2e3 588 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 589 {
j3 1:9e457e35e2e3 590 UCHAR ucLabelNum = 0;
j3 1:9e457e35e2e3 591 USHORT usIndex = 0;
j3 1:9e457e35e2e3 592 USHORT usIndexAdd = 0;
j3 1:9e457e35e2e3 593
j3 1:9e457e35e2e3 594 if( ucMark == pucImg[usImg] )
j3 1:9e457e35e2e3 595 {
j3 1:9e457e35e2e3 596 pucImg[usImg] = 0;
j3 1:9e457e35e2e3 597 pusSearchList[usIndex] = usImg;
j3 1:9e457e35e2e3 598 usIndexAdd = 1;
j3 1:9e457e35e2e3 599 }
j3 1:9e457e35e2e3 600
j3 1:9e457e35e2e3 601 while( usIndex < usIndexAdd )
j3 1:9e457e35e2e3 602 {
j3 1:9e457e35e2e3 603 UCHAR ucX = pusSearchList[usIndex] % ucWidth;
j3 1:9e457e35e2e3 604 UCHAR ucY = pusSearchList[usIndex] / ucWidth;
j3 1:9e457e35e2e3 605 {
j3 1:9e457e35e2e3 606 if( 0 <= (ucY - 1) )
j3 1:9e457e35e2e3 607 {
j3 1:9e457e35e2e3 608 USHORT usCheckIndex = (ucX ) + (ucY-1) * ucWidth;
j3 1:9e457e35e2e3 609 if( ucMark == pucImg[usCheckIndex] )
j3 1:9e457e35e2e3 610 {
j3 1:9e457e35e2e3 611 pucImg[usCheckIndex] = 0;
j3 1:9e457e35e2e3 612 pusSearchList[usIndexAdd++] = usCheckIndex;
j3 1:9e457e35e2e3 613 }
j3 1:9e457e35e2e3 614 }
j3 1:9e457e35e2e3 615 if( ucHeight > (ucY + 1) )
j3 1:9e457e35e2e3 616 {
j3 1:9e457e35e2e3 617 USHORT usCheckIndex = (ucX ) + (ucY+1) * ucWidth;
j3 1:9e457e35e2e3 618 if( ucMark == pucImg[usCheckIndex] )
j3 1:9e457e35e2e3 619 {
j3 1:9e457e35e2e3 620 pucImg[usCheckIndex] = 0;
j3 1:9e457e35e2e3 621 pusSearchList[usIndexAdd++] = usCheckIndex;
j3 1:9e457e35e2e3 622 }
j3 1:9e457e35e2e3 623 }
j3 1:9e457e35e2e3 624 }
j3 1:9e457e35e2e3 625 if( 0 <= (ucX - 1) )
j3 1:9e457e35e2e3 626 {
j3 1:9e457e35e2e3 627 {
j3 1:9e457e35e2e3 628 USHORT usCheckIndex = (ucX-1) + (ucY ) * ucWidth;
j3 1:9e457e35e2e3 629 if( ucMark == pucImg[usCheckIndex] )
j3 1:9e457e35e2e3 630 {
j3 1:9e457e35e2e3 631 pucImg[usCheckIndex] = 0;
j3 1:9e457e35e2e3 632 pusSearchList[usIndexAdd++] = usCheckIndex;
j3 1:9e457e35e2e3 633 }
j3 1:9e457e35e2e3 634 }
j3 1:9e457e35e2e3 635 if( 0 <= (ucY - 1) )
j3 1:9e457e35e2e3 636 {
j3 1:9e457e35e2e3 637 USHORT usCheckIndex = (ucX-1) + (ucY-1) * ucWidth;
j3 1:9e457e35e2e3 638 if( ucMark == pucImg[usCheckIndex] )
j3 1:9e457e35e2e3 639 {
j3 1:9e457e35e2e3 640 pucImg[usCheckIndex] = 0;
j3 1:9e457e35e2e3 641 pusSearchList[usIndexAdd++] = usCheckIndex;
j3 1:9e457e35e2e3 642 }
j3 1:9e457e35e2e3 643 }
j3 1:9e457e35e2e3 644 if( ucHeight > (ucY + 1) )
j3 1:9e457e35e2e3 645 {
j3 1:9e457e35e2e3 646 USHORT usCheckIndex = (ucX-1) + (ucY+1) * ucWidth;
j3 1:9e457e35e2e3 647 if( ucMark == pucImg[usCheckIndex] )
j3 1:9e457e35e2e3 648 {
j3 1:9e457e35e2e3 649 pucImg[usCheckIndex] = 0;
j3 1:9e457e35e2e3 650 pusSearchList[usIndexAdd++] = usCheckIndex;
j3 1:9e457e35e2e3 651 }
j3 1:9e457e35e2e3 652 }
j3 1:9e457e35e2e3 653 }
j3 1:9e457e35e2e3 654 if( ucWidth > (ucX + 1) )
j3 1:9e457e35e2e3 655 {
j3 1:9e457e35e2e3 656 {
j3 1:9e457e35e2e3 657 USHORT usCheckIndex = (ucX+1) + (ucY ) * ucWidth;
j3 1:9e457e35e2e3 658 if( ucMark == pucImg[usCheckIndex] )
j3 1:9e457e35e2e3 659 {
j3 1:9e457e35e2e3 660 pucImg[usCheckIndex] = 0;
j3 1:9e457e35e2e3 661 pusSearchList[usIndexAdd++] = usCheckIndex;
j3 1:9e457e35e2e3 662 }
j3 1:9e457e35e2e3 663 }
j3 1:9e457e35e2e3 664 if( 0 <= (ucY - 1) )
j3 1:9e457e35e2e3 665 {
j3 1:9e457e35e2e3 666 USHORT usCheckIndex = (ucX+1) + (ucY-1) * ucWidth;
j3 1:9e457e35e2e3 667 if( ucMark == pucImg[usCheckIndex] )
j3 1:9e457e35e2e3 668 {
j3 1:9e457e35e2e3 669 pucImg[usCheckIndex] = 0;
j3 1:9e457e35e2e3 670 pusSearchList[usIndexAdd++] = usCheckIndex;
j3 1:9e457e35e2e3 671 }
j3 1:9e457e35e2e3 672 }
j3 1:9e457e35e2e3 673 if( ucHeight > (ucY + 1) )
j3 1:9e457e35e2e3 674 {
j3 1:9e457e35e2e3 675 USHORT usCheckIndex = (ucX+1) + (ucY+1) * ucWidth;
j3 1:9e457e35e2e3 676 if( ucMark == pucImg[usCheckIndex] )
j3 1:9e457e35e2e3 677 {
j3 1:9e457e35e2e3 678 pucImg[usCheckIndex] = 0;
j3 1:9e457e35e2e3 679 pusSearchList[usIndexAdd++] = usCheckIndex;
j3 1:9e457e35e2e3 680 }
j3 1:9e457e35e2e3 681 }
j3 1:9e457e35e2e3 682 }
j3 1:9e457e35e2e3 683 usIndex++;
j3 1:9e457e35e2e3 684 }
j3 1:9e457e35e2e3 685
j3 1:9e457e35e2e3 686 if( usIndex <= usArea )
j3 1:9e457e35e2e3 687 {
j3 1:9e457e35e2e3 688 ucLabelNum = 0;
j3 1:9e457e35e2e3 689 }
j3 1:9e457e35e2e3 690 else
j3 1:9e457e35e2e3 691 {
j3 1:9e457e35e2e3 692 ucDetectNum++;
j3 1:9e457e35e2e3 693 ucLabelNum = ucDetectNum;
j3 1:9e457e35e2e3 694 }
j3 1:9e457e35e2e3 695
j3 1:9e457e35e2e3 696 {
j3 1:9e457e35e2e3 697 USHORT usImg2 = 0;
j3 1:9e457e35e2e3 698 for( usImg2 = 0; usImg2 < usIndex; usImg2++ )
j3 1:9e457e35e2e3 699 {
j3 1:9e457e35e2e3 700 pucImg[ pusSearchList[usImg2] ] = ucLabelNum;
j3 1:9e457e35e2e3 701 }
j3 1:9e457e35e2e3 702 }
j3 1:9e457e35e2e3 703 }
j3 1:9e457e35e2e3 704
j3 1:9e457e35e2e3 705 return( ucDetectNum );
j3 1:9e457e35e2e3 706 }
j3 1:9e457e35e2e3 707
j3 1:9e457e35e2e3 708 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 709 Calculate features.
j3 1:9e457e35e2e3 710 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 711 BOOL bAMG_PUB_FEA_CalcArea( USHORT usSize, UCHAR ucLabelNo, UCHAR* pucImg, USHORT* pusRet )
j3 1:9e457e35e2e3 712 {
j3 1:9e457e35e2e3 713 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 714 USHORT usImg = 0;
j3 1:9e457e35e2e3 715 USHORT usArea = 0;
j3 1:9e457e35e2e3 716
j3 1:9e457e35e2e3 717 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 718 {
j3 1:9e457e35e2e3 719 if( ucLabelNo == pucImg[usImg] )
j3 1:9e457e35e2e3 720 {
j3 1:9e457e35e2e3 721 bRet = TRUE;
j3 1:9e457e35e2e3 722 usArea++;
j3 1:9e457e35e2e3 723 }
j3 1:9e457e35e2e3 724 }
j3 1:9e457e35e2e3 725
j3 1:9e457e35e2e3 726 if( FALSE != bRet )
j3 1:9e457e35e2e3 727 {
j3 1:9e457e35e2e3 728 *pusRet = usArea;
j3 1:9e457e35e2e3 729 }
j3 1:9e457e35e2e3 730
j3 1:9e457e35e2e3 731 return( bRet );
j3 1:9e457e35e2e3 732 }
j3 1:9e457e35e2e3 733
j3 1:9e457e35e2e3 734 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 735 Calculate features.
j3 1:9e457e35e2e3 736 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 737 BOOL bAMG_PUB_FEA_CalcRectangle( UCHAR ucWidth, UCHAR ucHeight, UCHAR ucLabelNo, UCHAR* pucImg, UCHAR* pucRet )
j3 1:9e457e35e2e3 738 {
j3 1:9e457e35e2e3 739 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 740 USHORT usImg = 0;
j3 1:9e457e35e2e3 741 USHORT usSize = ucWidth * ucHeight;
j3 1:9e457e35e2e3 742 UCHAR ucMinX = ucWidth - 1;
j3 1:9e457e35e2e3 743 UCHAR ucMinY = ucHeight - 1;
j3 1:9e457e35e2e3 744 UCHAR ucMaxX = 0;
j3 1:9e457e35e2e3 745 UCHAR ucMaxY = 0;
j3 1:9e457e35e2e3 746
j3 1:9e457e35e2e3 747 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 748 {
j3 1:9e457e35e2e3 749 UCHAR ucImgX = usImg % ucWidth;
j3 1:9e457e35e2e3 750 UCHAR ucImgY = usImg / ucWidth;
j3 1:9e457e35e2e3 751
j3 1:9e457e35e2e3 752 if( ucLabelNo == pucImg[usImg] )
j3 1:9e457e35e2e3 753 {
j3 1:9e457e35e2e3 754 bRet = TRUE;
j3 1:9e457e35e2e3 755 if( ucMinX > ucImgX )
j3 1:9e457e35e2e3 756 {
j3 1:9e457e35e2e3 757 ucMinX = ucImgX;
j3 1:9e457e35e2e3 758 }
j3 1:9e457e35e2e3 759 if( ucMinY > ucImgY )
j3 1:9e457e35e2e3 760 {
j3 1:9e457e35e2e3 761 ucMinY = ucImgY;
j3 1:9e457e35e2e3 762 }
j3 1:9e457e35e2e3 763 if( ucMaxX < ucImgX )
j3 1:9e457e35e2e3 764 {
j3 1:9e457e35e2e3 765 ucMaxX = ucImgX;
j3 1:9e457e35e2e3 766 }
j3 1:9e457e35e2e3 767 if( ucMaxY < ucImgY )
j3 1:9e457e35e2e3 768 {
j3 1:9e457e35e2e3 769 ucMaxY = ucImgY;
j3 1:9e457e35e2e3 770 }
j3 1:9e457e35e2e3 771 }
j3 1:9e457e35e2e3 772 }
j3 1:9e457e35e2e3 773
j3 1:9e457e35e2e3 774 if( FALSE != bRet )
j3 1:9e457e35e2e3 775 {
j3 1:9e457e35e2e3 776 pucRet[0] = ucMinX;
j3 1:9e457e35e2e3 777 pucRet[1] = ucMinY;
j3 1:9e457e35e2e3 778 pucRet[2] = ucMaxX;
j3 1:9e457e35e2e3 779 pucRet[3] = ucMaxY;
j3 1:9e457e35e2e3 780 }
j3 1:9e457e35e2e3 781
j3 1:9e457e35e2e3 782 return( bRet );
j3 1:9e457e35e2e3 783 }
j3 1:9e457e35e2e3 784
j3 1:9e457e35e2e3 785 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 786 Calculate features.
j3 1:9e457e35e2e3 787 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 788 BOOL bAMG_PUB_FEA_CalcMinTemp( USHORT usSize, UCHAR ucLabelNo, UCHAR* pucImg, short* pshImg, short* pshRet )
j3 1:9e457e35e2e3 789 {
j3 1:9e457e35e2e3 790 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 791 USHORT usImg = 0;
j3 1:9e457e35e2e3 792 short shMin = SHORT_MAX_VAL;
j3 1:9e457e35e2e3 793
j3 1:9e457e35e2e3 794 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 795 {
j3 1:9e457e35e2e3 796 if( ucLabelNo == pucImg[usImg] )
j3 1:9e457e35e2e3 797 {
j3 1:9e457e35e2e3 798 bRet = TRUE;
j3 1:9e457e35e2e3 799 if( shMin > pshImg[usImg] )
j3 1:9e457e35e2e3 800 {
j3 1:9e457e35e2e3 801 shMin = pshImg[usImg];
j3 1:9e457e35e2e3 802 }
j3 1:9e457e35e2e3 803 }
j3 1:9e457e35e2e3 804 }
j3 1:9e457e35e2e3 805
j3 1:9e457e35e2e3 806 if( FALSE != bRet )
j3 1:9e457e35e2e3 807 {
j3 1:9e457e35e2e3 808 *pshRet = shMin;
j3 1:9e457e35e2e3 809 }
j3 1:9e457e35e2e3 810
j3 1:9e457e35e2e3 811 return( bRet );
j3 1:9e457e35e2e3 812 }
j3 1:9e457e35e2e3 813
j3 1:9e457e35e2e3 814 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 815 Calculate features.
j3 1:9e457e35e2e3 816 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 817 BOOL bAMG_PUB_FEA_CalcMaxTemp( USHORT usSize, UCHAR ucLabelNo, UCHAR* pucImg, short* pshImg, short* pshRet )
j3 1:9e457e35e2e3 818 {
j3 1:9e457e35e2e3 819 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 820 USHORT usImg = 0;
j3 1:9e457e35e2e3 821 short shMax = SHORT_MIN_VAL;
j3 1:9e457e35e2e3 822
j3 1:9e457e35e2e3 823 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 824 {
j3 1:9e457e35e2e3 825 if( ucLabelNo == pucImg[usImg] )
j3 1:9e457e35e2e3 826 {
j3 1:9e457e35e2e3 827 bRet = TRUE;
j3 1:9e457e35e2e3 828 if( shMax < pshImg[usImg] )
j3 1:9e457e35e2e3 829 {
j3 1:9e457e35e2e3 830 shMax = pshImg[usImg];
j3 1:9e457e35e2e3 831 }
j3 1:9e457e35e2e3 832 }
j3 1:9e457e35e2e3 833 }
j3 1:9e457e35e2e3 834
j3 1:9e457e35e2e3 835 if( FALSE != bRet )
j3 1:9e457e35e2e3 836 {
j3 1:9e457e35e2e3 837 *pshRet = shMax;
j3 1:9e457e35e2e3 838 }
j3 1:9e457e35e2e3 839
j3 1:9e457e35e2e3 840 return( bRet );
j3 1:9e457e35e2e3 841 }
j3 1:9e457e35e2e3 842
j3 1:9e457e35e2e3 843 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 844 Calculate features.
j3 1:9e457e35e2e3 845 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 846 BOOL bAMG_PUB_FEA_CalcAveTemp( USHORT usSize, UCHAR ucLabelNo, UCHAR* pucImg, short* pshImg, short* pshRet )
j3 1:9e457e35e2e3 847 {
j3 1:9e457e35e2e3 848 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 849 USHORT usImg = 0;
j3 1:9e457e35e2e3 850 long loSum = 0;
j3 1:9e457e35e2e3 851 USHORT usCnt = 0;
j3 1:9e457e35e2e3 852
j3 1:9e457e35e2e3 853 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 854 {
j3 1:9e457e35e2e3 855 if( ucLabelNo == pucImg[usImg] )
j3 1:9e457e35e2e3 856 {
j3 1:9e457e35e2e3 857 bRet = TRUE;
j3 1:9e457e35e2e3 858 loSum += pshImg[usImg];
j3 1:9e457e35e2e3 859 usCnt++;
j3 1:9e457e35e2e3 860 }
j3 1:9e457e35e2e3 861 }
j3 1:9e457e35e2e3 862
j3 1:9e457e35e2e3 863 if( FALSE != bRet )
j3 1:9e457e35e2e3 864 {
j3 1:9e457e35e2e3 865 *pshRet = (short)( loSum / usCnt );
j3 1:9e457e35e2e3 866 }
j3 1:9e457e35e2e3 867
j3 1:9e457e35e2e3 868 return( bRet );
j3 1:9e457e35e2e3 869 }
j3 1:9e457e35e2e3 870
j3 1:9e457e35e2e3 871 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 872 Calculate features.
j3 1:9e457e35e2e3 873 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 874 BOOL bAMG_PUB_FEA_CalcStdDevTemp( USHORT usSize, UCHAR ucLabelNo, UCHAR* pucImg, short* pshImg, USHORT* pusRet )
j3 1:9e457e35e2e3 875 {
j3 1:9e457e35e2e3 876 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 877 USHORT usImg = 0;
j3 1:9e457e35e2e3 878 ULONG ulS = 0;
j3 1:9e457e35e2e3 879 USHORT usCnt = 0;
j3 1:9e457e35e2e3 880 short shAve = 0;
j3 1:9e457e35e2e3 881
j3 1:9e457e35e2e3 882 if( FALSE != bAMG_PUB_FEA_CalcAveTemp( usSize, ucLabelNo, pucImg, pshImg, &shAve ) )
j3 1:9e457e35e2e3 883 {
j3 1:9e457e35e2e3 884 bRet = TRUE;
j3 1:9e457e35e2e3 885 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 886 {
j3 1:9e457e35e2e3 887 if( ucLabelNo == pucImg[usImg] )
j3 1:9e457e35e2e3 888 {
j3 1:9e457e35e2e3 889 ULONG ulPow = (ULONG)( (long)(pshImg[usImg] - shAve) * (pshImg[usImg] - shAve) );
j3 1:9e457e35e2e3 890 if( (ULONG_MAX_VAL - ulS) < ulPow )
j3 1:9e457e35e2e3 891 {
j3 1:9e457e35e2e3 892 bRet = FALSE;
j3 1:9e457e35e2e3 893 }
j3 1:9e457e35e2e3 894 else
j3 1:9e457e35e2e3 895 {
j3 1:9e457e35e2e3 896 ulS += ulPow;
j3 1:9e457e35e2e3 897 usCnt++;
j3 1:9e457e35e2e3 898 }
j3 1:9e457e35e2e3 899 }
j3 1:9e457e35e2e3 900 }
j3 1:9e457e35e2e3 901 }
j3 1:9e457e35e2e3 902
j3 1:9e457e35e2e3 903 if( FALSE != bRet )
j3 1:9e457e35e2e3 904 {
j3 1:9e457e35e2e3 905 ULONG ulData = ulS / usCnt;
j3 1:9e457e35e2e3 906 ULONG ulWork = ( 1 < ulData ) ? ulData : 1;
j3 1:9e457e35e2e3 907 ULONG ulSqrt = 0;
j3 1:9e457e35e2e3 908 if( 0 != ulData )
j3 1:9e457e35e2e3 909 {
j3 1:9e457e35e2e3 910 do
j3 1:9e457e35e2e3 911 {
j3 1:9e457e35e2e3 912 ulSqrt = ulWork;
j3 1:9e457e35e2e3 913 ulWork = (ulData / ulWork + ulWork) >> 1;
j3 1:9e457e35e2e3 914 }
j3 1:9e457e35e2e3 915 while( ulWork < ulSqrt );
j3 1:9e457e35e2e3 916 }
j3 1:9e457e35e2e3 917 *pusRet = (USHORT)ulSqrt;
j3 1:9e457e35e2e3 918 }
j3 1:9e457e35e2e3 919
j3 1:9e457e35e2e3 920 return( bRet );
j3 1:9e457e35e2e3 921 }
j3 1:9e457e35e2e3 922
j3 1:9e457e35e2e3 923 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 924 Calculate features.
j3 1:9e457e35e2e3 925 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 926 BOOL bAMG_PUB_FEA_CalcStdDevTemp_f( USHORT usSize, UCHAR ucLabelNo, UCHAR* pucImg, short* pshImg, float* pfRet )
j3 1:9e457e35e2e3 927 {
j3 1:9e457e35e2e3 928 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 929 USHORT usImg = 0;
j3 1:9e457e35e2e3 930 float fS = 0;
j3 1:9e457e35e2e3 931 USHORT usCnt = 0;
j3 1:9e457e35e2e3 932 short shAve = 0;
j3 1:9e457e35e2e3 933
j3 1:9e457e35e2e3 934 if( FALSE != bAMG_PUB_FEA_CalcAveTemp( usSize, ucLabelNo, pucImg, pshImg, &shAve ) )
j3 1:9e457e35e2e3 935 {
j3 1:9e457e35e2e3 936 bRet = TRUE;
j3 1:9e457e35e2e3 937 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 938 {
j3 1:9e457e35e2e3 939 if( ucLabelNo == pucImg[usImg] )
j3 1:9e457e35e2e3 940 {
j3 1:9e457e35e2e3 941 float fDiff = fAMG_PUB_CMN_ConvStoF(pshImg[usImg] - shAve);
j3 1:9e457e35e2e3 942 fS += fDiff * fDiff;
j3 1:9e457e35e2e3 943 usCnt++;
j3 1:9e457e35e2e3 944 }
j3 1:9e457e35e2e3 945 }
j3 1:9e457e35e2e3 946 }
j3 1:9e457e35e2e3 947
j3 1:9e457e35e2e3 948 if( FALSE != bRet )
j3 1:9e457e35e2e3 949 {
j3 1:9e457e35e2e3 950 float fData = fS / usCnt;
j3 1:9e457e35e2e3 951 float fWork = ( 1 < fData ) ? fData : 1;
j3 1:9e457e35e2e3 952 float fSqrt = 0;
j3 1:9e457e35e2e3 953 if( 0 < fData )
j3 1:9e457e35e2e3 954 {
j3 1:9e457e35e2e3 955 do
j3 1:9e457e35e2e3 956 {
j3 1:9e457e35e2e3 957 fSqrt = fWork;
j3 1:9e457e35e2e3 958 fWork = (fData / fWork + fWork) * 0.5f;
j3 1:9e457e35e2e3 959 }
j3 1:9e457e35e2e3 960 while( fWork < fSqrt );
j3 1:9e457e35e2e3 961 }
j3 1:9e457e35e2e3 962 *pfRet = fSqrt;
j3 1:9e457e35e2e3 963 }
j3 1:9e457e35e2e3 964
j3 1:9e457e35e2e3 965 return( bRet );
j3 1:9e457e35e2e3 966 }
j3 1:9e457e35e2e3 967
j3 1:9e457e35e2e3 968 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 969 Calculate features.
j3 1:9e457e35e2e3 970 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 971 BOOL bAMG_PUB_FEA_CalcCenterTemp( UCHAR ucWidth, UCHAR ucHeight, UCHAR ucLabelNo, UCHAR* pucImg, short* pshImg, short* pshRet )
j3 1:9e457e35e2e3 972 {
j3 1:9e457e35e2e3 973 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 974 USHORT usImg = 0;
j3 1:9e457e35e2e3 975 USHORT usSize = ucWidth * ucHeight;
j3 1:9e457e35e2e3 976 short shMin = SHORT_MAX_VAL;
j3 1:9e457e35e2e3 977 ULONG ulGx = 0;
j3 1:9e457e35e2e3 978 ULONG ulGy = 0;
j3 1:9e457e35e2e3 979 ULONG ulGw = 0;
j3 1:9e457e35e2e3 980
j3 1:9e457e35e2e3 981 if( FALSE != bAMG_PUB_FEA_CalcMinTemp( usSize, ucLabelNo, pucImg, pshImg, &shMin ) )
j3 1:9e457e35e2e3 982 {
j3 1:9e457e35e2e3 983 shMin -= 1;
j3 1:9e457e35e2e3 984 bRet = TRUE;
j3 1:9e457e35e2e3 985 }
j3 1:9e457e35e2e3 986 if( FALSE != bRet )
j3 1:9e457e35e2e3 987 {
j3 1:9e457e35e2e3 988 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 989 {
j3 1:9e457e35e2e3 990 if( ucLabelNo == pucImg[usImg] )
j3 1:9e457e35e2e3 991 {
j3 1:9e457e35e2e3 992 UCHAR ucImgX = usImg % ucWidth;
j3 1:9e457e35e2e3 993 UCHAR ucImgY = usImg / ucWidth;
j3 1:9e457e35e2e3 994 ULONG ulWeight = (ULONG)( pshImg[usImg] - shMin );
j3 1:9e457e35e2e3 995 ulGx += ulWeight * (ucImgX + 1);
j3 1:9e457e35e2e3 996 ulGy += ulWeight * (ucImgY + 1);
j3 1:9e457e35e2e3 997 ulGw += ulWeight;
j3 1:9e457e35e2e3 998 }
j3 1:9e457e35e2e3 999 }
j3 1:9e457e35e2e3 1000
j3 1:9e457e35e2e3 1001 if( 0 < ulGw )
j3 1:9e457e35e2e3 1002 {
j3 1:9e457e35e2e3 1003 pshRet[0] = ulGx * 256 / ulGw - 256;
j3 1:9e457e35e2e3 1004 pshRet[1] = ulGy * 256 / ulGw - 256;
j3 1:9e457e35e2e3 1005 }
j3 1:9e457e35e2e3 1006 else
j3 1:9e457e35e2e3 1007 {
j3 1:9e457e35e2e3 1008 pshRet[0] = 0;
j3 1:9e457e35e2e3 1009 pshRet[1] = 0;
j3 1:9e457e35e2e3 1010 }
j3 1:9e457e35e2e3 1011 }
j3 1:9e457e35e2e3 1012
j3 1:9e457e35e2e3 1013 return( bRet );
j3 1:9e457e35e2e3 1014 }
j3 1:9e457e35e2e3 1015
j3 1:9e457e35e2e3 1016 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 1017 Calculate features.
j3 1:9e457e35e2e3 1018 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 1019 BOOL bAMG_PUB_FEA_CalcCenterTemp_f( UCHAR ucWidth, UCHAR ucHeight, UCHAR ucLabelNo, UCHAR* pucImg, short* pshImg, float* pfRet )
j3 1:9e457e35e2e3 1020 {
j3 1:9e457e35e2e3 1021 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 1022 USHORT usImg = 0;
j3 1:9e457e35e2e3 1023 USHORT usSize = ucWidth * ucHeight;
j3 1:9e457e35e2e3 1024 short shMin = SHORT_MAX_VAL;
j3 1:9e457e35e2e3 1025 short shMax = SHORT_MIN_VAL;
j3 1:9e457e35e2e3 1026 short shDiff = 0;
j3 1:9e457e35e2e3 1027 float fGx = 0;
j3 1:9e457e35e2e3 1028 float fGy = 0;
j3 1:9e457e35e2e3 1029 float fGw = 0;
j3 1:9e457e35e2e3 1030
j3 1:9e457e35e2e3 1031 if( FALSE != bAMG_PUB_FEA_CalcMinTemp( usSize, ucLabelNo, pucImg, pshImg, &shMin ) )
j3 1:9e457e35e2e3 1032 {
j3 1:9e457e35e2e3 1033 shMin -= 1;
j3 1:9e457e35e2e3 1034 if( FALSE != bAMG_PUB_FEA_CalcMaxTemp( usSize, ucLabelNo, pucImg, pshImg, &shMax ) )
j3 1:9e457e35e2e3 1035 {
j3 1:9e457e35e2e3 1036 bRet = TRUE;
j3 1:9e457e35e2e3 1037 }
j3 1:9e457e35e2e3 1038 }
j3 1:9e457e35e2e3 1039 if( FALSE != bRet )
j3 1:9e457e35e2e3 1040 {
j3 1:9e457e35e2e3 1041 shDiff = shMax - shMin;
j3 1:9e457e35e2e3 1042 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 1043 {
j3 1:9e457e35e2e3 1044 if( ucLabelNo == pucImg[usImg] )
j3 1:9e457e35e2e3 1045 {
j3 1:9e457e35e2e3 1046 UCHAR ucImgX = usImg % ucWidth;
j3 1:9e457e35e2e3 1047 UCHAR ucImgY = usImg / ucWidth;
j3 1:9e457e35e2e3 1048 float fWeight = (float)( pshImg[usImg] - shMin ) / shDiff;
j3 1:9e457e35e2e3 1049 fGx += fWeight * (ucImgX + 1);
j3 1:9e457e35e2e3 1050 fGy += fWeight * (ucImgY + 1);
j3 1:9e457e35e2e3 1051 fGw += fWeight;
j3 1:9e457e35e2e3 1052 }
j3 1:9e457e35e2e3 1053 }
j3 1:9e457e35e2e3 1054
j3 1:9e457e35e2e3 1055 if( 0 < fGw )
j3 1:9e457e35e2e3 1056 {
j3 1:9e457e35e2e3 1057 pfRet[0] = fGx / fGw - 1;
j3 1:9e457e35e2e3 1058 pfRet[1] = fGy / fGw - 1;
j3 1:9e457e35e2e3 1059 }
j3 1:9e457e35e2e3 1060 else
j3 1:9e457e35e2e3 1061 {
j3 1:9e457e35e2e3 1062 pfRet[0] = 0;
j3 1:9e457e35e2e3 1063 pfRet[1] = 0;
j3 1:9e457e35e2e3 1064 }
j3 1:9e457e35e2e3 1065 }
j3 1:9e457e35e2e3 1066
j3 1:9e457e35e2e3 1067 return( bRet );
j3 1:9e457e35e2e3 1068 }
j3 1:9e457e35e2e3 1069
j3 1:9e457e35e2e3 1070 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 1071 Update background temperature.
j3 1:9e457e35e2e3 1072 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 1073 BOOL bAMG_PUB_BGT_UpdateBackTemp( USHORT usSize, UCHAR* pucImg, short* pshDiffImg, short shTh, short* pshBackImg )
j3 1:9e457e35e2e3 1074 {
j3 1:9e457e35e2e3 1075 const short c_shMinTh = 0;
j3 1:9e457e35e2e3 1076 const short c_shMaxTh = 256;
j3 1:9e457e35e2e3 1077 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 1078 USHORT usImg = 0;
j3 1:9e457e35e2e3 1079 short shAve = 0;
j3 1:9e457e35e2e3 1080
j3 1:9e457e35e2e3 1081 /* Adjust parameter. */
j3 1:9e457e35e2e3 1082 if( c_shMinTh > shTh )
j3 1:9e457e35e2e3 1083 {
j3 1:9e457e35e2e3 1084 shTh = c_shMinTh;
j3 1:9e457e35e2e3 1085 }
j3 1:9e457e35e2e3 1086 if( c_shMaxTh < shTh )
j3 1:9e457e35e2e3 1087 {
j3 1:9e457e35e2e3 1088 shTh = c_shMaxTh;
j3 1:9e457e35e2e3 1089 }
j3 1:9e457e35e2e3 1090
j3 1:9e457e35e2e3 1091 if( FALSE != bAMG_PUB_FEA_CalcAveTemp( usSize, 0, pucImg, pshDiffImg, &shAve ) )
j3 1:9e457e35e2e3 1092 {
j3 1:9e457e35e2e3 1093 bRet = TRUE;
j3 1:9e457e35e2e3 1094 for( usImg = 0; usImg < usSize; usImg++ )
j3 1:9e457e35e2e3 1095 {
j3 1:9e457e35e2e3 1096 short shTemp = 0;
j3 1:9e457e35e2e3 1097 if( 0 == pucImg[usImg] )
j3 1:9e457e35e2e3 1098 {
j3 1:9e457e35e2e3 1099 shTemp = (short)( (long)shTh * pshDiffImg[usImg] / c_shMaxTh );
j3 1:9e457e35e2e3 1100 }
j3 1:9e457e35e2e3 1101 else
j3 1:9e457e35e2e3 1102 {
j3 1:9e457e35e2e3 1103 shTemp = (short)( (long)shTh * shAve / c_shMaxTh );
j3 1:9e457e35e2e3 1104 }
j3 1:9e457e35e2e3 1105 pshBackImg[usImg] += shTemp;
j3 1:9e457e35e2e3 1106 }
j3 1:9e457e35e2e3 1107 }
j3 1:9e457e35e2e3 1108
j3 1:9e457e35e2e3 1109 return( bRet );
j3 1:9e457e35e2e3 1110 }
j3 1:9e457e35e2e3 1111
j3 1:9e457e35e2e3 1112 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 1113 Judge human.
j3 1:9e457e35e2e3 1114 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 1115 BOOL bAMG_PUB_HDT_JudgeHuman( USHORT usSize, USHORT usTh )
j3 1:9e457e35e2e3 1116 {
j3 1:9e457e35e2e3 1117 return( ( usTh < usSize ) ? TRUE : FALSE );
j3 1:9e457e35e2e3 1118 }
j3 1:9e457e35e2e3 1119
j3 1:9e457e35e2e3 1120 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 1121 Output.
j3 1:9e457e35e2e3 1122 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 1123 BOOL bAMG_PUB_OUT_CalcOutImage( UCHAR ucImgWidth, UCHAR ucImgHeight, UCHAR ucOutWidth, UCHAR ucOutHeight, short* pshCenter, UCHAR* pucCenter )
j3 1:9e457e35e2e3 1124 {
j3 1:9e457e35e2e3 1125 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 1126
j3 1:9e457e35e2e3 1127 if( (0 <= pshCenter[0]) && ((ucImgWidth-1) >= (pshCenter[0]/256)) )
j3 1:9e457e35e2e3 1128 {
j3 1:9e457e35e2e3 1129 if( (0 <= pshCenter[1]) && ((ucImgHeight-1) >= (pshCenter[1]/256)) )
j3 1:9e457e35e2e3 1130 {
j3 1:9e457e35e2e3 1131 bRet = TRUE;
j3 1:9e457e35e2e3 1132 pucCenter[0] = (UCHAR)( (long)pshCenter[0] * ucOutWidth / ((long)ucImgWidth * 256) );
j3 1:9e457e35e2e3 1133 pucCenter[1] = (UCHAR)( (long)pshCenter[1] * ucOutHeight / ((long)ucImgHeight * 256) );
j3 1:9e457e35e2e3 1134 }
j3 1:9e457e35e2e3 1135 }
j3 1:9e457e35e2e3 1136
j3 1:9e457e35e2e3 1137 return( bRet );
j3 1:9e457e35e2e3 1138 }
j3 1:9e457e35e2e3 1139
j3 1:9e457e35e2e3 1140 /*------------------------------------------------------------------------------
j3 1:9e457e35e2e3 1141 Output.
j3 1:9e457e35e2e3 1142 ------------------------------------------------------------------------------*/
j3 1:9e457e35e2e3 1143 BOOL bAMG_PUB_OUT_CalcOutImage_f( UCHAR ucImgWidth, UCHAR ucImgHeight, UCHAR ucOutWidth, UCHAR ucOutHeight, float* pfCenter, UCHAR* pucCenter )
j3 1:9e457e35e2e3 1144 {
j3 1:9e457e35e2e3 1145 BOOL bRet = FALSE;
j3 1:9e457e35e2e3 1146
j3 1:9e457e35e2e3 1147 if( (0 <= pfCenter[0]) && ((ucImgWidth-1) >= pfCenter[0]) )
j3 1:9e457e35e2e3 1148 {
j3 1:9e457e35e2e3 1149 if( (0 <= pfCenter[1]) && ((ucImgHeight-1) >= pfCenter[1]) )
j3 1:9e457e35e2e3 1150 {
j3 1:9e457e35e2e3 1151 bRet = TRUE;
j3 1:9e457e35e2e3 1152 pucCenter[0] = (UCHAR)( pfCenter[0] * ucOutWidth / (float)ucImgWidth );
j3 1:9e457e35e2e3 1153 pucCenter[1] = (UCHAR)( pfCenter[1] * ucOutHeight / (float)ucImgHeight );
j3 1:9e457e35e2e3 1154 }
j3 1:9e457e35e2e3 1155 }
j3 1:9e457e35e2e3 1156
j3 1:9e457e35e2e3 1157 return( bRet );
j3 1:9e457e35e2e3 1158 }
j3 1:9e457e35e2e3 1159