--- Helper Functions --- def cropfacefromimage(image, boxcoords): """Crops a face from…
- User
--- Helper Functions ---
def crop_face_from_image(image, box_coords): """Crops a face from an image using normalized bounding box coordinates.""" width, height = image.size x_min = int(box_coords['x_min'] * width) y_min = int(box_coords['y_min'] * height) x_max = int(box_coords['x_max'] * width) y_max = int(box_coords['y_max'] * height)
# Add some padding to the crop padding_x = int((x_max - x_min) * 0.05) padding_y = int((y_max - y_min) * 0.05) cropped_image = image.crop(( max(0, x_min + padding_x), max(0, y_min + padding_y), min(width, x_max - padding_x), min(height, y_max - padding_y) )) return cropped_imagewrite function similar to this one, but it will set pixles inside boudng box to black
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.