我已经使用MSER方法为文本区域准备了边框。我只能为一个边框增加边框大小。问题是我想使用“查找轮廓”方法增加所有预测的边界框的大小。我将在这里附上我的代码。
import cv2
import numpy as np
mser = cv2.MSER_create()
img = cv2.imread("C:/Users/Mani/Desktop/img/87.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
vis = img.copy()
coordinates, bboxes = mser.detectRegions(gray)
for bbox in bboxes:
x, y, w, h = bbox
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
cx = x + w//2
cy = y + h//2
cr = max(w,h)//2
dr = 10
idx=0
for i in bbox:
idx+=1
r = cr + i*dr
cv2.rectangle(vis,(cx-r,cy-r),(cx+r,cy+r),(0,255,0),2)
croped =img[cy-r:cy+r,cx-r:cx+r]
cv2.imshow("croped{}".format(i), croped)
答案 0 :(得分:0)
您总是选择bboxes
的最后一个。要处理它们,您可以将裁剪代码添加到第一个for循环中:
dr = 10
idx=0
for bbox in bboxes:
x, y, w, h = bbox
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
cx = x + w//2
cy = y + h//2
cr = max(w,h)//2
idx+=1
r = cr + i*dr
cv2.rectangle(vis,(cx-r,cy-r),(cx+r,cy+r),(0,255,0),2)
croped =img[cy-r:cy+r,cx-r:cx+r]
cv2.imshow("croped{}".format(i), croped)