Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박선진
/
video-emergency-detection
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
3
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박선진
2020-06-20 15:36:02 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6ca0911403532498c51896a1fdd812b30dd5e01a
6ca09114
1 parent
b9285fe6
seperate process class for readability
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
36 deletions
detection-API/__pycache__/process.cpython-38.pyc
detection-API/index.py
detection-API/process.py
detection-API/__pycache__/process.cpython-38.pyc
0 → 100644
View file @
6ca0911
No preview for this file type
detection-API/index.py
View file @
6ca0911
import
base64
import
face_recognition
import
numpy
as
np
from
cv2
import
cv2
import
os
import
process
known_path
=
'./images/'
# directory path of known faces
image_format
=
'jpg'
# image to base64 encoding
# you have to set 'encoded_image' to frame code
with
open
(
"./images/obama.jpg"
,
"rb"
)
as
img_file
:
encoded_image
=
base64
.
b64encode
(
img_file
.
read
())
#base64 to image(uint8) decoding
img64_decode
=
base64
.
decodebytes
(
encoded_image
)
im_arr
=
np
.
frombuffer
(
img64_decode
,
dtype
=
np
.
uint8
)
decoded_img
=
cv2
.
imdecode
(
im_arr
,
flags
=
cv2
.
IMREAD_COLOR
)
#encoding frame
unknown_face_encoding
=
face_recognition
.
face_encodings
(
decoded_img
)[
0
]
# Load & encode all images from known_path
known_list
=
os
.
listdir
(
known_path
)
known_faces
=
[]
for
f
in
known_list
:
if
f
.
split
(
'.'
)[
-
1
]
!=
image_format
:
continue
known_img
=
face_recognition
.
load_image_file
(
known_path
+
f
)
known_img_encoding
=
face_recognition
.
face_encodings
(
known_img
)[
0
]
known_faces
.
append
(
known_img_encoding
)
# results is an array of True/False telling if the unknown face matched anyone in the known_faces array
results
=
face_recognition
.
compare_faces
(
known_faces
,
unknown_face_encoding
)
print
(
results
)
#print(not True in results)
\ No newline at end of file
if
__name__
==
'__main__'
:
p
=
process
.
Process
()
p
.
ProcessImage
()
\ No newline at end of file
...
...
detection-API/process.py
0 → 100644
View file @
6ca0911
import
base64
import
face_recognition
import
numpy
as
np
from
cv2
import
cv2
import
os
class
Process
:
def
__init__
(
self
):
known_path
=
'./images/'
# directory path of known faces
image_format
=
'jpg'
known_list
=
os
.
listdir
(
known_path
)
self
.
known_faces
=
[]
# Load & encode all images from known_path
for
f
in
known_list
:
if
f
.
split
(
'.'
)[
-
1
]
!=
image_format
:
continue
known_img
=
face_recognition
.
load_image_file
(
known_path
+
f
)
known_img_encoding
=
face_recognition
.
face_encodings
(
known_img
)[
0
]
self
.
known_faces
.
append
(
known_img_encoding
)
def
ProcessImage
(
self
):
# image to base64 encoding
# you have to set 'encoded_image' to frame code
with
open
(
"./images/obama.jpg"
,
"rb"
)
as
img_file
:
encoded_image
=
base64
.
b64encode
(
img_file
.
read
())
#base64 to image(uint8) decoding
img64_decode
=
base64
.
b64decode
(
encoded_image
)
im_arr
=
np
.
frombuffer
(
img64_decode
,
dtype
=
np
.
uint8
)
decoded_img
=
cv2
.
imdecode
(
im_arr
,
flags
=
cv2
.
IMREAD_COLOR
)
face
=
self
.
FaceRecognition
(
decoded_img
)
#True면 침입자 발생
result
=
{
"unknown_person"
:
face
}
print
(
result
)
return
result
def
FaceRecognition
(
self
,
decoded_img
):
#encoding frame
try
:
unknown_face_encoding
=
face_recognition
.
face_encodings
(
decoded_img
)[
0
]
# results is an array of True/False telling if the unknown face matched anyone in the known_faces array
# 아는 얼굴이면 False, 모르는 얼굴이면 True
results
=
face_recognition
.
compare_faces
(
self
.
known_faces
,
unknown_face_encoding
)
return
not
True
in
results
except
IndexError
:
print
(
"얼굴없음"
)
return
False
\ No newline at end of file
Please
register
or
login
to post a comment