Skip to content

Commit

Permalink
fix: error when recognize training
Browse files Browse the repository at this point in the history
fix #156
  • Loading branch information
NateScarlet committed Aug 21, 2021
1 parent 899f22f commit 2d34537
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions auto_derby/single_mode/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def _ocr_training_effect(img: Image) -> int:
)
sharpened_img = imagetools.mix(sharpened_img, cv_img, 0.5)

white_outline_img = imagetools.constant_color_key(sharpened_img, (255, 255, 255))
white_outline_img = imagetools.constant_color_key(
sharpened_img,
(255, 255, 255),
(234, 245, 240),
)
white_outline_img = cv2.dilate(
white_outline_img,
cv2.getStructuringElement(
Expand All @@ -70,6 +74,7 @@ def _ocr_training_effect(img: Image) -> int:
(30, 109, 216),
(69, 104, 197),
(119, 139, 224),
(103, 147, 223),
)

bg_mask_img = imagetools.bg_mask_by_outline(brown_outline_img)
Expand All @@ -91,7 +96,7 @@ def _ocr_training_effect(img: Image) -> int:
assert fill_img.shape == cv_img.shape

text_img = imagetools.color_key(masked_img, fill_img)
imagetools.fill_area(text_img, (0,), size_lt=4)
imagetools.fill_area(text_img, (0,), size_lt=8)

text_img_extra = imagetools.constant_color_key(
masked_img, (175, 214, 255), threshold=0.95
Expand Down
25 changes: 25 additions & 0 deletions auto_derby/single_mode/training_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,31 @@ def test_update_by_training_scene_issue130():
assert partner1.has_hint == False


def test_update_by_training_scene_issue156():
with _test.screenshot("training_scene_issue156.png") as img:
training = Training.from_training_scene(img)
assert training.type == training.TYPE_SPEED
assert training.level == 1
assert training.speed == 21
assert training.stamina == 0
assert training.power == 13
assert training.guts == 0
assert training.wisdom == 0
assert training.skill == 4

assert len(training.partners) == 3, len(training.partners)
partner1, partner2, partner3 = training.partners
assert partner1.type == Partner.TYPE_POWER
assert partner1.level == 2
assert partner1.has_hint == False
assert partner2.type == Partner.TYPE_SPEED
assert partner2.level == 4
assert partner2.has_hint == False
assert partner3.type == Partner.TYPE_STAMINA
assert partner3.level == 4
assert partner3.has_hint == False


def benchmark_from_training_scene():
RUN_COUNT = 10
img = PIL.Image.open(_TEST_DATA_PATH / "training_scene_5.png").convert("RGB")
Expand Down

0 comments on commit 2d34537

Please sign in to comment.