当前位置:网站首页>Opencv face detection Haar cascade (1)
Opencv face detection Haar cascade (1)
2022-07-08 02:20:00 【So come on】
The goal is : Determine the position of the face in the picture , And draw a rectangular box .
1. The core principle
(1) Use Haar-like Feature detection
Be careful : The characteristic value is the sum of white rectangular pixels minus the sum of black rectangular pixels
(2)Integral Image : Integral graph accelerates feature calculation
(3)AdaBoost : Select key features , Face and non face classification
(4)Cascade : cascade , Weak classifiers become strong classifiers
It provides four cascaded classifiers ( For the front of the face ):
(1)haarcascade_frontalface_alt.xml (FA1): 22 stages and 20 x 20 haar features
(2)haarcascade_frontalface_alt2.xml (FA2): 20 stages and 20 x 20 haar features
(3)haarcascade_frontalface_alt_tree.xml (FAT): 47 stages and 20 x 20 haar features
(4)haarcascade_frontalface_default.xml (FD): 25 stages and 24 x 24 haar features
# 1 Import library
import cv2
import numpy as np
import matplotlib.pyplot as plt
# 2 Method : display picture
def show_iamge(image, title, pos):
# BGR to RGB
img_RGB = image[:,:,::-1]
plt.subplot(1, 1, pos)
plt.title(title)
plt.imshow(img_RGB)
plt.axis("off") # Turn off the axis
# 3 Method : Draw the face detected in the picture
def plot_rectangle(image, faces):
# Get the detected face data , return 4 It's worth : coordinate (x,y), Wide and high width, height
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (255, 0, 0), 3)
return image
# 4 The main function
def main():
# 5 Read a picture
image = cv2.imread("wedding photos.jpg")
# 6 Convert to grayscale images
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# 7 adopt OpenCV Own method cv2.CascadeClassifier() Load cascade classifiers
face_alt2 = cv2.CascadeClassifier("haarcascade_frontalface_alt2.xml")
# 8 Pass the first 7 Step , Detect the face in the image
face_alt2_detect = face_alt2.detectMultiScale(gray)
# 9 Draw the face detected in the picture
face_alt2_result = plot_rectangle(image.copy(), face_alt2_detect)
# 10 Create a canvas
plt.figure(figsize=(9, 6))
plt.suptitle("Face detection with Haar Cascade", fontsize=14, fontweight="bold")
# 11 Finally, the whole detection effect is displayed
show_iamge(face_alt2_result, "face_alt2", 1)
plt.show()
# 12 Main program entry
if __name__ == '__main__':
main()
边栏推荐
- #797div3 A---C
- [knowledge map paper] r2d2: knowledge map reasoning based on debate dynamics
- 云原生应用开发之 gRPC 入门
- Xmeter newsletter 2022-06 enterprise v3.2.3 release, error log and test report chart optimization
- Semantic segmentation | learning record (5) FCN network structure officially implemented by pytoch
- CorelDRAW2022下载安装电脑系统要求技术规格
- Yolov5 lite: how to speed up the Yolo model on CPU?
- Introduction to Microsoft ad super Foundation
- 银行需要搭建智能客服模块的中台能力,驱动全场景智能客服务升级
- In depth analysis of ArrayList source code, from the most basic capacity expansion principle, to the magic iterator and fast fail mechanism, you have everything you want!!!
猜你喜欢
Semantic segmentation | learning record (1) semantic segmentation Preface
Infrared dim small target detection: common evaluation indicators
mysql报错ORDER BY clause is not in SELECT list, references column ‘‘which is not in SELECT list解决方案
牛熊周期与加密的未来如何演变?看看红杉资本怎么说
idea窗口不折叠
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.2 data preprocessing_ Learning thinking and exercise answers
A comprehensive and detailed explanation of static routing configuration, a quick start guide to static routing
MQTT X Newsletter 2022-06 | v1.8.0 发布,新增 MQTT CLI 和 MQTT WebSocket 工具
Semantic segmentation | learning record (5) FCN network structure officially implemented by pytoch
Learn CV two loss function from scratch (4)
随机推荐
Learn CV two loss function from scratch (3)
Anan's judgment
Xiaobai tutorial: Raspberry pie 3b+onnxruntime+scrfd+flask to realize public face detection system
Beaucoup d'enfants ne savent pas grand - chose sur le principe sous - jacent du cadre orm, non, ice River vous emmène 10 minutes à la main "un cadre orm minimaliste" (collectionnez - le maintenant)
Deep understanding of softmax
In depth understanding of the se module of the attention mechanism in CV
Applet running under the framework of fluent 3.0
JVM memory and garbage collection-3-runtime data area / method area
[knowledge map paper] Devine: a generative anti imitation learning framework for knowledge map reasoning
MQTT X Newsletter 2022-06 | v1.8.0 发布,新增 MQTT CLI 和 MQTT WebSocket 工具
Yolov5 Lite: experiment and thinking of repovgg re parameterization on the industrial landing of Yolo
Thread deadlock -- conditions for deadlock generation
《通信软件开发与应用》课程结业报告
VR/AR 的产业发展与技术实现
leetcode 866. Prime Palindrome | 866. 回文素数
关于TXE和TC标志位的小知识
Random walk reasoning and learning in large-scale knowledge base
QT -- create QT program
1385:团伙(group)
Le chemin du poisson et des crevettes