Spaces:
Sleeping
Sleeping
Upload webapp.py
Browse files
webapp.py
CHANGED
|
@@ -10,6 +10,15 @@ import check_hkid_validity as chv
|
|
| 10 |
import search_engine as se
|
| 11 |
import socket
|
| 12 |
import pickle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def main():
|
| 15 |
|
|
@@ -123,30 +132,48 @@ def main():
|
|
| 123 |
|
| 124 |
FRAME_WINDOW = st.image([])
|
| 125 |
|
| 126 |
-
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 127 |
-
s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1000000)
|
| 128 |
|
| 129 |
-
server_ip = "127.0.0.1"
|
| 130 |
-
server_port = 6666
|
| 131 |
|
| 132 |
-
camera = cv2.VideoCapture(1)
|
|
|
|
|
|
|
| 133 |
|
| 134 |
while run:
|
| 135 |
|
|
|
|
|
|
|
| 136 |
# Capture frame-by-frame
|
| 137 |
# Grab a single frame of video
|
| 138 |
-
ret, frame = camera.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 141 |
|
| 142 |
-
FRAME_WINDOW.image(frame)
|
| 143 |
|
| 144 |
-
if ret is not None:
|
| 145 |
-
|
| 146 |
|
| 147 |
-
x_as_bytes = pickle.dumps(buffer)
|
| 148 |
|
| 149 |
-
s.sendto((x_as_bytes),(server_ip, server_port))
|
| 150 |
|
| 151 |
# camera.release()
|
| 152 |
# if ret:
|
|
|
|
| 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 |
|
|
|
|
| 132 |
|
| 133 |
FRAME_WINDOW = st.image([])
|
| 134 |
|
|
|
|
|
|
|
| 135 |
|
| 136 |
+
# server_ip = "127.0.0.1"
|
| 137 |
+
# server_port = 6666
|
| 138 |
|
| 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 |
+
|
| 147 |
# Capture frame-by-frame
|
| 148 |
# Grab a single frame of video
|
| 149 |
+
# ret, frame = camera.read()
|
| 150 |
+
|
| 151 |
+
# Initialize the WebRTC streaming
|
| 152 |
+
webrtc_ctx = webrtc_streamer(
|
| 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
|
| 164 |
+
result, process_this_frame, face_locations, faces, face_names, score = demo.process_frame(frame, process_this_frame, face_locations, faces, face_names, score)
|
| 165 |
+
st.video(result)
|
| 166 |
|
| 167 |
+
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 168 |
|
| 169 |
+
# FRAME_WINDOW.image(frame)
|
| 170 |
|
| 171 |
+
# if ret is not None:
|
| 172 |
+
# ret, buffer = cv2.imencode(".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY),30])
|
| 173 |
|
| 174 |
+
# x_as_bytes = pickle.dumps(buffer)
|
| 175 |
|
| 176 |
+
# s.sendto((x_as_bytes),(server_ip, server_port))
|
| 177 |
|
| 178 |
# camera.release()
|
| 179 |
# if ret:
|