将NumberRecognizer移入recog,简化各处number写法
This commit is contained in:
parent
f084957e1e
commit
429f919d61
20 changed files with 101 additions and 501 deletions
|
@ -2,7 +2,6 @@ from datetime import datetime
|
|||
|
||||
import cv2
|
||||
|
||||
from mower.models import Digtal
|
||||
from mower.solvers.infra.base_mixin import BaseMixin
|
||||
from mower.solvers.infra.drone import DroneSolver
|
||||
from mower.solvers.infra.enter_room import EnterRoomSolver
|
||||
|
@ -85,30 +84,8 @@ class SwitchProductSolver(SceneGraphSolver, BaseMixin):
|
|||
img = cv2.resize(img, None, None, scale, scale)
|
||||
img = thres2(img, thres)
|
||||
img = cv2.bitwise_not(img)
|
||||
contours, _ = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
rect = [cv2.boundingRect(c) for c in contours]
|
||||
rect.sort(key=lambda c: c[0])
|
||||
|
||||
value = ""
|
||||
for x, y, w, h in rect:
|
||||
if h < 8 and w < 8:
|
||||
value += "."
|
||||
continue
|
||||
elif h < 20 and w < 20:
|
||||
continue
|
||||
digit = cropimg(img, ((x, y), (x + w, y + h)))
|
||||
digit = cv2.copyMakeBorder(
|
||||
digit, 10, 10, 10, 10, cv2.BORDER_CONSTANT, None, (0,)
|
||||
)
|
||||
score = []
|
||||
for i in range(10):
|
||||
im = Digtal().riic_base_digits[i]
|
||||
result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED)
|
||||
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
|
||||
score.append(min_val)
|
||||
value += str(score.index(min(score)))
|
||||
|
||||
return value
|
||||
rect_limits = [{"w": 20, "h": 20, "char": ""}, {"w": 8, "h": 8, "char": "."}]
|
||||
return config.recog.num.number("riic_base", img=img, rect_limits=rect_limits)
|
||||
|
||||
def read_speed(self) -> float:
|
||||
speed1 = self.number(((1185, 955), (1255, 977)), 17, 120)
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
from datetime import datetime, timedelta
|
||||
|
||||
import cv2
|
||||
|
||||
from mower.models import Digtal
|
||||
from mower.solvers.infra.enter_room import EnterRoomSolver
|
||||
from mower.utils import config
|
||||
from mower.utils import typealias as tp
|
||||
from mower.utils.email import send_message
|
||||
from mower.utils.graph import SceneGraphSolver
|
||||
from mower.utils.image import cmatch, cropimg, loadres, thres2
|
||||
from mower.utils.image import cmatch, cropimg, loadres
|
||||
from mower.utils.log import logger
|
||||
from mower.utils.recognize import Scene
|
||||
|
||||
|
@ -55,32 +52,7 @@ class ChooseProductSolver(SceneGraphSolver):
|
|||
|
||||
def number(self, scope: tp.Scope, height: int, thres: int) -> int:
|
||||
"数字识别"
|
||||
img = cropimg(config.recog.gray, scope)
|
||||
default_height = 25
|
||||
if height != default_height:
|
||||
scale = 25 / height
|
||||
img = cv2.resize(img, None, None, scale, scale)
|
||||
img = thres2(img, thres)
|
||||
contours, _ = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
rect = [cv2.boundingRect(c) for c in contours]
|
||||
rect.sort(key=lambda c: c[0])
|
||||
|
||||
value = 0
|
||||
|
||||
for x, y, w, h in rect:
|
||||
digit = cropimg(img, ((x, y), (x + w, y + h)))
|
||||
digit = cv2.copyMakeBorder(
|
||||
digit, 10, 10, 10, 10, cv2.BORDER_CONSTANT, None, (0,)
|
||||
)
|
||||
score = []
|
||||
for i in range(10):
|
||||
im = Digtal().riic_base_digits[i]
|
||||
result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED)
|
||||
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
|
||||
score.append(min_val)
|
||||
value = value * 10 + score.index(min(score))
|
||||
|
||||
return value
|
||||
return config.recog.num.number_int("riic_base", scope, height, thres)
|
||||
|
||||
def transition(self) -> bool:
|
||||
if (scene := self.scene()) == Scene.INFRA_DETAILS:
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
import cv2
|
||||
|
||||
from mower.models import Digtal
|
||||
from mower.solvers.infra.base_mixin import BaseMixin
|
||||
from mower.solvers.infra.enter_room import EnterRoomSolver
|
||||
from mower.utils import config
|
||||
from mower.utils import typealias as tp
|
||||
from mower.utils.graph import SceneGraphSolver
|
||||
from mower.utils.image import cropimg, thres2
|
||||
from mower.utils.recognize import Scene
|
||||
|
||||
|
||||
|
@ -30,34 +26,10 @@ class GetRemainTimeSolver(SceneGraphSolver, BaseMixin):
|
|||
|
||||
def number(self, scope: tp.Scope, height: int, thres: int) -> str:
|
||||
"数字识别"
|
||||
img = cropimg(config.recog.gray, scope)
|
||||
default_height = 25
|
||||
if height != default_height:
|
||||
scale = 25 / height
|
||||
img = cv2.resize(img, None, None, scale, scale)
|
||||
img = thres2(img, thres)
|
||||
contours, _ = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
rect = [cv2.boundingRect(c) for c in contours]
|
||||
rect.sort(key=lambda c: c[0])
|
||||
|
||||
value = ""
|
||||
for x, y, w, h in rect:
|
||||
if h < 7 and w < 7:
|
||||
value += ":"
|
||||
continue
|
||||
digit = cropimg(img, ((x, y), (x + w, y + h)))
|
||||
digit = cv2.copyMakeBorder(
|
||||
digit, 10, 10, 10, 10, cv2.BORDER_CONSTANT, None, (0,)
|
||||
)
|
||||
score = []
|
||||
for i in range(10):
|
||||
im = Digtal().riic_base_digits[i]
|
||||
result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED)
|
||||
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
|
||||
score.append(min_val)
|
||||
value += str(score.index(min(score)))
|
||||
|
||||
return value
|
||||
rect_limits = [{"w": 7, "h": 7, "char": ":"}]
|
||||
return config.recog.num.number(
|
||||
"riic_base", scope, height, thres, rect_limits=rect_limits
|
||||
)
|
||||
|
||||
def read_remain_time(self) -> int:
|
||||
h, m, s = self.number(((758, 670), (960, 705)), 30, 100).split("::")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue