Commit 0457e6bf authored by sachith.fernando's avatar sachith.fernando

extract frames on a given time in order to run face recognition

parent 0c116b06
...@@ -6,10 +6,14 @@ import imutils ...@@ -6,10 +6,14 @@ import imutils
import cv2,os,urllib.request import cv2,os,urllib.request
import numpy as np import numpy as np
from django.conf import settings from django.conf import settings
from time import sleep
import random
face_detection_videocam = cv2.CascadeClassifier(os.path.join( face_detection_videocam = cv2.CascadeClassifier(os.path.join(
settings.BASE_DIR,'opencv_haarcascade_data/haarcascade_frontalface_default.xml')) settings.BASE_DIR,'opencv_haarcascade_data/haarcascade_frontalface_default.xml'))
face_detection_webcam = cv2.CascadeClassifier(os.path.join( face_detection_webcam = cv2.CascadeClassifier(os.path.join(
settings.BASE_DIR,'opencv_haarcascade_data/haarcascade_frontalface_default.xml')) settings.BASE_DIR,'opencv_haarcascade_data/haarcascade_frontalface_default.xml'))
# load our serialized face detector model from disk # load our serialized face detector model from disk
prototxtPath = os.path.sep.join([settings.BASE_DIR, "face_detector/deploy.prototxt"]) 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"]) 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) ...@@ -17,28 +21,6 @@ faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)
maskNet = load_model(os.path.join(settings.BASE_DIR,'face_detector/mask_detector.model')) 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): class IPWebCam(object):
def __init__(self): def __init__(self):
self.url = "http://192.168.8.100:8080/shot.jpg" self.url = "http://192.168.8.100:8080/shot.jpg"
...@@ -47,6 +29,8 @@ class IPWebCam(object): ...@@ -47,6 +29,8 @@ class IPWebCam(object):
cv2.destroyAllWindows() cv2.destroyAllWindows()
def get_frame(self): 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) imgResp = urllib.request.urlopen(self.url)
imgNp = np.array(bytearray(imgResp.read()),dtype=np.uint8) imgNp = np.array(bytearray(imgResp.read()),dtype=np.uint8)
img= cv2.imdecode(imgNp,-1) img= cv2.imdecode(imgNp,-1)
...@@ -60,6 +44,9 @@ class IPWebCam(object): ...@@ -60,6 +44,9 @@ class IPWebCam(object):
resize = cv2.resize(img, (640, 480), interpolation = cv2.INTER_LINEAR) resize = cv2.resize(img, (640, 480), interpolation = cv2.INTER_LINEAR)
frame_flip = cv2.flip(resize,1) frame_flip = cv2.flip(resize,1)
ret, jpeg = cv2.imencode('.jpg', frame_flip) 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() return jpeg.tobytes()
...@@ -161,16 +148,3 @@ class MaskDetect(object): ...@@ -161,16 +148,3 @@ class MaskDetect(object):
cv2.rectangle(frame, (startX, startY), (endX, endY), color, 2) cv2.rectangle(frame, (startX, startY), (endX, endY), color, 2)
ret, jpeg = cv2.imencode('.jpg', frame) ret, jpeg = cv2.imencode('.jpg', frame)
return jpeg.tobytes() 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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment