Free Motion Capture for Everyone πβ¨
TypeScript
mediapipe overlays
aaroncherianb8d97458a7c2
diff --git a/freemocap/fmc_mediapipe.py b/freemocap/fmc_mediapipe.pyindex 7ee15f0e..1a32e360 100644--- a/freemocap/fmc_mediapipe.py+++ b/freemocap/fmc_mediapipe.py@@ -9,6 +9,7 @@ import mediapipe as mp# from numba import jitmp_drawing = mp.solutions.drawing_utils+mp_drawing_styles = mp.solutions.drawing_stylesmp_holistic = mp.solutions.holisticdiff --git a/freemocap/webcam/camera_settings.py b/freemocap/webcam/camera_settings.pyindex 9549d8a8..c39f4821 100644--- a/freemocap/webcam/camera_settings.py+++ b/freemocap/webcam/camera_settings.py@@ -67,7 +67,7 @@ def initialize(session, stage, board):current_path_to_save = session.preferences['saved']['path_to_save']except:current_path_to_save = session.preferences['default']['path_to_save']- rotDict, paramDict, session.sessionID,savepath = recordGUI.RunParametersGUI(sessionID_in, rotation_entry, parameter_entry, current_path_to_save, cam_inputs, task)+ rotDict, paramDict, session.sessionID,savepath, mediaPipeOverlay = recordGUI.RunParametersGUI(sessionID_in, rotation_entry, parameter_entry, current_path_to_save, cam_inputs, task)#update the saved parameters in the YAML#recordingconfig.rotation_settings['saved'] = rotDict@@ -87,7 +87,7 @@ def initialize(session, stage, board):if task == "setup":# run setup processes, and then check if th user wants to proceed to recording- camsetup.RunSetup(cam_inputs, rotation_input, paramDict)+ camsetup.RunSetup(cam_inputs, rotation_input, paramDict,mediaPipeOverlay)proceedToRecording, restartSetup, session.sessionID, savepath = recordGUI.RunProceedtoRecordGUI(sessionID_in,current_path_to_save)diff --git a/freemocap/webcam/camsetup.py b/freemocap/webcam/camsetup.pyindex b27b096b..c24c3de5 100644--- a/freemocap/webcam/camsetup.py+++ b/freemocap/webcam/camsetup.py@@ -3,6 +3,11 @@ import cv2import imutilsimport os+import mediapipe as mp++mp_drawing = mp.solutions.drawing_utils+mp_drawing_styles = mp.solutions.drawing_styles+mp_holistic = mp.solutions.holisticclass VideoSetup(threading.Thread):"""@@ -31,6 +36,7 @@ class VideoSetup(threading.Thread):else:cap = cv2.VideoCapture(self.camID, cv2.CAP_ANY)+cap.set(cv2.CAP_PROP_FRAME_WIDTH, resWidth)cap.set(cv2.CAP_PROP_FRAME_HEIGHT, resHeight)cap.set(cv2.CAP_PROP_EXPOSURE, exposure)@@ -66,8 +72,91 @@ class VideoSetup(threading.Thread):breakcv2.destroyWindow(camName)+class MediaPipeVideoSetup(threading.Thread):+ """+ Class to run and thread webcams for preview purposes+ """+ def __init__(self, camID, parameterDictionary, rotNum):+ self.camID = camID+ self.parameterDictionary = parameterDictionary+ self.rotNum = rotNum+ threading.Thread.__init__(self)++ def run(self):+ # print("Starting " + self.previewName)+ self.record(self.parameterDictionary, self.rotNum)++ def record(self, parameterDictionary, rotNum):+ exposure = parameterDictionary.get("exposure")+ resWidth = parameterDictionary.get("resWidth")+ resHeight = parameterDictionary.get("resHeight")+ camName = "Camera" + str(self.camID)++ cv2.namedWindow(camName)++ if os.name == 'nt': #use CAP_DSHOW for windows, CAP_ANY otherwise (*might* make things ubuntu/mac compatible, but not sure. See https://github.com/jonmatthis/freemocap/issues/52)+ cap = cv2.VideoCapture(self.camID, cv2.CAP_DSHOW)+ else:+ cap = cv2.VideoCapture(self.camID, cv2.CAP_ANY)++ with mp_holistic.Holistic(+ static_image_mode=True,+ model_complexity=0,+ enable_segmentation=True) as holistic:++ cap.set(cv2.CAP_PROP_FRAME_WIDTH, resWidth)+ cap.set(cv2.CAP_PROP_FRAME_HEIGHT, resHeight)+ cap.set(cv2.CAP_PROP_EXPOSURE, exposure)++ # showing values of the properties+ print("__________________________________________")+ print("cv2::videocapture properties for Camera# {}".format(self.camID))+ print("CV_CAP_PROP_FRAME_WIDTH: '{}'".format(cap.get(cv2.CAP_PROP_FRAME_WIDTH)))+ print("CV_CAP_PROP_FRAME_HEIGHT : '{}'".format(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))+ print("CAP_PROP_FPS : '{}'".format(cap.get(cv2.CAP_PROP_FPS)))+ print("CAP_PROP_EXPOSURE : '{}'".format(cap.get(cv2.CAP_PROP_EXPOSURE)))+ print("CAP_PROP_POS_MSEC : '{}'".format(cap.get(cv2.CAP_PROP_POS_MSEC)))+ print("CAP_PROP_FRAME_COUNT : '{}'".format(cap.get(cv2.CAP_PROP_FRAME_COUNT)))+ print("CAP_PROP_BRIGHTNESS : '{}'".format(cap.get(cv2.CAP_PROP_BRIGHTNESS)))+ print("CAP_PROP_CONTRAST : '{}'".format(cap.get(cv2.CAP_PROP_CONTRAST)))+ print("CAP_PROP_SATURATION : '{}'".format(cap.get(cv2.CAP_PROP_SATURATION)))+ print("CAP_PROP_HUE : '{}'".format(cap.get(cv2.CAP_PROP_HUE)))+ print("CAP_PROP_GAIN : '{}'".format(cap.get(cv2.CAP_PROP_GAIN)))+ print("CAP_PROP_CONVERT_RGB : '{}'".format(cap.get(cv2.CAP_PROP_CONVERT_RGB)))+ print("__________________________________________")-def RunSetup(cam_inputs, rotation_input, paramDict):+ while True:+ ret1, frame1 = cap.read()+ if ret1 == True:+ frame1.flags.writeable = False+ results = holistic.process(cv2.cvtColor(frame1, cv2.COLOR_BGR2RGB))+ mp_drawing.draw_landmarks(+ frame1,+ results.face_landmarks,+ mp_holistic.FACEMESH_CONTOURS,+ landmark_drawing_spec=None,+ connection_drawing_spec=mp_drawing_styles+ .get_default_face_mesh_contours_style())+ mp_drawing.draw_landmarks(+ frame1,+ results.pose_landmarks,+ mp_holistic.POSE_CONNECTIONS,+ landmark_drawing_spec=mp_drawing_styles+ .get_default_pose_landmarks_style())+ if rotNum is not None:+ frame1 = imutils.rotate_bound(frame1, angle=rotNum)+ cv2.imshow(camName, frame1)+ if cv2.waitKey(1) & 0xFF == 27:+ # == ord('q') for q+ break++ else:+ break+ cv2.destroyWindow(camName)++++def RunSetup(cam_inputs, rotation_input, paramDict,mediaPipeOverlay):"""Start video setup by threading instances of the VideoSetup class"""@@ -77,7 +166,10 @@ def RunSetup(cam_inputs, rotation_input, paramDict):ulist = []for cam_input, cam_rotation in zip(cam_inputs, rotation_input):- u = VideoSetup(cam_input, paramDict, cam_rotation)+ if mediaPipeOverlay == True:+ u = MediaPipeVideoSetup(cam_input, paramDict, cam_rotation)+ else:+ u = VideoSetup(cam_input, paramDict, cam_rotation)u.start()ulist.append(u)diff --git a/freemocap/webcam/recordGUI.py b/freemocap/webcam/recordGUI.pyindex 80d6fc20..d03f96c6 100644--- a/freemocap/webcam/recordGUI.py+++ b/freemocap/webcam/recordGUI.py@@ -100,6 +100,7 @@ class SettingsGUI:self.sessionID_in = sessionID_inself.task = taskself.currentPath = current_path_to_save+ self.mediaPipeOverlay = False# check if any previous parameters existif self.parameter_dictionary is not None:existing_parameters = True@@ -168,6 +169,10 @@ class SettingsGUI:codecLabel = Label(parametersFrame, text="codec").pack(side="left")self.codecEntry = Entry(parametersFrame)self.codecEntry.pack(side="left")++ self.var1 = tk.IntVar()+ c1 = tk.Checkbutton(parametersFrame, text='Mediapipe Overlay',variable=self.var1, onvalue=1, offvalue=0)+ c1.pack(side = 'right')# ---SessionID entry- default is the date/timeif self.task == "record":@@ -232,6 +237,10 @@ class SettingsGUI:"framerate": int(self.FPSEntry.get()),"codec": str(self.codecEntry.get()),}++ if self.var1.get()==1:+ self.mediaPipeOverlay=True+# spit out the sessionIDif self.task == "record":self.sessionID_out = self.sessionIDEntry.get()@@ -359,7 +368,7 @@ def RunParametersGUI(sessionID_in, rotation_entry, parameter_entry,current_path_sessionID = Nonesavepath = None- return recording_settings.rotation_output, paramDict, sessionID,savepath+ return recording_settings.rotation_output, paramDict, sessionID,savepath, recording_settings.mediaPipeOverlaydef RunProceedtoRecordGUI(sessionID_in,current_path_to_save):