nnibras commited on
Commit
e28bfd7
·
verified ·
1 Parent(s): 1db9c1a

Update src/gradio_interface.py

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