python判断性别程序_python 实现性别识别
使用keras实现性别识别,模型数据使用的是oarriaga/face_classification的模型
实现效果
准备工作
在开始之前先要安装keras和tensorflow
安装keras使用命令:pip3 install keras
安装tensorflow使用命令:pip3 install tensorflow
编码部分
们使用OpenCV先识别到人脸,然后在通过keras识别性别,具体代码如下
#coding=utf-8
#性别识别
import cv2
from keras.models import load_model
import numpy as np
import ChineseText
img = cv2.imread("img/gather.png")
face_classifier = cv2.CascadeClassifier(
"C:\Python36\Lib\site-packages\opencv-master\data\haarcascades\haarcascade_frontalface_default.xml"
)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_classifier.detectMultiScale(
gray, scaleFactor=1.2, minNeighbors=3, minSize=(140, 140))
gender_classifier = load_model(
"classifier/gender_models/simple_CNN.81-0.96.hdf5")
gender_labels = {0: '女', 1: '男'}
color = (255, 255, 255)
for (x, y, w, h) in faces:
face = img[(y - 60):(y + h + 60), (x - 30):(x + w + 30)]
face = cv2.resize(face, (48, 48))
face = np.expand_dims(face, 0)
face = face / 255.0
gender_label_arg = np.argmax(gender_classifier.predict(face))
gender = gender_labels[gender_label_arg]
cv2.rectangle(img, (x, y), (x + h, y + w), color, 2)
img = ChineseText.cv2ImgAddText(img, gender, x + h, y, color, 30)
cv2.imshow("Image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
以上就是python 实现性别识别的详细内容,更多关于python 性别识别的资料请关注脚本之家其它相关文章!
python判断性别程序_python 实现性别识别相关推荐
- python判断素数程序_Python程序检查素数
python判断素数程序 什么是质数? (What is a prime number?) A prime number is a natural number that is greater tha ...
- python判断质数程序_python判断质数
学习python断断续续有两个多星期了.学习了基本的列表.元组.字典等基本数据结构的操作,从现在开始学习一些基本的语法.函数和模块,以及用python实现一些算法. 虽然现在还没有学到很深的地步,但是 ...
- python判断素数程序_python素数判断
广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 质数(prime number),又称素数,指在大于1的自然数中,除了1和该数自 ...
- python判断三角形程序_python三角形判定怎么做
python三角形判定怎么做?下面给大家带来具体的例子: 例子:a = int(input("The length of the side a = ")) b = int(inpu ...
- python判断素数程序_使用面向对象方法检查素数的Python程序
python判断素数程序 This program will check whether a given number is Prime or Not, in this program we will ...
- python判断火车票座位_Python抢票程序优化,可以选择车次和座次
Python抢票程序优化,可以选择车次和座次 阅读文本大概需要 5 分钟. pk 哥在元旦前写了一篇关于自动化抢票的程序 用Python抢火车票加邮件通知,同时建了一个火车票助力群,本来只是写着玩玩, ...
- python判断字母数字_Python判断字符串是否为字母或者数字(浮点数)的多种方法
str为字符串s为字符串 str.isalnum() 所有字符都是数字或者字母 str.isalpha() 所有字符都是字母 str.isdigit() 所有字符都是数字 str.isspace() ...
- python判断偶数奇数_Python程序检查数字是奇数还是偶数
python判断偶数奇数 Here you will get python program to check number is odd or even. 在这里,您将获得python程序以检查数字是 ...
- python判断汉字个数_python判断列表里数量python中文乱码问题大总结
在运行这样类似的代码:#!/usr/bin/env python s="中文" print s 最近经常遇到这样的问题: 问题一:SyntaxError: Non-ASCII ch ...
最新文章
- 解决安装下载好的whl库包时,报错:zipfile.BadZipFile: File is not a zip file
- 尾递归及示例(JAVA)
- 从0到70%:Chrome上位揭秘!
- 深入探究函数返回局部变量
- PMCAFF微课堂已结束 | 前YY产品总监深度揭秘P2P运营推广精髓
- linux c++ 调用matlab,ubuntu系统下C++调用matlab程序的方法详解
- Java 8:使用交替接口公开的类型安全地图生成器
- react学习(54)--注意传递请求
- 对std::listT的封装
- 用计算机进行有理数除法时,有理数的乘除法怎么算?,什么是有理数的乘除法。越详细越好。...
- 在Windows下编译OpenSSL(VS2005)
- Cookie的简单理解和使用
- h5 px 转dp_西游女儿国h5手游下载-西游女儿国h5手游下载v2.1.4 安卓版
- 常见职位角色及其英文缩写
- win10连上wifi却上不了网
- 那个直播软件有软件测试课程,资讯详情-直播软件有哪些测试方法-柠檬班-自动化测试-软件测试培训-自学官网...
- 【R语言】【可视化】 之 维恩图
- windows下mysql免安装配置
- pcie gen3 bios设置_u盘pe设置联想台式机lenovo BIOS从u盘启动教程
- 【NVMe2.0b 16-1】Get Log Page