您的位置:首页 > 运维架构

OpenCV 学习笔记

2014-01-23 17:27 375 查看
OpenCV 一直知道这东西,不过一直没研究过。。

想做人脸识别,学习一下下

先研究一下如何编译iPhone上使用的库。。 http://niw.at/articles/2009/03/14/using-opencv-on-iphone/en 讲的很好

下面这些是在使用时要注意的:


Using
OpenCV library in your own project

The demo application which you can download from my repository is
well configured to use these libraries. If you wanted to use OpenCV
libraries on your own project, you should need to adding next
configurations on it. You can see these settings on the Xcode
project of this demo application.

Add
libopencv_core.a
etc,
from OpenCV lib directory for either simulators or devices.
Actually Xcode doesn’t care which one is for devices or simulators
at this point because it is selected by the library search
path.

Add
Accelerate.framework
which
is used internally from OpenCV library.

Select your active build target, then open
the build tab in the info panel by Get Info menu.

Add
-lstdc++
and
-lz
to
Other Linker Flags

Add path to
OpenCV
include
directory
to Header Search Paths for both simulators and devices.

Add path to
OpenCV
lib
directory
to Library Search Paths for both simulators and
devices.

示例代码 https://github.com/niw/iphone_opencv_test
Aug 9, 2012
准备在OpenCV中使用PCA算法,一直没弄出来,这两天又研究了一下,找到一个不错的例子。

- (void)test

{

float a[] = {

1.5,2.3,

3.0,1.7,

1.2,2.9,

2.1,2.2,

3.1,3.1,

1.3,2.7,

2.0,1.7,

1.0,2.0,

0.5,0.6,

1.0,0.1

};

const int rows = 10, cols = 2;

CvMat* mat = cvCreateMat(rows, cols, CV_32FC1);

cvSetData(mat, a,
mat->step);

// std::cout
<< "original matrix: "
<< std::endl;

PrintMatrix(mat, rows, cols);

// std::cout
<< "================================"
<< std::endl;

const int dim = 2;
// dimension

CvMat* avg2 = cvCreateMat(1, cols, CV_32FC1);

CvMat* eigenVector2 = cvCreateMat(dim, cols, CV_32FC1);

CvMat* eigenValue2 = cvCreateMat(dim, 1, CV_32FC1);

// CvMat*
vector_pca=cvCreateMat(dim, 3, CV_32FC1);

cvCalcPCA(mat, avg2, eigenValue2,
eigenVector2, CV_PCA_DATA_AS_ROW);

//
cvProjectPCA(mat,avg2,eigenVector2,vector_pca);

// std::cout
<< "average2: "
<< std::endl;

PrintMatrix(avg2, 1, cols);

// std::cout
<< "eigenVector2: "
<< std::endl;

PrintMatrix(eigenVector2, dim, cols);

// std::cout
<< "eigenValues2: "
<< std::endl;

PrintMatrix(eigenValue2, dim, 1);

// std::cout
<< "================================"
<< std::endl;

// PrintMatrix(vector_pca,
dim, 3);

}

下面代码用来把RGBA的图像,转换成CvMat类型,用来进行特征值计算。

const
int rows = 100, cols = 100;

IplImage *img_src = Image1;

IplImage *img_resize =
cvCreateImage(cvSize(rows,cols), IPL_DEPTH_8U, 3);

cvResize(img_src, img_resize,
CV_INTER_LINEAR);

IplImage *img_gray =
cvCreateImage(cvSize(rows,cols), IPL_DEPTH_8U, 1);

cvCvtColor(img_resize,
img_gray, CV_RGB2GRAY);

CvMat *mat = cvCreateMat(rows, cols, CV_32FC1);

cvConvert(img_gray, mat); //得到转换成100*100维图片后转换成矩阵;

就这样就能算出一张人脸的特征值(识别部分OpenCVTest中提供的有),接下来详细的算法还待研究。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: