Untitled

                Never    
# -*- coding: utf-8 -*-
# import the necessary packages
from imutils.video import VideoStream
import datetime
import imutils
import time
import face_recognition
import numpy as np
import cv2
firstFrame = None
lmm_image = cv2.imread("dataset/Danilov Maxim/IMG_20190513_140052.jpg")
fourcc = cv2.VideoWriter_fourcc(*'XVID')
output_movie = cv2.VideoWriter('output.avi', fourcc, 29.97, (640, 360))
print(len(lmm_image))
lmm_face_encoding = face_recognition.face_encodings(lmm_image)[0]
print(lmm_face_encoding)
al_image = cv2.imread("dataset/Boldysheva Ekaterina/IMG_20190513_135904.jpg")
al_face_encoding = face_recognition.face_encodings(al_image)[0]
known_faces = [
    lmm_face_encoding,
    al_face_encoding
]

# Initialize some variables
face_locations = []
face_encodings = []
face_names = []
frame_number = 0
cap = cv2.VideoCapture('video/test_out_02.avi')
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
while(cap.isOpened()):
      ret, frame = cap.read()
      frame_number += 1
      text = "Unoccupied"
      if frame is None:
            break
      rgb_frame = frame[:, :, ::-1]
      frame = imutils.resize(frame, width=500)
      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
      #gaussian = cv2.GaussianBlur(gray, (21, 21), 0)
      gaussian = cv2.GaussianBlur(gray, (15, 15), 0)
      if firstFrame is None:
            firstFrame = gaussian
            continue
      frameDelta = cv2.absdiff(firstFrame, gaussian)
      thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
      #thresh = cv2.threshold(frameDelta, 55, 555, cv2.THRESH_BINARY)[1]
      thresh = cv2.dilate(thresh, None, iterations=2)
      #thresh = cv2.dilate(thresh, None, iterations=4)
      cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
            cv2.CHAIN_APPROX_SIMPLE)
      cnts = imutils.grab_contours(cnts)
      face_names = []
      # loop over the contours
      for c in cnts:
          # if the contour is too small, ignore it
          if cv2.contourArea(c) < 100:
                continue
          (x, y, w, h) = cv2.boundingRect(c)
          cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
          print("MOTION")
          text = "Occupied"
      # show the frame and record if the user presses a key
      cv2.imshow("Security Feed", frame)
      cv2.imshow("Thresh", thresh)
      cv2.imshow("Frame Delta", frameDelta)
      key = cv2.waitKey(1) & 0xFF
      if key == ord("q"):
            break
cap.release()
cv2.destroyAllWindows()

Raw Text