Findcontours检索未排序的轮廓 [英] Findcontours retrieve contours unsorted

查看:96
本文介绍了Findcontours检索未排序的轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用适用于Android的opencv实现OCR,一切正常,直到使用Imgproc.findcontours()查找轮廓的部分为止,它以与输入图像中不同的顺序返回轮廓 IE : 输入图像M N O P从findcontours()获得的第一个轮廓是P 输入图像E F G H从findcontours()得到的第一个轮廓是E(在这里是正确的) 输入图像I J K L从findcontours()获得的第一个轮廓是J 所以看来它随机提取轮廓了,我们该如何解决呢?因为我们要退还图片中准确书写的字词

WE are implementing OCR using opencv for android, everything went fine till the part of findning contours using Imgproc.findcontours() it gives back the contours not in the same order as they were in the input image i.e : input image M N O P the first contour gets from findcontours() is P input image E F G H the first contour gets from findcontours() is E (here is right) input image I J K L the first contour gets from findcontours() is J so it seems that it extracts the contours randomly how can we fix this? because we want to give back the word as it was written exactly in the image

推荐答案

OpenCV在寻找轮廓时似乎没有任何顺序.如果需要对它进行排序,则应该手动进行,这是一项额外的任务.

OpenCV doesn't seems to have any order while finding contours. If we need it sorted we should do it manually, which is an extra task.

但是出于OCR的目的,我也遇到了这个问题.所以我要做的就是找到检测到的轮廓的质心.可以用片刻找出来.

But for OCR purposes, I too had this problem. So what i did was to find the centroids of the detected contours. It can be found out using moments.

使用矩来查找质心

或者您可以找到轮廓的边界框,然后找到该边界框的中心. ocr之后将数据放在相同的质心上.

Or you can find the bounding box of the contour, then find the center of that bounding box. Later after ocr put the data on the same centroid.

这是我自己准备OCR时使用的方法.您可以在此SOF问题中找到完整的详细信息:简单数字识别OpenCV-Python中的OCR

This was the method I used when I prepared OCR myself. You can find the complete details in this SOF question : Simple Digit Recognition OCR in OpenCV-Python

:FindContours的顺序(在发表评论后)

EDIT : Order of FindContours, (after comment from vasile)

原始图片:

找到轮廓的顺序:

这篇关于Findcontours检索未排序的轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆