Update src/gradio_interface.py
Browse files- src/gradio_interface.py +42 -41
src/gradio_interface.py
CHANGED
|
@@ -1,41 +1,42 @@
|
|
| 1 |
-
from src.segmentation import segment_person
|
| 2 |
-
from src.stereoscopic_insert import insert_person
|
| 3 |
-
from src.anaglyph_converter import create_anaglyph
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
-
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
| 1 |
+
from src.segmentation import segment_person
|
| 2 |
+
from src.stereoscopic_insert import insert_person
|
| 3 |
+
from src.anaglyph_converter import create_anaglyph
|
| 4 |
+
from src.trial_insert import insert_person_V2
|
| 5 |
+
import cv2
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def generate_anaglyph(
|
| 10 |
+
person_image_path, left_image_path, right_image_path, depth="medium"
|
| 11 |
+
):
|
| 12 |
+
"""
|
| 13 |
+
Generate an anaglyph 3D image by segmenting a person from an uploaded image,
|
| 14 |
+
inserting the segmented person into a stereoscopic pair, and converting the result
|
| 15 |
+
to an anaglyph format.
|
| 16 |
+
|
| 17 |
+
Parameters:
|
| 18 |
+
- person_image_path: file path to the uploaded person image.
|
| 19 |
+
- left_image_path: file path to the uploaded left stereoscopic image.
|
| 20 |
+
- right_image_path: file path to the uploaded right stereoscopic image.
|
| 21 |
+
- depth: depth level for the person in the 3D scene ("close", "medium", or "far").
|
| 22 |
+
|
| 23 |
+
Returns:
|
| 24 |
+
- Anaglyph PIL image ready for display.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
# Segment the person from the uploaded image
|
| 28 |
+
person_image = segment_person(person_image_path)
|
| 29 |
+
|
| 30 |
+
# Save the segmented image temporarily for overlay purposes
|
| 31 |
+
person_image.save("temp_person.png")
|
| 32 |
+
|
| 33 |
+
# Insert the segmented person into the stereoscopic images
|
| 34 |
+
left_image, right_image = insert_person_V2(
|
| 35 |
+
left_image_path, right_image_path, "temp_person.png", depth
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Create the final anaglyph image from the left and right images
|
| 39 |
+
anaglyph_image = create_anaglyph(left_image, right_image)
|
| 40 |
+
anaglyph_pil = Image.fromarray(cv2.cvtColor(anaglyph_image, cv2.COLOR_BGR2RGB))
|
| 41 |
+
|
| 42 |
+
return anaglyph_pil
|