openCV学习笔记(十二)-- 图像矩,点多边形距离测试

  1. 图像矩
  2. 点多边形距离测试

1. 图像矩
在这里插入图片描述
图像中心计算
在这里插入图片描述
计算矩的API
在这里插入图片描述
具体实现步骤
在这里插入图片描述
再找出图像的中心质点后,可以在输出图像中画出来
在这里插入图片描述
实现代码:

//图像矩
	#include<opencv2/opencv.hpp>
#include<math.h>
#include<iostream>

using namespace cv;
using namespace std;


Mat src,dst,gray_src,temp,dst1;
const char* output_win = "output_img";
RNG rng(12345);
int threshold_v = 100;
int threshold_max = 255;
void Demo_Moments(int, void*);
int main(int argc, char** argv) {
   
	src = imread("C:/Users/18929/Desktop/博客项目/项目图片/06.jpg");
	if (src.empty()) {
   
		printf("could not load image");
		return -1;
	}
	namedWindow("input_image", WINDOW_AUTOSIZE);
	namedWindow(output_win, WINDOW_AUTOSIZE);

	cvtColor(src, gray_src, CV_BGR2GRAY);
	//模糊一下,二值化时减少噪点
	blur(gray_src, gray_src, Size(3, 3), Point(-1, -1));

	imshow("input_image", gray_src);

	createTrackbar("Threshold Value", output_win, &threshold_v, threshold_max, Demo_Moments);
	Demo_Moments(0, 0);

	waitKey(0);
	return 0;

}

void Demo_Moments(int, void*) {
   
	Mat canny_output;
	vector<vector<Point>> contours;
	vector<Vec4i> hoerachy;

	Canny(gray_src, canny_output, threshold_v, threshold_v * 2, 3, false
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值