Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-101
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sachith Fernando
2020-101
Commits
0457e6bf
Commit
0457e6bf
authored
Nov 05, 2020
by
sachith.fernando
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract frames on a given time in order to run face recognition
parent
0c116b06
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
35 deletions
+9
-35
AttendanceApp/camera.py
AttendanceApp/camera.py
+9
-35
No files found.
AttendanceApp/camera.py
View file @
0457e6bf
...
...
@@ -6,10 +6,14 @@ import imutils
import
cv2
,
os
,
urllib
.
request
import
numpy
as
np
from
django.conf
import
settings
from
time
import
sleep
import
random
face_detection_videocam
=
cv2
.
CascadeClassifier
(
os
.
path
.
join
(
settings
.
BASE_DIR
,
'opencv_haarcascade_data/haarcascade_frontalface_default.xml'
))
face_detection_webcam
=
cv2
.
CascadeClassifier
(
os
.
path
.
join
(
settings
.
BASE_DIR
,
'opencv_haarcascade_data/haarcascade_frontalface_default.xml'
))
# load our serialized face detector model from disk
prototxtPath
=
os
.
path
.
sep
.
join
([
settings
.
BASE_DIR
,
"face_detector/deploy.prototxt"
])
weightsPath
=
os
.
path
.
sep
.
join
([
settings
.
BASE_DIR
,
"face_detector/res10_300x300_ssd_iter_140000.caffemodel"
])
...
...
@@ -17,28 +21,6 @@ faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)
maskNet
=
load_model
(
os
.
path
.
join
(
settings
.
BASE_DIR
,
'face_detector/mask_detector.model'
))
# class VideoCamera(object):
# def __init__(self):
# self.video = cv2.VideoCapture(0)
#
# def __del__(self):
# self.video.release()
#
# def get_frame(self):
# success, image = self.video.read()
# # We are using Motion JPEG, but OpenCV defaults to capture raw images,
# # so we must encode it into JPEG in order to correctly display the
# # video stream.
#
# gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# faces_detected = face_detection_videocam.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)
# for (x, y, w, h) in faces_detected:
# cv2.rectangle(image, pt1=(x, y), pt2=(x + w, y + h), color=(255, 0, 0), thickness=2)
# frame_flip = cv2.flip(image,1)
# ret, jpeg = cv2.imencode('.jpg', frame_flip)
# return jpeg.tobytes()
class
IPWebCam
(
object
):
def
__init__
(
self
):
self
.
url
=
"http://192.168.8.100:8080/shot.jpg"
...
...
@@ -47,6 +29,8 @@ class IPWebCam(object):
cv2
.
destroyAllWindows
()
def
get_frame
(
self
):
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'XVID'
)
out
=
cv2
.
VideoWriter
(
'output.avi'
,
fourcc
,
20.0
,
(
640
,
480
))
imgResp
=
urllib
.
request
.
urlopen
(
self
.
url
)
imgNp
=
np
.
array
(
bytearray
(
imgResp
.
read
()),
dtype
=
np
.
uint8
)
img
=
cv2
.
imdecode
(
imgNp
,
-
1
)
...
...
@@ -60,6 +44,9 @@ class IPWebCam(object):
resize
=
cv2
.
resize
(
img
,
(
640
,
480
),
interpolation
=
cv2
.
INTER_LINEAR
)
frame_flip
=
cv2
.
flip
(
resize
,
1
)
ret
,
jpeg
=
cv2
.
imencode
(
'.jpg'
,
frame_flip
)
count
=
random
.
randint
(
0
,
9
)
# capture frame and save on a given time in order to run the face recognition
sleep
(
3
);
cv2
.
imwrite
(
"lecture
%
d.jpg"
%
count
,
img
)
return
jpeg
.
tobytes
()
...
...
@@ -161,16 +148,3 @@ class MaskDetect(object):
cv2
.
rectangle
(
frame
,
(
startX
,
startY
),
(
endX
,
endY
),
color
,
2
)
ret
,
jpeg
=
cv2
.
imencode
(
'.jpg'
,
frame
)
return
jpeg
.
tobytes
()
# class LiveWebCam(object):
# def __init__(self):
# self.url = cv2.VideoCapture("rtsp://admin:Mumbai@123@203.192.228.175:554/")
#
# def __del__(self):
# cv2.destroyAllWindows()
#
# def get_frame(self):
# success,imgNp = self.url.read()
# resize = cv2.resize(imgNp, (640, 480), interpolation = cv2.INTER_LINEAR)
# ret, jpeg = cv2.imencode('.jpg', resize)
# return jpeg.tobytes()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment