首页 > 解决方案 > 数字边界框 Opencv Python

问题描述

我正在尝试从门牌号码中提取边界框,这是我的代码,距离想要的结果还很远。

问题是,在这种情况下,该框不会将数字框起来

thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
original = img.copy()
# Find contours, obtain bounding box, extract and save ROI
ROI_number = 0
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
  rect = cv2.boundingRect(c)
  x,y,w,h = rect
  #x,y,w,h = cv2.boundingRect(c)
  if 100< w < 1000 and 100< h < 1000:
    print(x, y, w, h, w*h)
  
    cv2.rectangle(img, (x, y), (x + w, y + h), (36,255,12), 2)
    ROI = original[y:y+h, x:x+w]
    #cv2.imwrite('ROI_{}.png'.format(ROI_number), ROI)
    ROI_number += 1

原来的

在此处输入图像描述

盒装

在此处输入图像描述

标签: pythonimage-processingobject-detectionopencv-python

解决方案


推荐阅读