添加检测后处理参数score_mode=slow 增加识别率

This commit is contained in:
DogeVenci committed 2022-07-12 10:53:59 +08:00
1 parent 7b41085e26
commit 166dade003
3 files changed
+29 -1

No files matched your search

+1
View File
@@ -37,6 +37,7 @@ Det:
max_candidates: 1000
unclip_ratio: 1.6
use_dilation: true
score_mode: "fast"
Cls:
module_name: ch_ppocr_v2_cls
@@ -26,3 +26,4 @@ post_process:
max_candidates: 1000
unclip_ratio: 1.6
use_dilation: true
score_mode: "fast"
@@ -299,12 +299,14 @@ class DBPostProcess(object):
box_thresh=0.7,
max_candidates=1000,
unclip_ratio=2.0,
score_mode="fast",
use_dilation=False):
self.thresh = thresh
self.box_thresh = box_thresh
self.max_candidates = max_candidates
self.unclip_ratio = unclip_ratio
self.min_size = 3
self.score_mode = score_mode
if use_dilation:
self.dilation_kernel = np.array([[1, 1], [1, 1]])
@@ -337,7 +339,10 @@ class DBPostProcess(object):
if sside < self.min_size:
continue
points = np.array(points)
score = self.box_score_fast(pred, points.reshape(-1, 2))
if self.score_mode == "fast":
score = self.box_score_fast(pred, points.reshape(-1, 2))
else:
score = self.box_score_slow(pred, contour)
if self.box_thresh > score:
continue
@@ -400,6 +405,27 @@ class DBPostProcess(object):
box[:, 1] = box[:, 1] - ymin
cv2.fillPoly(mask, box.reshape(1, -1, 2).astype(np.int32), 1)
return cv2.mean(bitmap[ymin:ymax + 1, xmin:xmax + 1], mask)[0]
def box_score_slow(self, bitmap, contour):
'''
box_score_slow: use polyon mean score as the mean score
'''
h, w = bitmap.shape[:2]
contour = contour.copy()
contour = np.reshape(contour, (-1, 2))
xmin = np.clip(np.min(contour[:, 0]), 0, w - 1)
xmax = np.clip(np.max(contour[:, 0]), 0, w - 1)
ymin = np.clip(np.min(contour[:, 1]), 0, h - 1)
ymax = np.clip(np.max(contour[:, 1]), 0, h - 1)
mask = np.zeros((ymax - ymin + 1, xmax - xmin + 1), dtype=np.uint8)
contour[:, 0] = contour[:, 0] - xmin
contour[:, 1] = contour[:, 1] - ymin
cv2.fillPoly(mask, contour.reshape(1, -1, 2).astype(np.int32), 1)
return cv2.mean(bitmap[ymin:ymax + 1, xmin:xmax + 1], mask)[0]
def __call__(self, pred, shape_list):
pred = pred[:, 0, :, :]