* 物件提取
* 流程:
* 1.轉換成灰度影象,並且二值化
* 2. 通過膨脹消除洞洞
* 3. 二值圖取非運算,將物件的值設定為255
* 4. 計算物件二值圖的距離
* 5. 搜尋輪廓,繪製物件
輸出結果:
輸出結果
輸出結果
原始碼
#include#include
#include
int main(int argc, char* ar**)
cv::imshow("src",src);
cv::mat gray;
cv::cvtcolor(src,gray,cv::color_bgr2gray);
cv::mat graybinary;
cv::threshold(gray,graybinary,0,255,cv::thresh_binary|cv::thresh_otsu);
cv::imshow("gray binary",graybinary);
// 膨脹運算,腐蝕邊界
cv::dilate(graybinary,graybinary,cv::mat::ones(3,3,cv_8u),cv::point(-1,-1),3);
cv::imshow("gray binaty dilate",graybinary);
// 二值圖取非
cv::bitwise_not(graybinary,graybinary);
cv::imshow("bitwise_not", graybinary);
// 計算距離
cv::mat dist;
cv::distancetransform(graybinary,dist,cv::dist_l2,3);
cv::normalize(dist,dist,0,1,cv::norm_minmax);
cv::imshow("dist",dist);
// 距離二值化,分割貼上在一起的物件
cv::mat dist8u;
dist.convertto(dist8u,cv_8u);
cv::threshold(dist8u,dist8u,0,255,cv::thresh_binary|cv::thresh_otsu);
cv::imshow("dist binary",dist8u);
cv::dilate(dist8u,dist8u,cv::mat::ones(3,3,cv_8u),cv::point(-1,-1),3);
cv::imshow("dist binary dilate",dist8u);
// 繪製物件輪廓
cv::mat markers(src.size(),cv_8uc3);
cv::rng rng(123456);
for(int i =0; i cv::waitkey(0);
return 1;
}
opencv案例之物件提取
將中的某個元素,提取。這裡在黑白圖中扣取圓圈部分 include include include using namespace std using namespace cv define pic path work opencv pic define pic name case3.png intm...
opencv 火焰提取
在網上找了些 湊了湊 好歹實現了把火焰提取出來,演算法主要是ostu演算法,網上關於ostu的解釋很多,大家可以看看,我就直接貼圖了 了,圖大了點,希望對大家有用 如下 include cv.h include highgui.h include include include include os...
python 網路爬蟲之資訊標記與提取
find all name,attrs,recursive,string,kwargs 返回列表型別,儲存查詢結果 屬性說明 name 對標籤名稱的檢索字串,可以 attrs 對標籤屬性值的檢索字串,可標註屬性檢索 recursive 是否對子孫所有節點進行搜尋,預設true string 對標籤中...