def execute(self, template_object: np.ndarray, target_object: np.ndarray, *_, **__) -> FindItEngineResponse: resp = FindItEngineResponse() resized_target = cv2.resize(target_object, template_object.shape[::-1], interpolation=cv2.INTER_CUBIC) ssim = compare_ssim(resized_target, template_object) resp.append("conf", self.__dict__) resp.append("ssim", ssim, important=True) resp.append("ok", True, important=True) return resp
def execute( self, template_object: np.ndarray, target_object: np.ndarray, engine_ocr_offset: int = None, engine_ocr_deep: bool = None, *_, **__, ) -> FindItEngineResponse: resp = FindItEngineResponse() if engine_ocr_offset: self.engine_ocr_offset = engine_ocr_offset if engine_ocr_deep: self.engine_ocr_deep = engine_ocr_deep # _ft is not JSON serializable conf_dict = {k: _ for k, _ in self.__dict__.items() if k != "_ft"} resp.append("conf", conf_dict, important=True) # check language for each_lang in self.engine_ocr_lang.split("+"): if each_lang not in self.engine_ocr_available_lang_list: resp.append("raw", "this language not available", important=True) resp.append("ok", False, important=True) return resp word_block_list = self._ft.find_word( image_object=target_object, deep=self.engine_ocr_deep, offset=self.engine_ocr_offset, ) available_result_list = [i for i in word_block_list if i.content] result_text = self._improve_text_result( [i.content for i in available_result_list]) resp.append("content", result_text, important=True) resp.append("raw", [i.__dict__ for i in word_block_list]) resp.append("ok", True, important=True) return resp
def execute( self, template_object: np.ndarray, target_object: np.ndarray, engine_template_mask_pic_object: np.ndarray = None, engine_template_mask_pic_path: str = None, *_, **__, ) -> FindItEngineResponse: resp = FindItEngineResponse() resp.append("conf", self.__dict__) # mask if (engine_template_mask_pic_path is not None) or (engine_template_mask_pic_object is not None): logger.info("mask detected") engine_template_mask_pic_object = toolbox.pre_pic( engine_template_mask_pic_path, engine_template_mask_pic_object) # template matching min_val, max_val, min_loc, max_loc, point_list = self._compare_template( template_object, target_object, self.engine_template_scale, engine_template_mask_pic_object, ) # 'target_point' must existed resp.append("target_point", max_loc, important=True) resp.append("target_sim", max_val, important=True) resp.append( "raw", { "min_val": min_val, "max_val": max_val, "min_loc": min_loc, "max_loc": max_loc, "all": point_list, }, ) resp.append("ok", True, important=True) return resp
def execute(self, template_object: np.ndarray, target_object: np.ndarray, *_, **__) -> FindItEngineResponse: resp = FindItEngineResponse() resp.append('conf', self.__dict__) point_list = self.get_feature_point_list(template_object, target_object) # no point found if not point_list: resp.append('target_point', (-1, -1), important=True) resp.append('raw', 'not found') resp.append('ok', False, important=True) return resp center_point = self.calculate_center_point(point_list) readable_center_point = list(center_point) readable_point_list = [list(each) for each in point_list] resp.append('target_point', readable_center_point, important=True) resp.append('feature_point_num', len(readable_point_list), important=True) resp.append('raw', readable_point_list) resp.append('ok', True, important=True) return resp
def execute(self, template_object: np.ndarray, target_object: np.ndarray, engine_template_mask_pic_object: np.ndarray = None, engine_template_mask_pic_path: str = None, *_, **__) -> FindItEngineResponse: resp = FindItEngineResponse() resp.append('conf', self.__dict__) # mask if (engine_template_mask_pic_path is not None) or (engine_template_mask_pic_object is not None): logger.info('mask detected') engine_template_mask_pic_object = toolbox.pre_pic( engine_template_mask_pic_path, engine_template_mask_pic_object) # template matching min_val, max_val, min_loc, max_loc, point_list = self._compare_template( template_object, target_object, self.engine_template_scale, engine_template_mask_pic_object) # 'target_point' must existed resp.append('target_point', max_loc, important=True) resp.append('target_sim', max_val, important=True) resp.append( 'raw', { 'min_val': min_val, 'max_val': max_val, 'min_loc': min_loc, 'max_loc': max_loc, 'all': point_list, }) resp.append('ok', True, important=True) return resp