[openvino+Raspberry Pi] Real-time camera face detection

content

Reference steps 

face detection py code 

picture form

webcam live

Raspberry Pi+openvino face detection real-time effect

Openvino Raspberry Pi real-time face detection test results_bilibili_bilibili 


Reference steps 

  • Openvino: Install, deploy. (You can refer to the following documents, verification is not recommended)

Raspberry Pi + Neural Compute Stick 2 deploys Openvino's human_pose_estimation_demo instance_hwxhxyz1998403's blog-CSDN blog_openpose Raspberry Pi

Raspberry Pi 4B uses OpenVINO to deploy the human key point detection model Demo (the files used in the video are downloaded in the introduction)_bilibili_bilibili

Installation package link: https://pan.baidu.com/s/1g-pCfJY0wkwTCclqOCKOng 
Extraction code: 48z7

refer to this section

  

face detection py code 

picture form

#coding=utf-8
import cv2 as cv
# Load the model.
net = cv.dnn.readNet('face-detection-adas-0001.xml',
                     'face-detection-adas-0001.bin')
# Specify target device.
net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)
# Read an image.
frame = cv.imread('/home/pi/Downloads/inference_engine_vpu_arm/deployment_tools/inference_engine/samples/cpp/build/1.jpeg')
if frame is None:
    raise Exception('Image not found!')
# Prepare input blob and perform an inference.
blob = cv.dnn.blobFromImage(frame, size=(672, 384), ddepth=cv.CV_8U)
net.setInput(blob)
out = net.forward()
# Draw detected faces on the frame.
for detection in out.reshape(-1, 7):
    confidence = float(detection[2])
    xmin = int(detection[3] * frame.shape[1])
    ymin = int(detection[4] * frame.shape[0])
    xmax = int(detection[5] * frame.shape[1])
    ymax = int(detection[6] * frame.shape[0])
    if confidence > 0.5:
        cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))
# Save the frame to an image file.
cv.imwrite('out111.png', frame)

webcam live

#coding=utf-8
import cv2 as cv
import numpy as np

print("start!")
# Load the model.
net = cv.dnn.readNet('face-detection-adas-0001.xml',
                     'face-detection-adas-0001.bin')
# Specify target device.
net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)
# Read an image.
#frame = cv.imread('/home/pi/Downloads/inference_engine_vpu_arm/deployment_tools/inference_engine/samples/cpp/build/1.jpeg')

#
cap = cv.VideoCapture(0)
while(1):
    ret, frame = cap.read()
    frame = cv.resize(frame,(480,320),interpolation=cv.INTER_CUBIC)
    # Prepare input blob and perform an inference.
    blob = cv.dnn.blobFromImage(frame, size=(672, 384), ddepth=cv.CV_8U)
    net.setInput(blob)
    out = net.forward()
    # Draw detected faces on the frame.
    for detection in out.reshape(-1, 7):
        confidence = float(detection[2])
        xmin = int(detection[3] * frame.shape[1])
        ymin = int(detection[4] * frame.shape[0])
        xmax = int(detection[5] * frame.shape[1])
        ymax = int(detection[6] * frame.shape[0])
        if confidence > 0.5:
            cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))
    cv.imshow('capture',frame)
    if cv.waitKey(1) &0xFF==ord('q'):
        # Save the frame to an image file.
        cv.imwrite('out111.png', frame)
        print('save done')
cap.release()
cv.destroyAllWindows()

Raspberry Pi+openvino face detection real-time effect

Openvino Raspberry Pi real-time face detection test results_bilibili_bilibili 

A small record of problems (which involves some specific problems of my robot, just for my own review)

  1.  The mobile phone needs to turn on the positioning to enter the LAN connection. By mistake, press and hold KEY1 to enter the direct connection mode and try again.
  2. Problem: cmake compilation problem, just change a terminal again.

Guess you like

Origin blog.csdn.net/dujuancao11/article/details/123227771
Recommended