Spaces:
Sleeping
Sleeping
| import cv2 | |
| import numpy as np | |
| import gradio as gr | |
| def rotate_image_90_left(image): | |
| """ | |
| Rotate image 90 degrees counter-clockwise (left) | |
| Args: | |
| image: Input image as numpy array | |
| Returns: | |
| Rotated image or None if input is None | |
| """ | |
| if image is None: | |
| return None | |
| try: | |
| return cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE) | |
| except Exception as e: | |
| print(f"Error rotating image left: {e}") | |
| return image | |
| def rotate_image_90_right(image): | |
| """ | |
| Rotate image 90 degrees clockwise (right) | |
| Args: | |
| image: Input image as numpy array | |
| Returns: | |
| Rotated image or None if input is None | |
| """ | |
| if image is None: | |
| return None | |
| try: | |
| return cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE) | |
| except Exception as e: | |
| print(f"Error rotating image right: {e}") | |
| return image | |
| def rotate_image_180(image): | |
| """ | |
| Rotate image 180 degrees | |
| Args: | |
| image: Input image as numpy array | |
| Returns: | |
| Rotated image or None if input is None | |
| """ | |
| if image is None: | |
| return None | |
| try: | |
| return cv2.rotate(image, cv2.ROTATE_180) | |
| except Exception as e: | |
| print(f"Error rotating image 180 degrees: {e}") | |
| return image | |
| def reset_image_to_original(current_image, original_image): | |
| """ | |
| Reset image to its original state | |
| Args: | |
| current_image: Current modified image (fallback if no original) | |
| original_image: Original image to restore (Gradio State object) | |
| Returns: | |
| Original image if available, otherwise current image (may be None) | |
| """ | |
| if original_image is None: | |
| return current_image | |
| return original_image.value | |