opencv3 1 距離變換

2021-07-25 12:51:00 字數 1684 閱讀 3455

distancetransform函式:到邊緣點的距離(黑色的(0)都認為是邊緣)

兩種呼叫方式:distancetransform(edge, dist, disttype, masksize);

distancetransform(edge, dist, labels, disttype, masksize, labeltype);

顯示時候最好convert成0-255的uchar型別

如mat dis;

dist.convertto(dis , cv_8u, 1, 0);

imshow("dist",dis);

另外,opencv\sources\samples\cpp\distrans.cpp有偽彩色和維諾圖的顯示方式。

各引數定義

edge:邊緣影象

dist 32s的距離變換圖

disttype 距離型別

masksize:距離變換的mask,越大越費時間,精度會提高一些。

label :label圖,生成的是維諾圖,還能表示連通域when labeltype==dist_label_ccomp, the function scans through the input image and

marks all the zero pixels with distinct labels.

labeltype:可取 0 1兩個值  dist_label_ccomp時,每個黑色連通域的影象以及距離變換離他最小的地方會被標成同乙個label each connected component of zeros in src (as well as all the non-zero pixels closest to the

connected component) will be assigned the same label

dist_label_pixel = 1   /** each zero pixel (and all the non-zero pixels closest to it) gets its own label. */  每個區域得到自己的label

enum distancetypes {

dist_user    = -1,  //!< user defined distance                          //使用者自定義距離

dist_l1      = 1,   //!< distance = |x1-x2| + |y1-y2|                     //l1模距離

dist_l2      = 2,   //!< the ****** euclidean distance                 //l2模距離 歐氏距離

dist_c       = 3,   //!< distance = max(|x1-x2|,|y1-y2|)         

dist_l12     = 4,   //!< l1-l2 metric: distance = 2(sqrt(1+x*x/2) - 1))

dist_fair    = 5,   //!< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998

dist_welsch  = 6,   //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846

dist_huber   = 7    //!< distance = |x|用法

Opencv3 1基於Vibe去除前景

vibe.h 和vibe.cpp還有main函式 vibe.h include include opencv2 opencv.hpp using namespace cv using namespace std define num samples 20 每個畫素點的樣本個數 define min ...

深度學習2 安裝opencv3 1

2 以下內容來自 本人因為被坑過,所以建議各位最好在安裝caffe第三方庫前安裝 opencv。主要原因是caffe官網要安裝 apt get install libopencv dev 命令會導致你安裝的opencv版本與此產生版本衝突,所以建議先安裝opencv。不然你衝突了還要解除安裝重新安裝...

OpenCV 距離變換實現

距離變換實現影象的每個畫素到最近前景目標或到影象邊界的距離,距離變換的步驟如下 1.將影象進行二值化,子影象值為0,背景為255 2.利用maskl從左向右,從上到下掃瞄,p點是當前畫素點,q點是maskl中鄰域的點,d 為距離計算,包括棋盤距離 城市距離和歐式距離。f p 為p點的畫素值,計算f ...