|
from src.segmentation import segment_person |
|
from src.stereoscopic_insert import insert_person |
|
from src.anaglyph_converter import create_anaglyph |
|
from src.trial_insert import insert_person_V2 |
|
import cv2 |
|
from PIL import Image |
|
|
|
|
|
def generate_anaglyph( |
|
person_image_path, left_image_path, right_image_path, depth="medium" |
|
): |
|
""" |
|
Generate an anaglyph 3D image by segmenting a person from an uploaded image, |
|
inserting the segmented person into a stereoscopic pair, and converting the result |
|
to an anaglyph format. |
|
|
|
Parameters: |
|
- person_image_path: file path to the uploaded person image. |
|
- left_image_path: file path to the uploaded left stereoscopic image. |
|
- right_image_path: file path to the uploaded right stereoscopic image. |
|
- depth: depth level for the person in the 3D scene ("close", "medium", or "far"). |
|
|
|
Returns: |
|
- Anaglyph PIL image ready for display. |
|
""" |
|
|
|
|
|
person_image = segment_person(person_image_path) |
|
|
|
|
|
person_image.save("temp_person.png") |
|
|
|
|
|
left_image, right_image = insert_person_V2( |
|
left_image_path, right_image_path, "temp_person.png", depth |
|
) |
|
|
|
|
|
anaglyph_image = create_anaglyph(left_image, right_image) |
|
anaglyph_pil = Image.fromarray(cv2.cvtColor(anaglyph_image, cv2.COLOR_BGR2RGB)) |
|
|
|
return anaglyph_pil |
|
|