資源簡介
使用Hu矩進行形狀匹配
https://blog.csdn.net/LuohenYJ/article/details/88603274

代碼片段和文件信息
//
#include?“pch.h“
#include?
#include?“opencv2/opencv.hpp“
using?namespace?cv;
using?namespace?std;
int?main()
{
//是否進行log轉換
bool?showLogTransformedHuMoments?=?true;
//?Obtain?filename?圖像地址
string?filename(“./image/s0.png“);
//?Read?Image?讀圖
Mat?im?=?imread(filename?IMREAD_GRAYSCALE);
//?Threshold?image?閾值分割
threshold(im?im?0?255?THRESH_OTSU);
//?Calculate?Moments?計算矩
//第二個參數True表示非零的像素都會按值1對待,也就是說相當于對圖像進行了二值化處理,閾值為1
Moments?moment?=?moments(im?false);
//?Calculate?Hu?Moments?計算Hu矩
double?huMoments[7];
HuMoments(moment?huMoments);
//?Print?Hu?Moments
cout?<
for?(int?i?=?0;?i?7;?i++)
{
if?(showLogTransformedHuMoments)
{
//?Log?transform?Hu?Moments?to?make?squash?the?range
cout?<-1?*?copysign(1.0?huMoments[i])?*?log10(abs(huMoments[i]))?<“?“;
}
else
{
//?Hu?Moments?without?log?transform.?
cout?< }
}
//?One?row?per?file
cout?<
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-03-16?19:17??HuMoments\
?????文件????????1151??2019-03-16?18:49??HuMoments\HuMoments.cpp
?????文件?????????961??2019-03-16?18:49??HuMoments\HuMoments.py
?????目錄???????????0??2019-03-16?19:17??HuMoments\image\
?????文件????????5516??2019-02-21?14:06??HuMoments\image\K0.png
?????文件????????8079??2019-02-21?14:06??HuMoments\image\S0.png
?????文件???????17427??2019-02-21?14:06??HuMoments\image\S1.png
?????文件???????16459??2019-02-21?14:06??HuMoments\image\S2.png
?????文件???????17358??2019-02-21?14:06??HuMoments\image\S3.png
?????文件????????2467??2019-02-21?14:06??HuMoments\image\S4.png
?????文件???????17521??2019-02-21?14:06??HuMoments\image\S5.png
?????文件?????????681??2019-03-16?18:47??HuMoments\shapeMatcher.cpp
?????文件?????????631??2019-03-16?18:49??HuMoments\shapeMatcher.py
- 上一篇:graph.h
- 下一篇:llpdflib中文開發指南
評論
共有 條評論