python疲勞駕駛困倦低頭檢測功能的實現(xiàn)
python疲勞駕駛困倦低頭檢測,代碼如下所示:
def get_head_pose(shape): # 頭部姿態(tài)估計 # (像素坐標(biāo)集合)填寫2D參考點 # 17左眉左上角/21左眉右角/22右眉左上角/26右眉右上角/36左眼左上角/39左眼右上角/42右眼左上角/ # 45右眼右上角/31鼻子左上角/35鼻子右上角/48左上角/54嘴右上角/57嘴中央下角/8下巴角 image_pts = np.float32([shape[17], shape[21], shape[22], shape[26], shape[36], shape[39], shape[42], shape[45], shape[31], shape[35], shape[48], shape[54], shape[57], shape[8]]) # solvePnP計算姿勢——求解旋轉(zhuǎn)和平移矩陣: # rotation_vec表示旋轉(zhuǎn)矩陣,translation_vec表示平移矩陣,cam_matrix與K矩陣對應(yīng),dist_coeffs與D矩陣對應(yīng)。 _, rotation_vec, translation_vec = cv2.solvePnP(object_pts, image_pts, cam_matrix, dist_coeffs) # projectPoints重新投影誤差:原2d點和重投影2d點的距離(輸入3d點、相機內(nèi)參、相機畸變、r、t,輸出重投影2d點) reprojectdst, _ = cv2.projectPoints(reprojectsrc, rotation_vec, translation_vec, cam_matrix, dist_coeffs) reprojectdst = tuple(map(tuple, reprojectdst.reshape(8, 2))) # 以8行2列顯示 # 計算歐拉角calc euler angle rotation_mat, _ = cv2.Rodrigues(rotation_vec) # 羅德里格斯公式(將旋轉(zhuǎn)矩陣轉(zhuǎn)換為旋轉(zhuǎn)向量) pose_mat = cv2.hconcat((rotation_mat, translation_vec)) # 水平拼接,vconcat垂直拼接 # decomposeProjectionMatrix將投影矩陣分解為旋轉(zhuǎn)矩陣和相機矩陣 _, _, _, _, _, _, euler_angle = cv2.decomposeProjectionMatrix(pose_mat) pitch, yaw, roll = [math.radians(_) for _ in euler_angle] pitch = math.degrees(math.asin(math.sin(pitch))) roll = -math.degrees(math.asin(math.sin(roll))) yaw = math.degrees(math.asin(math.sin(yaw))) print('pitch:{}, yaw:{}, roll:{}'.format(pitch, yaw, roll)) return reprojectdst, euler_angle # 投影誤差,歐拉角 def eye_aspect_ratio(eye): # 垂直眼標(biāo)志(X,Y)坐標(biāo) A = dist.euclidean(eye[1], eye[5]) # 計算兩個集合之間的歐式距離 B = dist.euclidean(eye[2], eye[4]) # 計算水平之間的歐幾里得距離 # 水平眼標(biāo)志(X,Y)坐標(biāo) C = dist.euclidean(eye[0], eye[3]) # 眼睛長寬比的計算 ear = (A + B) / (2.0 * C) # 返回眼睛的長寬比 return ear def mouth_aspect_ratio(mouth): # 嘴部 A = np.linalg.norm(mouth[2] - mouth[9]) # 51, 59 B = np.linalg.norm(mouth[4] - mouth[7]) # 53, 57 C = np.linalg.norm(mouth[0] - mouth[6]) # 49, 55 mar = (A + B) / (2.0 * C) return mar
python疲勞駕駛困倦低頭檢測
https://download.csdn.net/download/babyai996/85068772
到此這篇關(guān)于python疲勞駕駛困倦低頭檢測功能的實現(xiàn)的文章就介紹到這了,更多相關(guān)python疲勞駕駛檢測內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python數(shù)據(jù)寫入列表并導(dǎo)出折線圖
這篇文章主要介紹了python數(shù)據(jù)寫入列表并導(dǎo)出折線圖,文章以舉例展開對文章主題的介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-01-01

python利用paramiko實現(xiàn)交換機巡檢的示例

使用python-magic和wxPython實現(xiàn)識別文檔類型

python統(tǒng)計文本字符串里單詞出現(xiàn)頻率的方法