距离变换distanceTransform应用——寻找图像的质心
来源:互联网 发布:淘宝账号为什么会被盗 编辑:程序博客网 时间:2024/05/21 17:29
距离变换distanceTransform应用——寻找图像的质心
OpenCV中distanceTransform方法用于计算图像中每一个非零点距离离自己最近的零点的距离,distanceTransform的第二个Mat矩阵参数dst保存了每一个点与最近的零点的距离信息,图像上越亮的点,代表了离零点的距离越远。
可以根据距离变换的这个性质,经过简单的运算,用于细化字符的轮廓和查找物体质心(中心)。
#include "core/core.hpp" #include "imgproc/imgproc.hpp" #include "highgui/highgui.hpp" using namespace cv;int main(int argc, char *argv[]){ float maxValue = 0; //定义距离变换矩阵中的最大值 Point Pt(0, 0); Mat image = imread("corner.tif"); Mat imageGray; cvtColor(image, imageGray, CV_RGB2GRAY); imageGray = ~imageGray; //取反 GaussianBlur(imageGray, imageGray, Size(5, 5), 2); //滤波 threshold(imageGray, imageGray, 20, 200, CV_THRESH_BINARY); //阈值化 Mat imageThin(imageGray.size(), CV_32FC1); //定义保存距离变换结果的Mat矩阵 distanceTransform(imageGray, imageThin, CV_DIST_L2, 3); //距离变换 Mat distShow; distShow = Mat::zeros(imageGray.size(), CV_8UC1); //定义细化后的字符轮廓 for (int i = 0; i<imageThin.rows; i++) { for (int j = 0; j<imageThin.cols; j++) { distShow.at<uchar>(i, j) = imageThin.at<float>(i, j); if (imageThin.at<float>(i, j)>maxValue) { maxValue = imageThin.at<float>(i, j); //获取距离变换的极大值 Pt = Point(j, i); //坐标 } } } normalize(distShow, distShow, 0, 255, CV_MINMAX); //为了显示清晰,做了0~255归一化 circle(image, Pt, maxValue, Scalar(0, 0, 255), 3); circle(image, Pt, 3, Scalar(0, 255, 0), 3); imshow("Source Image", image); imshow("Thin Image", distShow); waitKey(); return 0;}
阅读全文
0 0
- 距离变换distanceTransform应用——寻找图像的质心
- Opencv距离变换distanceTransform应用——细化字符轮廓&&查找物体质心
- Opencv距离变换distanceTransform应用——细化字符轮廓&&查找物体质心
- Opencv距离变换distanceTransform应用——细化字符轮廓&&查找物体质心
- 距离变换distanceTransform应用——细化字符轮廓
- Opencv距离变换distanceTransform应用
- DistanceTransform(距离变换)
- 图像识别中距离变换的原理及作用详解,并附用OpenCV中的distanceTransform实现距离变换的代码!
- 用OpenCV的distanceTransform函数作图像的距离变换
- 基于distanceTransform-距离变换的手掌中心提取
- 基于distanceTransform-距离变换的手掌中心提取
- 关于距离变换函数distanceTransform使用注意事项
- OpenCV距离变换函数:distanceTransform()介绍
- 图像距离变换与应用
- 图像的距离变换---扫描
- opencv例程之图像的距离变换
- 二值图像的距离变换研究
- 基于距离变换的图像匹配
- linux下openvpn服务器搭建
- docker remote api 调用
- HDU-6070 Dirt Ratio
- uvalive 4329 Ping Pong(树状数组)
- Uboot到底如何启动内核
- 距离变换distanceTransform应用——寻找图像的质心
- Python-numpy
- Easyui-combobox使用
- MySql操作
- 数据库设计
- 清晰明了告诉你RequireJS 的使用。
- bootstrap中多个modal之间的切换
- 安装以及配置Maven
- 懒虫小鑫