mirror of
https://github.com/283375/arcaea-offline-ocr.git
synced 2025-07-01 20:36:27 +00:00
Compare commits
2 Commits
82229b8b5c
...
3400df2d52
Author | SHA1 | Date | |
---|---|---|---|
3400df2d52
|
|||
4fd31b1e9b
|
@ -0,0 +1,2 @@
|
|||||||
|
from .common import DeviceOcrResult
|
||||||
|
from .ocr import DeviceOcr
|
||||||
|
3
src/arcaea_offline_ocr/device/rois/__init__.py
Normal file
3
src/arcaea_offline_ocr/device/rois/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from .definition import *
|
||||||
|
from .extractor import *
|
||||||
|
from .masker import *
|
@ -1 +1,2 @@
|
|||||||
from .auto import *
|
from .auto import *
|
||||||
|
from .common import DeviceRois
|
||||||
|
@ -5,9 +5,9 @@ from ..definition.common import DeviceRois
|
|||||||
|
|
||||||
|
|
||||||
class DeviceRoisExtractor:
|
class DeviceRoisExtractor:
|
||||||
def __init__(self, img: cv2.Mat, sizes: DeviceRois):
|
def __init__(self, img: cv2.Mat, rois: DeviceRois):
|
||||||
self.img = img
|
self.img = img
|
||||||
self.sizes = sizes
|
self.sizes = rois
|
||||||
|
|
||||||
def __construct_int_rect(self, rect):
|
def __construct_int_rect(self, rect):
|
||||||
return tuple(round(r) for r in rect)
|
return tuple(round(r) for r in rect)
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
import io
|
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from typing import Callable, TypeVar, Union, overload
|
from typing import Callable, TypeVar, Union, overload
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image, ImageCms
|
|
||||||
|
|
||||||
from .types import XYWHRect
|
from .types import XYWHRect
|
||||||
|
|
||||||
@ -46,25 +44,3 @@ def apply_factor(item, factor: float):
|
|||||||
return item * factor
|
return item * factor
|
||||||
elif 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])
|
||||||
|
|
||||||
|
|
||||||
def convert_to_srgb(pil_img: Image.Image):
|
|
||||||
"""
|
|
||||||
Convert PIL image to sRGB color space (if possible)
|
|
||||||
and save the converted file.
|
|
||||||
|
|
||||||
https://stackoverflow.com/a/65667797/16484891
|
|
||||||
|
|
||||||
CC BY-SA 4.0
|
|
||||||
"""
|
|
||||||
icc = pil_img.info.get("icc_profile", "")
|
|
||||||
icc_conv = ""
|
|
||||||
|
|
||||||
if icc:
|
|
||||||
io_handle = io.BytesIO(icc) # virtual file
|
|
||||||
src_profile = ImageCms.ImageCmsProfile(io_handle)
|
|
||||||
dst_profile = ImageCms.createProfile("sRGB")
|
|
||||||
img_conv = ImageCms.profileToProfile(pil_img, src_profile, dst_profile)
|
|
||||||
icc_conv = img_conv.info.get("icc_profile", "")
|
|
||||||
|
|
||||||
return img_conv if icc != icc_conv else pil_img
|
|
||||||
|
Reference in New Issue
Block a user