图像矩

图像矩描述了图像的全局特征

一阶矩与形状有关

二阶距显示曲线围绕直线平均值的扩展程度

三阶矩是关于平均值的对称性测量

由二阶和三阶矩可以导出7个不变矩,不变矩是图像的统计特性,满足平移、伸缩、旋转的不变性

矩的计算:

1.C++ Moments moments(InputArray array,bool binaryImage=false)

用于计算多边形和光栅形状的最高达三阶的所有矩,用来计算形状的重心,面积,主轴等

2.C++ double contourArea(InputArray contour,bool oriented =false)

用于计算整个或者部分轮廓的面积

int main()
{
    vector contour;
	contour.push_back(Point2f(0,0));
	contour.push_back(Point2f(10,20));
	contour.push_back(Point2f(30,50));
	contour.push_back(Point2f(5,4));
	contour.push_back(Point2f(7,8));
	contour.push_back(Point2f(70,8));
	double area1=contourArea(contour);
	cout< points;
	approxPolyDP(contour,points,5,true);
	double area2=contourArea(points);
	cout<中心矩的计算方法是:某个矩除以0阶矩

m10/m00;Yc = m01/m00用来表示图像的重心

Mat src,dst;
int s_threshold=80;
void thresCallback(int,void*);

int main()
{
	src=imread("mangseng.jpg",0);
	
	namedWindow("a");
	createTrackbar("阈值","a",&s_threshold,255,thresCallback);
	thresCallback(s_threshold,0);

	waitKey(0);

}

void thresCallback(int,void*)
{
	Mat result;
	threshold(src,dst,s_threshold,255,THRESH_BINARY);
	vector> contour;
	vector hierarchy;
	result.create(dst.size(),CV_8UC3);//创建一个最后接受结果用的Mat

	findContours(dst,contour,hierarchy,RETR_CCOMP,CHAIN_APPROX_SIMPLE);
	//这里轮廓应该有很多个,还是要有一个循环遍历
	//计算图像的矩
    vector mu(contour.size());
	for(int i=0;i mc(contour.size());
	 for(int j=0;j(mu[j].m10/mu[j].m00),saturate_cast(mu[j].m01/mu[j].m00)) ;//计算中心的公式
	}

	//5.可视化
	for(int x=0;x


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值