发布时间:2023-02-23 12:00
基于YCgCr空间的肤色分割 + Dlib关键点检测 + 基于NMEAR的疲劳检测实现
1.安装opencv:
pip install opencv-python
2.安装dlib:
pip install dlib-19.7.0-cp36-cp36m-win_amd64.whl
3.报缺少什么就pip安装什么库
@jit(nopython=True) # jit实现for循环的加速
def for_ij2(image, Cr, Cb, result):
for j in range(image.shape[0]):
for i in range(image.shape[1]):
if 133 < Cr[j][i] < 173 and 77 < Cb[j][i] < 127:
result[j][i] = 255
# else:result[j][i] = 0
return result
def face_detect(image, element):
YCrCbMat = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb)
print(YCrCbMat.shape)
Cr = YCrCbMat[:, :, 1]
Cb = YCrCbMat[:, :, 2]
# print(Y.shape, Cr.shape, Cb.shape)
result = np.zeros(image.shape[:2], dtype=np.uint8)
t1 = time.time()
result = for_ij2(image, Cr, Cb, result)
temp = cv2.morphologyEx(result, cv2.MORPH_CLOSE, element)
contours, hierarchy = cv2.findContours(temp, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
return contours
def eye_aspect_ratio(eye):
left = dist.euclidean(eye[1], eye[5])
right = dist.euclidean(eye[2], eye[4])
horizontal = dist.euclidean(eye[0], eye[3])
ear = 2.0*horizontal/(left+right)
return ear
if self.startCheck:
if ear > self.eyesRatioLimit:
self.eyesCloseCount += 1
if self.eyesCloseCount >= 20: # 检测到时间超过20次则发出警告
cv2.putText(frame, "!!!!!!!!!!SLEEP!!!!!!!!!!!", (150, 70),cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
threadNames = []
threadingList = threading.enumerate()
for i in range(len(threadingList)):
threadNames.append(threadingList[i].getName())
if "BlinkThread" not in threadNames:
print(threadingList)
thread = BlinkThread(1, "BlinkThread")
thread.start()
else:
self.eyesCloseCount = 0
简单的小demo,完整版详见本人GitHub
R语言Bootstrap、百分位Bootstrap法抽样参数估计置信区间分析通勤时间和学生锻炼数据
[OpenCV实战]20 使用OpenCV实现基于增强相关系数最大化的图像对齐
【酷炫烟花特效表白(Html5+CSS3+JS,带背景音乐哦!)】
数据质量管理工具预研——Griffin VS Deequ VS Great expectations VS Qualitis
云原生【Kubernetes】—— 认识 k8s、k8s 架构、核心概念点介绍
Android 面试题:为什么 Activity 都重建了 ViewModel 还存在?—— Jetpack 系列(3)
Vue3.0 + Vite + Ant Design Vue + TypeScript 管理后台vue-vben-admin