python使用opencv查找轮廓_OpenCV Python:在imag中查找轮廓/边/矩形

我正在使用Python2.7.12和OpenCV 3.0.0-rc1

我正在做一个文本识别项目。

如您所见,图像包含许多“框”,其中有文本。

我的方法是找到这些盒子,把它们分割成不同的图像,然后把它们送给TesseractOCR。

程序将整个图像视为一个轮廓。

我怎样才能找到里面的那个小的?

或者,如果你有其他方法,欢迎

代码:import cv2

def threshold(im, method):

# make it grayscale

im_gray = cv2.cvtColor(im, cv2.COLOR_RGB2GRAY)

if method == 'fixed':

threshed_im = cv2.threshold(im_gray, 128, 255, cv2.THRESH_BINARY)

elif method == 'mean':

threshed_im = cv2.adaptiveThreshold(im_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 10)

elif method == 'gaussian':

threshed_im = cv2.adaptiveThreshold(im_gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 5, 7)

else:

return None

return threshed_im

image = cv2.imread('demo4.jpg')

# threshold it

thresh = threshold(image, 'mean')

# find contours

_, cnts, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

print len(cnts)

cv2.drawContours(image, cnts, -1, (0, 255, 0), 20)

cv2.imshow('contours', image)

cv2.waitKey()

cv2.drawContours(thresh, cnts, -1, (0, 255, 0), 20)

cv2.imshow('contours', thresh)

cv2.waitKey()

`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值