Позиционирование тени отражения изображения [закрыто]Python

Программы на Python
Anonymous
Позиционирование тени отражения изображения [закрыто]

Сообщение Anonymous »

Я удаляю BG с помощью rembg. Затем я делаю отражение машины. Но проблема в том, что я не могу сохранить четыре кадра отражения параллельно четырем кадрам исходной машины. Я хочу сделать изображение номер 2 таким, как изображение 1 ниже.
изображение 1 (ожидаемый результат)
image2(текущий вывод)

def remove_background(image, background_image=None):
input_data = image. читать()

Код: Выделить всё

# Get the background image if provided
if background_image:
background_image = BackgroundImage.objects.get(id=background_image).image
print("==============================background_image", background_image)
else:
background_image = None

# Check if the input data is empty
if not input_data:
raise ValueError("Empty image data")

# Remove background using rembg
output_data = rembg.remove(input_data, alpha_matting_foreground_threshold=50)

# Check if the output data is empty
if not output_data:
raise ValueError("Failed to remove background")

# Convert the output data to a PIL Image
img_without_bg = Image.open(BytesIO(output_data)).convert("RGBA")

# Crop the image to the bounding box of the car object
bbox = img_without_bg.getbbox()
car_object_cropped = img_without_bg.crop(bbox)

if background_image:
# Open the background image
bg_img = Image.open(background_image).convert("RGBA")

# Calculate the resize ratio for the car object
car_width, car_height = car_object_cropped.size
print("car_width, car_height:--------------- ",car_width, car_height)
bg_width, bg_height = bg_img.size
resize_ratio = min(bg_width / car_width, bg_height / car_height) * 0.8
if car_width  < car_height*2 and car_width

Подробнее здесь: [url]https://stackoverflow.com/questions/78565076/image-reflection-shadow-positioning[/url]

Вернуться в «Python»