Spaces:
Paused
Paused
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import cv2
|
| 3 |
-
import numpy as np
|
| 4 |
-
from typing import Union, List
|
| 5 |
-
from pathlib import Path
|
| 6 |
-
from PIL import Image
|
| 7 |
-
import torch
|
| 8 |
-
|
| 9 |
-
# Function to resize images
|
| 10 |
-
|
| 11 |
-
def resize_images(images, scale_percent=50):
|
| 12 |
-
resized_images = []
|
| 13 |
-
for img in images:
|
| 14 |
-
width = int(img.shape[1] * scale_percent / 100)
|
| 15 |
-
height = int(img.shape[0] * scale_percent / 100)
|
| 16 |
-
dim = (width, height)
|
| 17 |
-
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
|
| 18 |
-
resized_images.append(resized)
|
| 19 |
-
return resized_images
|
| 20 |
-
|
| 21 |
-
# Function to stitch images
|
| 22 |
-
|
| 23 |
-
def stitch_images(image_paths, scale_percent=50):
|
| 24 |
-
images = [cv2.imread(path) for path in image_paths]
|
| 25 |
-
resized_images = resize_images(images, scale_percent)
|
| 26 |
-
stitcher = cv2.Stitcher_create()
|
| 27 |
-
status, stitched_image = stitcher.stitch(resized_images)
|
| 28 |
-
|
| 29 |
-
if status == cv2.Stitcher_OK:
|
| 30 |
-
print("Stitching successful!")
|
| 31 |
-
return stitched_image
|
| 32 |
-
else:
|
| 33 |
-
print(f"Stitching failed with status code: {status}")
|
| 34 |
-
return None
|
| 35 |
-
|
| 36 |
-
# Main image processing function
|
| 37 |
-
|
| 38 |
-
def process_image(image_paths, scale_percent=50):
|
| 39 |
-
stitched_image = stitch_images(image_paths, scale_percent)
|
| 40 |
-
|
| 41 |
-
if stitched_image is not None:
|
| 42 |
-
try:
|
| 43 |
-
stitched_image_rgb = cv2.cvtColor(stitched_image, cv2.COLOR_BGR2RGB)
|
| 44 |
-
return stitched_image_rgb
|
| 45 |
-
except Exception as e:
|
| 46 |
-
print(str(e))
|
| 47 |
-
return stitched_image
|
| 48 |
-
|
| 49 |
-
# Gradio interface function
|
| 50 |
-
|
| 51 |
-
def gradio_stitch_and_detect(image_files):
|
| 52 |
-
image_paths = [file.name for file in image_files]
|
| 53 |
-
result_image = process_image(image_paths, scale_percent=50)
|
| 54 |
-
|
| 55 |
-
if result_image is not None:
|
| 56 |
-
result_image_rgb = result_image
|
| 57 |
-
pil_image = Image.fromarray(result_image_rgb)
|
| 58 |
-
pil_image.save("stitched_image.jpg", "JPEG")
|
| 59 |
-
return pil_image, "stitched_image.jpg"
|
| 60 |
-
|
| 61 |
-
return None, None
|
| 62 |
-
|
| 63 |
-
# Gradio interface
|
| 64 |
-
with gr.Blocks() as interface:
|
| 65 |
-
gr.Markdown("<h1 style='color: #2196F3; text-align: center;'>Image Stitcher 🧵</h1>")
|
| 66 |
-
gr.Markdown("<h3 style='color: #2196F3; text-align: center;'>=== Upload the images (.jpg, .png, etc) you want to stitch ===</h3>")
|
| 67 |
-
|
| 68 |
-
image_upload = gr.Files(type="filepath", label="Upload Images")
|
| 69 |
-
stitch_button = gr.Button("Stitch", variant="primary")
|
| 70 |
-
stitched_image = gr.Image(type="pil", label="Stitched Image")
|
| 71 |
-
download_button = gr.File(label="Download Stitched Image")
|
| 72 |
-
|
| 73 |
-
stitch_button.click(gradio_stitch_and_detect, inputs=image_upload, outputs=[stitched_image, download_button])
|
| 74 |
-
|
| 75 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|