# Standard library imports import logging from typing import Dict, Optional # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Third-party imports import cv2 import numpy as np class BaseLineDetector: """Base class for line detection methods""" def detect(self, image: np.ndarray) -> Dict: raise NotImplementedError class OpenCVLineDetector(BaseLineDetector): """Basic line detection using OpenCV""" def detect(self, image: np.ndarray) -> Dict: # Convert to grayscale if needed if len(image.shape) == 3: gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) else: gray = image # Basic line detection using HoughLinesP edges = cv2.Canny(gray, 50, 150, apertureSize=3) lines = cv2.HoughLinesP(edges, 1, np.pi/180, 100, minLineLength=100, maxLineGap=10) detections = [] if lines is not None: for line in lines: x1, y1, x2, y2 = line[0] detections.append({ 'start': [float(x1), float(y1)], 'end': [float(x2), float(y2)] }) return {'detections': detections} # Try to import DeepLSD in a separate try-except block DEEPLSD_AVAILABLE = False DeepLSDDetector = None try: from deeplsd.models.deeplsd_inference import DeepLSD class DeepLSDDetector(BaseLineDetector): def __init__(self, model_path: Optional[str] = None): self.model = DeepLSD(model_path) if model_path else None def detect(self, image: np.ndarray) -> Dict: return {'detections': []} # Placeholder implementation DEEPLSD_AVAILABLE = True except ImportError as e: logger.warning(f"DeepLSD not available: {e}")