新分支 加入了标靶判断
This commit is contained in:
@@ -224,7 +224,7 @@ def detect_triangle_markers(
|
||||
blackhat_kernel_frac = 0.018
|
||||
try:
|
||||
import config as _tcfg
|
||||
_timing_log = bool(getattr(_tcfg, "TRIANGLE_TIMING_LOG", True))
|
||||
_timing_log = bool(getattr(_tcfg, "ARCHERY_TIMING_ENABLE", True)) and bool(getattr(_tcfg, "TRIANGLE_TIMING_LOG", True))
|
||||
except Exception:
|
||||
_timing_log = True
|
||||
|
||||
@@ -641,7 +641,40 @@ def detect_triangle_markers(
|
||||
med_l = float(np.median(legs))
|
||||
leg_dev = max(abs(l - med_l) / (med_l + 1e-6) for l in legs)
|
||||
|
||||
score = (diag_ratio - 1.0) * 3.0 + (h_ratio - 1.0) + (v_ratio - 1.0) + leg_dev * 2.0
|
||||
# 方向一致性:四个标靶角的直角顶点朝向应符合大致的四象限布局。
|
||||
# 对于相邻标靶很近的情况,这个方向信息能显著减少“把同一方向的两个三角混成一组”的误判。
|
||||
orient_pen = 0.0
|
||||
orient_vote = []
|
||||
for c in cands_4:
|
||||
cen = np.array(c["center_px"], dtype=np.float32)
|
||||
rpt = np.array(c["right_pt"], dtype=np.float32)
|
||||
vx = float(cen[0] - rpt[0])
|
||||
vy = float(cen[1] - rpt[1])
|
||||
# 方向太接近轴线时,说明顶点朝向不稳定,增加惩罚
|
||||
if abs(vx) < 1e-6 or abs(vy) < 1e-6:
|
||||
orient_pen += 1.0
|
||||
orient_vote.append(None)
|
||||
continue
|
||||
if abs(vx) < abs(vy) * 0.15 or abs(vy) < abs(vx) * 0.15:
|
||||
orient_pen += 0.5
|
||||
# 以中心相对右角顶点的方向做粗分类:TL=向右下,TR=向左下,BL=向右上,BR=向左上
|
||||
if vx > 0 and vy > 0:
|
||||
orient_vote.append(0)
|
||||
elif vx < 0 and vy > 0:
|
||||
orient_vote.append(1)
|
||||
elif vx > 0 and vy < 0:
|
||||
orient_vote.append(2)
|
||||
else:
|
||||
orient_vote.append(3)
|
||||
|
||||
# 如果 4 个候选的方向落点本身就重复很多,说明可能混入了别的靶标角,直接加罚。
|
||||
valid_votes = [v for v in orient_vote if v is not None]
|
||||
if valid_votes:
|
||||
from collections import Counter
|
||||
vc = Counter(valid_votes)
|
||||
orient_pen += max(0, max(vc.values()) - 1) * 0.8
|
||||
|
||||
score = (diag_ratio - 1.0) * 3.0 + (h_ratio - 1.0) + (v_ratio - 1.0) + leg_dev * 2.0 + orient_pen
|
||||
return score, (tl, bl, br, tr)
|
||||
|
||||
assigned = None
|
||||
@@ -947,7 +980,33 @@ def _assign_marker_ids_from_filtered(filtered, verbose=True):
|
||||
v_ratio = max(s_left, s_right) / (min(s_left, s_right) + 1e-6)
|
||||
med_l = float(np.median(legs))
|
||||
leg_dev = max(abs(l - med_l) / (med_l + 1e-6) for l in legs)
|
||||
score = (diag_ratio - 1.0) * 3.0 + (h_ratio - 1.0) + (v_ratio - 1.0) + leg_dev * 2.0
|
||||
orient_pen = 0.0
|
||||
orient_vote = []
|
||||
for c in cands_4:
|
||||
cen = np.array(c["center_px"], dtype=np.float32)
|
||||
rpt = np.array(c["right_pt"], dtype=np.float32)
|
||||
vx = float(cen[0] - rpt[0])
|
||||
vy = float(cen[1] - rpt[1])
|
||||
if abs(vx) < 1e-6 or abs(vy) < 1e-6:
|
||||
orient_pen += 1.0
|
||||
orient_vote.append(None)
|
||||
continue
|
||||
if abs(vx) < abs(vy) * 0.15 or abs(vy) < abs(vx) * 0.15:
|
||||
orient_pen += 0.5
|
||||
if vx > 0 and vy > 0:
|
||||
orient_vote.append(0)
|
||||
elif vx < 0 and vy > 0:
|
||||
orient_vote.append(1)
|
||||
elif vx > 0 and vy < 0:
|
||||
orient_vote.append(2)
|
||||
else:
|
||||
orient_vote.append(3)
|
||||
valid_votes = [v for v in orient_vote if v is not None]
|
||||
if valid_votes:
|
||||
from collections import Counter
|
||||
vc = Counter(valid_votes)
|
||||
orient_pen += max(0, max(vc.values()) - 1) * 0.8
|
||||
score = (diag_ratio - 1.0) * 3.0 + (h_ratio - 1.0) + (v_ratio - 1.0) + leg_dev * 2.0 + orient_pen
|
||||
return score, (tl, bl, br, tr)
|
||||
|
||||
assigned = None
|
||||
@@ -1113,7 +1172,7 @@ def try_triangle_scoring(
|
||||
|
||||
try:
|
||||
import config as _cfg_tl
|
||||
_try_timing_log = bool(getattr(_cfg_tl, "TRIANGLE_TIMING_LOG", True))
|
||||
_try_timing_log = bool(getattr(_cfg_tl, "ARCHERY_TIMING_ENABLE", True)) and bool(getattr(_cfg_tl, "TRIANGLE_TIMING_LOG", True))
|
||||
_crop_min_side = int(getattr(_cfg_tl, "TRIANGLE_CROP_ROI_MIN_SIDE_PX", 64))
|
||||
except Exception:
|
||||
_try_timing_log = True
|
||||
|
||||
Reference in New Issue
Block a user