没有合适的资源?快使用搜索试试~ 我知道了~
获取连通域(可根据面积筛选封闭图形)
5星 · 超过95%的资源 需积分: 50 45 下载量 12 浏览量
2018-11-19
08:47:25
上传
评论 2
收藏 4KB TXT 举报
温馨提示
试读
6页
利用opencv获取图像的连通域(并可根据面积筛选封闭图形)
资源推荐
资源详情
资源评论
#include <opencv2\opencv.hpp>
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <list>
using namespace std;
using namespace cv;
typedef struct _Feather
{
int label; // 连通域的label值
int area; // 连通域的面积
Rect boundingbox; // 连通域的外接矩形框
} Feather;
/*
Input:
src: 待检测连通域的二值化图像
Output:
dst: 标记后的图像
featherList: 连通域特征的清单
return:
连通域数量。
*/
int bwLabel(Mat & src, Mat & dst, vector<Feather> & featherList)
{
int rows = src.rows;
int cols = src.cols;
int labelValue = 0;
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <list>
using namespace std;
using namespace cv;
typedef struct _Feather
{
int label; // 连通域的label值
int area; // 连通域的面积
Rect boundingbox; // 连通域的外接矩形框
} Feather;
/*
Input:
src: 待检测连通域的二值化图像
Output:
dst: 标记后的图像
featherList: 连通域特征的清单
return:
连通域数量。
*/
int bwLabel(Mat & src, Mat & dst, vector<Feather> & featherList)
{
int rows = src.rows;
int cols = src.cols;
int labelValue = 0;
Point seed, neighbor;
stack<Point> pointStack; // 堆栈
int area = 0; // 用于计算连通域的面积
int leftBoundary = 0; // 连通域的左边界,即外接最小矩形的左边框,横坐标值,依此类推
int rightBoundary = 0;
int topBoundary = 0;
int bottomBoundary = 0;
Rect box; // 外接矩形框
Feather feather;
featherList.clear(); // 清除数组
dst.release();
dst = src.clone();
for (int i = 0; i < rows; i++)
{
uchar *pRow = dst.ptr<uchar>(i);
for (int j = 0; j < cols; j++)
{
if (pRow[j] == 255)
{
area = 0;
labelValue++; // labelValue最大为254,最小为1.
seed = Point(j, i); // Point(横坐标,纵坐标)
dst.at<uchar>(seed) = labelValue;
pointStack.push(seed);
area++;
leftBoundary = seed.x;
rightBoundary = seed.x;
stack<Point> pointStack; // 堆栈
int area = 0; // 用于计算连通域的面积
int leftBoundary = 0; // 连通域的左边界,即外接最小矩形的左边框,横坐标值,依此类推
int rightBoundary = 0;
int topBoundary = 0;
int bottomBoundary = 0;
Rect box; // 外接矩形框
Feather feather;
featherList.clear(); // 清除数组
dst.release();
dst = src.clone();
for (int i = 0; i < rows; i++)
{
uchar *pRow = dst.ptr<uchar>(i);
for (int j = 0; j < cols; j++)
{
if (pRow[j] == 255)
{
area = 0;
labelValue++; // labelValue最大为254,最小为1.
seed = Point(j, i); // Point(横坐标,纵坐标)
dst.at<uchar>(seed) = labelValue;
pointStack.push(seed);
area++;
leftBoundary = seed.x;
rightBoundary = seed.x;
剩余5页未读,继续阅读
资源评论
- dancyniu2020-10-16学习了算法不错
hhhhhhh_____
- 粉丝: 6
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功