電腦視覺: OpenCV 簡介
大綱 電腦視覺資料庫 (OpenCV) 功能簡介 環境設定 簡單的範例 OpenCV 專案 與Visual Studio 2012 C++ express整合 簡單的範例 讀圖&高斯模糊 開啟攝影機 OpenCV 專案 影像差異 人臉偵測 物件偵測
關於OpenCV OpenCV(開放原始碼之電腦視覺)包含眾多即時 電腦視覺功能的函式庫。 應用領域: 影像處理 人機介面(HCI) 物件辨識 影像切割 人臉辨識 手勢辨識 移動偵測 動作認知 場景重構(Structure From Motion) 立體聲和多台攝影機校正及深度計算 移動機器人視覺
HI! OpenCV http://opencv.org/ 從英特爾1999年發布OpenCV以來,功 能仍持續更新與增加中,目前由itseez 維護 最新的版本為2.4.8 (Dec. 2013) 1.x 的原始碼是用C語言編寫,2.x改以 C++編寫 跨平台: Windows, xNIX, MacOS, Android, iOS, etc… 超過2500個函式
Books
OpenCV 發展歷史 動機起源於讓電腦視覺有更低的門檻,並充分利 用 Intel 處理器的運算效能 Timeline: Gary Bradski (c) 2008 Gary Bradski, 2009
應用範例:自動駕駛
OpenCV Overview: > 2500 functions Robot support 通用圖像處理函式 影像金字塔 特徵描述 切割 攝影機校正 特徵擷取 轉換 工具和資料結構 追蹤 機器學習 偵測與辨識 Fitting 矩陣數學
OpenCV Structure CV MLL HighGUI CXCORE IPP Aux Image Processing and Vision Algorithms MLL Statistical Classifiers and Clustering Tools HighGUI GUI, Image and Video I/O CXCORE basic structures and algorithms, XML support, drawing functions IPP Fast architecture-specific low-level functions Aux Experimental or less used routines Gary Bradski, 2009 9 9
API Modules core - a compact module defining basic data structures, including the dense multi-dimensional array Mat and basic functions used by all other modules. imgproc - an image processing module that includes linear and non-linear image filtering, geometrical image transformations (resize, affine and perspective warping, generic table-based remapping), color space conversion, histograms, and so on. video - a video analysis module that includes motion estimation, background subtraction, and object tracking algorithms. calib3d - basic multiple-view geometry algorithms, single and stereo camera calibration, object pose estimation, stereo correspondence algorithms, and elements of 3D reconstruction. features2d - salient feature detectors, descriptors, and descriptor matchers. objdetect - detection of objects and instances of the predefined classes (for example, faces, eyes, mugs, people, cars, and so on). highgui - an easy-to-use interface to video capturing, image and video codecs, as well as simple UI capabilities. gpu - GPU-accelerated algorithms from different OpenCV modules.
下載 OpenCV for Windows OpenCV for Linux/Mac OpenCV for Android OpenCV for iOS
安裝與設定 使用 Visual Studio 2012 (中文) http://www.dotblogs.com.tw/v6610688/archive/20 13/10/25/image_process_intro_opencv.aspx http://www.cmlab.csie.ntu.edu.tw/~jsyeh/wiki/dok u.php?id=%E8%91%89%E6%AD%A3%E8%81%96% E8%80%81%E5%B8%AB:%E6%95%99%E7%A0%94 %E7%A9%B6%E7%94%9F%E5%AD%B8opencv http://docs.opencv.org/trunk/doc/tutorials/introdu ction/windows_visual_studio_Opencv/windows_ visual_studio_Opencv.html#windows-visual- studio-how-to
OpenCV Tutorials Core module: Image processing module
範例
讀圖及高斯模糊
讀圖及高斯模糊(處理結果)
存取像素 http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html#SECTION00053000000000000000
結果
開啟攝影機
影像差異 連續影像相減(Temporal differencing) 原理是利用再時間上連續的影像做一對 一的像素相減 若是兩者差異為零,就表示此像素不屬 於移動物件像素 反之,則此像素為移動物件像素。
簡介 由前後Frame相減,可以找出不相同的 部位 但無法看出動作的方向
Frame Difference 程式碼
優點及缺點 優點: 缺點: 計算簡單快速 此法對於環境的改變適應性佳 但是偵測出的移動物件常常會發生內部破 碎的情形 移動物件的形狀較不完整,對於後續的移 動物件追蹤與辨識將無法提供完整的資訊
人臉偵測
介紹 如何偵測具有特徵的物體,例如人臉?
挑戰 收集並標示數據是很重要的,但很花時 間 如何取得的想要的特徵 如何分類 如何測試或檢驗 還好,我們有openCV 即使是巢狀或串級的分類 如何測試或檢驗 還好,我們有openCV
How to use Try our package – FaceDetection FaceDetect.cmd Usage: facedetect [-- cascade="<cascade_path>"] [--nested-cascade[="nested_cascade_path"]] [--scale[=<image scale> [filename|camera_index] FaceDetect.exe 執行辨識的程式
正面臉部偵測 Facedetect --cascade="./haarcascades/haarcascade_frontalface_alt.xml” --nested-cascade="./haarcascades/haarcascade_eye.xml” --scale=1.3 先找到在正面的臉 接者尋找眼睛 縮放標記
試試其他模組 haarcascade_eye.xml haarcascade_eye_tree_eyeglasses.xml haarcascade_frontalface_alt.xml haarcascade_frontalface_alt2.xml haarcascade_frontalface_alt_tree.xml haarcascade_frontalface_default.xml haarcascade_fullbody.xml haarcascade_lefteye_2splits.xml haarcascade_lowerbody.xml haarcascade_mcs_eyepair_big.xml haarcascade_mcs_eyepair_small.xml haarcascade_mcs_lefteye.xml haarcascade_mcs_mouth.xml haarcascade_mcs_nose.xml haarcascade_mcs_righteye.xml haarcascade_mcs_upperbody.xml haarcascade_profileface.xml haarcascade_righteye_2splits.xml haarcascade_upperbody.xml
如何製作自己的Object Detector Collect a database of positive samples and a database of negative samples. Mark object by objectmarker.exe Build a vec file out of positive samples using createsamples.exe Run haartraining.exe to build the classifier. Run performance.exe to evaluate the classifier. Run haarconv.exe to convert classifier to .xml file
Links Original paper: http://research.microsoft.com/~viola/Pu bs/Detect/violaJones_CVPR2001.pdf How-to build a cascade of boosted classifiers based on Haar-like features: http://lab.cntl.kyutech.ac.jp/~kobalab/nis hida/opencv/OpenCV_ObjectDetection_ HowTo.pdf Objectmarker.exe and haarconv.exe, *.dll: http://www.iem.pw.edu.pl/~domanskj/ha arkit.rar http://note.sonots.com/SciSoftware/haar training.html
推薦的參考網站 Another Introduction http://cvinhais.homeip.net/opencv/Lectures/OPENCV_Lectur e1_Introduction.pdf Open Computer Vision Library (Sourceforge) http://sourceforge.net/projects/opencvlibrary/ OpenCV Official Forum http://tech.groups.yahoo.com/group/OpenCV/ OpenCV中文網站 http://www.opencv.org.cn/index.php/ 優質OpenCV教學網 http://yester-place.blogspot.com/ Learning OpenCV: Computer Vision with the OpenCV Library (Paperback) http://www.amazon.com/Learning-OpenCV-Computer-Vision- Library/dp/0596516134
參考資料 http://vbie.eic.nctu.edu.tw/vol_2/skill_7.htm http://vbie.eic.nctu.edu.tw/vol_13/tech1.htm http://www.cse.ohio- state.edu/~jwdavis/CVL/Research/MHI/mhi.h tml 特徵檢測專題 http://www.opencv.org.cn/index.php/%E7%89%B9 %E5%BE%81%E6%A3%80%E6%B5%8B%E4%B8%9 3%E9%A2%98