1. 程式人生 > >opencv教程(一)(c++)

opencv教程(一)(c++)

opencv教程3.1.0(一)(c++)

opencv包含以下幾個模組,每個模組中包含一些共享或者靜態的庫
1.core:核心元件模組
基礎結構及操作,動態結構,陣列操作,繪圖函式、XML/YAML、聚類及實用程式和系統函式巨集。
2.Imagpro:影象處理模組
包括線性和非線性影象濾波,幾何影象變換(調整大小,仿射和透視扭曲,通用的基於表的重新對映),色彩空間轉換,直方圖等的影象處理模組。
3.video:視訊分析模組,包括運動估計,背景減除和物件跟蹤演算法。
4.calib3d:基本的多檢視幾何演算法,單個和立體相機校準,物體姿態估計,立體聲對應演算法和3D重建的元素。
5.features2d:2維特徵框架
特徵檢測與描述,特徵檢測提取匹配介面,關鍵點與匹配點繪圖及物件分類。
6.objdetect:檢測物件和預定義類的例項(例如,面部,眼睛,杯子,人,汽車等)。級聯分類器及SVM。
7.highgui:頂層GUI及視訊I/O
使用者介面,讀/寫影象及視訊,QT新功能。
cv Namespace


所有OpenCV類和函式都被放置在cv名稱空間中。 因此,要從程式碼訪問此功能,需使用cv :: specifier或使用名稱空間cv;
**個人理解是有了cv可以呼叫#include中的方法,兩者互相關聯。
1

#include "opencv2/core.hpp"
...
cv::Mat H = cv::findHomography(points1, points2, CV_RANSAC, 5);
...
  • 1
  • 2
  • 3
  • 4

2

#include "opencv2/core.hpp"
using namespace cv;
...
Mat H = findHomography(points1, points2, CV_RANSAC, 5 );
...
  • 1
  • 2
  • 3
  • 4
  • 5

為了防止cv可能與STL或者其他庫衝突,我們用第一種方法。
自動記憶體管理
opencv自動管理記憶體問題
首先,函式和方法使用的std :: vector,Mat和其他資料結構具有解構函式,在需要時釋放基礎記憶體緩衝區。 這意味著在Mat的情況下,解構函式並不總是釋放緩衝區。 他們考慮到可能的資料共享。 解構函式將與矩陣資料緩衝器相關聯的引用計數器遞減。 當且僅當引用計數器達到0時,即當沒有其他結構指向相同的緩衝區時,緩衝區被解除分配。 類似地,當Mat例項被複制時,實際資料不會被真正複製。 相反,引用計數器增加以記住擁有相同資料的另一個所有者。 還有Mat :: clone方法可以建立矩陣資料的完整副本。 見下面的例子:

// create a big 8Mb matrix
Mat A(1000, 1000, CV_64F);
// create another header for the same matrix;
// this is an instant operation, regardless of the matrix size.
Mat B = A;
// create another header for the 3-rd row of A; no data is copied either
Mat C = B.row(3);
 // now create a separate copy of the matrix
 Mat D = B.clone();
 // copy the 5-th row of B to C, that is, copy the 5-th row of A
// to the 3-rd row of A.
 B.row(5).copyTo(C);
// now let A and D share the data; after that the modified version
 // of A is still referenced by B and C.
 A = D;
 // now make B an empty matrix (which references no memory buffers),
 // but the modified version of A will still be referenced by C,
 // despite that C is just a single row of the original A
B.release();
 // finally, make a full copy of C. As a result, the big modified
// matrix will be deallocated, since it is not referenced by anyone
C = C.clone();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

輸出資料的自動分配
*灰度影象通道數量為一
限制