如何对轮廓的序列进行采样
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
为您提供轮廓上所有可能的点。
我使用 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
为您提供轮廓上所有可能的点。