60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
# untitled.py
|
||
|
#
|
||
|
# Copyright 2018 <pi@RPi-01>
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation; either version 2 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
|
# MA 02110-1301, USA.
|
||
|
#
|
||
|
#
|
||
|
|
||
|
from time import sleep
|
||
|
from picamera import PiCamera
|
||
|
from io import BytesIO
|
||
|
import cv2
|
||
|
import numpy as np
|
||
|
|
||
|
camera = PiCamera()
|
||
|
camera.resolution = (640, 480)
|
||
|
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
||
|
stream = BytesIO()
|
||
|
#camera.start_recording('my_video.h264')
|
||
|
#print('started recodring')
|
||
|
#camera.wait_recording(10)
|
||
|
#camera.stop_recording()
|
||
|
while True:
|
||
|
print('taking photo')
|
||
|
camera.capture('img.jpg')
|
||
|
img = cv2.imread('img.jpg',1)
|
||
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||
|
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
||
|
|
||
|
for (x,y,w,h) in faces:
|
||
|
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
||
|
#roi_gray = gray[y:y+h, x:x+w]
|
||
|
#roi_color = img[y:y+h, x:x+w]
|
||
|
|
||
|
cv2.imshow('image',img)
|
||
|
cv2.waitKey(100)
|
||
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||
|
break
|
||
|
#cv2.destroyAllWindows()
|
||
|
print('Finshed')
|
||
|
|
||
|
|
||
|
|