pn23 commited on
Commit
662bc01
·
verified ·
1 Parent(s): b9f6605

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import io
3
+ import cv2
4
+
5
+
6
+ st.title("Play Uploaded File")
7
+
8
+ uploaded_file = st.file_uploader("Choose a video...", type=["mp4"])
9
+ temporary_location = False
10
+
11
+ if uploaded_file is not None:
12
+ g = io.BytesIO(uploaded_file.read()) ## BytesIO Object
13
+ temporary_location = "testout_simple.mp4"
14
+
15
+ with open(temporary_location, 'wb') as out: ## Open temporary file as bytes
16
+ out.write(g.read()) ## Read bytes into file
17
+
18
+ # close file
19
+ out.close()
20
+
21
+
22
+ @st.cache(allow_output_mutation=True)
23
+ def get_cap(location):
24
+ print("Loading in function", str(location))
25
+ video_stream = cv2.VideoCapture(str(location))
26
+
27
+ # Check if camera opened successfully
28
+ if (video_stream.isOpened() == False):
29
+ print("Error opening video file")
30
+ return video_stream
31
+
32
+
33
+ scaling_factorx = 0.25
34
+ scaling_factory = 0.25
35
+ image_placeholder = st.empty()
36
+
37
+ if temporary_location:
38
+ while True:
39
+ # here it is a CV2 object
40
+ video_stream = get_cap(temporary_location)
41
+ # video_stream = video_stream.read()
42
+ ret, image = video_stream.read()
43
+ if ret:
44
+ image = cv2.resize(image, None, fx=scaling_factorx, fy=scaling_factory, interpolation=cv2.INTER_AREA)
45
+ else:
46
+ print("there was a problem or video was finished")
47
+ cv2.destroyAllWindows()
48
+ video_stream.release()
49
+ break
50
+ # check if frame is None
51
+ if image is None:
52
+ print("there was a problem None")
53
+ # if True break the infinite loop
54
+ break
55
+
56
+ image_placeholder.image(image, channels="BGR", use_column_width=True)
57
+
58
+ cv2.destroyAllWindows()
59
+ video_stream.release()
60
+
61
+
62
+ cv2.destroyAllWindows()