【Mastering OpenCV with Practical CV Projects 之一】全文回顾

Mastering OpenCV with Practical Computer Vision Projects

Step-by-step tutorials to solve common real-world computer vision problems for desktop or mobile, from
augmented reality and number plate recognition to face recognition and 3D head tracking, based on OpenCV.

一、图像处理之Android

这部分实现简单图像处理算法在Andriod手机上应用,需要桌面端编写C/C++,然后,连接到Android设备,需要写一个Java GUI界面,这也是移动端常见的开发模式。

桌面端程序:

// ---------------------------------------------------
// Get access to the camera.
// VideoCapture camera;  
// camera.open("../dog.avi");  
VideoCapture camera;
initCamera(camera, cameraNumber);

// ---------------------------------------------------
// Get access to the webcam or video source. cameraNumber should be a number
// (eg: "0" or "1") but can also be a video file or stream URL.
void initCamera(VideoCapture &videoCapture, char* cameraNumber)
{
    // First try to access to the camera as a camera number such as 0
    try {   // Surround the OpenCV call by a try/catch block so we can give a useful error message!
        if ( isdigit(cameraNumber[0]) ) {
            videoCapture.open(atoi(cameraNumber));
        }
    } catch (cv::Exception &e) {}

    if ( !videoCapture.isOpened() ) {
        // Also try to access to the camera as a video file or URL.
        try {   // Surround the OpenCV call by a try/catch block so we can give a useful error message!
            videoCapture.open(cameraNumber);
        } catch (cv::Exception &e) {}

        if ( !videoCapture.isOpened() ) {
            cerr << "ERROR: Could not access the camera " << cameraNumber << " !" << endl;
            exit(1);
        }
    }
    cout << "Loaded camera " << cameraNumber << endl;
}

// ---------------------------------------------------
// Run the cartoonifier filter using the selected mode.
cartoonifyImage(cameraFrame, displayedFrame, m_sketchMode, m_alienMode, m_evilMode, debugType);

// show
imshow(windowName, displayedFrame);

Android上实现程序:

CartoonifierApp.java:
import android.view.Menu;
import android.view.MenuItem;
...

本章展示了如何将应用程序从桌面应用程序移植到Android移动应用程序中,遵循以下建议:首先开发一个工作桌面版本,将其移植到移动应用程序,并创建适合移动应用程序的用户界面。图像处理代码在两个项目之间共享,以便读者可以修改桌面应用程序的卡通过滤器,并且通过重建Android应用程序,它也应该自动显示Android应用程序中的修改。

二、增强现实之iPhone

这一节是在iPhone/iPad上创建一个AR应用,需要用XCode IDE建立App工程,调用OpenCV库。
OpenCV 是一个实时计算机视觉库. 最早是 Intel 组织开发,现在是由Willow Garage and Itseez维护.库是用 C and C++ languages. 官方也绑定 Python and 非官方绑定 Java and .NET languages.幸运的是这个库兼容多种平台, 因此,可以顺利应用在 iOS devices. 从 2.4.2版本起, OpenCV library 官方支持 iOS platform and 可以通过 website at http://opencv.org/ 下载 distribution package.
iOS platform 主要以 Objective-C 作为编程语言. 你可以在 AVFoundation framework上做开发, 我们的类也是通过 Objective-C 实现.
为了呈现3D虚拟物体,我们需要一个3D虚拟引擎,开源的或者商业的3D引擎有(Unity, Unreal Engine, Ogre, and so on). 他们还是通过 OpenGL or DirectX 从视频卡接收指令。
DirectX 优先考虑在Window平台. OpenGL则是比较可靠的 应用在cross-platform.
下面OpenCV实现图像处理类和OpenGL实现3D显示。
OpenCV
OpenGL
通过OpenCV接口函数调用OpenGL 3D引擎,实现静止图像、视频、摄像头的增强现实。

三、SfM

Structure from Motion (SfM),通过相机抓拍的图像,提取三维空间位姿关系。这里参考经典著作《Multiple View Geometry in Computer Vision》。
- 相机标定
通过OpenCV计算相机的本质矩阵E。
- 匹配
采用光流跟踪和KNN进行特征点匹配。
- 计算深度
Triangulation,是Hartley和Sturm提出的计算深度方法。OpenCV里直接调用库即可。
- 多视角重构
一种是通过估计相机位姿,也就是PNP;另一种方法是通过三角化更多3D点,通过ICP进行优化。
- 重建优化
这里采用Bundle Adjustment(BA)将空间点适配到整体模型;
- 可视化
通过PCL实现3D点云可视化。
最后,代码实现需要用到的OpenCV v2.4、PCL v1.6、SSBA v3.0或者更高版本。这部分也是和SLAM关系紧密的。

四、车牌识别之SVM和神经网络

Automatic Number Plate Recognition (ANPR),通过机动车辆车牌识别案例,介绍了图像分割,特征提取和模式识别算法,尤其是SVM(Support Vector Machines)和ANN(Artificial Neural Networks)。
针对运动车辆车牌识别,除了一些图像预处理工作,还需要以下几种模式识别算法:
1. Segmentation: This step detects and removes each patch/region of interest in the image
2. Feature extraction: This step extracts from each patch a set of characteristics.
3. Classification: This step extracts each character from the plate recognition step or classifies each image patch into “plate” or “no plate” in the plate-detection step.
综上所述,两步走,第一步在图像中找到车牌位置,通过SVM将车牌里的号码分离出来;第二步,提取每个号码的特征,利用神经网络分类识别字符。

五、人脸跟踪

本章通过OpenCV实现一个人脸跟踪应用,尤其是被跟踪的人提前知道的情况下,并且图像和路标标注的训练数据是可用的。
主要分为以下几个步骤:
1. Geometrical constraints
2. Facial feature detectors
3. Face detection and initialization
4. Face tracking
可能细心的同学发现,这里缺少数据标注,是的,我们需要借用工程中的标注工具。

六、三维位姿估计

本章将教你使用OpenCV如何创建一个活跃的自己外观模型以及如何使用它来搜索在给定的帧中你的模型位于最接近的位置。除此之外,你将通过学习Posit算法,在“姿势”图像中拟合3D模型。有了这些工具,你就可以实时追踪视频中的3D模型了。

七、人脸识别

本章将介绍人脸检测和人脸识别的原理,并提供一个检测脸部并识别它们的项目。

上面就是OpenCV动手实践的全部内容,学习完之后,基本上掌握OpenCV在图像领域的应用,往后,需要选择自己感兴趣的领域,融合更多的功能,实现产品需求。

代码下载地址, 见附录【2】.
文档下载地址,见附录【3】.
PCA详解, 见附录【4】


附录

【1】 http://PacktLib.PacktPub.com
【2】 https://github.com/070411209/Mastering-OpenCV3-Second-Edition
【3】 https://download.csdn.net/download/wangbaodong070411209/10491159
【4】 https://en.wikipedia.org/wiki/Principal_component_analysis
【5】https://docs.opencv.org/3.4.1/d3/d8d/classcv_1_1PCA.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值