Face detection based on camera capture video in OPENCV - Mir NXP i.MX93 development board

Publisher:EE小广播Latest update time:2024-11-07 Source: EEWORLD Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This review is provided by the excellent reviewer "eefocus_3914144" of eefocus.com.


This article will introduce the test of the OpenCV-based face detection solution based on the Mir Electronics MYD-LMX93 development board (Mir is based on the NXP i.MX93 development board).


OpenCV provides a very simple interface for capturing a video with a camera (I use the built-in camera on my computer)


1. Install python3-opencv


apt install python3-opencv


2. Check the formats and resolutions supported by the camera


root@debian:~# v4l2-ctl --device=/dev/video0 --list-formats-ext

image.png


After testing, it can only support 640*480

For this create opencv_test.py

import cv2

video = cv2.VideoCapture(0)

Set camera parameters

video .set(cv2.CAP_PROP_FRAME_WIDTH, 1280)

video .set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while True:

ret, frame = video.read()

cv2.imshow("A video", frame)

c = cv2.waitKey(1)

if c == 27:

breakvideo.release()cv2.destroyAllWindows()


Save and execute "python3 opencv_test.py


image.png


After OpenCV is installed, it can provide feasibility for the subsequent face detection.


To realize the face recognition function, we must first perform face detection and determine the position of the face in the picture before proceeding to the next step.


OpenCV face detection method


In OpenCV, two features (i.e. two methods) are mainly used for face detection, Haar feature and LBP feature. Haar feature face detection is the most commonly used. In addition, OpenCV also integrates deep learning methods to achieve face detection.


【References】


Use the OpenCV toolkit to successfully implement face detection and face recognition, including traditional vision and deep learning methods (with complete code, model download...)_opencv face recognition-CSDN blog


[Haar cascade detector pre-trained model download]


opencv/opencv: Open Source Computer Vision Library (github.com)

After downloading, there is a model in the opencv-4.xdatahaarcascades folder. Upload it to the development board.


[Get the image for face detection]


I found the ** picture on Baidu and uploaded it to the development board.


【Write detection code】


import numpy as np

import cv2 as cv


if __name__ == '__main__':

# (6) Use the Haar cascade classifier pre-trained model to detect faces

# Read the image to be detected

img = cv.imread("yanmi.jpg")

print(img.shape)


# Load the Haar cascade classifier pre-trained model

model_path = "haarcascade_frontalface_alt2.xml"

face_detector = cv.CascadeClassifier(model_path) #

# Detect faces using cascade classifier

faces = face_detector.detectMultiScale(img, scaleFactor=1.1, minNeighbors=1,

minSize=(30, 30), maxSize=(300, 300))

print(faces.shape) # (17, 4)

print(faces[0]) # (x, y, width, height)


# Draw the face detection frame

for x, y, width, height in faces:

cv.rectangle(img, (x, y), (x + width, y + height), (0, 0, 255), 2, cv.LINE_8, 0)

# Display the image

cv2.imshow("faces", img)

cv2.waitKey(0)

cv2.destroyAllWindows()


[Experimental results]


After running the program, it can be correctly identified, and the effect is as follows:


image.png

Reference address:Face detection based on camera capture video in OPENCV - Mir NXP i.MX93 development board

Previous article:Infineon Technologies SECORA™ Pay Bio Enhances Convenience and Trust in Contactless Biometric Payments
Next article:最后一页

Latest Internet of Things Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号