mirror of
https://github.com/283375/arcaea-offline-ocr.git
synced 2025-04-18 13:00:18 +00:00
chore: code linting
This commit is contained in:
parent
76e6adbbf7
commit
17f6c2bac7
@ -25,3 +25,14 @@ src_paths = ["src/arcaea_offline_ocr"]
|
|||||||
|
|
||||||
[tool.pyright]
|
[tool.pyright]
|
||||||
ignore = ["**/__debug*.*"]
|
ignore = ["**/__debug*.*"]
|
||||||
|
|
||||||
|
[tool.pylint.main]
|
||||||
|
# extension-pkg-allow-list = ["cv2"]
|
||||||
|
generated-members = ["cv2.*"]
|
||||||
|
|
||||||
|
[tool.pylint.logging]
|
||||||
|
disable = [
|
||||||
|
"missing-module-docstring",
|
||||||
|
"missing-class-docstring",
|
||||||
|
"missing-function-docstring"
|
||||||
|
]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional, Union
|
from typing import Optional
|
||||||
|
|
||||||
import attrs
|
import attrs
|
||||||
|
|
||||||
|
@ -67,8 +67,9 @@ class DeviceOcr:
|
|||||||
roi = self.masker.score(self.extractor.score)
|
roi = self.masker.score(self.extractor.score)
|
||||||
contours, _ = cv2.findContours(roi, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
|
contours, _ = cv2.findContours(roi, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
|
||||||
for contour in contours:
|
for contour in contours:
|
||||||
x, y, w, h = cv2.boundingRect(contour)
|
if (
|
||||||
if h < roi.shape[0] * 0.6:
|
cv2.boundingRect(contour)[3] < roi.shape[0] * 0.6
|
||||||
|
): # h < score_component_h * 0.6
|
||||||
roi = cv2.fillPoly(roi, [contour], [0])
|
roi = cv2.fillPoly(roi, [contour], [0])
|
||||||
return ocr_digits_by_contour_knn(roi, self.knn_model)
|
return ocr_digits_by_contour_knn(roi, self.knn_model)
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ from .common import DeviceRoisMasker
|
|||||||
|
|
||||||
|
|
||||||
class DeviceRoisMaskerAuto(DeviceRoisMasker):
|
class DeviceRoisMaskerAuto(DeviceRoisMasker):
|
||||||
|
# pylint: disable=abstract-method
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mask_bgr_in_hsv(roi_bgr: Mat, hsv_lower: Mat, hsv_upper: Mat):
|
def mask_bgr_in_hsv(roi_bgr: Mat, hsv_lower: Mat, hsv_upper: Mat):
|
||||||
return cv2.inRange(
|
return cv2.inRange(
|
||||||
|
@ -36,7 +36,7 @@ class FixRects:
|
|||||||
if rect in consumed_rects:
|
if rect in consumed_rects:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
x, y, w, h = rect
|
x, _, w, h = rect
|
||||||
# grab those small rects
|
# grab those small rects
|
||||||
if not img_height * 0.1 <= h <= img_height * 0.6:
|
if not img_height * 0.1 <= h <= img_height * 0.6:
|
||||||
continue
|
continue
|
||||||
@ -46,7 +46,7 @@ class FixRects:
|
|||||||
for other_rect in rects:
|
for other_rect in rects:
|
||||||
if rect == other_rect:
|
if rect == other_rect:
|
||||||
continue
|
continue
|
||||||
ox, oy, ow, oh = other_rect
|
ox, _, ow, _ = other_rect
|
||||||
if abs(x - ox) < tolerance and abs((x + w) - (ox + ow)) < tolerance:
|
if abs(x - ox) < tolerance and abs((x + w) - (ox + ow)) < tolerance:
|
||||||
group.append(other_rect)
|
group.append(other_rect)
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ def phash_opencv(img_gray, hash_size=8, highfreq_factor=4):
|
|||||||
"""
|
"""
|
||||||
Perceptual Hash computation.
|
Perceptual Hash computation.
|
||||||
|
|
||||||
Implementation follows http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
|
Implementation follows
|
||||||
|
http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
|
||||||
|
|
||||||
Adapted from `imagehash.phash`, pure opencv implementation
|
Adapted from `imagehash.phash`, pure opencv implementation
|
||||||
|
|
||||||
@ -69,14 +70,14 @@ class ImagePhashDatabase:
|
|||||||
self.partner_icon_ids: List[str] = []
|
self.partner_icon_ids: List[str] = []
|
||||||
self.partner_icon_hashes = []
|
self.partner_icon_hashes = []
|
||||||
|
|
||||||
for id, hash in zip(self.ids, self.hashes):
|
for _id, _hash in zip(self.ids, self.hashes):
|
||||||
id_splitted = id.split("||")
|
id_splitted = _id.split("||")
|
||||||
if len(id_splitted) > 1 and id_splitted[0] == "partner_icon":
|
if len(id_splitted) > 1 and id_splitted[0] == "partner_icon":
|
||||||
self.partner_icon_ids.append(id_splitted[1])
|
self.partner_icon_ids.append(id_splitted[1])
|
||||||
self.partner_icon_hashes.append(hash)
|
self.partner_icon_hashes.append(_hash)
|
||||||
else:
|
else:
|
||||||
self.jacket_ids.append(id)
|
self.jacket_ids.append(_id)
|
||||||
self.jacket_hashes.append(hash)
|
self.jacket_hashes.append(_hash)
|
||||||
|
|
||||||
def calculate_phash(self, img_gray: Mat):
|
def calculate_phash(self, img_gray: Mat):
|
||||||
return phash_opencv(
|
return phash_opencv(
|
||||||
|
@ -42,5 +42,5 @@ def apply_factor(item: T, factor: float) -> T:
|
|||||||
def apply_factor(item, factor: float):
|
def apply_factor(item, factor: float):
|
||||||
if isinstance(item, (int, float)):
|
if isinstance(item, (int, float)):
|
||||||
return item * factor
|
return item * factor
|
||||||
elif isinstance(item, Iterable):
|
if isinstance(item, Iterable):
|
||||||
return item.__class__([i * factor for i in item])
|
return item.__class__([i * factor for i in item])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user