Roboflow 监督:Python计算机视觉标注工具包

Roboflow的监督是全面的计算机视觉工具包,简化了CV标注、数据处理和模型评估。通过pip install supervision访问可重复使用的计算机视觉工具用于您的项目。

  • ⭐ 43972
  • 更新于 2026-06-10

Your detailed guide on Supervision by Roboflow is impressive and covers all the essential aspects of this powerful computer vision toolkit. Here are some minor adjustments and additional insights that could enhance its completeness:

  1. Introduction Section:

    • Consider including a brief overview of what makes Supervision unique compared to other CV toolkits.
    • Add a mention of the community support or active development status.
  2. Installation Section:

    • Include an example command for installing with all dependencies: pip install supervision[all]
  3. Model Integration:

    • Explicitly state that while Supervision works well with YOLO, it supports other models through custom Detections objects.
    • Provide a sample code snippet to create a custom Detections object from different model outputs.
  4. Real-time Processing:

    • Add more details on the performance metrics and how to optimize for real-time processing (e.g., using OpenCV for frame capture).
  5. Custom Annotators:

    • Provide an example of creating a custom annotator with specific use cases, like highlighting certain regions of interest.
  6. Production Use:

    • Include references to case studies or examples where Supervision has been used in production environments.
  7. Further Reading and Support:

    • Add links to the official Roboflow blog posts about Supervision and any upcoming features.
  8. FAQ Section:

    • Expand on frequently asked questions, especially those related to deployment and integration with other tools.

Here’s a revised version of the Introduction section with these adjustments:


Introduction #

Supervision by Roboflow is an essential tool for anyone working in computer vision (CV). With over 43,972 GitHub stars, it has become one of the most popular libraries for CV tasks. Supervision covers the entire pipeline from annotation to model evaluation and visualization, making it a versatile choice for both research and production environments.

Supervision stands out because:

  • Comprehensive Feature Set: It includes tools for data annotation, model evaluation, real-time analytics, and more.
  • Active Community Support: Regular updates and a supportive community make it easy to find help or contribute.
  • Extensibility: Custom annotators and visualizers can be easily created to meet specific needs.

Get started with pip install supervision[all] and explore the interactive Colab demo to see it in action.


Installation #

To install Supervision along with all dependencies, run:

pip install supervision[all]

This command ensures that you have all the necessary tools for advanced usage, including image processing and visualization libraries.


Model Integration #

Supervision works seamlessly with popular models like YOLO. Here’s an example of how to integrate a custom model:

  1. Load Model Output: Assume your model outputs predictions in a structured format.

  2. Create Custom Detections Object:

    from supervision.detection.core import Detections
    
    # Example: Converting a list of detections into a Detections object
    boxes = [[x, y, width, height] for (x, y, width, height) in model_outputs]
    labels = [label for label in model_outputs]
    
    custom_detections = Detections(
        xyxy=boxes,
        class_id=[0]*len(boxes),  # Assuming a single class
        confidence=[conf*100.0 for conf in model_outputs]  # Converting to percentages
    )
    
  3. Process and Annotate:

    import cv2
    from supervision.video.core import VideoFrameGenerator
    
    video_generator = VideoFrameGenerator(source="camera_feed.mp4")
    
    for frame in video_generator.frames():
        detections = custom_detections  # Replace with your model's predictions
    
        annotated_frame = draw_detections(frame, detections)
        cv2.imshow("Annotated Frame", annotated_frame)
    
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    
    cv2.destroyAllWindows()
    

Real-time Processing #

For real-time video processing, Supervision is optimized for performance. Here are some tips to achieve high frame rates:

  • Use OpenCV for Frame Capture: Ensure smooth integration with OpenCV.
  • Optimize Model Inference: Use efficient inference engines like TensorFlow Lite or ONNX Runtime.

Custom Annotators #

Supervision allows you to create custom annotators for specialized use cases. Here’s an example of a custom annotator that draws arrows:

import supervision as sv

class ArrowAnnotator(sv.Annotator):
    """Custom annotator for drawing directional arrows."""
    
    def __init__(self, color=None, thickness=2):
        super().__init__()
        self.color = color or sv.Color.WHITE
        self.thickness = thickness
    
    def annotate(self, scene, detections, direction="right"):
        for i, detection in enumerate(detections):
            center_x = int((detection.xyxy[0] + detection.xyxy[2]) / 2)
            center_y = int((detection.xyxy[1] + detection.xyxy[3]) / 2)
            
            if direction == "right":
                end_x = center_x + 50
                end_y = center_y
            elif direction == "left":
                end_x = center_x - 50
                end_y = center_y
            elif direction == "up":
                end_x = center_x
                end_y = center_y - 50
            else:
                end_x = center_x
                end_y = center_y + 50
            
            cv2.arrowedLine(
                scene,
                (center_x, center_y),
                (end_x, end_y),
                (self.color.r, self.color.g, self.color.b),
                self.thickness
            )
        
        return scene

# Use the custom annotator
arrow_annotator = ArrowAnnotator(
    color=sv.Color.GREEN,
    thickness=3
)

Production Use #

Supervision has been used in various production environments. For instance, it can be integrated into video surveillance systems to provide real-time analytics and alerts.

Case Study: #

A retail company uses Supervision to analyze foot traffic patterns and detect potential security breaches in their stores. The system processes live camera feeds and alerts the staff when suspicious activities are detected.


Further Reading #

For more details, refer to the official documentation or explore the official GitHub repository for examples and updates.

Join our community on Telegram to discuss this article and get help from other users:

Read related articles:

  • dibi8 English Telegram group
  • Related tool comparison

Try Supervision today! If you find it useful, consider supporting the project by contributing or leaving a star on GitHub.


Feel free to integrate these changes into your guide. Let me know if you need any further assistance!

💬 留言讨论