⛔ 修掉一个让狂气防线一直哑着的 bug: OCR 把 LUNACY 读成 UNACY
按计划任务的方式(pythonw, 无控制台)实跑, 发现"合成前狂气(OCR): None"重试
72 秒仍然读不到 —— 而同一块底栏的体力(read_enkephalin)却一直读得到。
同屏两个读数一个成一个不成, 说明是我的读取逻辑坏了, 不是画面问题。
dump 底栏 OCR 一眼就看到了:
UNACY @(674,795) <- 本来应该是 "LUNACY", 首字母 L 被吃掉
9699 @(664,823) <- 数字明明在
而代码写的是 `'LUNACY' in text` —— "UNACY" 不含 "LUNACY", 所以每次都被判成
"读不到", 狂气校验直接退化成 None -> 跳过比对。**第三道防线一直是形同虚设的**,
而且因为日志里只写"读不到", 看起来像是画面没渲染好, 很难往这个方向想。
修法: 认词根 "NACY"(LUNACY / UNACY / NACY 都能命中, 这个词根不会出现在别处);
再兜一层按位置找标签 —— 底栏那一带(y 775~815, x<700)最靠左的短文本元素。
实测修复后: 找到 'UNACY' @(674,795), read_lunacy() 连读三次都是 9699(稳定)。
新增 5 个用例(截断标签能认、完整标签能认、截断标签下能读出数字、标签完全读不出
时按位置兜底、彻底没有标签时返回 None)。全套 272/272 通过。
This commit is contained in:
@@ -43,6 +43,48 @@ class ScreenDetectTest(QuietLogMixin, unittest.TestCase):
|
|||||||
self.assertFalse(cm.panel_open('Window | Sinners | Drive'))
|
self.assertFalse(cm.panel_open('Window | Sinners | Drive'))
|
||||||
|
|
||||||
|
|
||||||
|
class LunacyLabelTest(QuietLogMixin, unittest.TestCase):
|
||||||
|
"""⛔ 实测坑: OCR 会把 "LUNACY" 读成 "UNACY"(首字母 L 被吃掉)。
|
||||||
|
|
||||||
|
原来写的是 `'LUNACY' in text`, 而 "UNACY" 不含 "LUNACY" —— 于是每次都被判成
|
||||||
|
"读不到", 狂气校验退化成 None -> 跳过比对, 第三道防线形同虚设。同一块底栏的
|
||||||
|
体力却一直读得到, 所以只看日志很难发现, 是 dump 了底栏 OCR 才抓到的。
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _with(self, its):
|
||||||
|
with mock.patch.object(cm, 'items', lambda: its):
|
||||||
|
return cm.find_lunacy_label()
|
||||||
|
|
||||||
|
def test_matches_truncated_label(self):
|
||||||
|
lab = self._with([{'text': 'UNACY', 'x': 674, 'y': 795, 'w': 44, 'h': 22}])
|
||||||
|
self.assertIsNotNone(lab)
|
||||||
|
self.assertEqual(lab['text'], 'UNACY')
|
||||||
|
|
||||||
|
def test_matches_full_label(self):
|
||||||
|
self.assertIsNotNone(self._with([{'text': 'LUNACY', 'x': 670, 'y': 795}]))
|
||||||
|
|
||||||
|
def test_full_read_works_with_truncated_label(self):
|
||||||
|
its = [{'text': 'UNACY', 'x': 674, 'y': 795, 'w': 44, 'h': 22},
|
||||||
|
{'text': '9699', 'x': 664, 'y': 823, 'w': 70, 'h': 37}]
|
||||||
|
with mock.patch.object(cm, 'items', lambda: its), \
|
||||||
|
mock.patch.object(cm.time, 'sleep', lambda s: None):
|
||||||
|
self.assertEqual(cm.read_lunacy(), 9699)
|
||||||
|
|
||||||
|
def test_falls_back_to_position_when_label_unreadable(self):
|
||||||
|
# 标签整个读不出来时, 按位置兜底: 底栏那一带最靠左的短文本
|
||||||
|
its = [{'text': '???', 'x': 674, 'y': 795, 'w': 44, 'h': 22},
|
||||||
|
{'text': '9699', 'x': 664, 'y': 823, 'w': 70, 'h': 37}]
|
||||||
|
lab = self._with(its)
|
||||||
|
self.assertIsNotNone(lab)
|
||||||
|
with mock.patch.object(cm, 'items', lambda: its), \
|
||||||
|
mock.patch.object(cm.time, 'sleep', lambda s: None):
|
||||||
|
self.assertEqual(cm.read_lunacy(), 9699)
|
||||||
|
|
||||||
|
def test_no_label_at_all_returns_none(self):
|
||||||
|
its = [{'text': 'Window', 'x': 994, 'y': 809}]
|
||||||
|
self.assertIsNone(self._with(its))
|
||||||
|
|
||||||
|
|
||||||
class ReadOwnedTest(QuietLogMixin, unittest.TestCase):
|
class ReadOwnedTest(QuietLogMixin, unittest.TestCase):
|
||||||
|
|
||||||
def test_reads_owned(self):
|
def test_reads_owned(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user