From a3af308c2904b15f6198ab3d6c8441e33984a5d6 Mon Sep 17 00:00:00 2001 From: Alberto Casas Ortiz Date: Tue, 17 Dec 2024 13:58:33 -0800 Subject: [PATCH 1/5] Added second arg to exception so it is returned correctly. --- utilsDetector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilsDetector.py b/utilsDetector.py index 31557464..b2232245 100644 --- a/utilsDetector.py +++ b/utilsDetector.py @@ -324,7 +324,7 @@ def runMMposeVideo( os.rename(pkl_path_tmp, pklPath) else: raise FileNotFoundError( - "We could not detect any pose in your video. Please verify that the subject is correctly in front of the camera." + "We could not detect any pose in your video. Please verify that the subject is correctly in front of the camera.", 'missing file - hrnet' ) except Exception as e: if len(e.args) == 2: # specific exception From bba78d35e561ffc89134d7324b7dd53031abf769 Mon Sep 17 00:00:00 2001 From: Alberto Casas Ortiz Date: Tue, 17 Dec 2024 14:34:07 -0800 Subject: [PATCH 2/5] Checking how many cameras failed before deciding to continue or to raise exception. --- utilsDetector.py | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/utilsDetector.py b/utilsDetector.py index b2232245..5454d158 100644 --- a/utilsDetector.py +++ b/utilsDetector.py @@ -37,19 +37,39 @@ def runPoseDetector(CameraDirectories, trialRelativePath, pathPoseDetector, trialRelativePath) extension = getVideoExtension(pathVideoWithoutExtension) trialRelativePath += extension - + + successful_cams = 0 # Counter for successful cameras + last_exception = None # To store the last exception + for camName in CameraDirectories_selectedCams: cameraDirectory = CameraDirectories_selectedCams[camName] print('Running {} for {}'.format(poseDetector, camName)) - if poseDetector == 'OpenPose': - runOpenPoseVideo( - cameraDirectory,trialRelativePath,pathPoseDetector, trialName, - resolutionPoseDetection=resolutionPoseDetection, - generateVideo=generateVideo) - elif poseDetector == 'mmpose': - runMMposeVideo( - cameraDirectory,trialRelativePath,pathPoseDetector, trialName, - generateVideo=generateVideo, bbox_thr=bbox_thr) + + try: + if poseDetector == 'OpenPose': + runOpenPoseVideo( + cameraDirectory, trialRelativePath, pathPoseDetector, trialName, + resolutionPoseDetection=resolutionPoseDetection, + generateVideo=generateVideo) + successful_cams += 1 + elif poseDetector == 'mmpose': + runMMposeVideo( + cameraDirectory, trialRelativePath, pathPoseDetector, trialName, + generateVideo=generateVideo, bbox_thr=bbox_thr) + successful_cams += 1 + except Exception as e: + print(f"Exception for {camName}: {e}") + last_exception = e + + # After the loop, decide based on the successful count + if successful_cams == 0: + print("No cameras succeeded.") + raise last_exception + elif successful_cams == 1: + print("Only 1 camera succeeded.") + raise last_exception + else: + print(f"At least 2 cameras succeeded ({successful_cams}). Continuing execution.") return extension @@ -323,7 +343,7 @@ def runMMposeVideo( if os.path.exists(pkl_path_tmp): os.rename(pkl_path_tmp, pklPath) else: - raise FileNotFoundError( + raise Exception( "We could not detect any pose in your video. Please verify that the subject is correctly in front of the camera.", 'missing file - hrnet' ) except Exception as e: From 3d55d65ff34063ba819df2d08a496184d6cba39a Mon Sep 17 00:00:00 2001 From: Alberto Casas Ortiz Date: Tue, 17 Dec 2024 14:49:23 -0800 Subject: [PATCH 3/5] Checking if pkl file exist in utilsChecker before using it. --- utilsChecker.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utilsChecker.py b/utilsChecker.py index 41f8f931..eedf5408 100644 --- a/utilsChecker.py +++ b/utilsChecker.py @@ -820,12 +820,18 @@ def synchronizeVideos(CameraDirectories, trialRelativePath, pathPoseDetector, openposePklDir = os.path.join(outputPklFolder, trialName) pathOutputPkl = os.path.join(cameraDirectory, openposePklDir) ppPklPath = os.path.join(pathOutputPkl, trialPrefix+'_rotated_pp.pkl') + # Check if the pkl file exists before trying to use it. + if not os.path.exists(ppPklPath): + print(f"{ppPklPath} does not exist. Excluding {camName}.") + camsToExclude.append(camName) + continue key2D, confidence = loadPklVideo( ppPklPath, videoFullPath, imageBasedTracker=imageBasedTracker, poseDetector=poseDetector,confidenceThresholdForBB=0.3) thisVideo = cv2.VideoCapture(videoFullPath.replace('.mov', '_rotated.avi')) frameRate = np.round(thisVideo.get(cv2.CAP_PROP_FPS)) if key2D.shape[1] == 0 and confidence.shape[1] == 0: + print(f"Excluding {camName}.") camsToExclude.append(camName) else: pointList.append(key2D) From af0c46ec924baaff121c7e889344369408446fe6 Mon Sep 17 00:00:00 2001 From: Alberto Casas Ortiz Date: Tue, 17 Dec 2024 15:17:02 -0800 Subject: [PATCH 4/5] Assuring neutral always requires all cameras. --- utilsChecker.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utilsChecker.py b/utilsChecker.py index eedf5408..15a79bfc 100644 --- a/utilsChecker.py +++ b/utilsChecker.py @@ -820,8 +820,11 @@ def synchronizeVideos(CameraDirectories, trialRelativePath, pathPoseDetector, openposePklDir = os.path.join(outputPklFolder, trialName) pathOutputPkl = os.path.join(cameraDirectory, openposePklDir) ppPklPath = os.path.join(pathOutputPkl, trialPrefix+'_rotated_pp.pkl') + # Check if neutral. + components = ppPklPath.split(os.sep) + is_neutral = 'neutral' in components # Check if the pkl file exists before trying to use it. - if not os.path.exists(ppPklPath): + if not is_neutral and not os.path.exists(ppPklPath): print(f"{ppPklPath} does not exist. Excluding {camName}.") camsToExclude.append(camName) continue From ff482c844c9796916c25c4a1f1f38fa76b7b46c2 Mon Sep 17 00:00:00 2001 From: Alberto Casas Ortiz Date: Tue, 17 Dec 2024 15:27:39 -0800 Subject: [PATCH 5/5] Assuring neutral always requires all cameras. --- utilsChecker.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utilsChecker.py b/utilsChecker.py index 15a79bfc..840acd4e 100644 --- a/utilsChecker.py +++ b/utilsChecker.py @@ -824,9 +824,13 @@ def synchronizeVideos(CameraDirectories, trialRelativePath, pathPoseDetector, components = ppPklPath.split(os.sep) is_neutral = 'neutral' in components # Check if the pkl file exists before trying to use it. - if not is_neutral and not os.path.exists(ppPklPath): - print(f"{ppPklPath} does not exist. Excluding {camName}.") - camsToExclude.append(camName) + if not os.path.exists(ppPklPath): + if is_neutral: + exception = "Pose detection failed for at least one camera. Verify your setup and try again. Visit https://www.opencap.ai/best-pratices to learn more about data collection and https://www.opencap.ai/troubleshooting for potential causes for a failed neutral pose." + raise Exception(exception, exception) + else: + print(f"{ppPklPath} does not exist. Excluding {camName}.") + camsToExclude.append(camName) continue key2D, confidence = loadPklVideo( ppPklPath, videoFullPath, imageBasedTracker=imageBasedTracker,