Ask Your Question

what is the use of cvEigenDecomposite method in javacv

asked 2013-03-20 01:26:33 -0500

sujith.92 gravatar image

i'm new to opencv. i am trying to recognize face using javacv with the help of code got in internet but struck with the method cvEigenDecomposite. plesae explain the use of that function.

thanks in advance

edit retag flag offensive close merge delete

3 answers

Sort by ┬╗ oldest newest most voted

answered 2013-03-21 03:51:05 -0500

updated 2013-03-21 05:37:47 -0500

As far as I know Samuel Audet (the JavaCV lead dev) has written a wrapper for the cv::FaceRecognizer:

You can find an example on how to use it in Petter Christian Bjelland blog:

Now to your original question. I guess the names are misleading in the old OpenCV API. Let me attempt to explain it, but first give you an advice on using the OpenCV2 C++ API. I write this as a reference to people coming here from Google, so excuse if this is a lengthy answer. This may not directly apply to you using JavaCV, but for everyone else: I strongly suggest using the new OpenCV2 interface, just because the old C API is probably not supported in the future anymore.

Instead of cvCalcEigenObjects, cvEigenDecomposite and cvEigenProjection OpenCV now comes with the cv::PCA class, which makes performing a Principal Component Analysis really simple. Instead of going through it in-depth I am now pasting a sample (so people have it as a starting point) and then I'll answer your question on the old API.

This is an example to perform a Principal Component Analysis on a given set of images, in this example either with a hardcoded set of images or a CSV file. I think a modified version of this was added to the OpenCV documentation recently. By the way you'll find a source code example on using cv::PCA::project and cv::PCA::backProject in the documentation on cv::PCA:

 * Copyright (c) 2012. Philipp Wagner <bytefish[at]gmx[dot]de>.
 * Released to public domain under terms of the BSD Simplified license.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *   * Neither the name of the organization nor the names of its contributors
 *     may be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *   See <>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <fstream>
#include <sstream>

using namespace cv;
using namespace std;

// Reads the images and labels from a given CSV file, a valid file would
// look like this:
//      /path/to/person0/image0.jpg;0
//      /path/to/person0/image1.jpg;0
//      /path/to/person1/image0.jpg;1
//      /path/to/person1/image1.jpg;1
//      ...
void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels) {
    std::ifstream file(filename.c_str(), ifstream::in);
        throw std::exception();
    std::string line, path, classlabel;
    // For each line in the given file:
    while (std::getline(file, line)) {
        // Get the current line:
        std::stringstream liness(line);
        // Split it at the semicolon:
        std::getline(liness, path, ';');
        std::getline(liness ...
edit flag offensive delete link more



Nice guid! +1 for promoting the C++ API!

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-21 04:55:33 -0500 )edit

answered 2013-03-20 03:47:59 -0500

What it actually do is creating a representation of your input image. Read more into eigenfaces, which will explain the decomposition.

Basically, you have a set of eigenfaces, representing axes of a multidimensional space. There you want to transform your input image to and see which co├Ârdinates/parameters it gets for each axis. These results can than be compared with the parameters of stored faces by using a distance measure.

This link explains the principle a bit more:

edit flag offensive delete link more

answered 2015-03-09 23:20:08 -0500

Not sure if this would be the correct placement of this question.

I have been trying to implement face recognition in java using Opencv and Javacv libraries in eclipse. I searched for coding examples on this topic and i found a link showing that. But my problem is that there are functions like cvEigenDecomposite and cvCreateMat used in the example code. But cvEigenDecomposite generates error and also the function cvCreateMat produces error when taking CV_32FC1 as the last parameter. Does anyone have any idea on this? Has there been an alternative developed for this in the recent versions or am I missing something?

Please help me find an answer to this. Any help will be appreciated.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2013-03-20 01:26:33 -0500

Seen: 2,707 times

Last updated: Mar 21 '13