Fortune Telling Collection - Comprehensive fortune-telling - Why is face recognition developed in python?

Why is face recognition developed in python?

You can use OpenCV. In general, the face detection function of OpenCV is good. Ubuntu just provides python-opencv package, which can be used to easily realize face detection code.

Python-opencv should be installed before writing code:

#! /usr/bin/python

#? -*-? Code:? UTF 8? -*-

#? face_detect.py

#? Face? Testing? Use? OpenCV。 ? Foundation? Open? Sample? Code? From:

#? /m76db 1d6b

#? Usage:? python? face_detect.py? & ltimage _ file & gt

Import? sys,? Operating System (operating system)

From where? opencv.cv? Import? *

From where? opencv.highgui? Import? *

From where? PIL? Import? Image? ImageDraw

From where? Math? Import? sqrt

def? Detection object (image):

"""converts? Ann? Image? Where to? Gray scale? And then what? Fingerprints? That? Where? Yes? Really? Face? Found ""

Gray scale? =? cvCreateImage(cvSize(image . width,? image.height),? 8,? 1)

CvCvtColor (picture,? Gray scale,? CV_BGR2GRAY)

Storage? =? cvCreateMemStorage(0)

CvClearMemStorage (storage)

CvEqualizeHist (gray scale,? Gray scale)

Cascade? =? cvLoadHaarClassifierCascade(

/usr/share/opencv/Haar cascades/Haar cascade _ frontal face _ default . XML ',

cvSize( 1, 1))

Face? =? CvHaarDetectObjects (gray scale, cascade,? Storage? 1. 1,? 2,

CV_HAAR_DO_CANNY_PRUNING,? cvSize(20,20))

The result? =? []

For what? f? Are you online? Faces:

result.append((f.x,? Swallow? f.x+f.width,? f.y+f.height))

Return? result

def? Gray scale (r, g,? b):

Return? int(r? *? .3? +? g? *? .59? +? b? *? . 1 1)

def? Infile (output file):

Image? =? cvLoadImage(infile);

What if? Picture:

Face? =? Detection object (image)

im? =? Image.open(infile)

What if? Faces:

Painting? =? ImageDraw。 Drawing (im)

For what? f? Are you online? Faces:

Draw.rectangle(f, outline =(255,? 0,? 255))

im.save(outfile,“JPEG”,? Mass = 100)

Otherwise:

Print? "error:? Can't? Testing? Face? Open? %s "? %? infile

What if? __name__? ==? " __main__ "

process('input.jpg ',? output . jpg’)