import sys import more_itertools import multiprocessing import traceback from template_matching.core.matcher import Matcher from template_matching.errors import TemplateMatchingException from aion.logger_library.LoggerClient import LoggerClient log = LoggerClient("TemplateMatchingServer") def pool_matching(args_queue, return_queue, templates_data, image_path): matcher = Matcher(templates_data, image_path) while True: exit_status = True return_value = None function_name, kwargs = args_queue.get() try: if function_name == 'set_templates': matcher.set_templates(kwargs['templates_data']) elif function_name == 'run': return_value = matcher.run(kwargs['image_path']) else: raise TemplateMatchingException( 'pool_matching() recieve Invalid function name ({function_name}).'
import shutil from pathlib import Path from datetime import datetime, timedelta from wsgiref.util import setup_testing_defaults from wsgiref.simple_server import make_server from StatusJsonPythonModule import StatusJsonRest from aion.logger_library.LoggerClient import LoggerClient HOST = '0.0.0.0' PORT = 8001 SAVEDIR = '/home/shinwa/luna/Data/get-image-from-vr-device/file/output' UIDIR = '/home/shinwa/luna/UI/ui-backend-for-vr-face-recognition/public/uploads/vr_img' log = LoggerClient("GetImageFromVrDevice") def filedelete(target_dir): deltime = datetime.now() - timedelta(minutes=5) del_border = deltime.timestamp() path = Path(target_dir) for row in path.glob('*'): if del_border > row.stat().st_mtime: row.unlink() class PostImageFile(object): def __init__(self): # read status json file
import sys import pprint from aion.logger_library.LoggerClient import LoggerClient client = LoggerClient('TemplateMatchingSummaryServer') def print(message, debug=False): message = pprint.pformat(message, indent=4) if not debug or (debug and sys.flags.debug): client.print(message) return
from pathlib import Path import os from multiprocessing import Process, Queue import cv2 import numpy as np from aion.logger_library.LoggerClient import LoggerClient log = LoggerClient("OutputResultOfTemplateMatching", stdout_log_level=4) class OutputImageWriter(): def __init__(self, output_dir, debug=False): self.output_dir = output_dir self.debug = debug if debug: self._initialize_window() @log.function_log def _initialize_window(self): cv2.namedWindow("template", cv2.WINDOW_NORMAL) cv2.resizeWindow('template', 1280, 720) cv2.startWindowThread() def _load_image(self, image_path): image = None path = Path(image_path) if path.suffix == ".npy": image = np.load(str(image_path)) elif path.suffix == ".jpg": image = cv2.imread(str(image_path))
import copy from aion.logger_library.LoggerClient import LoggerClient log = LoggerClient("TemplateMatching") class ImageSettings(): def __init__(self, data): self.data = data self.path = data.get('path') self.trim_points = data.get('trim_points') self.trim_points_ratio = data.get('trim_points_ratio') self.new_trim_points = None def calc_trim_points(self, image_width, image_height): if self.trim_points is None: self.new_trim_points = [[0, 0], [image_width, image_height]] elif self.trim_points_ratio is None: self.new_trim_points = self.trim_points else: ex_width = int(image_width * self.trim_points_ratio) ex_height = int(image_height * self.trim_points_ratio) x0 = max(0, self.trim_points[0][0] - ex_width) y0 = max(0, self.trim_points[0][1] - ex_height) x1 = min(image_width, self.trim_points[1][0] + ex_width) y1 = min(image_height, self.trim_points[1][1] + ex_height) self.new_trim_points = [[x0, y0], [x1, y1]]
#!/usr/bin/env python3 import copy import math import os import aion.common_library as common from aion.logger_library.LoggerClient import LoggerClient from aion.websocket_server import BaseServerClass, ServerFunctionFailedException from template_matching import MultiprocessMatching, OutputImageGenerator log = LoggerClient("TemplateMatchingServer", stdout_log_level=4) OUTPUT_PATH = common.get_output_path(os.getcwd(), __file__).replace("-server", "") N_TEMPLATES = 20 N_PROCESS = 5 class TemplateMatchingServer(BaseServerClass): @log.function_log async def set_templates(self, sid, data): required_keys = ['templates'] for key in required_keys: if key not in data: raise ServerFunctionFailedException(f"Bad Request: not found 'templates' in request body") templates_data = data['templates'] self.match.set_templates(templates_data) return {} @log.function_log