Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,15 +4,7 @@ import cv2 as cv
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
|
| 7 |
-
def video_change(v):
|
| 8 |
-
vc = cv.VideoCapture(v)
|
| 9 |
-
fps = vc.get(cv.CAP_PROP_FPS)
|
| 10 |
-
fms = vc.get(cv.CAP_PROP_FRAME_COUNT)
|
| 11 |
-
w = vc.get(cv.CAP_PROP_FRAME_WIDTH)
|
| 12 |
-
h = vc.get(cv.CAP_PROP_FRAME_HEIGHT)
|
| 13 |
-
vc.release()
|
| 14 |
-
return fps, fms, w, h, gr.update(maximum=int(fms)-1)
|
| 15 |
-
def video_change2(v, vc):
|
| 16 |
if vc:
|
| 17 |
vc.release()
|
| 18 |
vc = cv.VideoCapture(v)
|
|
@@ -22,15 +14,7 @@ def video_change2(v, vc):
|
|
| 22 |
h = vc.get(cv.CAP_PROP_FRAME_HEIGHT)
|
| 23 |
return fps, fms, w, h, gr.update(maximum=int(fms)-1), vc
|
| 24 |
|
| 25 |
-
|
| 26 |
-
def get_nth_frame(v, n):
|
| 27 |
-
vc = cv.VideoCapture(v)
|
| 28 |
-
vc.set(cv.CAP_PROP_POS_FRAMES, n)
|
| 29 |
-
ok, img = vc.read()
|
| 30 |
-
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
|
| 31 |
-
vc.release()
|
| 32 |
-
return img
|
| 33 |
-
def get_nth_frame2(vc, n):
|
| 34 |
vc.set(cv.CAP_PROP_POS_FRAMES, n)
|
| 35 |
ok, img = vc.read()
|
| 36 |
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
|
|
@@ -56,11 +40,11 @@ with gr.Blocks() as demo:
|
|
| 56 |
btn = gr.Button(value="Submit")
|
| 57 |
|
| 58 |
input_video.change(
|
| 59 |
-
|
| 60 |
inputs=[input_video, state_vc],
|
| 61 |
outputs=[output_fps, output_fms, output_w, output_h, input_n, state_vc]
|
| 62 |
)
|
| 63 |
-
btn.click(
|
| 64 |
|
| 65 |
gr.Markdown("*****")
|
| 66 |
|
|
@@ -71,11 +55,11 @@ with gr.Blocks() as demo:
|
|
| 71 |
return [ path+"/test.mp4", path+"/label.csv"]
|
| 72 |
with gr.Row():
|
| 73 |
df = gr.Dataframe(
|
|
|
|
| 74 |
headers=["start_index", "end_index", "label"],
|
| 75 |
datatype=["number", "number", "number"],
|
| 76 |
-
row_count=0,
|
| 77 |
-
col_count=(3, "fixed"),
|
| 78 |
height=500,
|
|
|
|
| 79 |
)
|
| 80 |
file = gr.File(file_count='multiple')
|
| 81 |
btn_make_dataset = gr.Button(value="make dataset")
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
|
| 7 |
+
def video_change(v, vc):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
if vc:
|
| 9 |
vc.release()
|
| 10 |
vc = cv.VideoCapture(v)
|
|
|
|
| 14 |
h = vc.get(cv.CAP_PROP_FRAME_HEIGHT)
|
| 15 |
return fps, fms, w, h, gr.update(maximum=int(fms)-1), vc
|
| 16 |
|
| 17 |
+
def get_nth_frame(vc, n):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
vc.set(cv.CAP_PROP_POS_FRAMES, n)
|
| 19 |
ok, img = vc.read()
|
| 20 |
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
|
|
|
|
| 40 |
btn = gr.Button(value="Submit")
|
| 41 |
|
| 42 |
input_video.change(
|
| 43 |
+
video_change,
|
| 44 |
inputs=[input_video, state_vc],
|
| 45 |
outputs=[output_fps, output_fms, output_w, output_h, input_n, state_vc]
|
| 46 |
)
|
| 47 |
+
btn.click(get_nth_frame, inputs=[state_vc, input_n], outputs=output_img)
|
| 48 |
|
| 49 |
gr.Markdown("*****")
|
| 50 |
|
|
|
|
| 55 |
return [ path+"/test.mp4", path+"/label.csv"]
|
| 56 |
with gr.Row():
|
| 57 |
df = gr.Dataframe(
|
| 58 |
+
value=[[1,2,3], [4,5,6]]
|
| 59 |
headers=["start_index", "end_index", "label"],
|
| 60 |
datatype=["number", "number", "number"],
|
|
|
|
|
|
|
| 61 |
height=500,
|
| 62 |
+
interactive=False,
|
| 63 |
)
|
| 64 |
file = gr.File(file_count='multiple')
|
| 65 |
btn_make_dataset = gr.Button(value="make dataset")
|