Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
KHY_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Graduate
2020-06-05 14:25:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8994125b2d7e62e3dfecc8fd2278a65011010f8b
8994125b
1 parent
2a709637
Modify server.py
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
20 deletions
server/models/__pycache__/inception_resnet_v1.cpython-37.pyc
server/models/__pycache__/mtcnn.cpython-37.pyc
server/models/utils/__pycache__/detect_face.cpython-37.pyc
server/server.py
server/models/__pycache__/inception_resnet_v1.cpython-37.pyc
View file @
8994125
No preview for this file type
server/models/__pycache__/mtcnn.cpython-37.pyc
View file @
8994125
No preview for this file type
server/models/utils/__pycache__/detect_face.cpython-37.pyc
View file @
8994125
No preview for this file type
server/server.py
View file @
8994125
...
...
@@ -42,6 +42,10 @@ async def get_distance(arr1, arr2):
distance
=
np
.
linalg
.
norm
(
arr1
-
arr2
)
return
distance
async
def
get_cosine_similarity
(
arr1
,
arr2
):
similarity
=
np
.
inner
(
arr1
,
arr2
)
/
(
np
.
linalg
.
norm
(
arr1
)
*
np
.
linalg
.
norm
(
arr2
))
return
similarity
def
get_argmin
(
someone
,
database
):
distance
=
get_distance
(
someone
,
database
)
for
i
in
range
(
len
(
distance
)):
...
...
@@ -126,7 +130,7 @@ async def thread(websocket, path):
cursor
.
execute
(
sql
)
result
=
cursor
.
fetchall
()
verified_id
=
'0'
distance_min
=
1.0
distance_min
=
99
for
row_data
in
result
:
db_embedding
=
np
.
frombuffer
(
row_data
[
'embedding'
],
dtype
=
np
.
float32
)
db_embedding
=
db_embedding
.
reshape
((
1
,
512
))
...
...
@@ -138,7 +142,7 @@ async def thread(websocket, path):
# 출석 데이터 전송
send
=
''
print
(
'[debug] distance:'
,
distance_min
)
if
distance_min
>=
0.
6
:
if
distance_min
>=
0.
5
:
# 해당하는 사람 DB에 없음
msg
=
'[{ip}] verification failed'
.
format
(
ip
=
remote_ip
)
print
(
msg
)
...
...
@@ -146,36 +150,40 @@ async def thread(websocket, path):
else
:
# 해당하는 사람 DB에 있음
# logging
msg
=
'[{ip}] verification success {id}'
.
format
(
ip
=
remote_ip
,
id
=
verified_id
)
print
(
msg
)
# TODO: lecture DB에 tuple 삽입해야 아래 코드가 돌아감
# 해당하는 사람이 DB에 있으면 출석 처리
# 테이블 맨 뒤에 datetime attribute가 있음. 서버 시간 가져오게 default로 설정해둠.
#sql = "INSERT INTO student_attendance(lecture_id, student_id, status) VALUES (%s, %s, %s, %s)"
# TODO: attend / late 처리
#cursor.execute(sql, ('0', verified_id, 'attend'))
# client에 전달
send
=
json
.
dumps
({
'status'
:
'success'
,
'student_id'
:
verified_id
})
# DB에 오늘 이미 출석한 기록이 있는지 확인
sql
=
"SELECT DATE(timestamp) FROM student_attendance WHERE (lecture_id=
%
s) AND (student_id=
%
s) AND (DATE(timestamp) = CURDATE());"
cursor
.
execute
(
sql
,
(
'0'
,
verified_id
))
# 출석 기록이 없는 경우에만
if
not
cursor
.
fetchone
():
# 테이블 맨 뒤에 datetime attribute가 있음. 서버 시간 가져오게 default로 설정해둠.
sql
=
"INSERT INTO student_attendance(lecture_id, student_id, status) VALUES (
%
s,
%
s,
%
s)"
# TODO: attend / late 처리
cursor
.
execute
(
sql
,
(
'0'
,
verified_id
,
'attend'
))
attendance_db
.
commit
()
# log 작성
msg
=
'[{ip}] verification success {id}'
.
format
(
ip
=
remote_ip
,
id
=
verified_id
)
print
(
msg
)
# client에 전달
send
=
json
.
dumps
({
'status'
:
'success'
,
'student_id'
:
verified_id
})
else
:
send
=
json
.
dumps
({
'status'
:
'already'
,
'student_id'
:
verified_id
})
await
websocket
.
send
(
send
)
elif
data
[
'action'
]
==
"save_image"
:
# 출석이 제대로 이뤄지지 않으면 이미지를 저장하여
# 나중에 교강사가 출석을 확인할 수 있도록 한다
msg
=
'[{ip}] save image'
.
format
(
ip
=
remote_ip
)
print
(
msg
)
arr
=
np
.
asarray
(
data
[
'image'
],
dtype
=
np
.
uint8
)
blob
=
arr
.
tobytes
()
#datetime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# TODO: lecture DB에 tuple 삽입해야 아래 코드가 돌아감
# 테이블 맨 뒤에 datetime attribute가 있음. 서버 시간 가져오게 default로 설정해둠.
#
cursor = attendance_db.cursor(pymysql.cursors.DictCursor)
#sql = "INSERT INTO undefined_image(lecture_id, datetime, image, width, height) VALUES (%s,
%s, _binary %s, %s, %s)"
#cursor.execute(sql, ('0', datetime
, blob, arr.shape[0], arr.shape[1]))
#
attendance_db.commit()
cursor
=
attendance_db
.
cursor
(
pymysql
.
cursors
.
DictCursor
)
sql
=
"INSERT INTO undefined_image(lecture_id, image, width, height) VALUES (
%
s, _binary
%
s,
%
s,
%
s)"
cursor
.
execute
(
sql
,
(
'0'
,
blob
,
arr
.
shape
[
0
],
arr
.
shape
[
1
]))
attendance_db
.
commit
()
else
:
print
(
"unsupported event: {}"
,
data
)
finally
:
...
...
Please
register
or
login
to post a comment