import os import cv2 import CaMeasurer import pandas as pd import numpy as np from .criteria_definition import * def read_four_integers(file_path:str) -> list[int]: """ Legacy code to read YOLO x1 x2 position from a text file. """ with open(file_path, 'r') as file: line = file.readline() numbers = list(map(int, line.strip().split())) if len(numbers) != 2: raise ValueError("The file does not contain exactly four integers.") return numbers def read_csv_for_endpoint_beginning(df, image_name): """ Reads a CSV file and returns the endpoint and beginning values for a given image name. Args: csv_path (str): Path to the CSV file containing the image data. image_name (str): Name of the image to look up (e.g., 'image001.jpg'). Returns: list: A list containing [endpoint, beginning]. Raises: FileNotFoundError: If the CSV file doesn't exist. ValueError: If the image is not found or the row does not contain exactly two integers. Author: - Yassin Riyazi """ # try: # # df = pd.read_csv(csv_path) # except FileNotFoundError: # raise FileNotFoundError(f"CSV file not found at: {csv_path}") match = df[df['image'] == image_name] if match.empty: raise ValueError(f"Image '{image_name}' not found in the CSV.") row = match.iloc[0] endpoint = int(row['endpoint']) beginning = int(row['beginning']) return [endpoint, beginning] def polyOrderDecider(degree,num_px_ratio): if degree<=60 : pixelNum=int(60*num_px_ratio) polyOrder=2 elif 60