Opt: Move rgb2gray from to module/base/utils.py

This commit is contained in:
LmeSzinc 2020-09-03 19:40:33 +08:00
parent 857adacfbf
commit ffa36b0fc2
8 changed files with 19 additions and 22 deletions

View File

@ -4,7 +4,7 @@ import time
from PIL import Image
import module.config.server as server
from module.map_detection.utils import *
from module.base.utils import *
server.server = 'cn' # Don't need to edit, it's used to avoid error.

View File

@ -10,7 +10,6 @@ from module.map_detection.view import View
from module.base.base import ModuleBase
from module.config.config import AzurLaneConfig
from module.base.utils import *
from module.map_detection.utils import *
class Config:

View File

@ -231,6 +231,21 @@ def crop(image, area):
return cv2.copyMakeBorder(image[y1:y2, x1:x2], *border, borderType=cv2.BORDER_CONSTANT, value=(0, 0, 0))
def rgb2gray(image):
"""
Args:
image (np.ndarray): Shape (height, width, channel)
Returns:
np.ndarray: Shape (height, width)
"""
r, g, b = cv2.split(image)
return cv2.add(
cv2.multiply(cv2.max(cv2.max(r, g), b), 0.5),
cv2.multiply(cv2.min(cv2.min(r, g), b), 0.5)
)
def get_color(image, area):
"""Calculate the average color of a particular area of the image.

View File

@ -3,7 +3,7 @@ import time
import numpy as np
from PIL import Image, ImageDraw, ImageOps
from module.base.utils import crop, float2str, point2str
from module.base.utils import *
from module.config.config import AzurLaneConfig
from module.exception import MapDetectionError
from module.logger import logger

View File

@ -5,7 +5,7 @@ import numpy as np
from PIL import Image, ImageOps, ImageDraw
from scipy import signal
from module.base.utils import crop, point2str, float2str
from module.base.utils import *
from module.config.config import AzurLaneConfig
from module.exception import MapDetectionError
from module.logger import logger

View File

@ -233,21 +233,6 @@ class Lines:
return Lines(lines, is_horizontal=self.is_horizontal, config=self.config)
def rgb2gray(image):
"""
Args:
image (np.ndarray):
Returns:
np.ndarray:
"""
r, g, b = cv2.split(image)
return cv2.add(
cv2.multiply(cv2.max(cv2.max(r, g), b), 0.5),
cv2.multiply(cv2.min(cv2.min(r, g), b), 0.5)
)
def area2corner(area):
"""
Args:

View File

@ -2,10 +2,9 @@ import numpy as np
from module.base.decorator import Config
from module.base.timer import Timer
from module.base.utils import get_color
from module.base.utils import get_color, rgb2gray
from module.combat.assets import GET_ITEMS_1, GET_ITEMS_2, GET_ITEMS_3
from module.logger import logger
from module.map_detection.utils import rgb2gray
from module.research.assets import *
from module.research.project import ResearchSelector
from module.ui.page import *

View File

@ -3,7 +3,6 @@ import numpy as np
from module.base.button import ButtonGrid
from module.base.utils import *
from module.logger import logger
from module.map_detection.utils import rgb2gray
from module.ocr.ocr import Digit
from module.statistics.utils import *