简体   繁体   English

如何采样轮廓序列

[英]How to sampling the contour's sequence

I use opencv sobel filter to find the image's contour. 我使用opencv sobel滤镜查找图像的轮廓。

Now I want to sampling the contour's sequence such like {(0,1),(2,2),(3,4)...}. 现在,我想对轮廓序列进行采样,例如{(0,1),(2,2),(3,4)...}。

I need the algorithm can automatic separate each curve. 我需要可以自动分离每条曲线的算法。

Is there any algorithm in opencv or I have to do it by myself? opencv中是否有任何算法,或者我必须自己做?

I only think a simple way that scan the image and record the white point by deep first search but I think it performance isn't good. 我只认为通过深度优先搜索来扫描图像并记录白点的简单方法,但我认为它的性能不好。

What's wrong with findContours ? findContours什么问题?

Given an edge image, the purpose of findContours is to give you a two lists of structures, where one list gives you the pixel coordinates of each contour, and the other list gives a variety of pertinent information that belongs to each detected contour. 给定一个边缘图像, findContours的目的是为您提供两个结构列表,其中一个列表为您提供每个轮廓的像素坐标,而另一个列表为您提供属于每个检测到的轮廓的各种相关信息。

In C++, it's as simple as the following. 在C ++中,它很简单,如下所示。 Assuming your image is stored in a cv::Mat structure, you would do something like: 假设您的图像存储在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 contains information about the image topology. hierarchy包含有关图像拓扑的信息。 You can read this page on what the hierarchy means in more detail: http://docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_contours/py_contours_hierarchy/py_contours_hierarchy.html 您可以阅读此页面,了解有关层次结构的详细信息: http : //docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_contours/py_contours_hierarchy/py_contours_hierarchy.html

However, what you want to focus on is contours . 但是,您要关注的是contours It would be a vector containing vectors of points. 这将是一个包含点向量的向量。 Each element in contours would give you a list of Point structures that contain the (x,y) coordinates of a particular contour. contours每个元素都会为您提供一个Point结构列表,这些结构包含特定轮廓的(x,y)坐标。 CV_RETR_TREE gives you the full information of each contour, and CV_CHAIN_APPROX_NONE gives you all possible points along the contour. CV_RETR_TREE为您提供每个轮廓的完整信息,而CV_CHAIN_APPROX_NONE为您提供沿轮廓的所有可能点。

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

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