Skip to content

Commit

Permalink
fix(single-mode): error when recognize training effect
Browse files Browse the repository at this point in the history
fix #24
  • Loading branch information
NateScarlet committed Jun 6, 2021
1 parent 7880e35 commit 03bbd86
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion auto_derby/imagetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def constant_color_key(img: np.ndarray, *colors: Tuple[int, ...], threshold: flo
return ret


def sharpen(img: np.ndarray, size: float = 1, *, bit_size: int = 8) -> np.ndarray:
def sharpen(img: np.ndarray, size: int = 1, *, bit_size: int = 8) -> np.ndarray:
return cv2.filter2D(
img,
bit_size,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions auto_derby/single_mode/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ def _gradient(colors: Tuple[


def _ocr_training_effect(img: Image) -> int:
cv_img = cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)

cv_img = cv2.cvtColor(
np.asarray(imagetools.resize_by_heihgt(img, 32)),
cv2.COLOR_RGB2BGR,
)
sharpened_img = imagetools.sharpen(cv_img)

outline_img = imagetools.color_key(
sharpened_img,
np.full_like(
sharpened_img,
cv_img,
(255, 255, 255),
),
0.95,
)
).clip(0, 255)

bg_mask_img = imagetools.bg_mask_by_outline(outline_img)
Expand All @@ -58,9 +59,13 @@ def _ocr_training_effect(img: Image) -> int:
((95, 179, 255), round(img.height * 0.63)),
((74, 157, 255), round(img.height * 0.70)),
((74, 117, 255), round(img.height * 0.83)),
((74, 117, 255), img.height),
((74, 117, 255), cv_img.shape[0]),
)).astype(np.uint8)
fill_img = np.repeat(np.expand_dims(fill_gradient, 1), img.width, axis=1)
fill_img = np.repeat(
np.expand_dims(fill_gradient, 1),
cv_img.shape[1],
axis=1,
)
assert fill_img.shape == cv_img.shape

fg_mask_img = 255 - bg_mask_img
Expand Down
12 changes: 12 additions & 0 deletions auto_derby/single_mode/training_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,15 @@ def test_update_by_training_scene_issue9():
assert training.guts == 0
assert training.wisdom == 0
assert training.skill == 2


def test_update_by_training_scene_issue24():
img = PIL.Image.open(
_TEST_DATA_PATH / "training_scene_issue24.png").convert("RGB")
training = Training.from_training_scene(img)
assert training.speed == 0
assert training.stamina == 9
assert training.power == 0
assert training.guts == 4
assert training.wisdom == 0
assert training.skill == 2

0 comments on commit 03bbd86

Please sign in to comment.