import numpy as np from mmdet.apis import init_detector, inference_detector import easyocr import matplotlib.patches as patches import os from pathlib import Path def load_detection_model(): model = init_detector('configs/rotated_rtmdet/custom.py', 'Fine_tuned_Roberta_model.pth', device='cpu') return model def load_ocr_model(): model_storage_directory = '/code/.EasyOCR/model' # Ensure this path matches the one in Dockerfile reader = easyocr.Reader(['en'], model_storage_directory=model_storage_directory) return reader def plot_rotated_box(ax, center, width, height, angle): angle_rad = angle rotation_matrix = np.array([ [np.cos(angle_rad), -np.sin(angle_rad)], [np.sin(angle_rad), np.cos(angle_rad)] ]) half_width = width / 2 half_height = height / 2 corners = np.array([ [-half_width, -half_height], [half_width, -half_height], [half_width, half_height], [-half_width, half_height] ]) rotated_corners = np.dot(corners, rotation_matrix.T) rotated_corners[:, 0] += center[0] rotated_corners[:, 1] += center[1] rotated_box = patches.Polygon(rotated_corners, closed=True, edgecolor='r', facecolor='none', linewidth=2) ax.add_patch(rotated_box) return rotated_corners