//定義Canny邊緣檢測圖像
Mat canny_output;
vector<vector<Point> > contours;//是一個向量,並且是一個雙重向量,向量內每個元素保存了一組由連續的point點構成的點的集合的向量,每一組point點集就是一個輪廓,有多少輪廓,向量contours就有多少元素
vector<Vec4i> hierarchy;
vector<vector<Point> > contours
的功能是在openCV裏面找邊界。contours被定義成二維浮點型向量,這裏面將來會存儲找到的邊界(x,y)座標。
vector<Vec4i>hierarchy
是定義的層級。這個在找邊界findcontours
的時候會自動生成,這裏只是給它開闢一個空間。
//查找輪廓
findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
在 findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
就能算出邊界的座標,存在contours
裏面。