Skip to content

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

TypeScript

tweaks to make mediapipe processing more accurate and plotting more robust

jon matthis931f864857f9
diff --git a/freemocap/fmc_mediapipe.py b/freemocap/fmc_mediapipe.py
index 6ef08446..8856a0db 100644
--- a/freemocap/fmc_mediapipe.py
+++ b/freemocap/fmc_mediapipe.py
@@ -25,7 +25,11 @@ def runMediaPipe(session, dummyRun=False):
mediaPipe_imgPathList_yaml = []
mediaPipe_jsonPathList_yaml = []
- with mp_holistic.Holistic() as holistic:
+ with mp_holistic.Holistic(
+ static_image_mode = True, #use 'static image mode' to avoid system getting 'stuck' on ghost skeletons
+ model_complexity = 2, #in this house, we turn the Speed/Accuracy dial all the way towards accuracy \o/) as holistic:
+ ) as holistic:
+
eachCamerasData = [] # Create an empty list that holds each cameras data
for (
thisVidPath
@@ -73,8 +77,8 @@ def runMediaPipe(session, dummyRun=False):
image_height, image_width, _ = image.shape
results = holistic.process(
- cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
- ) # THIS IS WHERE THE MAGIC HAPENS (ps. Convert the BGR image to RGB before processing.)
+ 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
diff --git a/freemocap/play_skeleton_animation.py b/freemocap/play_skeleton_animation.py
index b2398fd5..b9da5e4d 100644
--- a/freemocap/play_skeleton_animation.py
+++ b/freemocap/play_skeleton_animation.py
@@ -516,6 +516,10 @@ def PlaySkeletonAnimation(
mz = np.nanmean(mediaPipe_skel_fr_mar_xyz[int(numFrames/2),:,2])
+ if np.isnan(mx) or np.isnan(my) or np.isnan(mz):
+ mx = 0
+ my = 0
+ mz = 0
# groundX = np.arange(mx-100,mx+100)
# groundZ = np.arange(my-100,my+100)
# groundXX, groundZZ = np.meshgrid(groundX, groundZ)
diff --git a/freemocap/webcam/checkcams.py b/freemocap/webcam/checkcams.py
index 92c179d1..1a31dd1d 100644
--- a/freemocap/webcam/checkcams.py
+++ b/freemocap/webcam/checkcams.py
@@ -7,9 +7,9 @@ def TestDevice(source):
Checks to see if there is a camera available at the input
"""
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)
+ cap = cv2.VideoCapture(source, cv2.CAP_DSHOW)
else:
- cap = cv2.VideoCapture(self.camID, cv2.CAP_ANY)
+ cap = cv2.VideoCapture(source, cv2.CAP_ANY)
# if cap is None or not cap.isOpened():
# print('Warning: unable to open video source: ', source)
diff --git a/freemocap/webcam/startcamrecording.py b/freemocap/webcam/startcamrecording.py
index 6d4060db..3a791cc2 100644
--- a/freemocap/webcam/startcamrecording.py
+++ b/freemocap/webcam/startcamrecording.py
@@ -52,9 +52,9 @@ def CamRecording(
cv2.namedWindow(camID) # name the preview window for the camera its showing
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)
+ cam = cv2.VideoCapture(camInput, cv2.CAP_DSHOW)
else:
- cap = cv2.VideoCapture(self.camID, cv2.CAP_ANY)
+ cam = cv2.VideoCapture(camInput, cv2.CAP_ANY)
# if not cam.isOpened():
diff --git a/freemocap_runme_script.py b/freemocap_runme_script.py
index 28e30b89..29f03a60 100644
--- a/freemocap_runme_script.py
+++ b/freemocap_runme_script.py
@@ -3,16 +3,16 @@ import freemocap as fmc
from pathlib import Path
import sys
-fmc.RunMe(
- # sessionID = 'sesh_2021-08-29_17_55_45',
- sessionID=None,
- stage = 1,
- useOpenPose=False,
- runOpenPose=True,
- useMediaPipe=True,
- runMediaPipe = True,
- useDLC=False,
- recordVid = True ,
- reconstructionConfidenceThreshold = 0.7,
- calVideoFrameLength = -1,
-)
+fmc.RunMe(stage=4)
+# # sessionID = 'sesh_2021-08-29_17_55_45',
+# sessionID=None,
+# stage = 1,
+# useOpenPose=False,
+# runOpenPose=True,
+# useMediaPipe=True,
+# runMediaPipe = True,
+# useDLC=False,
+# recordVid = True ,
+# reconstructionConfidenceThreshold = 0.7,
+# calVideoFrameLength = -1,
+# )
diff --git a/update_pip.txt b/update_pip.txt
index 99f6e430..78abef26 100644
--- a/update_pip.txt
+++ b/update_pip.txt
@@ -1,8 +1,8 @@
-git commit --allow-empty -m "REL: v0.0.29"
-git tag -a v0.0.29 # Don't forget the leading v
+git commit --allow-empty -m "REL: v0.0.31"
+git tag -a v0.0.31 # Don't forget the leading v
git push origin main
-git push origin v0.0.29
+git push origin v0.0.31
python3 -m pip install --upgrade wheel
git clean -dfx
python setup.py sdist