Vehicle-Anti-Theft-Face-Rec.../Facial_Recognition_Software.py

28 lines
696 B
Python
Raw Normal View History

2020-10-12 20:15:18 +00:00
import cv2
import numpy as np
2020-10-03 01:26:03 +00:00
2020-10-12 20:59:52 +00:00
import sys,os,numpy
from glob import glob
2020-10-12 20:15:18 +00:00
from skimage import io
2020-10-03 01:26:03 +00:00
2020-10-12 20:15:18 +00:00
#read test photo
2020-10-12 20:59:52 +00:00
pwd = sys.path[0]
img = cv2.imread(pwd + "/Facial_test_images/photo2.jpg")
2020-10-12 20:15:18 +00:00
color = (0, 255, 0)
2020-10-03 01:26:03 +00:00
2020-10-12 20:15:18 +00:00
grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
2020-10-03 01:26:03 +00:00
2020-10-12 20:59:52 +00:00
classfier = cv2.CascadeClassifier(pwd + "/Facial_models/haarcascade_frontalface_alt2.xml")
2020-10-03 01:26:03 +00:00
2020-10-12 20:15:18 +00:00
faceRects = classfier.detectMultiScale(grey, scaleFactor=1.2, minNeighbors=3, minSize=(32, 32))
2020-10-03 01:26:03 +00:00
2020-10-12 20:15:18 +00:00
if len(faceRects) > 0:
for faceRect in faceRects:
x, y, w, h = faceRect
cv2.rectangle(img, (x - 10, y - 10), (x + w + 10, y + h + 10), color, 3)
2020-10-03 01:26:03 +00:00
2020-10-12 20:15:18 +00:00
cv2.imwrite('output.jpg',img)
cv2.imshow("face_image",img)
cv2.waitKey(0)