Spaces:
No application file
A newer version of the Gradio SDK is available:
6.2.0
Customization Guide
The "Live Object Detection with YOLO and OpenCV" project provides various customization options that allow you to tailor the real-time object detection system to your requirements. This guide will walk you through the available customization options and how to modify the code to achieve your desired changes.
Adjust Confidence Threshold
The confidence threshold controls the sensitivity of the object detection system. Lowering the threshold may result in more detections with lower confidence scores, while increasing it will only display high-confidence detections. To adjust the confidence threshold:
Open the
live.pyPython file in your preferred code editor.Locate the following line of code:
# Set the confidence threshold (0.3 by default) confidence_threshold = 0.3Change the value of
confidence_thresholdto your desired confidence score (between 0 and 1).Save the file and run the script again to see the effects of the new threshold.
Modify Bounding Box Annotations
You can customize the appearance of bounding box annotations for detected objects. To modify the box annotations:
Open the
live.pyPython file in your preferred code editor.Locate the box annotator setup section:
# Initialize the box annotator for visualizing detections box_annotator = sv.BoxAnnotator( thickness=2, text_thickness=2, text_scale=1 )You can change the values of
thickness,text_thickness, andtext_scaleto adjust the appearance of the bounding boxes and text labels.Save the file and run the script again to see the updated bounding box annotations.
Select Specific Object Classes
If you are interested in detecting only specific object classes or excluding some classes, you can do so by modifying the list of selected classes.
Open the
live.pyPython file in your preferred code editor.Find the following line of code:
# Extract labels and confidence scores for the detected objects label = [f"{model.model.names[ci]} {con:0.2f}" for _, _, con, ci, _ in detection]By default, this code includes all the detected classes. You can customize the
labellist comprehension to include only the classes you want to display. For example, to detect only "person" and "car," you can modify the code as follows:label = [f"{model.model.names[ci]} {con:0.2f}" for _, _, con, ci, _ in detection if model.model.names[ci] in ["person", "car"]]Save the file and run the script again to see the changes with the selected classes.
Feel free to experiment with these customization options to tailor the "Live Object Detection with YOLO and OpenCV" project to suit your specific use cases and preferences. If you encounter any issues or have further questions, refer to the "Troubleshooting Guide" or feel free to ask for assistance in the repository's issues section.
Happy customizing!