博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OpenCV 学习笔记
阅读量:4072 次
发布时间:2019-05-25

本文共 2750 字,大约阅读时间需要 9 分钟。

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中提供的有),接下来详细的算法还待研究。

转载地址:http://ljeji.baihongyu.com/

你可能感兴趣的文章
IO口的作用
查看>>
UIView的使用setNeedsDisplay
查看>>
归档与解归档
查看>>
Window
查看>>
为什么button在设置标题时要用一个方法,而不像lable一样直接用一个属性
查看>>
字符串的截取
查看>>
2. Add Two Numbers
查看>>
17. Letter Combinations of a Phone Number (DFS, String)
查看>>
93. Restore IP Addresses (DFS, String)
查看>>
19. Remove Nth Node From End of List (双指针)
查看>>
49. Group Anagrams (String, Map)
查看>>
139. Word Break (DP)
查看>>
23. Merge k Sorted Lists (Divide and conquer, Linked List) 以及java匿名内部类
查看>>
Tensorflow入门资料
查看>>
剑指_用两个栈实现队列
查看>>
剑指_顺时针打印矩阵
查看>>
剑指_栈的压入弹出序列
查看>>
剑指_复杂链表的复制
查看>>
服务器普通用户(非管理员账户)在自己目录下安装TensorFlow
查看>>
星环后台研发实习面经
查看>>