人脸识别为啥用python开发
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了人脸识别为啥用python开发相关的知识,希望对你有一定的参考价值。
可以使用OpenCV,OpenCV的人脸检测功能在一般场合还是不错的。而ubuntu正好提供了python-opencv这个包,用它可以方便地实现人脸检测的代码。
写代码之前应该先安装python-opencv:
#!/usr/bin/python# -*- coding: UTF-8 -*-
# face_detect.py
# Face Detection using OpenCV. Based on sample code from:
# http://python.pastebin.com/m76db1d6b
# Usage: python face_detect.py <image_file>
import sys, os
from opencv.cv import *
from opencv.highgui import *
from PIL import Image, ImageDraw
from math import sqrt
def detectObjects(image):
"""Converts an image to grayscale and prints the locations of any faces found"""
grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)
cvCvtColor(image, grayscale, CV_BGR2GRAY)
storage = cvCreateMemStorage(0)
cvClearMemStorage(storage)
cvEqualizeHist(grayscale, grayscale)
cascade = cvLoadHaarClassifierCascade(
\'/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml\',
cvSize(1,1))
faces = cvHaarDetectObjects(grayscale, cascade, storage, 1.1, 2,
CV_HAAR_DO_CANNY_PRUNING, cvSize(20,20))
result = []
for f in faces:
result.append((f.x, f.y, f.x+f.width, f.y+f.height))
return result
def grayscale(r, g, b):
return int(r * .3 + g * .59 + b * .11)
def process(infile, outfile):
image = cvLoadImage(infile);
if image:
faces = detectObjects(image)
im = Image.open(infile)
if faces:
draw = ImageDraw.Draw(im)
for f in faces:
draw.rectangle(f, outline=(255, 0, 255))
im.save(outfile, "JPEG", quality=100)
else:
print "Error: cannot detect faces on %s" % infile
if __name__ == "__main__":
process(\'input.jpg\', \'output.jpg\') 参考技术A 就这一个功能没多少钱,但app是个功能的集合,一般都会含有多种功能一起,像你这样的app一般是4到5万差不多。app广告能卖多少钱,看你的app受欢迎程度还有你和广告商具体怎么谈了
以上是关于人脸识别为啥用python开发的主要内容,如果未能解决你的问题,请参考以下文章
Python OpenCV开发MR智能人脸识别打卡系统(三工具模块设计)
Python OpenCV开发MR智能人脸识别打卡系统(四服务模块设计)
Python OpenCV开发MR智能人脸识别打卡系统(五程序入口设计与测试)