mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2026-10-10 09:12:05 +00:00
feat: add area_center function and enhance OCR processing for white letters
This commit is contained in:
@@ -274,6 +274,20 @@ def area_size(area):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def area_center(area):
|
||||||
|
"""
|
||||||
|
Get the center of an area
|
||||||
|
|
||||||
|
Args:
|
||||||
|
area: (upper_left_x, upper_left_y, bottom_right_x, bottom_right_y)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
tuple: (x, y)
|
||||||
|
"""
|
||||||
|
x1, y1, x2, y2 = area
|
||||||
|
return (x1 + x2) / 2, (y1 + y2) / 2
|
||||||
|
|
||||||
|
|
||||||
def point_limit(point, area):
|
def point_limit(point, area):
|
||||||
"""
|
"""
|
||||||
Limit point in an area.
|
Limit point in an area.
|
||||||
|
|||||||
+19
-1
@@ -3,13 +3,14 @@ import time
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pponnxcr.predict_system import BoxedResult
|
from pponnxcr.predict_system import BoxedResult
|
||||||
|
|
||||||
import module.config.server as server
|
import module.config.server as server
|
||||||
from module.base.button import ButtonWrapper
|
from module.base.button import ButtonWrapper
|
||||||
from module.base.decorator import cached_property
|
from module.base.decorator import cached_property
|
||||||
from module.base.utils import area_pad, corner2area, crop, float2str
|
from module.base.utils import area_pad, corner2area, crop, extract_white_letters, float2str
|
||||||
from module.exception import ScriptError
|
from module.exception import ScriptError
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from module.ocr.keyword import Keyword
|
from module.ocr.keyword import Keyword
|
||||||
@@ -416,3 +417,20 @@ class Duration(Ocr):
|
|||||||
if number is None:
|
if number is None:
|
||||||
return 0
|
return 0
|
||||||
return int(number)
|
return int(number)
|
||||||
|
|
||||||
|
|
||||||
|
class OcrWhiteLetterOnComplexBackground(Ocr):
|
||||||
|
def pre_process(self, image):
|
||||||
|
image = extract_white_letters(image, threshold=255)
|
||||||
|
image = cv2.merge([image, image, image])
|
||||||
|
return image
|
||||||
|
|
||||||
|
def detect_and_ocr(self, *args, **kwargs):
|
||||||
|
# Try hard to lower TextSystem.box_thresh
|
||||||
|
backup = self.model.text_detector.box_thresh
|
||||||
|
self.model.text_detector.box_thresh = 0.2
|
||||||
|
|
||||||
|
result = super().detect_and_ocr(*args, **kwargs)
|
||||||
|
|
||||||
|
self.model.text_detector.box_thresh = backup
|
||||||
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user