You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.1 KiB
Python

import cv2
import mediapipe as mp
import analysisPoint as mp_drawing
mp_holistic = mp.solutions.holistic
import numpy as np
class MediapipeProcess:
def mediapipe_det(image,holistic):
'''
调用模型获得检测结果
'''
image.flags.writeable = False
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = holistic.process(image)
return results
def get_analysis_result(image,results):
'''
images: 检测的图片
results: 图片的检测结果
对上述结果进行分析
'''
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
face_result = mp_drawing.draw_landmarks(
image,
results.face_landmarks,
mp_holistic.FACEMESH_CONTOURS)
right_hand_result = mp_drawing.draw_landmarks(
image,
results.right_hand_landmarks,
mp_holistic.HAND_CONNECTIONS)
left_hand_result = mp_drawing.draw_landmarks(
image,
results.left_hand_landmarks,
mp_holistic.HAND_CONNECTIONS)
face_bbox = MediapipeProcess.point_to_bbox(face_result)
right_hand_bbox = MediapipeProcess.point_to_bbox(right_hand_result)
left_hand_bbox = MediapipeProcess.point_to_bbox(left_hand_result)
result_dict = {'face_bbox':face_bbox,'hand_bbox':[right_hand_bbox,left_hand_bbox]}
return result_dict
def point_to_bbox(result_list):
'''
根据关键点坐标,获取坐标点的最小外接矩形
'''
result_array = np.array(result_list)
if result_array.all():
rect = cv2.minAreaRect(result_array) # 得到最小外接矩形的(中心(x,y), (宽,高), 旋转角度)
bbox = cv2.boxPoints(rect) # 获取最小外接矩形的4个顶点坐标(ps: cv2.boxPoints(rect) for OpenCV 3.x)
bbox = np.int0(bbox)
return bbox
else:
pass
# if __name__ == '__main__':
# # media_holistic(video_file='E:/Bank_files/Bank_02/dataset/video_person/after_1/0711-1_199_0.avi',
# video_save_path='E:/Bank_files/Bank_02/videos_mediapipe/test_data/0725_test')