I want to modify a script. # Install necessary libraries !pip install ultralytics…
- User
I want to modify a script. # Install necessary libraries !pip install ultralytics opencv-python
Import packages
from ultralytics import YOLO import cv2
def yolo_add_watermark(img_path): # Load YOLOv8 model model = YOLO('yolov8n.pt') # Make sure this is the correct path to your weights
# Detect faces in the image results = model(img_path) img = cv2.imread(img_path) # Get image dimensions img_height, img_width = img.shape[:2] # Define watermark text and its position watermark_text = "Sample Watermark" font = cv2.FONT_HERSHEY_SIMPLEX font_scale = 1 font_thickness = 2 text_size = cv2.getTextSize(watermark_text, font, font_scale, font_thickness)[0] # Default position (bottom-right) watermark_x = img_width - text_size[0] - 10 watermark_y = img_height - 10 # Iterate over detected faces to adjust watermark position if needed for result in results: boxes = result.boxes for box in boxes: bounding_coordinates = box.xyxy x1, y1, x2, y2 = (int(bounding_coordinates[0, 0].item()), int(bounding_coordinates[0, 1].item()), int(bounding_coordinates[0, 2].item()), int(bounding_coordinates[0, 3].item())) # If the watermark overlaps with any face, move it to top-left if (watermark_x < x2 and watermark_x + text_size[0] > x1 and watermark_y - text_size[1] < y2 and watermark_y > y1): watermark_x = 10 watermark_y = 30 break # Adjust once and break out of loop # Add watermark to the image cv2.putText(img, watermark_text, (watermark_x, watermark_y), font, font_scale, (255, 255, 255), font_thickness) # Save the watermarked image output_path = "watermarked_image.jpg" cv2.imwrite(output_path, img) return output_pathRun the function
output_image = yolo_add_watermark('/content/R9nMWkrc.jpeg') # Update with the correct path to your image
- Assistant
- User
I want my watermark should apply in multiple places of image exept on the faces (remember, there may multiple faces available). I should able to control opacity and text size.
- Assistant
- User
It's just putting two watermark. I want many watermark. Add a widget for interactive interface for watermark text, watermark numbers watermark size and opacity.
- Assistant
- User
I want watermark should place across the whole images exept face
- Assistant
- User
If I increase size watermark text overlap one with another. I don't want them overlapping
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.