(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), (