here's my code imagepath = r"C:\Users\Plathera\Desktop\4242\New folder (3)\AQOHFVLO.png"…
- User
here's my code
image_path = r"C:\Users\Plathera\Desktop\4242\New folder (3)\AQOHFVLO.png" folder_to_save = r"C:\Users\Plathera\Desktop\4242\New folder//"
import cv2 import numpy as np
def extract_objects(image): # Convert image to grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Threshold the grayscale image to get the black objects _, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV) # Find contours of the black objects contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # Extract and save each black object larger than 100 pixels as a separate image object_images = [] for i, contour in enumerate(contours): x, y, w, h = cv2.boundingRect(contour) if w * h > 1: # Check if object is larger than 100 pixels object_image = image[y:y+h, x:x+w] cv2.imwrite(folder_to_save + f"object{i+1}.png", object_image) object_images.append(object_image) return object_imagesLoad the white wallpaper image
image = cv2.imread(image_path)
Extract the black objects larger than 100 pixels from the image
object_images = extract_objects(image)
make that if one object above another then combine them together
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.