Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

Stop making unnecessary MediaPipe and OpenPose stuff and stopped saving open pose images

jon matthis0b4262c1e3ef
diff --git a/freemocap/fmc_mediapipe.py b/freemocap/fmc_mediapipe.py
index 1a32e360..6cca4945 100644
--- a/freemocap/fmc_mediapipe.py
+++ b/freemocap/fmc_mediapipe.py
@@ -18,12 +18,7 @@ def runMediaPipe(session, dummyRun=False):
Run MediaPipe on synced videos, and save body tracking data to be parsed
"""
- session.mediaPipeDataPath.mkdir(exist_ok = True)
- mediaPipe_jsonPathList = [] # list to hold the paths to the json files
- mediaPipe_imgPathList = []
- mediaPipe_imgPathList_yaml = []
- mediaPipe_jsonPathList_yaml = []
with mp_holistic.Holistic(
static_image_mode = False, #use 'static image mode' to avoid system getting 'stuck' on ghost skeletons?
@@ -31,26 +26,10 @@ def runMediaPipe(session, dummyRun=False):
) as holistic:
eachCamerasData = [] # Create an empty list that holds each cameras data
- for (
- thisVidPath
- ) in (
- session.syncedVidPath.iterdir()
- ): # Run MediaPipe 'Holistic' (body, hands, face) tracker on each video in the raw video folder
- if (
- thisVidPath.suffix == ".mp4"
- ): # NOTE - at some point we should build some list of 'synced video names' and check against that
-
- vidPath = session.mediaPipeDataPath / thisVidPath.stem
- jsonPath = vidPath / "json"
- jsonPath.mkdir(
- parents=True, exist_ok=True
- ) # this camera's json files (with keypoints)
- imgPath = vidPath / "images"
- imgPath.mkdir(parents=True, exist_ok=True)
- mediaPipe_jsonPathList.append(jsonPath)
- mediaPipe_imgPathList.append(imgPath)
- mediaPipe_imgPathList_yaml.append(str(imgPath))
- mediaPipe_jsonPathList_yaml.append(str(jsonPath))
+ for ( thisVidPath ) in ( session.syncedVidPath.iterdir() ): # Run MediaPipe 'Holistic' (body, hands, face) tracker on each video in the raw video folder
+ if ( thisVidPath.suffix.lower() == ".mp4" ): # NOTE - at some point we should build some list of 'synced video names' and check against that
+
+
mediaPipe_dataList = [] # Create an empty list for mediapipes data
if not dummyRun:
cap = cv2.VideoCapture(str(thisVidPath))
@@ -80,82 +59,18 @@ def runMediaPipe(session, dummyRun=False):
cv2.cvtColor(image, cv2.COLOR_BGR2RGB), #Convert the BGR image to RGB before processing
) # NOTE: THIS IS WHERE THE MAGIC HAPENS
- try:
- results.pose_landmarks.landmark
- try:
- results.left_hand_landmarks.landmark
- try:
- results.right_hand_landmarks.landmark
- try:
- results.face_landmarks.landmark
- f = 9
- except:
- pass
- except:
- pass
- except:
- pass
- except:
- pass
-
mediaPipe_dataList.append(
results
) # Append data to mediapipe data list
- saveImages = False
- if saveImages:
- # Draw pose, left and right hands, and face landmarks on the image.
- annotated_image = image.copy()
- mp_drawing.draw_landmarks(
- annotated_image,
- results.face_landmarks,
- mp_holistic.FACE_CONNECTIONS,
- )
- mp_drawing.draw_landmarks(
- annotated_image,
- results.left_hand_landmarks,
- mp_holistic.HAND_CONNECTIONS,
- )
- mp_drawing.draw_landmarks(
- annotated_image,
- results.right_hand_landmarks,
- mp_holistic.HAND_CONNECTIONS,
- )
- mp_drawing.draw_landmarks(
- annotated_image,
- results.pose_landmarks,
- mp_holistic.POSE_CONNECTIONS,
- )
-
- # save annotated image
- frameName = str(frameNum).zfill(6)
-
- cv2.imwrite(
- str(imgPath) + "/" + frameName + ".png",
- annotated_image,
- )
-
# load the next image (will break `while-loop` on the last frame)
success, image = cap.read() # load next image from video
- f = 9
eachCamerasData.append(
mediaPipe_dataList
) # Append that cameras data for every frame to the camera datalist
session.image_height = image_height
session.image_width = image_width
-
- session.mediaPipe_jsonPathList = mediaPipe_jsonPathList
- session.mediaPipe_imgPathList = mediaPipe_imgPathList
-
- session.session_settings['mediaPipe_imgPathList'] = mediaPipe_imgPathList_yaml
- session.session_settings['mediaPipe_jsonPathList'] = mediaPipe_jsonPathList_yaml
-
- #yaml = YAML()
- #data = yaml.load(session.yamlPath)
- #data["mediaPipe_imgPathList"] = mediaPipe_imgPathList_yaml
- #data["mediaPipe_jsonPathList"] = mediaPipe_jsonPathList_yaml
- #yaml.dump(data, session.yamlPath)
session.mediaPipeData = eachCamerasData
diff --git a/freemocap/fmc_openpose.py b/freemocap/fmc_openpose.py
index fd71e0e3..fc71ab8d 100644
--- a/freemocap/fmc_openpose.py
+++ b/freemocap/fmc_openpose.py
@@ -50,10 +50,6 @@ def runOpenPose(session, runOpenPose=False):
str(thisVidPath),
"--write_json",
str(jsonPath),
- "--write_images",
- str(imgPath),
- "--write_images_format",
- "png",
"--net_resolution",
"-1x320",
"--hand",
diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.py
index b3b795a2..20ff44da 100644
--- a/freemocap/fmc_runme.py
+++ b/freemocap/fmc_runme.py
@@ -182,15 +182,15 @@ def RunMe(sessionID=None,
-
- if useBlender == True:
- #blenderExePath = Path('C:\Program Files\Blender Foundation\Blender 2.93')
- #os.chdir(blenderExePath)
- output = subprocess.run([blenderEXEpath, "--background", "--python", str(subprocessPath), "--", str(sesh.dataArrayPath/'mediaPipeSkel_3d.npy')], capture_output=True, text=True, check=True)
- print(output)
+ if stage <=5:
+ if useBlender == True:
+ #blenderExePath = Path('C:\Program Files\Blender Foundation\Blender 2.93')
+ #os.chdir(blenderExePath)
+ output = subprocess.run([blenderEXEpath, "--background", "--python", str(subprocessPath), "--", str(sesh.dataArrayPath/'mediaPipeSkel_3d.npy')], capture_output=True, text=True, check=True)
+ print(output)
# %% Stage Five - Make Skreleton Animation
- if stage <= 5:
+ if stage <= 6:
print('Starting Skeleton Plotting')
play_skeleton_animation.PlaySkeletonAnimation(
sesh,
diff --git a/freemocap/play_skeleton_animation.py b/freemocap/play_skeleton_animation.py
index cf9a0321..77706315 100644
--- a/freemocap/play_skeleton_animation.py
+++ b/freemocap/play_skeleton_animation.py
@@ -63,7 +63,7 @@ def PlaySkeletonAnimation(
vidType=1,
startFrame=0,
azimuth=-90,
- elevation=-61,
+ elevation=-70,
useOpenPose=True,
useMediaPipe=False,
useDLC=False,
@@ -262,7 +262,9 @@ def PlaySkeletonAnimation(
if not thisArtistKey == 'blackLine':
xCurrTimeArtists[thisArtistKey][0].set_ydata(xCurrTimeYdata[thisArtistKey][frameNum] )
yCurrTimeArtists[thisArtistKey][0].set_ydata(yCurrTimeYdata[thisArtistKey][frameNum] )
-
+
+ yCurrTimeArtists['frameNumber'].set_x(frameNum/fps+3/fps)
+ yCurrTimeArtists['frameNumber'].set_text('Frame# '+ str(frameNum))
# if recordVid:
# thisFramePath = str(animationFramePath) + '/'+ str(session.sessionID) + "_frame_" + str(frameNum).zfill(6) + ".png"
# plt.savefig(thisFramePath)
@@ -532,7 +534,7 @@ def PlaySkeletonAnimation(
# groundYY = np.zeros_like(groundXX)
# groundMesh = ax3d.plot_surface(groundXX, groundZZ, groundYY, color='k', alpha=.5)
- axRange = 750#session.board.square_length * 10
+ axRange = 400#session.board.square_length * 10
# Setting the axes properties
ax3d.set_xlim3d([mx-axRange, mx+axRange])
@@ -739,8 +741,9 @@ def PlaySkeletonAnimation(
yCurrTimeYdata['rHandDot'] = rHandY
yCurrTimeArtists['lHandDot'] = yTimeSeriesAx.plot([startFrame/fps], [lHandY[startFrame]], markeredgecolor=humon_blue, markerfacecolor = 'k', marker='o', markersize=3)
yCurrTimeYdata['lHandDot'] = lHandY
-
-
+
+
+ yCurrTimeArtists['frameNumber'] = yTimeSeriesAx.text(startFrame/fps+3/fps, ylimRange*.7, "Frame# " + str(startFrame), fontsize=6)
yTimeSeriesAx.tick_params(labelsize=6, direction='in', width=.5)
yTimeSeriesAx.tick_params( pad=2)
@@ -807,7 +810,7 @@ def PlaySkeletonAnimation(
# )
# thisVidAxis.text(-565,1440, 'Music - artist: Neon Exdeath, song: Meowmaline, album: Jewel Tones',color=humon_green, fontsize=6)
- thisVidAxis.text(-150,510, 'github.com/jonmatthis/freemocap || jonmatthis.com/freemocap',color=humon_green, fontsize=6)
+ thisVidAxis.text(0,thisVidCap.get(cv2.CAP_PROP_FRAME_HEIGHT)*1.06, 'github.com/jonmatthis/freemocap || freemocap.org',color=humon_green, fontsize=6)
logoAx = fig.add_subplot(position=[.85, .85, .15, .15])
logoIm = cv2.imread(r'logo\fmc-logo-black-border-white-bkgd.png') #JSM NOTE - THis doesn't work, but SOMETIMES IT DOES?!
diff --git a/freemocap_runme_script.py b/freemocap_runme_script.py
index b6b94b4a..3b002dae 100644
--- a/freemocap_runme_script.py
+++ b/freemocap_runme_script.py
@@ -1,3 +1,3 @@
import freemocap as fmc
-fmc.RunMe(sessionID = 'sesh_2021-10-19_18_40_12', stage=5, useOpenPose=True, setDataPath=False)
+fmc.RunMe(sessionID = 'sesh_2021-10-15_18_09_48_goPro', stage=5, )
diff --git a/runme_FreeMoCap.py b/runme_FreeMoCap.py
index 84f332f9..694ea3e0 100644
--- a/runme_FreeMoCap.py
+++ b/runme_FreeMoCap.py
@@ -1,7 +1,4 @@
-from freemocap import session
import freemocap as fmc
-#fmc.RunMe(useOpenPose = False, useMediaPipe=True, stage = 5, sessionID ='sesh_2021-09-13_14_34_12', recordVid=False)
-
-fmc.RunMe(useBlender=True)
+fmc.RunMe()