Fixed facerec_eigenfaces.cpp demo sample: it contained hardcoded values, which made wrong element access possible. Fixed unsigned integer/signed integer warnings in facerec.cpp.

This commit is contained in:
Philipp Wagner 2012-07-29 22:41:40 +02:00
parent f160c49473
commit 5983f8008f
2 changed files with 7 additions and 6 deletions

View File

@ -169,8 +169,9 @@ int main(int argc, const char *argv[]) {
imwrite(format("%s/eigenface_%d.png", output_folder.c_str(), i), norm_0_255(cgrayscale)); imwrite(format("%s/eigenface_%d.png", output_folder.c_str(), i), norm_0_255(cgrayscale));
} }
} }
// Display or save the image reconstruction at some predefined steps: // Display or save the image reconstruction at some predefined steps:
for(int num_components = 10; num_components < 300; num_components+=15) { for(int num_components = min(W.cols, 10); num_components < min(W.cols, 300); num_components+=15) {
// slice the eigenvectors from the model // slice the eigenvectors from the model
Mat evs = Mat(W, Range::all(), Range(0, num_components)); Mat evs = Mat(W, Range::all(), Range(0, num_components));
Mat projection = subspaceProject(evs, mean, images[0].reshape(1,1)); Mat projection = subspaceProject(evs, mean, images[0].reshape(1,1));

View File

@ -751,11 +751,11 @@ void LBPH::train(InputArray _src, InputArray _lbls) {
CV_Error(CV_StsBadArg, error_message); CV_Error(CV_StsBadArg, error_message);
} }
// append labels to _labels matrix // append labels to _labels matrix
for(int labelIdx = 0; labelIdx < labels.total(); labelIdx++) { for(size_t labelIdx = 0; labelIdx < labels.total(); labelIdx++) {
_labels.push_back(labels.at<int>(labelIdx)); _labels.push_back(labels.at<int>((int)labelIdx));
} }
// store the spatial histograms of the original data // store the spatial histograms of the original data
for(int sampleIdx = 0; sampleIdx < src.size(); sampleIdx++) { for(size_t sampleIdx = 0; sampleIdx < src.size(); sampleIdx++) {
// calculate lbp image // calculate lbp image
Mat lbp_image = elbp(src[sampleIdx], _radius, _neighbors); Mat lbp_image = elbp(src[sampleIdx], _radius, _neighbors);
// get spatial histogram from this lbp image // get spatial histogram from this lbp image
@ -788,11 +788,11 @@ void LBPH::predict(InputArray _src, int &minClass, double &minDist) const {
// find 1-nearest neighbor // find 1-nearest neighbor
minDist = DBL_MAX; minDist = DBL_MAX;
minClass = -1; minClass = -1;
for(int sampleIdx = 0; sampleIdx < _histograms.size(); sampleIdx++) { for(size_t sampleIdx = 0; sampleIdx < _histograms.size(); sampleIdx++) {
double dist = compareHist(_histograms[sampleIdx], query, CV_COMP_CHISQR); double dist = compareHist(_histograms[sampleIdx], query, CV_COMP_CHISQR);
if((dist < minDist) && (dist < _threshold)) { if((dist < minDist) && (dist < _threshold)) {
minDist = dist; minDist = dist;
minClass = _labels.at<int>(sampleIdx); minClass = _labels.at<int>((int) sampleIdx);
} }
} }
} }