Created
August 25, 2011 12:16
-
-
Save roberto-butti/1170526 to your computer and use it in GitHub Desktop.
opencv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from opencv import cv as opencv | |
from opencv import highgui | |
import sys | |
print "Inizializzazione webcam" | |
camera = highgui.cvCreateCameraCapture(-1) | |
if (camera): | |
print "Camera inizializzata" | |
else: | |
sys.exit("Camera NON inizializzata") | |
im = highgui.cvQueryFrame(camera) | |
if (im): | |
print "Acquisizione FRAME" | |
else: | |
sys.exit("Errore acquisizione FRAME da webcam") | |
filexml ="haarcascade_frontalface_default.xml" | |
print "Caricamento file xml:"+filexml | |
cascade = opencv.cvLoadHaarClassifierCascade(filexml, opencv.cvSize(1,1)) | |
if (cascade): | |
print "Caricato" | |
else: | |
sys.exit("Non caricato") | |
storage = opencv.cvCreateMemStorage(0) | |
loop = True | |
while(loop): | |
frame = highgui.cvQueryFrame(camera) | |
if (frame == None): | |
break; | |
grayscale = opencv.cvCreateImage(opencv.cvSize(frame.width, frame.height), 8, 1) | |
opencv.cvCvtColor(frame, grayscale, opencv.CV_BGR2GRAY) | |
faces = opencv.cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2,opencv.CV_HAAR_DO_CANNY_PRUNING, opencv.cvSize(50,50)) | |
if faces: | |
#print 'face detected!' | |
for face in faces: | |
opencv.cvRectangle(grayscale, opencv.cvPoint( int(face.x), int(face.y)), | |
opencv.cvPoint(int(face.x + face.width), int(face.y + face.height)), | |
opencv.CV_RGB(127, 255, 0), 2) # RGB #7FFF00 width=2 | |
highgui.cvShowImage("Finestra", grayscale) | |
char = highgui.cvWaitKey(33) | |
if (char != -1): | |
if (ord(char) == 27): | |
loop = False | |
highgui.cvDestroyWindow("Finestra") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment