Fortune Telling Collection - Comprehensive fortune-telling - Why is face recognition developed in python?
Why is face recognition developed in python?
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’)
- Previous article:Mr. Tree, what does Heller mean? I really doubt my IQ solution.
- Next article:Toyoko met a fortune teller when she got married.
- Related articles
- Where are the three dragons and one phoenix in Dongyang?
- What does the division and combination of 2 and 7 mean?
- Cheng Nan fortune-telling blind _ Cheng Nan blind Chinese medicine
- Pupils must recite 80 ancient poems.
- Fortune-telling Street Free _ Fortune-telling Street All the streets are online fortune-telling by real people.
- Fortune teller in Yulin, northern Shaanxi _ Who is the fortune teller in Yulin, northern Shaanxi?
- Wuxi folk fortune telling
- What kind of woman looks pale?
- Why is Lu Dehua called a native chicken?
- 65438+9: 00 a.m. on February 3, 1983.