| from recognization import TextRecognition | |
| import os | |
| import argparse | |
| # Define the argument parser | |
| parser = argparse.ArgumentParser(description='Process an image.') | |
| parser.add_argument('--image_name', type=str, required=False, default='2.png', help='Path to the image file') | |
| parser.add_argument('--device', type=str, required=False, default='cpu', help='cpu or cuda') | |
| # Parse the arguments | |
| args = parser.parse_args() | |
| # Get the image path from the command line | |
| image_path = args.image_name | |
| device = args.device | |
| # Get current dir | |
| current_dir = os.path.dirname(os.path.abspath(__file__)) | |
| # Get model path | |
| model_path = os.path.join(current_dir , 'model/recognization_model.pth' ) | |
| recognizer = TextRecognition('model/recognization_model.pth' , device=device) | |
| # Get image path | |
| image_path = os.path.join(current_dir , f'data/{image_path}' ) | |
| result = recognizer.recognize_image(image_path) | |
| print(result) | |