修改原因:paddleocr自带的画框是下图所示(官方给出的一张图https://github.com/PaddlePaddle/PaddleOCR)
如果应用到工业上面,图片会非常大,且会遮挡原本不怎么清晰的文字,所以在tools/infer/utility.py改一下输出代码,直接添加下面代码
def draw_txt(image, boxes, txt=None, scores=None, drop_score=0.5,font_path="./doc/fonts/simfang.ttf"):
if scores is None:
scores = [1] * len(boxes)
box_num = len(boxes)
for i in range(box_num):
if scores is not None and (scores[i] < drop_score or
math.isnan(scores[i])):
continue
image1 = image
for i in range(len(txt)):
if txt == '':
break
if i == 0:
image1 = cv2.putText(np.array(image), txt[i],
(250,250*(i+1)), cv2.FONT_HERSHEY_SIMPLEX,
5.0, (255, 0, 0), 10)
else:
image1 = cv2.putText(np.array(image1), txt[i],
(250,250*(i+1)), cv2.FONT_HERSHEY_SIMPLEX,
5.0, (255, 0, 0), 10)
return np.array(image1)
然后tools/infer/predict_system.py中用draw_txt代替draw_ocr_box_txt(两个地方),上述代码编写文本位置(cv2.putText)可以自己调整自适应或者固定位置