mirror of
https://github.com/283375/arcaea-offline-ocr.git
synced 2025-04-22 15:00:18 +00:00
Compare commits
No commits in common. "master" and "v0.0.97" have entirely different histories.
48
.github/workflows/build-and-draft-release.yml
vendored
48
.github/workflows/build-and-draft-release.yml
vendored
@ -1,48 +0,0 @@
|
|||||||
name: "Build and draft a release"
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- "v[0-9]+.[0-9]+.[0-9]+"
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
discussions: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-and-draft-release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up Python environment
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.x"
|
|
||||||
|
|
||||||
- name: Build package
|
|
||||||
run: |
|
|
||||||
pip install build
|
|
||||||
python -m build
|
|
||||||
|
|
||||||
- name: Remove `v` in tag name
|
|
||||||
uses: mad9000/actions-find-and-replace-string@5
|
|
||||||
id: tagNameReplaced
|
|
||||||
with:
|
|
||||||
source: ${{ github.ref_name }}
|
|
||||||
find: "v"
|
|
||||||
replace: ""
|
|
||||||
|
|
||||||
- name: Draft a release
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
discussion_category_name: New releases
|
|
||||||
draft: true
|
|
||||||
generate_release_notes: true
|
|
||||||
files: |
|
|
||||||
dist/arcaea_offline_ocr-${{ steps.tagNameReplaced.outputs.value }}*.whl
|
|
||||||
dist/arcaea-offline-ocr-${{ steps.tagNameReplaced.outputs.value }}.tar.gz
|
|
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "arcaea-offline-ocr"
|
name = "arcaea-offline-ocr"
|
||||||
version = "0.0.99"
|
version = "0.0.97"
|
||||||
authors = [{ name = "283375", email = "log_283375@163.com" }]
|
authors = [{ name = "283375", email = "log_283375@163.com" }]
|
||||||
description = "Extract your Arcaea play result from screenshot."
|
description = "Extract your Arcaea play result from screenshot."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@ -16,8 +16,8 @@ classifiers = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
"Homepage" = "https://github.com/ArcaeaOffline/core-ocr"
|
"Homepage" = "https://github.com/283375/arcaea-offline-ocr"
|
||||||
"Bug Tracker" = "https://github.com/ArcaeaOffline/core-ocr/issues"
|
"Bug Tracker" = "https://github.com/283375/arcaea-offline-ocr/issues"
|
||||||
|
|
||||||
[tool.isort]
|
[tool.isort]
|
||||||
profile = "black"
|
profile = "black"
|
||||||
@ -25,14 +25,3 @@ 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
|
from typing import Optional, Union
|
||||||
|
|
||||||
import attrs
|
import attrs
|
||||||
|
|
||||||
|
@ -67,9 +67,8 @@ 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:
|
||||||
if (
|
x, y, w, h = cv2.boundingRect(contour)
|
||||||
cv2.boundingRect(contour)[3] < roi.shape[0] * 0.6
|
if h < 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)
|
||||||
|
|
||||||
@ -80,7 +79,6 @@ class DeviceOcr:
|
|||||||
self.masker.rating_class_prs(roi),
|
self.masker.rating_class_prs(roi),
|
||||||
self.masker.rating_class_ftr(roi),
|
self.masker.rating_class_ftr(roi),
|
||||||
self.masker.rating_class_byd(roi),
|
self.masker.rating_class_byd(roi),
|
||||||
self.masker.rating_class_etr(roi),
|
|
||||||
]
|
]
|
||||||
return max(enumerate(results), key=lambda i: np.count_nonzero(i[1]))[0]
|
return max(enumerate(results), key=lambda i: np.count_nonzero(i[1]))[0]
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@ 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(
|
||||||
@ -34,9 +32,6 @@ class DeviceRoisMaskerAutoT1(DeviceRoisMaskerAuto):
|
|||||||
BYD_HSV_MIN = np.array([170, 50, 50], np.uint8)
|
BYD_HSV_MIN = np.array([170, 50, 50], np.uint8)
|
||||||
BYD_HSV_MAX = np.array([179, 210, 198], np.uint8)
|
BYD_HSV_MAX = np.array([179, 210, 198], np.uint8)
|
||||||
|
|
||||||
ETR_HSV_MIN = np.array([130, 60, 80], np.uint8)
|
|
||||||
ETR_HSV_MAX = np.array([140, 145, 180], np.uint8)
|
|
||||||
|
|
||||||
TRACK_LOST_HSV_MIN = np.array([170, 75, 90], np.uint8)
|
TRACK_LOST_HSV_MIN = np.array([170, 75, 90], np.uint8)
|
||||||
TRACK_LOST_HSV_MAX = np.array([175, 170, 160], np.uint8)
|
TRACK_LOST_HSV_MAX = np.array([175, 170, 160], np.uint8)
|
||||||
|
|
||||||
@ -90,10 +85,6 @@ class DeviceRoisMaskerAutoT1(DeviceRoisMaskerAuto):
|
|||||||
def rating_class_byd(cls, roi_bgr: Mat) -> Mat:
|
def rating_class_byd(cls, roi_bgr: Mat) -> Mat:
|
||||||
return cls.mask_bgr_in_hsv(roi_bgr, cls.BYD_HSV_MIN, cls.BYD_HSV_MAX)
|
return cls.mask_bgr_in_hsv(roi_bgr, cls.BYD_HSV_MIN, cls.BYD_HSV_MAX)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def rating_class_etr(cls, roi_bgr: Mat) -> Mat:
|
|
||||||
return cls.mask_bgr_in_hsv(roi_bgr, cls.ETR_HSV_MIN, cls.ETR_HSV_MAX)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def max_recall(cls, roi_bgr: Mat) -> Mat:
|
def max_recall(cls, roi_bgr: Mat) -> Mat:
|
||||||
return cls.gray(roi_bgr)
|
return cls.gray(roi_bgr)
|
||||||
@ -125,7 +116,7 @@ class DeviceRoisMaskerAutoT1(DeviceRoisMaskerAuto):
|
|||||||
|
|
||||||
class DeviceRoisMaskerAutoT2(DeviceRoisMaskerAuto):
|
class DeviceRoisMaskerAutoT2(DeviceRoisMaskerAuto):
|
||||||
PFL_HSV_MIN = np.array([0, 0, 248], np.uint8)
|
PFL_HSV_MIN = np.array([0, 0, 248], np.uint8)
|
||||||
PFL_HSV_MAX = np.array([179, 40, 255], np.uint8)
|
PFL_HSV_MAX = np.array([179, 10, 255], np.uint8)
|
||||||
|
|
||||||
SCORE_HSV_MIN = np.array([0, 0, 180], np.uint8)
|
SCORE_HSV_MIN = np.array([0, 0, 180], np.uint8)
|
||||||
SCORE_HSV_MAX = np.array([179, 255, 255], np.uint8)
|
SCORE_HSV_MAX = np.array([179, 255, 255], np.uint8)
|
||||||
@ -142,9 +133,6 @@ class DeviceRoisMaskerAutoT2(DeviceRoisMaskerAuto):
|
|||||||
BYD_HSV_MIN = np.array([170, 50, 50], np.uint8)
|
BYD_HSV_MIN = np.array([170, 50, 50], np.uint8)
|
||||||
BYD_HSV_MAX = np.array([179, 210, 198], np.uint8)
|
BYD_HSV_MAX = np.array([179, 210, 198], np.uint8)
|
||||||
|
|
||||||
ETR_HSV_MIN = np.array([130, 60, 80], np.uint8)
|
|
||||||
ETR_HSV_MAX = np.array([140, 145, 180], np.uint8)
|
|
||||||
|
|
||||||
MAX_RECALL_HSV_MIN = np.array([125, 0, 0], np.uint8)
|
MAX_RECALL_HSV_MIN = np.array([125, 0, 0], np.uint8)
|
||||||
MAX_RECALL_HSV_MAX = np.array([145, 100, 150], np.uint8)
|
MAX_RECALL_HSV_MAX = np.array([145, 100, 150], np.uint8)
|
||||||
|
|
||||||
@ -196,10 +184,6 @@ class DeviceRoisMaskerAutoT2(DeviceRoisMaskerAuto):
|
|||||||
def rating_class_byd(cls, roi_bgr: Mat) -> Mat:
|
def rating_class_byd(cls, roi_bgr: Mat) -> Mat:
|
||||||
return cls.mask_bgr_in_hsv(roi_bgr, cls.BYD_HSV_MIN, cls.BYD_HSV_MAX)
|
return cls.mask_bgr_in_hsv(roi_bgr, cls.BYD_HSV_MIN, cls.BYD_HSV_MAX)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def rating_class_etr(cls, roi_bgr: Mat) -> Mat:
|
|
||||||
return cls.mask_bgr_in_hsv(roi_bgr, cls.ETR_HSV_MIN, cls.ETR_HSV_MAX)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def max_recall(cls, roi_bgr: Mat) -> Mat:
|
def max_recall(cls, roi_bgr: Mat) -> Mat:
|
||||||
return cls.mask_bgr_in_hsv(
|
return cls.mask_bgr_in_hsv(
|
||||||
|
@ -34,10 +34,6 @@ class DeviceRoisMasker:
|
|||||||
def rating_class_byd(cls, roi_bgr: Mat) -> Mat:
|
def rating_class_byd(cls, roi_bgr: Mat) -> Mat:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def rating_class_etr(cls, roi_bgr: Mat) -> Mat:
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def max_recall(cls, roi_bgr: Mat) -> Mat:
|
def max_recall(cls, roi_bgr: Mat) -> Mat:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -36,7 +36,7 @@ class FixRects:
|
|||||||
if rect in consumed_rects:
|
if rect in consumed_rects:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
x, _, w, h = rect
|
x, y, 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, _, ow, _ = other_rect
|
ox, oy, ow, oh = 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,8 +12,7 @@ def phash_opencv(img_gray, hash_size=8, highfreq_factor=4):
|
|||||||
"""
|
"""
|
||||||
Perceptual Hash computation.
|
Perceptual Hash computation.
|
||||||
|
|
||||||
Implementation follows
|
Implementation follows http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
|
||||||
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
|
||||||
|
|
||||||
@ -70,14 +69,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
|
||||||
if isinstance(item, Iterable):
|
elif 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