Beasto commited on
Commit
d946723
·
1 Parent(s): 9999467

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ from tensorflow.keras.models import load_model
3
+ from PIL import Image
4
+ import numpy as np
5
+ import streamlit as st
6
+
7
+ # Replace 'your_video.mp4' with the path to your video file
8
+ # Open the video file
9
+ video_path = st.file_uploader("Choose a video file", type=["mp4"])
10
+ video_path = st.video(video_path)
11
+
12
+ cap = cv2.VideoCapture(video_path)
13
+
14
+ # Get the frames per second (fps) of the video
15
+ fps = cap.get(cv2.CAP_PROP_FPS)
16
+
17
+ # Calculate the interval to capture one frame per second
18
+ interval = int(round(1 / fps))
19
+
20
+ # Initialize a counter for frames
21
+ frame_count = 0
22
+ model = load_model('HandSignClassifier.h5')
23
+ array = ['a','b','c','d','e','f','g','h','i','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y']
24
+ out = ''
25
+ while True:
26
+ # Read the next frame
27
+ ret, frame = cap.read()
28
+
29
+ # Break the loop if the video is over
30
+ if not ret:
31
+ break
32
+
33
+ # Check if it's time to capture a frame
34
+ if frame_count % interval == 0:
35
+ frame = np.array(frame)
36
+ frame = Image.fromarray(frame).resize((28,28))
37
+ frame = frame.comvert('L')
38
+ frame = np.reshape((1,28,28,1))
39
+ pred = model.predict(frame)
40
+ pred = np.argmax(pred)
41
+ pred = array[pred]
42
+ if out[-1] != pred:
43
+ out = out+pred
44
+
45
+ # Increment the frame counter
46
+ frame_count += 1
47
+
48
+ # Release the video capture object
49
+ cap.release()
50
+
51
+ print(out)