Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import socket
|
| 3 |
+
import pickle
|
| 4 |
+
import numpy as np
|
| 5 |
+
import demo
|
| 6 |
+
|
| 7 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 8 |
+
ip = "127.0.0.1"
|
| 9 |
+
port = 6666
|
| 10 |
+
s.bind((ip,port))
|
| 11 |
+
|
| 12 |
+
face_locations = []
|
| 13 |
+
# face_encodings = []
|
| 14 |
+
face_names = []
|
| 15 |
+
process_this_frame = True
|
| 16 |
+
|
| 17 |
+
score = []
|
| 18 |
+
|
| 19 |
+
faces = 0
|
| 20 |
+
|
| 21 |
+
while True:
|
| 22 |
+
print("Hello")
|
| 23 |
+
x = s.recvfrom(1000000)
|
| 24 |
+
clientip = x[1][0]
|
| 25 |
+
data = x[0]
|
| 26 |
+
|
| 27 |
+
data = pickle.loads(data)
|
| 28 |
+
|
| 29 |
+
frame = cv2.imdecode(data, cv2.IMREAD_COLOR)
|
| 30 |
+
|
| 31 |
+
result, process_this_frame, face_locations, faces, face_names, score = demo.process_frame(frame, process_this_frame, face_locations, faces, face_names, score)
|
| 32 |
+
|
| 33 |
+
result = cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
|
| 34 |
+
|
| 35 |
+
cv2.imshow('server side', result)
|
| 36 |
+
|
| 37 |
+
print(score)
|
| 38 |
+
if len(score) > 20:
|
| 39 |
+
avg_score = sum(score) / len(score)
|
| 40 |
+
break
|
| 41 |
+
|
| 42 |
+
if cv2.waitKey(5) & 0xFF == 27:
|
| 43 |
+
break
|
| 44 |
+
|
| 45 |
+
cv2.destroyAllWindows()
|
webapp.py
CHANGED
|
@@ -3,13 +3,13 @@ import similarity_check as sc
|
|
| 3 |
import cv2
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
| 6 |
-
from streamlit_webrtc import VideoTransformerBase, webrtc_streamer
|
| 7 |
import demo
|
| 8 |
import streamlit as st
|
| 9 |
import request_json.sbt_request_generator as sbt
|
| 10 |
import check_hkid_validity as chv
|
| 11 |
import search_engine as se
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
def main():
|
| 15 |
|
|
@@ -122,38 +122,53 @@ def main():
|
|
| 122 |
faces = 0
|
| 123 |
|
| 124 |
FRAME_WINDOW = st.image([])
|
| 125 |
-
# camera = cv2.VideoCapture(0)
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
while run:
|
| 129 |
|
| 130 |
# Capture frame-by-frame
|
| 131 |
# Grab a single frame of video
|
|
|
|
| 132 |
|
| 133 |
-
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
if st.button("Confirm"):
|
| 159 |
st.experimental_set_query_params(
|
|
|
|
| 3 |
import cv2
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
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 |
|
| 14 |
def main():
|
| 15 |
|
|
|
|
| 122 |
faces = 0
|
| 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(0)
|
| 133 |
|
| 134 |
while run:
|
| 135 |
|
| 136 |
# Capture frame-by-frame
|
| 137 |
# Grab a single frame of video
|
| 138 |
+
ret, frame = camera.read()
|
| 139 |
|
| 140 |
+
if ret is not None:
|
| 141 |
+
ret, buffer = cv2.imencode(".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY),30])
|
| 142 |
|
| 143 |
+
x_as_bytes = pickle.dumps(buffer)
|
| 144 |
+
|
| 145 |
+
s.sendto((x_as_bytes),(server_ip, server_port))
|
| 146 |
+
|
| 147 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 148 |
+
|
| 149 |
+
FRAME_WINDOW.image(frame)
|
| 150 |
+
|
| 151 |
+
# camera.release()
|
| 152 |
+
# if ret:
|
| 153 |
+
# # ret, buffer = cv2.imencode(".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY)])
|
| 154 |
+
# # result, process_this_frame, face_locations, faces, face_names, score = demo.process_frame(frame, process_this_frame, face_locations, faces, face_names, score)
|
| 155 |
+
# # Display the resulting image
|
| 156 |
+
# FRAME_WINDOW.image(frame)
|
| 157 |
+
# else:
|
| 158 |
+
# print("there is no frame detected")
|
| 159 |
+
# continue
|
| 160 |
+
|
| 161 |
+
# print(score)
|
| 162 |
+
# if len(score) > 20:
|
| 163 |
+
# avg_score = sum(score) / len(score)
|
| 164 |
+
# st.write(avg_score)
|
| 165 |
+
# # st.write(f'{demo.convert_distance_to_percentage(avg_score, 0.45)}')
|
| 166 |
+
# # camera.release()
|
| 167 |
+
# run = not run
|
| 168 |
+
# st.session_state['data']['avg_score'] = str(avg_score)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
## unrelated
|
| 172 |
|
| 173 |
if st.button("Confirm"):
|
| 174 |
st.experimental_set_query_params(
|