ankanpy commited on
Commit
6ea8758
·
verified ·
1 Parent(s): 4c51020

Upload 10 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ scene/scene1.jpg filter=lfs diff=lfs merge=lfs -text
37
+ scene/scene2.jpg filter=lfs diff=lfs merge=lfs -text
38
+ scene/scene3.jpg filter=lfs diff=lfs merge=lfs -text
39
+ scene/scene4.jpg filter=lfs diff=lfs merge=lfs -text
40
+ scene/scene5.jpg filter=lfs diff=lfs merge=lfs -text
41
+ scene/scene6.jpg filter=lfs diff=lfs merge=lfs -text
42
+ scene/scene7.jpg filter=lfs diff=lfs merge=lfs -text
43
+ scene/scene8.jpg filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+
5
+ # from panorama import stitch_images
6
+
7
+
8
+ def process_images(image_files, crop, y_start, y_end, x_start, x_end):
9
+ if not image_files:
10
+ return "No images uploaded.", None
11
+
12
+ # Extract the first element of each tuple if it's a tuple
13
+ extracted_images = []
14
+ for item in image_files:
15
+ if isinstance(item, tuple):
16
+ # If item is (img, None), extract 'img' only
17
+ img = item[0]
18
+ else:
19
+ # If for some reason it's not a tuple, assume it's already the image
20
+ img = item
21
+
22
+ # Check if img is not None and is a numpy array
23
+ if img is not None and isinstance(img, np.ndarray):
24
+ extracted_images.append(img)
25
+
26
+ # If after extraction no valid images found
27
+ if not extracted_images:
28
+ return "No valid images found for stitching.", None
29
+
30
+ try:
31
+ # Define crop coordinates
32
+ if crop:
33
+ crop_coords = (int(y_start), int(y_end), int(x_start), int(x_end))
34
+ else:
35
+ crop_coords = None
36
+
37
+ # Initialize OpenCV's Stitcher
38
+ stitcher = cv2.Stitcher_create()
39
+
40
+ # Perform stitching
41
+ status, panorama = stitcher.stitch(extracted_images)
42
+
43
+ if status != cv2.Stitcher_OK:
44
+ raise RuntimeError(f"Stitching failed with status code {status}.")
45
+
46
+ if crop:
47
+ y_start, y_end, x_start, x_end = crop_coords
48
+ cropped_panorama = panorama[y_start:y_end, x_start:x_end]
49
+ return panorama, cropped_panorama
50
+
51
+ return panorama, None
52
+
53
+ except Exception as e:
54
+ # Raise a gradio Error to avoid returning image outputs as text
55
+ raise gr.Error(f"Error during stitching: {str(e)}")
56
+
57
+
58
+ # Define Gradio interface using Blocks for better layout control
59
+ with gr.Blocks(title="Creating Panorama using OpenCV", theme=gr.themes.Soft()) as demo:
60
+ gr.Markdown("# Creating Panorama using OpenCV")
61
+ gr.Markdown("Upload the series of images sequentially and get the perfect Panorama!")
62
+
63
+ with gr.Row(equal_height=True):
64
+
65
+ examples = [
66
+ "./scene/scene1.jpg",
67
+ "./scene/scene2.jpg",
68
+ "./scene/scene3.jpg",
69
+ "./scene/scene4.jpg",
70
+ "./scene/scene5.jpg",
71
+ "./scene/scene6.jpg",
72
+ "./scene/scene7.jpg",
73
+ "./scene/scene8.jpg",
74
+ ]
75
+ with gr.Column():
76
+ image_upload = gr.Gallery(
77
+ value=examples,
78
+ columns=4,
79
+ label="Upload Images",
80
+ file_types=["image"],
81
+ format="jpeg",
82
+ type="numpy",
83
+ )
84
+ crop_checkbox = gr.Checkbox(label="Apply Cropping to Panorama", value=False)
85
+ with gr.Row():
86
+ y_start = gr.Number(label="Crop Y Start", value=90, interactive=True)
87
+ y_end = gr.Number(label="Crop Y End", value=867, interactive=True)
88
+ with gr.Row():
89
+ x_start = gr.Number(label="Crop X Start", value=1, interactive=True)
90
+ x_end = gr.Number(label="Crop X End", value=2000, interactive=True)
91
+ stitch_button = gr.Button("Stitch Images")
92
+ with gr.Row():
93
+ with gr.Column():
94
+ stitched_output = gr.Image(label="Stitched Panorama")
95
+ cropped_output = gr.Image(label="Cropped Panorama")
96
+
97
+
98
+ # Disable cropping input fields if checkbox is not selected
99
+ def toggle_crop_inputs(crop):
100
+ return gr.update(visible=crop), gr.update(visible=crop), gr.update(visible=crop), gr.update(visible=crop)
101
+
102
+ crop_checkbox.change(fn=toggle_crop_inputs, inputs=[crop_checkbox], outputs=[y_start, y_end, x_start, x_end])
103
+
104
+ # Define the button click event
105
+ stitch_button.click(
106
+ fn=process_images,
107
+ inputs=[image_upload, crop_checkbox, y_start, y_end, x_start, x_end],
108
+ outputs=[stitched_output, cropped_output],
109
+ )
110
+
111
+ gr.Markdown(
112
+ """
113
+ **Note**:
114
+ - Ensure that the uploaded images have overlapping regions for successful stitching.
115
+ - Cropping coordinates should be within the dimensions of the stitched panorama.
116
+ """
117
+ )
118
+
119
+ # Launch the Gradio interface
120
+ demo.launch(show_error=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ opencv-python==4.10.0.84
2
+ gradio
scene/scene1.jpg ADDED

Git LFS Details

  • SHA256: 885fe838a9d989eadb4cfb2e9cd6653f5db293b991adbce72ee124451c19df2b
  • Pointer size: 131 Bytes
  • Size of remote file: 344 kB
scene/scene2.jpg ADDED

Git LFS Details

  • SHA256: b2b8d0480baf1d1e866762609f02d687487351324182d3a22822da6149466c78
  • Pointer size: 131 Bytes
  • Size of remote file: 348 kB
scene/scene3.jpg ADDED

Git LFS Details

  • SHA256: 66569e03c9383a05588c490f2cde9b486cbb9b5da1fd1499afdb767563f855fd
  • Pointer size: 131 Bytes
  • Size of remote file: 358 kB
scene/scene4.jpg ADDED

Git LFS Details

  • SHA256: afca755569a093c53b6575a133c91177835aa8592a3066a7759edbe25257ff3d
  • Pointer size: 131 Bytes
  • Size of remote file: 378 kB
scene/scene5.jpg ADDED

Git LFS Details

  • SHA256: f1a244bc0f41f2b152c7076eb4b544361dc2fc184e76cef0e9696e6518cfdf31
  • Pointer size: 131 Bytes
  • Size of remote file: 403 kB
scene/scene6.jpg ADDED

Git LFS Details

  • SHA256: e6a70cd4154a997d0be4fa1c481917dd393a786cf1eae878447a9dc89d566687
  • Pointer size: 131 Bytes
  • Size of remote file: 425 kB
scene/scene7.jpg ADDED

Git LFS Details

  • SHA256: d9b1b3efc4eb5eae190651a89e3626ba63b2471ffc012140c09d3e8d1e5d6cba
  • Pointer size: 131 Bytes
  • Size of remote file: 420 kB
scene/scene8.jpg ADDED

Git LFS Details

  • SHA256: 2291f467e3dddc3d52a5ff2bf05b1ac8ba0bccafe5609023d77a8462bc928560
  • Pointer size: 131 Bytes
  • Size of remote file: 443 kB