feat: HSAP platform v2 — modular navigation, quality review, audit log, world model simulation
Major changes: - New frontend (platform/web/): Vite + React 18 + TypeScript + Tailwind - 4-module navigation: 数据送标 / 模型管理 / 车队管理 / 系统管理 - Data catalog with charts (DMS/ADAS/Lane 3-tab view) - Quality review workflow (标注质检): Good/Fine/Bad scoring with auto-advance - Audit enhancements: batch operations, rejection categories, Feishu notifications - Operation audit log (操作日志) - World model simulation studio (仿真工坊) - Dataset version management with snapshots and diff - ADAS 7-class dataset integration (138K images organized + compressed) - User management with Feishu integration and pagination - CRUD/search/filter on all pages, card layout redesign - PIL-optimized image overlay rendering - Auto-snapshot on build, in_review workflow stage - Removed embedded algorithm code (now in workspace)
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from ultralytics.solutions.solutions import BaseSolution, SolutionResults
|
||||
from ultralytics.utils.plotting import save_one_box
|
||||
|
||||
|
||||
class ObjectCropper(BaseSolution):
|
||||
"""A class to manage the cropping of detected objects in a real-time video stream or images.
|
||||
|
||||
This class extends the BaseSolution class and provides functionality for cropping objects based on detected bounding
|
||||
boxes. The cropped images are saved to a specified directory for further analysis or usage.
|
||||
|
||||
Attributes:
|
||||
crop_dir (str): Directory where cropped object images are stored.
|
||||
crop_idx (int): Counter for the total number of cropped objects.
|
||||
iou (float): IoU (Intersection over Union) threshold for non-maximum suppression.
|
||||
conf (float): Confidence threshold for filtering detections.
|
||||
|
||||
Methods:
|
||||
process: Crop detected objects from the input image and save them to the output directory.
|
||||
|
||||
Examples:
|
||||
>>> cropper = ObjectCropper()
|
||||
>>> frame = cv2.imread("frame.jpg")
|
||||
>>> processed_results = cropper.process(frame)
|
||||
>>> print(f"Total cropped objects: {cropper.crop_idx}")
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
"""Initialize the ObjectCropper class for cropping objects from detected bounding boxes.
|
||||
|
||||
Args:
|
||||
**kwargs (Any): Keyword arguments passed to the parent class and used for configuration including:
|
||||
- crop_dir (str): Path to the directory for saving cropped object images.
|
||||
"""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.crop_dir = self.CFG["crop_dir"] # Directory for storing cropped detections
|
||||
Path(self.crop_dir).mkdir(parents=True, exist_ok=True)
|
||||
if self.CFG["show"]:
|
||||
self.LOGGER.warning(f"show=True is not supported for ObjectCropper; saving crops to '{self.crop_dir}'.")
|
||||
self.CFG["show"] = False
|
||||
self.crop_idx = 0 # Initialize counter for total cropped objects
|
||||
self.iou = self.CFG["iou"]
|
||||
self.conf = self.CFG["conf"]
|
||||
|
||||
def process(self, im0) -> SolutionResults:
|
||||
"""Crop detected objects from the input image and save them as separate images.
|
||||
|
||||
Args:
|
||||
im0 (np.ndarray): The input image containing detected objects.
|
||||
|
||||
Returns:
|
||||
(SolutionResults): A SolutionResults object containing the total number of cropped objects and processed
|
||||
image.
|
||||
|
||||
Examples:
|
||||
>>> cropper = ObjectCropper()
|
||||
>>> frame = cv2.imread("image.jpg")
|
||||
>>> results = cropper.process(frame)
|
||||
>>> print(f"Total cropped objects: {results.total_crop_objects}")
|
||||
"""
|
||||
with self.profilers[0]:
|
||||
results = self.model.predict(
|
||||
im0,
|
||||
classes=self.classes,
|
||||
conf=self.conf,
|
||||
iou=self.iou,
|
||||
device=self.CFG["device"],
|
||||
verbose=False,
|
||||
)[0]
|
||||
self.clss = results.boxes.cls.tolist() # required for logging only.
|
||||
|
||||
for box in results.boxes:
|
||||
self.crop_idx += 1
|
||||
save_one_box(
|
||||
box.xyxy,
|
||||
im0,
|
||||
file=Path(self.crop_dir) / f"crop_{self.crop_idx}.jpg",
|
||||
BGR=True,
|
||||
)
|
||||
|
||||
# Return SolutionResults
|
||||
return SolutionResults(plot_im=im0, total_crop_objects=self.crop_idx)
|
||||
Reference in New Issue
Block a user