OpenCV學習 輪廓的特徵矩Moment

2021-06-27 18:27:54 字數 1595 閱讀 2962



opencv中的矩主要包括以下幾種:空間矩,中心矩和中心歸一化矩。

class moments

空間矩的公式為:

可以知道,對於01二值化的影象,m00即為輪廓的面積。 

中心矩的公式為:

其中:

歸一化的中心矩公式為:

矩的基本概念可參考:

在opencv中,還可以很方便的得到hu不變距,hu不變矩在影象旋轉、縮放、平移等操作後,仍能保持矩的不變性,所以有時候用hu不變距更能識別影象的特徵。hu不變矩的基本概念請參考*****:hu. visual pattern recognition by moment invariants, ire transactions on information theory, 8:2, pp. 179-187, 1962, 或者參考中文介紹:
opencv中計算矩的函式為:

moments moments

(inputarrayarray, boolbinaryimage=false )

hu不變矩主要是利用歸一化中心矩構造了7個不變特徵矩:

opencv中計算hu矩的公式為:

humoments

(const moments&m, outputarrayhu)

void humoments

(const moments&moments, doublehu[7])

matchshapes函式其實比較的是兩個輪廓的hu不變矩:

double comres;

comres = matchshapes(contours[0], contours[1],cv_contours_match_i1, 0.0);

printf("cv_contours_match_i1 比較結果是: %f\n", comres);

comres = matchshapes(contours[0], contours[1],cv_contours_match_i2, 0.0);

printf("cv_contours_match_i2 比較結果是: %f\n", comres);

comres = matchshapes(contours[0], contours[1],cv_contours_match_i3, 0.0);

printf("cv_contours_match_i3 比較結果是: %f\n", comres);

第三個引數決定比較的方式,下面是第三個引數的三個可選值。

opencv 輪廓特徵2

函式 moments moments inputarray array,bool binaryimage false 用來計算多邊形或珊格形狀的0 3階矩。moments類定義如下 classmoments mxx是0 3階矩,muxx是0 3階中心矩,nuxx是0 3階歸一化中心矩,公式如下 當計...

OpenCV 輪廓基本特徵

一 概述 我們通過cvfindcontours 函式獲取得影象輪廓有何作用呢?一般來說,我們對輪廓常用的操作有識別和處理,另外相關的還有多種對輪廓的處理,如簡化或擬合輪廓,匹配輪廓到模板,等等。我們在輪廓處理中經常需要對輪廓變化一些特徵進行概括,比如長度或者一些反映輪廓整體大小的度量。另外輪廓矩也是...

opencv 25 輪廓特徵屬性及應用之矩

double pointpolygontest inputarray contour,point2f pt,bool measuredist 計算點到輪廓的距離與位置關係 mat srcimg imread d 1 00.png imshow src srcimg cvtcolor srcimg,s...