Spaces:
Sleeping
Sleeping
File size: 3,282 Bytes
8b84132 3262c33 8b84132 3262c33 8b84132 3262c33 357413c 9fa941d 0a814d8 e8f5e32 8b84132 9d619c8 3262c33 d625296 3262c33 a2c4e9f e84165f 3262c33 a905457 472070e 14d6a63 3262c33 63a817e 3262c33 cc475cb 9d619c8 61e6052 453c795 8b84132 24d70b0 88ab719 0c36add 9fa941d bb50ba3 3262c33 8b84132 3262c33 d2f306b 0c36add 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 87 88 89 90 91 92 |
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= "Geoffrey_Hinton.jpeg"
Lecun= "Yann_LeCun.jpeg"
w_target="woman_target.png"
w_source="woman_source.png"
Morph= "women_teaser.mp4" #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)
inputs = gr.Image(label="Inputs", value=w_source)
targets = gr.Image(label="Targets", value=w_target, type="pil")
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=w_source, type="pil") # width=int(frame_width),height=int(frame_height))
target = gr.Image(label="Target", value=w_target, type="pil") # 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=[[w_source, w_target, 300], [w_source, w_target, 150]],
inputs=[inp, target, slider],
outputs=out,
fn=morphing,
cache_examples=True,
)
if __name__ == "__main__":
demo.queue()
demo.launch() |