Commit 6c18bec293a54b30909208e3ea81c63f4fba5e15
1 parent
cbd44c29
Indentation fixes
It looks worse than it is. De-indented some code, that’s all…
Showing
1 changed file
with
139 additions
and
139 deletions
openbr/plugins/cascade.cpp
| ... | ... | @@ -23,153 +23,153 @@ |
| 23 | 23 | |
| 24 | 24 | using namespace cv; |
| 25 | 25 | |
| 26 | - struct TrainParams{ | |
| 27 | - | |
| 28 | - public: | |
| 29 | - QString data; // REQUIRED: Filepath to store trained classifier | |
| 30 | - QString vec; // REQUIRED: Filepath to store vector of positive samples, default "vector" | |
| 31 | - QString img; // Filepath to source object image. Either this or info is REQUIRED | |
| 32 | - QString info; // Description file of source images. Either this or img is REQUIRED | |
| 33 | - QString bg; // REQUIRED: Filepath to background list file | |
| 34 | - int num; // Number of samples to generate | |
| 35 | - int bgcolor; // Background color supplied image (via img) | |
| 36 | - int bgthresh; // Threshold to determine bgcolor match | |
| 37 | - bool inv; // Invert colors | |
| 38 | - bool randinv; // Randomly invert colors | |
| 39 | - int maxidev; // Max intensity deviation of foreground pixels | |
| 40 | - double maxxangle; // Maximum rotation angle (X) | |
| 41 | - double maxyangle; // Maximum rotation angle (Y) | |
| 42 | - double maxzangle; // Maximum rotation angle (Z) | |
| 43 | - bool show; // Show generated samples | |
| 44 | - int w; // REQUIRED: Sample width | |
| 45 | - int h; // REQUIRED: Sample height | |
| 46 | - int numPos; // Number of positive samples | |
| 47 | - int numNeg; // Number of negative samples | |
| 48 | - int numStages; // Number of stages | |
| 49 | - int precalcValBufSize; // Precalculated val buffer size in Mb | |
| 50 | - int precalcIdxBufSize; // Precalculated index buffer size in Mb | |
| 51 | - bool baseFormatSave; // Save in old format | |
| 52 | - QString stageType; // Stage type (BOOST) | |
| 53 | - QString featureType; // Feature type (HAAR, LBP) | |
| 54 | - QString bt; // Boosted classifier type (DAB, RAB, LB, GAB) | |
| 55 | - double minHitRate; // Minimal hit rate per stage | |
| 56 | - double maxFalseAlarmRate; // Max false alarm rate per stage | |
| 57 | - double weightTrimRate; // Weight for trimming | |
| 58 | - int maxDepth; // Max weak tree depth | |
| 59 | - int maxWeakCount; // Max weak tree count per stage | |
| 60 | - QString mode; // Haar feature mode (BASIC, CORE, ALL) | |
| 61 | - | |
| 62 | - TrainParams(){ | |
| 63 | - num = -1; | |
| 64 | - maxidev = -1; | |
| 65 | - maxxangle = -1; | |
| 66 | - maxyangle = -1; | |
| 67 | - maxzangle = -1; | |
| 68 | - w = -1; | |
| 69 | - h = -1; | |
| 70 | - numPos = -1; | |
| 71 | - numNeg = -1; | |
| 72 | - numStages = -1; | |
| 73 | - precalcValBufSize = -1; | |
| 74 | - precalcIdxBufSize = -1; | |
| 75 | - minHitRate = -1; | |
| 76 | - maxFalseAlarmRate = -1; | |
| 77 | - weightTrimRate = -1; | |
| 78 | - maxDepth = -1; | |
| 79 | - maxWeakCount = -1; | |
| 80 | - inv = false; | |
| 81 | - randinv = false; | |
| 82 | - show = false; | |
| 83 | - baseFormatSave = false; | |
| 84 | - vec = "vector.vec"; | |
| 85 | - bgcolor = -1; | |
| 86 | - bgthresh = -1; | |
| 87 | - } | |
| 88 | - }; | |
| 26 | +struct TrainParams{ | |
| 27 | + | |
| 28 | +public: | |
| 29 | + QString data; // REQUIRED: Filepath to store trained classifier | |
| 30 | + QString vec; // REQUIRED: Filepath to store vector of positive samples, default "vector" | |
| 31 | + QString img; // Filepath to source object image. Either this or info is REQUIRED | |
| 32 | + QString info; // Description file of source images. Either this or img is REQUIRED | |
| 33 | + QString bg; // REQUIRED: Filepath to background list file | |
| 34 | + int num; // Number of samples to generate | |
| 35 | + int bgcolor; // Background color supplied image (via img) | |
| 36 | + int bgthresh; // Threshold to determine bgcolor match | |
| 37 | + bool inv; // Invert colors | |
| 38 | + bool randinv; // Randomly invert colors | |
| 39 | + int maxidev; // Max intensity deviation of foreground pixels | |
| 40 | + double maxxangle; // Maximum rotation angle (X) | |
| 41 | + double maxyangle; // Maximum rotation angle (Y) | |
| 42 | + double maxzangle; // Maximum rotation angle (Z) | |
| 43 | + bool show; // Show generated samples | |
| 44 | + int w; // REQUIRED: Sample width | |
| 45 | + int h; // REQUIRED: Sample height | |
| 46 | + int numPos; // Number of positive samples | |
| 47 | + int numNeg; // Number of negative samples | |
| 48 | + int numStages; // Number of stages | |
| 49 | + int precalcValBufSize; // Precalculated val buffer size in Mb | |
| 50 | + int precalcIdxBufSize; // Precalculated index buffer size in Mb | |
| 51 | + bool baseFormatSave; // Save in old format | |
| 52 | + QString stageType; // Stage type (BOOST) | |
| 53 | + QString featureType; // Feature type (HAAR, LBP) | |
| 54 | + QString bt; // Boosted classifier type (DAB, RAB, LB, GAB) | |
| 55 | + double minHitRate; // Minimal hit rate per stage | |
| 56 | + double maxFalseAlarmRate; // Max false alarm rate per stage | |
| 57 | + double weightTrimRate; // Weight for trimming | |
| 58 | + int maxDepth; // Max weak tree depth | |
| 59 | + int maxWeakCount; // Max weak tree count per stage | |
| 60 | + QString mode; // Haar feature mode (BASIC, CORE, ALL) | |
| 89 | 61 | |
| 90 | - QString buildTrainingArgs(TrainParams params){ | |
| 91 | - QString args = ""; | |
| 92 | - if (params.data != "") args += "-data " + params.data + " "; | |
| 93 | - else return ""; | |
| 94 | - if (params.vec != "") args += "-vec " + params.vec + " "; | |
| 95 | - else return ""; | |
| 96 | - if (params.bg != "") args += "-bg " + params.bg + " "; | |
| 97 | - else return ""; | |
| 98 | - if (params.numPos >= 0) args += "-numPos " + QString::number(params.numPos) + " "; | |
| 99 | - if (params.numNeg >= 0) args += "-numNeg " + QString::number(params.numNeg) + " "; | |
| 100 | - if (params.numStages >= 0) args += "-numStages " + QString::number(params.numStages) + " "; | |
| 101 | - if (params.precalcValBufSize >= 0) args += "-precalcValBufSize " + QString::number(params.precalcValBufSize) + " "; | |
| 102 | - if (params.precalcIdxBufSize >= 0) args += "-precalcIdxBufSize " + QString::number(params.precalcIdxBufSize) + " "; | |
| 103 | - if (params.baseFormatSave) args += "-baseFormatSave "; | |
| 104 | - if (params.stageType != "") args += "-stageType " + params.stageType + " "; | |
| 105 | - if (params.featureType != "") args += "-featureType " + params.featureType + " "; | |
| 106 | - if (params.w >= 0) args += "-w " + QString::number(params.w) + " "; | |
| 107 | - else return ""; | |
| 108 | - if (params.h >= 0) args += "-h " + QString::number(params.h) + " "; | |
| 109 | - else return ""; | |
| 110 | - if (params.bt != "") args += "-bt " + params.bt + " "; | |
| 111 | - if (params.minHitRate >= 0) args += "-minHitRate " + QString::number(params.minHitRate) + " "; | |
| 112 | - if (params.maxFalseAlarmRate >= 0) args += "-maxFalseAlarmRate " + QString::number(params.maxFalseAlarmRate) + " "; | |
| 113 | - if (params.weightTrimRate >= 0) args += "-weightTrimRate " + QString::number(params.weightTrimRate) + " "; | |
| 114 | - if (params.maxDepth >= 0) args += "-maxDepth " + QString::number(params.maxDepth) + " "; | |
| 115 | - if (params.maxWeakCount >= 0) args += "-maxWeakCount " + QString::number(params.maxWeakCount) + " "; | |
| 116 | - if (params.mode != "") args += "-mode " + params.mode + " "; | |
| 117 | - return args; | |
| 62 | + TrainParams(){ | |
| 63 | + num = -1; | |
| 64 | + maxidev = -1; | |
| 65 | + maxxangle = -1; | |
| 66 | + maxyangle = -1; | |
| 67 | + maxzangle = -1; | |
| 68 | + w = -1; | |
| 69 | + h = -1; | |
| 70 | + numPos = -1; | |
| 71 | + numNeg = -1; | |
| 72 | + numStages = -1; | |
| 73 | + precalcValBufSize = -1; | |
| 74 | + precalcIdxBufSize = -1; | |
| 75 | + minHitRate = -1; | |
| 76 | + maxFalseAlarmRate = -1; | |
| 77 | + weightTrimRate = -1; | |
| 78 | + maxDepth = -1; | |
| 79 | + maxWeakCount = -1; | |
| 80 | + inv = false; | |
| 81 | + randinv = false; | |
| 82 | + show = false; | |
| 83 | + baseFormatSave = false; | |
| 84 | + vec = "vector.vec"; | |
| 85 | + bgcolor = -1; | |
| 86 | + bgthresh = -1; | |
| 118 | 87 | } |
| 88 | +}; | |
| 119 | 89 | |
| 90 | +QString buildTrainingArgs(TrainParams params){ | |
| 91 | + QString args = ""; | |
| 92 | + if (params.data != "") args += "-data " + params.data + " "; | |
| 93 | + else return ""; | |
| 94 | + if (params.vec != "") args += "-vec " + params.vec + " "; | |
| 95 | + else return ""; | |
| 96 | + if (params.bg != "") args += "-bg " + params.bg + " "; | |
| 97 | + else return ""; | |
| 98 | + if (params.numPos >= 0) args += "-numPos " + QString::number(params.numPos) + " "; | |
| 99 | + if (params.numNeg >= 0) args += "-numNeg " + QString::number(params.numNeg) + " "; | |
| 100 | + if (params.numStages >= 0) args += "-numStages " + QString::number(params.numStages) + " "; | |
| 101 | + if (params.precalcValBufSize >= 0) args += "-precalcValBufSize " + QString::number(params.precalcValBufSize) + " "; | |
| 102 | + if (params.precalcIdxBufSize >= 0) args += "-precalcIdxBufSize " + QString::number(params.precalcIdxBufSize) + " "; | |
| 103 | + if (params.baseFormatSave) args += "-baseFormatSave "; | |
| 104 | + if (params.stageType != "") args += "-stageType " + params.stageType + " "; | |
| 105 | + if (params.featureType != "") args += "-featureType " + params.featureType + " "; | |
| 106 | + if (params.w >= 0) args += "-w " + QString::number(params.w) + " "; | |
| 107 | + else return ""; | |
| 108 | + if (params.h >= 0) args += "-h " + QString::number(params.h) + " "; | |
| 109 | + else return ""; | |
| 110 | + if (params.bt != "") args += "-bt " + params.bt + " "; | |
| 111 | + if (params.minHitRate >= 0) args += "-minHitRate " + QString::number(params.minHitRate) + " "; | |
| 112 | + if (params.maxFalseAlarmRate >= 0) args += "-maxFalseAlarmRate " + QString::number(params.maxFalseAlarmRate) + " "; | |
| 113 | + if (params.weightTrimRate >= 0) args += "-weightTrimRate " + QString::number(params.weightTrimRate) + " "; | |
| 114 | + if (params.maxDepth >= 0) args += "-maxDepth " + QString::number(params.maxDepth) + " "; | |
| 115 | + if (params.maxWeakCount >= 0) args += "-maxWeakCount " + QString::number(params.maxWeakCount) + " "; | |
| 116 | + if (params.mode != "") args += "-mode " + params.mode + " "; | |
| 117 | + return args; | |
| 118 | +} | |
| 120 | 119 | |
| 121 | - QString buildSampleArgs(TrainParams params){ | |
| 122 | - QString args = ""; | |
| 123 | - if (params.vec != "") args += "-vec "+params.vec+" "; | |
| 124 | - else return ""; | |
| 125 | - if (params.img != "") args += "-img " + params.img + " "; | |
| 126 | - else if (params.info != "") args += "-info " + params.info + " "; | |
| 127 | - else return ""; | |
| 128 | - if (params.bg != "") args += "-bg " + params.bg + " "; | |
| 129 | - if (params.num > 0) args += "-num " + QString::number(params.num) + " "; | |
| 130 | - if (params.bgcolor >=0 ) args += "-bgcolor " + QString::number(params.bgcolor) + " "; | |
| 131 | - if (params.bgthresh >= 0) args += "-bgthresh " + QString::number(params.bgthresh) + " "; | |
| 132 | - if (params.maxidev >= 0) args += "-maxidev " + QString::number(params.maxidev) + " "; | |
| 133 | - if (params.maxxangle >= 0) args += "-maxxangle " + QString::number(params.maxxangle) + " "; | |
| 134 | - if (params.maxyangle >= 0) args += "-maxyangle " + QString::number(params.maxyangle) + " "; | |
| 135 | - if (params.maxzangle >= 0) args += "-maxzangle " + QString::number(params.maxzangle) + " "; | |
| 136 | - if (params.w >= 0) args += "-w " + QString::number(params.w) + " "; | |
| 137 | - if (params.h >= 0) args += "-h " + QString::number(params.h) + " "; | |
| 138 | - if (params.show) args += "-show "; | |
| 139 | - if (params.inv) args += "-inv "; | |
| 140 | - if (params.randinv) args += "-randinv "; | |
| 141 | - return args; | |
| 142 | - } | |
| 143 | 120 | |
| 144 | - void execCommand(QString cmd, QString args){ | |
| 145 | - #ifdef _WIN32 | |
| 146 | - cmd += ".exe"; | |
| 147 | - #endif | |
| 148 | - cmd += " " + args; | |
| 149 | - system(cmd.toLocal8Bit().data()); | |
| 150 | - } | |
| 151 | - | |
| 152 | - void genSamples(TrainParams params, QString argStr = ""){ | |
| 153 | - QString cmdArgs = buildSampleArgs(params); | |
| 154 | - if (argStr != "") cmdArgs += " " + argStr; | |
| 155 | - execCommand("opencv_createsamples",cmdArgs); | |
| 156 | - } | |
| 121 | +QString buildSampleArgs(TrainParams params){ | |
| 122 | + QString args = ""; | |
| 123 | + if (params.vec != "") args += "-vec "+params.vec+" "; | |
| 124 | + else return ""; | |
| 125 | + if (params.img != "") args += "-img " + params.img + " "; | |
| 126 | + else if (params.info != "") args += "-info " + params.info + " "; | |
| 127 | + else return ""; | |
| 128 | + if (params.bg != "") args += "-bg " + params.bg + " "; | |
| 129 | + if (params.num > 0) args += "-num " + QString::number(params.num) + " "; | |
| 130 | + if (params.bgcolor >=0 ) args += "-bgcolor " + QString::number(params.bgcolor) + " "; | |
| 131 | + if (params.bgthresh >= 0) args += "-bgthresh " + QString::number(params.bgthresh) + " "; | |
| 132 | + if (params.maxidev >= 0) args += "-maxidev " + QString::number(params.maxidev) + " "; | |
| 133 | + if (params.maxxangle >= 0) args += "-maxxangle " + QString::number(params.maxxangle) + " "; | |
| 134 | + if (params.maxyangle >= 0) args += "-maxyangle " + QString::number(params.maxyangle) + " "; | |
| 135 | + if (params.maxzangle >= 0) args += "-maxzangle " + QString::number(params.maxzangle) + " "; | |
| 136 | + if (params.w >= 0) args += "-w " + QString::number(params.w) + " "; | |
| 137 | + if (params.h >= 0) args += "-h " + QString::number(params.h) + " "; | |
| 138 | + if (params.show) args += "-show "; | |
| 139 | + if (params.inv) args += "-inv "; | |
| 140 | + if (params.randinv) args += "-randinv "; | |
| 141 | + return args; | |
| 142 | +} | |
| 157 | 143 | |
| 144 | +void execCommand(QString cmd, QString args){ | |
| 145 | +#ifdef _WIN32 | |
| 146 | + cmd += ".exe"; | |
| 147 | +#endif | |
| 148 | + cmd += " " + args; | |
| 149 | + system(cmd.toLocal8Bit().data()); | |
| 150 | +} | |
| 158 | 151 | |
| 159 | - void trainCascade(TrainParams params,QString argStr = ""){ | |
| 160 | - QString cmdArgs = buildTrainingArgs(params); | |
| 161 | - if (argStr != "") cmdArgs += " " + argStr; | |
| 162 | - | |
| 163 | - execCommand("opencv_traincascade", cmdArgs); | |
| 164 | - } | |
| 165 | - | |
| 166 | - QString rectToString(QRectF r){ | |
| 167 | - QString out = " " + QString::number(r.x()) + " " + QString::number(r.y()) + " " + QString::number(r.width()) + " "+ QString::number(r.height()); | |
| 168 | - return out; | |
| 169 | - } | |
| 152 | +void genSamples(TrainParams params, QString argStr = ""){ | |
| 153 | + QString cmdArgs = buildSampleArgs(params); | |
| 154 | + if (argStr != "") cmdArgs += " " + argStr; | |
| 155 | + execCommand("opencv_createsamples",cmdArgs); | |
| 156 | +} | |
| 157 | + | |
| 158 | + | |
| 159 | +void trainCascade(TrainParams params,QString argStr = ""){ | |
| 160 | + QString cmdArgs = buildTrainingArgs(params); | |
| 161 | + if (argStr != "") cmdArgs += " " + argStr; | |
| 162 | + | |
| 163 | + execCommand("opencv_traincascade", cmdArgs); | |
| 164 | +} | |
| 165 | + | |
| 166 | +QString rectToString(QRectF r){ | |
| 167 | + QString out = " " + QString::number(r.x()) + " " + QString::number(r.y()) + " " + QString::number(r.width()) + " "+ QString::number(r.height()); | |
| 168 | + return out; | |
| 169 | +} | |
| 170 | 170 | |
| 171 | - namespace br | |
| 172 | - { | |
| 171 | +namespace br | |
| 172 | +{ | |
| 173 | 173 | |
| 174 | 174 | class CascadeResourceMaker : public ResourceMaker<CascadeClassifier> |
| 175 | 175 | { | ... | ... |