marcotam commited on
Commit
b8e2d45
1 Parent(s): 841bad9

Upload webapp.py

Browse files
Files changed (1) hide show
  1. webapp.py +27 -11
webapp.py CHANGED
@@ -7,18 +7,26 @@ import demo
7
  import streamlit as st
8
  import request_json.sbt_request_generator as sbt
9
  import check_hkid_validity as chv
10
- import search_engine as se
11
- import socket
12
- import pickle
13
  from streamlit_webrtc import webrtc_streamer, VideoTransformerBase, RTCConfiguration, WebRtcMode
14
 
15
- class WebcamTransformer(VideoTransformerBase):
16
- def __init__(self):
17
- self.frame_count = 0
 
 
18
 
19
- def transform(self, frame):
20
- self.frame_count += 1
21
- return frame
 
 
 
 
 
 
 
 
22
 
23
  def main():
24
 
@@ -139,8 +147,11 @@ def main():
139
  # camera = cv2.VideoCapture(1)
140
  # s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
141
  # s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1000000)
 
 
 
142
 
143
- while run:
144
 
145
  rtc_configuration = RTCConfiguration({"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]})
146
 
@@ -153,11 +164,16 @@ def main():
153
  key="face_rec",
154
  mode=WebRtcMode.SENDRECV,
155
  rtc_configuration=rtc_configuration,
156
- video_transformer_factory=WebcamTransformer,
 
157
  media_stream_constraints={"video": True, "audio": False},
158
  async_processing=True,
159
  )
160
 
 
 
 
 
161
  if webrtc_ctx.video_transformer:
162
  st.header("Webcam Preview")
163
  frame = webrtc_ctx.video_transformer.frame
 
7
  import streamlit as st
8
  import request_json.sbt_request_generator as sbt
9
  import check_hkid_validity as chv
10
+ import av
 
 
11
  from streamlit_webrtc import webrtc_streamer, VideoTransformerBase, RTCConfiguration, WebRtcMode
12
 
13
+ def init():
14
+ face_locations = []
15
+ # face_encodings = []
16
+ face_names = []
17
+ process_this_frame = True
18
 
19
+ score = []
20
+
21
+ faces = 0
22
+
23
+ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
24
+ image = frame.to_ndarray(format="bgr24")
25
+
26
+
27
+
28
+
29
+ return av.VideoFrame.from_ndarray(image, format="bgr24")
30
 
31
  def main():
32
 
 
147
  # camera = cv2.VideoCapture(1)
148
  # s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
149
  # s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1000000)
150
+
151
+ # if "face_rec" not in st.session_state:
152
+ # st.session_state.face_rec = []
153
 
154
+ if run:
155
 
156
  rtc_configuration = RTCConfiguration({"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]})
157
 
 
164
  key="face_rec",
165
  mode=WebRtcMode.SENDRECV,
166
  rtc_configuration=rtc_configuration,
167
+ # video_transformer_factory=WebcamTransformer,
168
+ video_frame_callback=video_frame_callback,
169
  media_stream_constraints={"video": True, "audio": False},
170
  async_processing=True,
171
  )
172
 
173
+ # print(f'xd: look here {type(webrtc_ctx)}')
174
+
175
+ # st.session_state.face_rec = webrtc_ctx
176
+
177
  if webrtc_ctx.video_transformer:
178
  st.header("Webcam Preview")
179
  frame = webrtc_ctx.video_transformer.frame