繁体   English   中英

如何采样轮廓序列

[英]How to sampling the contour's sequence

我使用opencv sobel滤镜查找图像的轮廓。

现在,我想对轮廓序列进行采样,例如{(0,1),(2,2),(3,4)...}。

我需要可以自动分离每条曲线的算法。

opencv中是否有任何算法,或者我必须自己做?

我只认为通过深度优先搜索来扫描图像并记录白点的简单方法,但我认为它的性能不好。

findContours什么问题?

给定一个边缘图像, findContours的目的是为您提供两个结构列表,其中一个列表为您提供每个轮廓的像素坐标,而另一个列表为您提供属于每个检测到的轮廓的各种相关信息。

在C ++中,它很简单,如下所示。 假设您的图像存储在cv::Mat结构中,您将执行以下操作:

#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;

Mat edge_output;  // Declare edge image
// ...
// ...
// Perform sobel detector on image and store in edge_output
// ...
//

// Declare a vector of Points and a vector to store the hierarchy
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

// Find contours
findContours(edge_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);

hierarchy包含有关图像拓扑的信息。 您可以阅读此页面,了解有关层次结构的详细信息: http : //docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_contours/py_contours_hierarchy/py_contours_hierarchy.html

但是,您要关注的是contours 这将是一个包含点向量的向量。 contours每个元素都会为您提供一个Point结构列表,这些结构包含特定轮廓的(x,y)坐标。 CV_RETR_TREE为您提供每个轮廓的完整信息,而CV_CHAIN_APPROX_NONE为您提供沿轮廓的所有可能点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM