正脸检测算法

本文介绍了从前期的人脸检测、关键点检测等基础步骤,到中期的图像裁剪和处理,再到后期的摄像头调试与优化,详细阐述了一个完整的正脸检测算法的应用流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(1)前期:人脸检测、关键点检测、闭眼检测、清晰度检测、单人脸多人脸朝向角度检测;
(2)中期:单人脸裁剪、多人脸自动裁剪和写入、联调图片读取和写入、绘制自适应人脸圆角矩形框;
(3)后期:线下展厅摄像头调试、测试优化效果、改多线程运行、优化运行时间。

import multiprocessing
from PIL import Image
import numpy as np
import cv2 as cv
import dlib
from scipy.spatial import distance
import math
import os
import cv2 as cv
import time
# 导入time库
import matplotlib.pyplot as plt
import time  # 获取时间戳
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import matplotlib as mpl
# 保存图片
# 代码开始运行
# 保存图片
pixel = 240 #过滤像素阈值
face_angle = 10 #正脸角度
def face_detect(i):

    print(i, 'yunxing')
    capture_usb = cv.VideoCapture(i, cv.CAP_DSHOW)
    print('0')
    # 打开自带的摄像头
    if capture_usb.isOpened():
        print('-----------')
        # capture_usb.set(cv.CAP_PROP_FRAME_WIDTH, 3840)
        # capture_usb.set(cv.CAP_PROP_FRAME_HEIGHT, 2160)
        capture_usb.set(cv.CAP_PROP_FRAME_WIDTH, 3840)
        capture_usb.set(cv.CAP_PROP_FRAME_HEIGHT, 2160)
        scale = 2
        detector = dlib.get_frontal_face_detector()
        predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
        # 持续读取摄像头数据
        now = int(time.time())
        print('1')
        while True:
            read_code2, frame = capture_usb.read()
            # image=frame
            # print(len(image))
            # print(len(image[0]))
            # print(len(image[0][0]))
            # exit()
            frame2 = frame
            # gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
            # cv.imshow('Window', frame)
            # cv.waitKey(1)
            now2 = int(time.time())
            if now2 - now >= 5:
                now = now2
                print('2')
                ###3#pic_path = save_img(now2, frame)
                # import matplotlib.pyplot as plt
                # 绘制矩形人脸框
                def draw_border(img, pt1, pt2, color, thickness, r, d):
                    x1, y1 = pt1
                    x2, y2 = pt2
                    # Top left
                    cv.line(img, (x1 + r, y1), (x1 + r + d, y1), color, thickness)
                    cv.line(img, (x1, y1 + r), (x1, y1 + r + d), color, thickness)
                    cv.ellipse(img, (x1 + r, y1 + r), (r, r), 180, 0, 90, color, thickness)

                    # Top right
                    cv.line(img, (x2 - r, y1), (x2 - r - d, y1), color, thickness)
                    cv.line(img, (x2, y1 + r), (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值