Opencv 图像矩
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
Mat img1, img2, img3, img4, img_result, img_gray1, img_gray2, img_gray3, img_canny1;
char win1[] = "window1";
char win2[] = "window2";
char win3[] = "window3";
char win4[] = "window4";
char win5[] = "window5";
int thread_value = 100;
int max_value = 255;
RNG rng1(12345);
int Demo_Moments();
void Demo_1(int, void*);
//图像矩
int Demo_Moments()
{
namedWindow(win1, CV_WINDOW_AUTOSIZE);
namedWindow(win2, CV_WINDOW_AUTOSIZE);
//namedWindow(win3, CV_WINDOW_AUTOSIZE);
img1 = imread("D://images//19.png");
//img2 = imread("D://images//1//p5_1.jpg");
if (img1.empty())
{
cout << "could not load image..." << endl;
return 0;
}
imshow(win1, img1);
//img4 = Mat::zeros(img1.size(), CV_8UC3);
//转灰度图
cvtColor(img1, img_gray1, CV_BGR2GRAY);
//模糊处理
//blur(img_gray1, img2, Size(3, 3), Point(-1, -1), BORDER_DEFAULT);
GaussianBlur(img1, img2, Size(3, 3), 0, 0);
createTrackbar("track", win1, &thread_value, max_value, Demo_1);
Demo_1(0, 0);
return 0;
}
void Demo_1(int, void*)
{
vector<vector<Point>> vec_p;
vector<Vec4i> vec_4i;
img4 = Mat::zeros(img1.size(), CV_8UC3);
//threshold(img2, img3, thread_value, max_value, THRESH_BINARY);
Canny(img2, img3, thread_value, thread_value * 2, 3, false);
findContours(img3, vec_p, vec_4i, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));
//vector<vector<Point>> convexs(vec_p.size());
vector<Moments> contours_moments(vec_p.size());
vector<Point2f> ccs(vec_p.size());
for (size_t i = 0; i<vec_p.size(); i++)
{
contours_moments[i] = moments(vec_p[i]);
ccs[i] = Point(static_cast<float>(contours_moments[i].m10/contours_moments[i].m00),static_cast<float>(contours_moments[i].m01/contours_moments[i].m00));
}
for (size_t j = 0; j<vec_p.size(); j++)
{
if (vec_p[j].size() <100)
{
continue;
}
Scalar color_1 = Scalar(rng1.uniform(0, 255), rng1.uniform(0, 255), rng1.uniform(0, 255));
printf("center point x : %.2f y : %.2f\n", ccs[j].x, ccs[j].y);
printf("contours %d area : %.2f arc length : %.2f\n", j, contourArea(vec_p[j]), arcLength(vec_p[j], true));
drawContours(img4, vec_p, j, color_1, 2, LINE_8, vec_4i, 0, Point(0, 0));
circle(img4,ccs[j],2,color_1,2,8);
}
imshow(win2, img4);
}
int main()
{
Demo_Moments();
waitKey(0);
return 0;
}
--------------------------------------------------------------------------
center point x : 627.00 y : 607.00
contours 5 area : 68.00 arc length : 498.84
center point x : 534.00 y : 609.00
contours 7 area : 41.50 arc length : 300.15
center point x : 691.00 y : 611.00
contours 8 area : 20.00 arc length : 207.97
center point x : 896.00 y : 570.00
contours 10 area : 56.00 arc length : 478.90
center point x : 880.00 y : 479.00
contours 11 area : 103.00 arc length : 691.15
center point x : 721.00 y : 427.00
contours 12 area : 26.50 arc length : 320.84
center point x : 411.00 y : 364.00
contours 16 area : 32.50 arc length : 333.81
center point x : 282.00 y : 362.00
contours 18 area : 53.50 arc length : 543.83
center point x : 334.00 y : 439.00
contours 19 area : 150.50 arc length : 1344.58
center point x : 606.00 y : 397.00
contours 21 area : 38.50 arc length : 389.95
center point x : 1017.00 y : 425.00
contours 23 area : 88.50 arc length : 742.42
center point x : 1088.00 y : 352.00
contours 27 area : 46.50 arc length : 380.23
center point x : 723.00 y : 416.00
contours 37 area : 119.50 arc length : 1088.67
center point x : 851.00 y : 268.00
contours 40 area : 26.50 arc length : 361.46
center point x : 96.00 y : 336.00
contours 43 area : 63.00 arc length : 541.73
center point x : 739.00 y : 255.00
contours 47 area : 46.00 arc length : 432.82
center point x : 806.00 y : 253.00
contours 53 area : 56.50 arc length : 310.58
center point x : 556.00 y : 318.00
contours 56 area : 58.50 arc length : 492.17
center point x : 100.00 y : 186.00
contours 63 area : 12.50 arc length : 163.78
center point x : 552.00 y : 193.00
contours 65 area : 32.50 arc length : 318.49
center point x : 420.00 y : 199.00
contours 66 area : 44.50 arc length : 372.09
center point x : 400.00 y : 242.00
contours 67 area : 61.00 arc length : 519.73
center point x : 735.00 y : 187.00
contours 71 area : 50.50 arc length : 246.63
center point x : 350.00 y : 114.00
contours 75 area : 31.50 arc length : 267.52
center point x : 202.00 y : 184.00
contours 77 area : 83.50 arc length : 604.34
center point x : 299.00 y : 153.00
contours 79 area : 139.50 arc length : 1052.33
center point x : 761.00 y : 126.00
contours 83 area : 15.50 arc length : 298.55
center point x : 983.00 y : 66.00
contours 85 area : 51.50 arc length : 433.06
center point x : 533.00 y : 129.00
contours 86 area : 58.00 arc length : 515.19
center point x : 533.00 y : 143.00
contours 88 area : 79.50 arc length : 3004.34
--------------------------------------------------------------------------
Opencv 图像矩的更多相关文章
- opencv::图像矩(Image Moments)
矩的概念介绍 1.几何矩 2.中心距 3.中心归一化距 4.图像中心Center(x0, y0) 计算矩 moments( InputArray array, // 输入数据 bool binaryI ...
- opencv 3.2图像矩(Image Moments)
图像矩乍看比较难理解,看了很多资料,大概明白了一些,但还是无法在脑海里形成一个模型概念,于是从源码中寻找它的应用. 今天就通过公式和程序抓取数据,来进一步理解图像矩 先看一个图片 这是程序运行结果, ...
- OpenCV——图像的矩(计算矩、轮廓面积、轮廓或曲线长度)
图像矩描述了图像的全局特征 一阶矩与形状有关 二阶距显示曲线围绕直线平均值的扩展程度 三阶矩是关于平均值的对称性测量 由二阶和三阶矩可以导出7个不变矩,不变矩是图像的统计特性,满足平移.伸缩.旋转的不 ...
- OpenCV图像金字塔:高斯金字塔、拉普拉斯金字塔与图片尺寸缩放
这篇已经写得很好,真心给作者点个赞.题目都是直接转过来的,直接去看吧. Reference Link : http://blog.csdn.net/poem_qianmo/article/detail ...
- 【OpenCV新手教程之十三】OpenCV图像金字塔:高斯金字塔、拉普拉斯金字塔与图片尺寸缩放
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/26157633 作者:毛星云(浅墨) ...
- Opencv 图像叠加 添加水印
Opencv 图像叠加 添加水印 C++: void Mat::copyTo(OutputArray m) const C++: void Mat::copyTo(OutputArray m, Inp ...
- opencv图像读取-imread
前言 图像的读取和保存一定要注意imread函数的各个参数及其意义,尽量不要使用默认参数,否则就像数据格式出现错误(here)一样,很难查找错误原因的: re: 1.opencv图像的读取与保存; 完
- 学习 opencv---(12)OpenCV 图像金字塔:高斯金字塔,拉普拉斯金字塔与图片尺寸缩放
在这篇文章里,我们一起学习下 图像金字塔 的一些基本概念,如何使用OpenCV函数pyrUp和pyrDown 对图像进行向上和向下采样,以及了解专门用于缩放图像尺寸的resize函数的用法.此博文一共 ...
- [OpenCV Qt教程] 在Qt图形界面中显示OpenCV图像的OpenGL Widget(第二部分)
本文译自:http://www.robot-home.it/blog/en/software/tutorial-opencv-qt-opengl-widget-per-visualizzare-imm ...
随机推荐
- Spring Boot 入门之持久层篇(三)
原文地址:Spring Boot 入门之持久层篇(三) 博客地址:http://www.extlight.com 一.前言 上一篇<Spring Boot 入门之 Web 篇(二)>介绍了 ...
- python自动发送邮件
Python 的 smtplib 模块提供了发送电子邮件的功能.测试报告出来后,然后就把报告发送到邮箱. 一.先来看简单的列子 使用QQ邮箱发送邮件,使用的是授权码,需要先到QQ邮箱申请授权码. 邮箱 ...
- vue的动画组件(transition)
当插入或删除包含在 transition 组件中的元素时,Vue 将会做以下处理: 自动嗅探目标元素是否应用了 CSS 过渡或动画,如果是,在恰当的时机添加/删除 CSS 类名. v-enter: 定 ...
- java入门很简单之各种循环
1.if结构的语法: <1> 简单的if :if (条件){ //代码块 ...
- UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 7: ordinal not in range(128) [duplicate]
Python在往文件里写东西的时候,如果ascii码报错 参考 http://stackoverflow.com/questions/19833440/unicodeencodeerror-ascii ...
- phpstudy mysql无法启动
在安装好phpstudy后,Apache可以启动,Mysql无法启动. 以管理员的身份运行cmd,然后输入sc delete mysql 即可
- 【学步者日记】实现破碎效果 Fracturing & Destruction 插件使用
全文见原始链接:http://note.youdao.com/noteshare?id=ef5ef90b71da4e960e5bc0da4f3f17ec 下面是预览 示例工程链接:https://pa ...
- Codeforces-20152016-northwestern-european-regional-contest-nwerc-A题
一.题目 二.题意 (1)一开始理解成:它最多需要开多少台电脑.同时,我又有个疑问,既然是最多需要开多少台,那不变成了总共有几个人开几台是最大的结果.然后,WA了无数发.直到比赛结束......其实说 ...
- SQL DATE_SUB 函数用法
SQL DATE_SUB 是一个mySql函数.不象SQL DATE_ADD 函数 增加时间值,SQL DATE_SUB 将从一个日期/时间值中减去一个时间值(时间间隔). SQL DATE_SUB ...
- mongodb的安装(linux下)
1.去官网下载安装包 2.解压tar包 tar -zxvf filename 3.移动路径,并进入路径 mv mongodb-linux-x86_64-3.0.6/ /usr/local/mongod ...