From e79462277674d2906904792e8251e76012fff607 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Fri, 11 May 2012 11:48:26 +0000 Subject: [PATCH] propagated 2 fixed from 2.4 to trunk --- modules/core/doc/operations_on_arrays.rst | 2 +- samples/cpp/facerec_demo.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/core/doc/operations_on_arrays.rst b/modules/core/doc/operations_on_arrays.rst index 979e21fad3..81513192d3 100644 --- a/modules/core/doc/operations_on_arrays.rst +++ b/modules/core/doc/operations_on_arrays.rst @@ -1956,7 +1956,7 @@ The function ``mulSpectrums`` performs the per-element multiplication of the two The function, together with :ocv:func:`dft` and -:ocv:func:`idft` , may be used to calculate convolution (pass ``conj=false`` ) or correlation (pass ``conj=false`` ) of two arrays rapidly. When the arrays are complex, they are simply multiplied (per element) with an optional conjugation of the second-array elements. When the arrays are real, they are assumed to be CCS-packed (see +:ocv:func:`idft` , may be used to calculate convolution (pass ``conj=false`` ) or correlation (pass ``conj=true`` ) of two arrays rapidly. When the arrays are complex, they are simply multiplied (per element) with an optional conjugation of the second-array elements. When the arrays are real, they are assumed to be CCS-packed (see :ocv:func:`dft` for details). diff --git a/samples/cpp/facerec_demo.cpp b/samples/cpp/facerec_demo.cpp index 256773b2c3..8b6d7dd61b 100644 --- a/samples/cpp/facerec_demo.cpp +++ b/samples/cpp/facerec_demo.cpp @@ -25,6 +25,17 @@ using namespace cv; using namespace std; +Mat toGrayscale(InputArray _src) { + Mat src = _src.getMat(); + // only allow one channel + if(src.channels() != 1) + CV_Error(CV_StsBadArg, "Only Matrices with one channel are supported"); + // create and return normalized image + Mat dst; + cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1); + return dst; +} + void read_csv(const string& filename, vector& images, vector& labels, char separator = ';') { std::ifstream file(filename.c_str(), ifstream::in); if (!file) @@ -79,10 +90,10 @@ int main(int argc, const char *argv[]) { for (int i = 0; i < min(10, W.cols); i++) { // get eigenvector #i Mat ev = W.col(i).clone(); - // reshape to original site - Mat grayscale, cgrayscale; - cvtColor(ev.reshape(1, height), grayscale, COLOR_BGR2GRAY); + // reshape to original size AND normalize between [0...255] + Mat grayscale = toGrayscale(ev.reshape(1, height)); // show image (with Jet colormap) + Mat cgrayscale; applyColorMap(grayscale, cgrayscale, COLORMAP_JET); imshow(format("%d", i), cgrayscale); }