我使用opencv sobel过滤器来查找图像的轮廓。
现在我想对轮廓序列进行采样,如{(0,1),(2,2),(3,4)......}。
我需要算法可以自动分离每条曲线。
opencv中是否有任何算法,或者我必须自己做?
我只想通过深度搜索扫描图像并记录白点的简单方法,但我认为它的表现并不好。
答案 0 :(得分:0)
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
为您提供沿轮廓的所有可能点。