使用OpenCV的PCACompute函数 [英] Using OpenCV's PCACompute function

查看:990
本文介绍了使用OpenCV的PCACompute函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Android版OpenCV来实现基于特征脸的面部识别.

I'm trying to implement facial recognition with eigenfaces, using OpenCV for Android.

我有一组训练图像,它们都是100x100像素的灰度图像.我目前正在使用Highgui.imread读取这些图像,因此每个图像都是一个宽度和高度为100的Mat.我正在尝试使用Core.PCACompute函数查找这组图像的主要成分.

I have a set of training images, which are all 100x100 pixel greyscale images. I am currently using Highgui.imread to read in these images, so each image is a Mat with a width and height of 100. I'm trying to use the Core.PCACompute function to find principal components of this set of images.

public static void PCACompute(Mat data, Mat mean, Mat eigenvectors, int maxComponents)

所以我的问题是:第一个参数(MAT数据)需要具有什么维度?即使数据只是一个Mat,也可以传递一组多张图像吗?

So my question is: what dimensions does the first argument (Mat data) need to have? Is it possible to pass it a set of multiple images even though data is only a single Mat?

还是我做错了,这不是用于特征脸的正确函数?我见过的一个教程使用了一个名为cvCalcEigenObjects的C ++函数,但是我找不到等效的Java方法...

Or am I doing it wrong, and this is not the correct function to use for eigenfaces? One tutorial I have seen uses a C++ function called cvCalcEigenObjects, but I am not able to find the equivalent Java method...

推荐答案

该函数需要单个Mat 作为输入.但是您可以传递数据像这样:

The function expects a single Mat as input. But you can pass data like this:

1711        public void testPCAComputeMatMatMat() {
1712            Mat data = new Mat(3, 4, CvType.CV_32F) {
1713                {
1714                    put(0, 0, 1, 2, 2, 4);
1715                    put(1, 0, 2, 4, 4, 8);
1716                    put(2, 0, 3, 6, 6, 12);
1717                }
1718            };
1719            Mat mean = new Mat();
1720            Mat vectors = new Mat();
1721    
1722            Core.PCACompute(data, mean, vectors);
1723    
1724            Mat mean_truth = new Mat(1, 4, CvType.CV_32F) {
1725                {
1726                    put(0, 0, 2, 4, 4, 8);
1727                }
1728            };
1729            Mat vectors_truth = new Mat(3, 4, CvType.CV_32F, new Scalar(0)) {
1730                {
1731                    put(0, 0, 0.2, 0.4, 0.4, 0.8);
1732                }
1733            };
1734            assertMatEqual(mean_truth, mean, EPS);
1735            assertMatEqual(vectors_truth, vectors, EPS);
1736        }

要开始使用面部识别,我建议您使用 doc ,因为它说明了 PCA会做什么.

To start playing with face recognition I suggest this doc, as it explains what PCA does.

此链接提供了一些信息和源代码,以使用图像进行训练来进行简单的人脸识别.

And this link provides some info and source code for doing simple face recognition using images for training.

这篇关于使用OpenCV的PCACompute函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆