Skip to content

Commit 8c9b1bb

Browse files
committed
Upd: crop digit area before item amount ocr
1 parent 3422abc commit 8c9b1bb

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

module/island/storage.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import cv2
22
import numpy as np
33

4+
import module.config.server as server
5+
46
from module.base.button import ButtonGrid
57
from module.base.decorator import cached_property, del_cached_property
68
from module.base.timer import Timer
@@ -14,8 +16,36 @@
1416
from module.statistics.item import Item, ItemGrid
1517
from module.ui.page import page_island_storage
1618

17-
18-
AMOUNT_OCR = Digit([], lang='cnocr', letter=(218, 218, 218), name='Amount_ocr')
19+
AMOUNT_BACKGROUND_COLOR = (75, 76, 78)
20+
AMOUNT_THRESHOLD = 230
21+
22+
23+
class AmountOcr(Digit):
24+
def pre_process(self, image):
25+
mask = color_similarity_2d(image, AMOUNT_BACKGROUND_COLOR)
26+
bg = np.mean(mask > AMOUNT_THRESHOLD, axis=0)
27+
match = np.where(bg > 0.8)[0]
28+
if len(match):
29+
left = match[0]
30+
total = mask.shape[1]
31+
if left < total:
32+
image = image[:, left:]
33+
mask = mask[:, left:]
34+
brightness = np.min(mask, axis=0)
35+
match = np.where(brightness < AMOUNT_THRESHOLD)[0]
36+
if len(match):
37+
left = match[0]
38+
total = mask.shape[1]
39+
if left < total:
40+
image = image[:, left:]
41+
image = super().pre_process(image)
42+
return image
43+
44+
45+
if server.server == 'jp':
46+
AMOUNT_OCR = AmountOcr([], letter=(255, 255, 255), name='Amount_ocr')
47+
else:
48+
AMOUNT_OCR = AmountOcr([], lang='cnocr', letter=(218, 218, 218), name='Amount_ocr')
1949

2050

2151
class StorageItem(Item):
@@ -180,7 +210,7 @@ def storage_items(self):
180210
storage_grid,
181211
templates={},
182212
template_area=(0, 15, 96, 80),
183-
amount_area=(36, 85, 95, 100),
213+
amount_area=(36, 85, 95, 102),
184214
)
185215
storage_items.load_template_folder(self.storage_template_folder)
186216
storage_items.amount_ocr = AMOUNT_OCR

0 commit comments

Comments
 (0)