Spaces:
Runtime error
Runtime error
File size: 3,072 Bytes
8b84132 3262c33 8b84132 3262c33 8b84132 3262c33 357413c 37219b3 8b84132 9d619c8 3262c33 d625296 3262c33 a2c4e9f e84165f 3262c33 a905457 472070e a6d7828 3262c33 63a817e 3262c33 cc475cb 9d619c8 8b84132 24d70b0 88ab719 c59fcd0 6766457 3262c33 8b84132 3262c33 d2f306b a079f8e 585528f 1263331 585528f 8b84132 3262c33 |
1 2 3 4 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
import gradio as gr
import numpy as np
import time
import os
import cv2 as cv
#from cv2 import (VideoCapture, imshow, waitKey, destroyAllWindows,
#CAP_PROP_FRAME_WIDTH, CAP_PROP_FRAME_HEIGHT, CAP_PROP_FPS, COLOR_RGB2BGR, cvtColor, INTER_LINEAR)
cwd = os.getcwd()
print(cwd)
#Hinton = os.path.join(cwd, "\Geoffrey_Hinton.jpeg")
#Lecun = os.path.join(cwd, "\Yann_LeCun.jpeg")
#Morph = os.path.join(cwd, "\video.mp4")
Hinton=cwd + "/Geoffrey_Hinton.jpeg"
Lecun=cwd + "/Yann_LeCun.jpeg"
Morph=cwd + "/video.mp4"
print(Lecun)
print(Hinton)
print(Morph)
# Create video capture object
capture = cv.VideoCapture(Morph)
# Check that a camera connection has been established
if not capture.isOpened():
print("Error opening video file")
else:
# Get video properties and print them
frame_width = capture.get(cv.CAP_PROP_FRAME_WIDTH)
frame_height = capture.get(cv.CAP_PROP_FRAME_HEIGHT)
fps = capture.get(cv.CAP_PROP_FPS)
print("Image frame width: ", int(frame_width))
print("Image frame height: ", int(frame_height))
print("Frame rate: ", int(fps))
def morphing(inp, target, slider):
capture = cv.VideoCapture(Morph)
for i in range(slider):
print(i)
# time.sleep(0.05)
# Read an image frame
ret, frame = capture.read()
# print(len(frame))
if ret:
image = cv.cvtColor(frame, cv.COLOR_RGB2BGR)
# Set rows and columns
# lets downsize the image using new width and height
down_width = int(frame_width/4)
down_height = int(frame_height/2)
down_points = (down_width, down_height)
# image = cv.resize(image, (720,1280), interpolation= cv.INTER_LINEAR)
yield image
# image = np.ones((240,240,3), np.uint8)
# image[:] = [255, 124, 0]
# yield image
ww= 256 #int(frame_width/2)
hh= 256 #int(frame_height/2)
with gr.Blocks(theme=gr.themes.Default(font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])) as demo:
gr.Markdown("Start choosing an input and target image for the morphing then click **Submit** to watch the output in slow motion.")
with gr.Row():
inp = gr.Image(label="Input", value=Lecun, width=ww, height=hh) # width=int(frame_width),height=int(frame_height))
target = gr.Image(label="Target", value=Hinton, width=ww, height=hh) # width=int(frame_width),height=int(frame_height))
out = gr.Image(label="Output", width=int(frame_width/2),height=int(frame_height/3)) # width=ww, height=hh) # width=int(frame_width),height=int(frame_height))
slider= gr.Slider(1, 1000, value=300, label="Steps", info="Choose between 1 and 1000")
btn = gr.Button("Submit")
btn.click(fn=morphing, inputs=[inp,target,slider], outputs=out)
gr.ClearButton([inp,target,slider,out])
gr.Examples(
examples=[[Lecun, Hinton, 300], [Lecun, Hinton, 150]],
inputs=[inp, target, slider],
outputs=out,
fn=morphing,
cache_examples=True,
)
if __name__ == "__main__":
demo.queue()
demo.launch() |