我如何在 opencv 中顺序访问轮廓
how do i access contour sequentially in opencv
我正在使用 opencv (cpp) 中的轮廓分割手写单词。但是在分段之后给出随机输出 contour.It 并不是像 word.Help 的从左到右排序那样我获得顺序。
假设你有类似下面的东西来提取轮廓:
// Contros found from input array
cv::Mat _src = src.getMat();
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
cv::findContours(_src, contours, hierarchy, CV_RETR_EXTERNAL,
params.contourDetMethod);
您可以遍历轮廓(此处 contors
)并使用 cv::boundingRect
创建边界框。现在您可以使用结果 Rect
与其他人的协调并找出它们的空间顺序。
我正在使用 opencv (cpp) 中的轮廓分割手写单词。但是在分段之后给出随机输出 contour.It 并不是像 word.Help 的从左到右排序那样我获得顺序。
假设你有类似下面的东西来提取轮廓:
// Contros found from input array
cv::Mat _src = src.getMat();
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
cv::findContours(_src, contours, hierarchy, CV_RETR_EXTERNAL,
params.contourDetMethod);
您可以遍历轮廓(此处 contors
)并使用 cv::boundingRect
创建边界框。现在您可以使用结果 Rect
与其他人的协调并找出它们的空间顺序。