├── README.md └── 1.py /README.md: -------------------------------------------------------------------------------- 1 | # Home-surveillance-system-using-Python -------------------------------------------------------------------------------- /1.py: -------------------------------------------------------------------------------- 1 | import cv2, time 2 | from datetime import datetime 3 | import argparse 4 | import os 5 | 6 | face_casacde=cv2.CascadeClassifier("haarcascade_frontalface_default.xml") 7 | 8 | 9 | video = cv2.VideoCapture(0) 10 | 11 | while True: 12 | check,frame=video.read() 13 | if frame is not None: 14 | gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) 15 | faces = face_casacde.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=10) 16 | for x,y,w,h in faces: 17 | img=cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3) 18 | exact_time=datetime.now().strftime('%Y-%b-%d-%H-%S-%f') 19 | cv2.imwrite("face detected"+str(exact_time)+".jpg",img) 20 | 21 | 22 | cv2.imshow("home surv",frame) 23 | key=cv2.waitKey(1) 24 | 25 | if key==ord('q'): 26 | ap=argparse.ArgumentParser() 27 | ap.add_argument("-ext","--extension",required=False,default='jpg') 28 | ap.add_argument("-o","--output",required=False,default='output.mp4') 29 | args=vars(ap.parse_args()) 30 | 31 | 32 | dir_path='.' 33 | ext=args['extension'] 34 | output=args['output'] 35 | 36 | 37 | images=[] 38 | 39 | for f in os.listdir(dir_path): 40 | if f.endswith(ext): 41 | images.append(f) 42 | 43 | 44 | 45 | image_path=os.path.join(dir_path,images[0]) 46 | frame=cv2.imread(image_path) 47 | height,width,channels=frame.shape 48 | 49 | 50 | forcc=cv2.VideoWriter_fourcc(*'mp4v') 51 | out=cv2.VideoWriter(output,forcc,5.0,(width,height)) 52 | 53 | 54 | for image in images: 55 | image_path=os.path.join(dir_path,image) 56 | frame=cv2.imread(image_path) 57 | out.write(frame) 58 | 59 | break 60 | 61 | 62 | video.release() 63 | cv2.destroyAllWindows --------------------------------------------------------------------------------