字母似乎总是在数字的末尾。如果这是真的,您可以采用更简单的方法:找到所有轮廓
创建边界框列表(即每个轮廓对应一个框)
确定哪一个是最右边的边界框
使用所有其他框的(x,y,width,height)信息来创建一个ROI并只裁剪数字
Python 2.7和opencv2.4的源代码:import cv2
### load input image and convert it to grayscale
img = cv2.imread("input.png")
print("img shape=", img.shape)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#### extract all contours
_, contours, _ = cv2.findContours(gray.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# debug: draw all contours
#cv2.drawContours(img, contours, -1, (0, 0, 255), 2)
#cv2.imwrite("all_contours.jpg", img)
#### create one bounding box for every contour found
bb_