In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Python+OpenCV to achieve cat face detection related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe everyone will read this article how to use Python+OpenCV to achieve cat face detection articles will have some gains, let's take a look at it.
development tools
Python version: 3.6.4
Related modules:
cv2 module;
And some Python modules.
environment construction
Install Python and add it to the environment variables, pip install the relevant modules you need.
Brief Introduction of Principle
To further improve the quality of articles on Wechat Official Account, I decided to talk briefly about Haar classifier, also known as Viola-Jones classifier.
For a detailed explanation of the principle, please refer to two papers in the relevant documents:
Rapid Object Detection using a Boosted Cascade of Simple Features;
Robust Real-Time Face Detection.
1) Haar-like characteristics
Haar-like rectangle feature is a digital image feature used for object detection. It is composed of two or more adjacent black and white rectangles. The feature value of rectangle is the sum of gray values of white rectangle minus the sum of gray values of black rectangle. In general, we think that rectangular features are sensitive to some simple graphic structures (segments, edges), etc.:
For cat face detection, we think that the eigenvalues obtained by placing such a rectangle in a non-cat face region are different from the eigenvalues obtained by placing it in a cat face region.
Using the above feature-based detection algorithm, not only can the state of a specific region be encoded, but also the efficiency is higher than that of pixel-based detection algorithms.
(2) Integral diagram
Let's consider how to compute the eigenvalues of a rectangle. For any point A(x, y) in the image, define the integral map of that point as the sum of all pixel values in the upper left corner, i.e.:
Therefore, to calculate the eigenvalues of the rectangular template, that is, to calculate the difference between the pixel sums between the two regions, it is only necessary to perform a simple addition and subtraction operation with the integral map of the endpoints of the characteristic region:
(3) Haar classifier
Haar classifier is a supervised learning classifier. To detect objects, it first performs histogram equalization and normalization on the image, and then detects whether it contains objects to be detected.
The flowchart is (Haar classifier essentially consists of Haar feature extractor, discrete strong classifier and strong classifier cascade):
Haar classifier uses Adaboost algorithm, but it is organized as a screening cascade classifier. In any level of calculation, once the conclusion that the input content is not in the detection class is obtained, the calculation will be terminated. Only through all levels of classifiers can the target object be considered detected, so as to improve the detection efficiency.
About AdaBoost algorithm, I will not expand the introduction, interested students can find their own relevant information to learn. I will introduce them in detail later when I have time.
(4) Scope of application
Suitable for "substantially rigid" object detection, such as faces, cars, bodies, bicycles, etc.
(5) Summary
The core idea of Viola-Jones target detection framework is to scan the image through sliding window (multi-scale scanning), and then input the Haar feature value of each window into the screening cascade classifier to determine whether there is a target object in the window to achieve target detection.
specific implementation
OpenCV has built-in Haar classifier based on Viola-Jones target detection framework, and provides pre-trained model for cat face detection. So it's very simple to implement.
For details of the implementation process, see the source code in the relevant documents.
effect demonstration
Usage:
Modify the image name in the source code to the image you need to detect:
Run DetectCatFace.py in cmd window.
Effect:
Original drawing 1:
Test result 1:
Original drawing 2:
Test result 2 (does not distinguish dogs from cats):
About "How to use Python+OpenCV to achieve cat face detection" The content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of "how to use Python+OpenCV to realize cat face detection." If you still want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.