merge #1
81
main.py
81
main.py
@ -6,41 +6,60 @@ import cv2
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
|
go = true
|
||||||
print('Initilizing Camera and cascade components..')
|
print('Initilizing Camera and cascade components..')
|
||||||
camera = PiCamera()
|
try:
|
||||||
print('[ OK ] Camera')
|
camera = PiCamera()
|
||||||
camera.resolution = (640, 480)
|
camera.resolution = (640, 480)
|
||||||
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
sleep(2)
|
||||||
print('[ OK ] CascadeClassifier')
|
print('[ OK ] Camera')
|
||||||
print('Starting Photo loop..')
|
except:
|
||||||
start()
|
print('[ Error ] Can not initialize PiCamera')
|
||||||
|
go = false
|
||||||
|
|
||||||
|
try:
|
||||||
|
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
||||||
|
sleep(1)
|
||||||
|
print('[ OK ] CascadeClassifier')
|
||||||
|
except:
|
||||||
|
print('[ Error ] Can not load cascade File')
|
||||||
|
go = false
|
||||||
|
if (go):
|
||||||
|
print('Starting Photo loop..')
|
||||||
|
start(camera)
|
||||||
|
else:
|
||||||
|
print('closing')
|
||||||
|
|
||||||
def start():
|
def start(camera):
|
||||||
while True:
|
while True:
|
||||||
print('Taking photo')
|
try:
|
||||||
camera.capture('img.jpg')
|
print('Taking photo')
|
||||||
print('Photo Captured')
|
camera.capture('img.jpg')
|
||||||
img = cv2.imread('img.jpg',1)
|
print('Photo Captured')
|
||||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
img = cv2.imread('img.jpg',1)
|
||||||
print('Photo Converted')
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||||
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
print('Photo Converted')
|
||||||
print('Photo Processed')
|
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
||||||
i = 0;
|
print('Photo Processed')
|
||||||
for (x,y,w,h) in faces:
|
i = 0;
|
||||||
i = i + 1
|
for (x,y,w,h) in faces:
|
||||||
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
i = i + 1
|
||||||
cv2.imwrite('result.jpg', gray)
|
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
||||||
roi_gray = gray[y:y+h, x:x+w]
|
#cv2.imwrite('result.jpg', gray)
|
||||||
roi_color = img[y:y+h, x:x+w]
|
roi_gray = gray[y:y+h, x:x+w]
|
||||||
print('Drawing on face ', i)
|
roi_color = img[y:y+h, x:x+w]
|
||||||
|
print('Drawing on face ', i)
|
||||||
cv2.imshow('image',img)
|
|
||||||
cv2.waitKey(100)
|
cv2.imshow('image',img)
|
||||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
cv2.waitKey(100)
|
||||||
cv2.destroyAllWindows()
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||||
break
|
cv2.destroyAllWindows()
|
||||||
|
break
|
||||||
|
|
||||||
print('Finshed')
|
except:
|
||||||
|
print('[ Error ] Unexpected exception')
|
||||||
|
print('Closing')
|
||||||
|
break
|
||||||
|
|
||||||
def recognize():
|
def recognize():
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user