windows下外接摄像头用python用于采集图像
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了windows下外接摄像头用python用于采集图像,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1579字,纯文字阅读大概需要3分钟。
内容图文
![windows下外接摄像头用python用于采集图像](/upload/InfoBanner/zyjiaocheng/929/2e003cd89ec24ce3a62e93b779e36128.jpg)
笔记本外接摄像头,采集图像代码,
import cv2
import dlib
from scipy.spatial import distance
def calculate_EAR(eye):
A = distance.euclidean(eye[1], eye[5])
B = distance.euclidean(eye[2], eye[4])
C = distance.euclidean(eye[0], eye[3])
ear_aspect_ratio = (A+B)/(2.0*C)
return ear_aspect_ratio
cap = cv2.VideoCapture(0)
hog_face_detector = dlib.get_frontal_face_detector()
dlib_facelandmark = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
while True:
_, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = hog_face_detector(gray)
for face in faces:
face_landmarks = dlib_facelandmark(gray, face)
leftEye = []
rightEye = []
for n in range(36,42):
x = face_landmarks.part(n).x
y = face_landmarks.part(n).y
leftEye.append((x,y))
next_point = n+1
if n == 41:
next_point = 36
x2 = face_landmarks.part(next_point).x
y2 = face_landmarks.part(next_point).y
cv2.line(frame,(x,y),(x2,y2),(0,255,0),1)
for n in range(42,48):
x = face_landmarks.part(n).x
y = face_landmarks.part(n).y
rightEye.append((x,y))
next_point = n+1
if n == 47:
next_point = 42
x2 = face_landmarks.part(next_point).x
y2 = face_landmarks.part(next_point).y
cv2.line(frame,(x,y),(x2,y2),(0,255,0),1)
left_ear = calculate_EAR(leftEye)
right_ear = calculate_EAR(rightEye)
EAR = (left_ear+right_ear)/2
EAR = round(EAR,2)
if EAR<0.26:
cv2.putText(frame,"DROWSY",(20,100),
cv2.FONT_HERSHEY_SIMPLEX,3,(0,0,255),4)
cv2.putText(frame,"Are you Sleepy?",(20,400),
cv2.FONT_HERSHEY_SIMPLEX,2,(0,0,255),4)
print("Drowsy")
print(EAR)
cv2.imshow("Are you Sleepy", frame)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
内容总结
以上是互联网集市为您收集整理的windows下外接摄像头用python用于采集图像全部内容,希望文章能够帮你解决windows下外接摄像头用python用于采集图像所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。