1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef bbf_SCAN_DETECTOR_EM_H 18 #define bbf_SCAN_DETECTOR_EM_H 19 20 /* ---- includes ----------------------------------------------------------- */ 21 22 #include "b_BasicEm/Context.h" 23 #include "b_BasicEm/Basic.h" 24 #include "b_BasicEm/UInt32Arr.h" 25 #include "b_BasicEm/Int16Arr.h" 26 #include "b_BasicEm/MemTbl.h" 27 #include "b_TensorEm/IdCluster2D.h" 28 #include "b_BitFeatureEm/Sequence.h" 29 #include "b_BitFeatureEm/BitParam.h" 30 #include "b_BitFeatureEm/Scanner.h" 31 32 /* ---- related objects --------------------------------------------------- */ 33 34 /* ---- typedefs ----------------------------------------------------------- */ 35 36 /* ---- constants ---------------------------------------------------------- */ 37 38 /* data format version number */ 39 #define bbf_SCAN_DETECTOR_VERSION 100 40 41 /* maximum number of features in scan detector */ 42 #define bbf_SCAN_DETECTOR_MAX_FEATURES 4 43 44 /* ---- object definition -------------------------------------------------- */ 45 46 /** discrete feature set */ 47 struct bbf_ScanDetector 48 { 49 /* ---- private data --------------------------------------------------- */ 50 51 /** minimum scale (12.20) */ 52 uint32 minScaleE; 53 54 /** maximum scale (0: unlimited) (12.20) */ 55 uint32 maxScaleE; 56 57 /** maximum image width (this variable must be specified before reading the parameter file) */ 58 uint32 maxImageWidthE; 59 60 /** maximum image height (this variable must be specified before reading the parameter file) */ 61 uint32 maxImageHeightE; 62 63 /** scanner */ 64 struct bbf_Scanner scannerE; 65 66 /* ---- public data ---------------------------------------------------- */ 67 68 /** patch width */ 69 uint32 patchWidthE; 70 71 /** patch height */ 72 uint32 patchHeightE; 73 74 /** minimum default scale (12.20) */ 75 uint32 minDefScaleE; 76 77 /** maximum default scale (0: unlimited) (12.20) */ 78 uint32 maxDefScaleE; 79 80 /** scale step factor (1.32) (leading bit is always one and therefore ignored) */ 81 uint32 scaleStepE; 82 83 /** overlap threshold (16.16) */ 84 uint32 overlapThrE; 85 86 /** border width in pixels (refers to scaled image) */ 87 uint32 borderWidthE; 88 89 /** border height in pixels (refers to scaled image) */ 90 uint32 borderHeightE; 91 92 /** number of features */ 93 uint32 featuresE; 94 95 /** bit param array */ 96 struct bbf_BitParam bitParamArrE[ bbf_SCAN_DETECTOR_MAX_FEATURES ]; 97 98 /** feature array */ 99 struct bbf_Sequence featureArrE[ bbf_SCAN_DETECTOR_MAX_FEATURES ]; 100 101 /** reference cluster */ 102 struct bts_IdCluster2D refClusterE; 103 104 /** reference distance (e.g. eye distance) in ref cluster (16.16) */ 105 uint32 refDistanceE; 106 107 }; 108 109 /* ---- associated objects ------------------------------------------------- */ 110 111 /* ---- external functions ------------------------------------------------- */ 112 113 /* ---- \ghd{ constructor/destructor } ------------------------------------- */ 114 115 /** initializes bbf_ScanDetector */ 116 void bbf_ScanDetector_init( struct bbs_Context* cpA, 117 struct bbf_ScanDetector* ptrA ); 118 119 /** resets bbf_ScanDetector */ 120 void bbf_ScanDetector_exit( struct bbs_Context* cpA, 121 struct bbf_ScanDetector* ptrA ); 122 123 /* ---- \ghd{ operators } -------------------------------------------------- */ 124 125 /** copy operator */ 126 void bbf_ScanDetector_copy( struct bbs_Context* cpA, 127 struct bbf_ScanDetector* ptrA, 128 const struct bbf_ScanDetector* srcPtrA ); 129 130 /** equal operator */ 131 flag bbf_ScanDetector_equal( struct bbs_Context* cpA, 132 const struct bbf_ScanDetector* ptrA, 133 const struct bbf_ScanDetector* srcPtrA ); 134 135 /* ---- \ghd{ query functions } -------------------------------------------- */ 136 137 /* ---- \ghd{ modify functions } ------------------------------------------- */ 138 139 /* ---- \ghd{ memory I/O } ------------------------------------------------- */ 140 141 /** word size (16-bit) object needs when written to memory */ 142 uint32 bbf_ScanDetector_memSize( struct bbs_Context* cpA, 143 const struct bbf_ScanDetector* ptrA ); 144 145 /** writes object to memory; returns number of words (16-bit) written */ 146 uint32 bbf_ScanDetector_memWrite( struct bbs_Context* cpA, 147 const struct bbf_ScanDetector* ptrA, uint16* memPtrA ); 148 149 /** reads object from memory; returns number of words (16-bit) read */ 150 uint32 bbf_ScanDetector_memRead( struct bbs_Context* cpA, 151 struct bbf_ScanDetector* ptrA, 152 const uint16* memPtrA, 153 struct bbs_MemTbl* mtpA ); 154 155 /* ---- \ghd{ exec functions } --------------------------------------------- */ 156 157 /** Scans over image returns number of detected positions 158 * After processing the output data are stored in composite format 159 * in scannerPtrA->outArrE. 160 * 161 * The output data array is located after execution at *outArrPtrPtrA. 162 * The output data are organized as follows: 163 * x(16.16) y(16.16), scale(12.20), confidence(4.28), x(16.16).... 164 * 165 * All positions are sorted by descending confidence 166 * 167 * If no faces were found, the function returns 0 but the output contains 168 * one valid position with the highest confidence; the associated activity 169 * value is negative (or 0) in that case. 170 * 171 * If roiPtrA is NULL, the whole image is considered for processsing 172 * otherwise *roiPtrA specifies a section of the original image to which 173 * processing is limited. All coordinates refer to that section and must 174 * eventually be adjusted externally. 175 * The roi rectangle must not include pixels outside of the original image 176 * (checked -> error). The rectangle may be of uneven width. 177 */ 178 uint32 bbf_ScanDetector_process( struct bbs_Context* cpA, 179 struct bbf_ScanDetector* ptrA, 180 const void* imagePtrA, 181 uint32 imageWidthA, 182 uint32 imageHeightA, 183 const struct bts_Int16Rect* roiPtrA, 184 int32** outArrPtrPtrA ); 185 186 #endif /* bbf_SCAN_DETECTOR_EM_H */ 187 188