| 12345678910111213141516171819202122232425262728293031 |
- """Remove recorded green reticle so the model learns the target shape, not the cursor."""
- from __future__ import annotations
- import cv2
- import numpy as np
- LOWER_HSV = np.array([40, 80, 80], dtype=np.uint8)
- UPPER_HSV = np.array([95, 255, 255], dtype=np.uint8)
- def green_reticle_mask(frame_bgr: np.ndarray) -> np.ndarray:
- hsv = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2HSV)
- mask = cv2.inRange(hsv, LOWER_HSV, UPPER_HSV)
- kernel = np.ones((5, 5), np.uint8)
- mask = cv2.dilate(mask, kernel, iterations=2)
- return mask
- def erase_green_reticle(frame_bgr: np.ndarray, fast: bool = True) -> np.ndarray:
- """Inpaint green reticle pixels. Real gameplay has no green cursor."""
- mask = green_reticle_mask(frame_bgr)
- if int(cv2.countNonZero(mask)) < 20:
- return frame_bgr
- if fast:
- # Much faster than TELEA; good enough for inference/display.
- blurred = cv2.GaussianBlur(frame_bgr, (21, 21), 0)
- out = frame_bgr.copy()
- out[mask > 0] = blurred[mask > 0]
- return out
- return cv2.inpaint(frame_bgr, mask, 3, cv2.INPAINT_TELEA)
|