Skip to content

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

TypeScript

setting cv2.VideoCapture to use 'cv2.CAP_DSHOW' for windows and 'cv2.CAP_ANY' for others

jon matthise5f265b75754
diff --git a/freemocap/webcam/camsetup.py b/freemocap/webcam/camsetup.py
index c24c3de5..c4c175af 100644
--- a/freemocap/webcam/camsetup.py
+++ b/freemocap/webcam/camsetup.py
@@ -2,6 +2,7 @@ import threading
import cv2
import imutils
import os
+import platform
import mediapipe as mp
@@ -31,7 +32,7 @@ class VideoSetup(threading.Thread):
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)
+ if platform.system() == 'Windows':
cap = cv2.VideoCapture(self.camID, cv2.CAP_DSHOW)
else:
cap = cv2.VideoCapture(self.camID, cv2.CAP_ANY)
@@ -94,7 +95,7 @@ class MediaPipeVideoSetup(threading.Thread):
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)
+ if platform.system() == 'Windows':
cap = cv2.VideoCapture(self.camID, cv2.CAP_DSHOW)
else:
cap = cv2.VideoCapture(self.camID, cv2.CAP_ANY)
diff --git a/freemocap/webcam/checkcams.py b/freemocap/webcam/checkcams.py
index 1a31dd1d..7a29d8f0 100644
--- a/freemocap/webcam/checkcams.py
+++ b/freemocap/webcam/checkcams.py
@@ -1,12 +1,13 @@
from tqdm import tqdm
import cv2
import os
+import platform
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)
+ if platform.system() == 'Windows':
cap = cv2.VideoCapture(source, cv2.CAP_DSHOW)
else:
cap = cv2.VideoCapture(source, cv2.CAP_ANY)
diff --git a/freemocap/webcam/startcamrecording.py b/freemocap/webcam/startcamrecording.py
index 3a791cc2..6826df0f 100644
--- a/freemocap/webcam/startcamrecording.py
+++ b/freemocap/webcam/startcamrecording.py
@@ -3,6 +3,7 @@ import cv2
import time
import pickle
import os
+import platform
class CamRecordingThread(threading.Thread):
def __init__(
@@ -51,7 +52,7 @@ 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)
+ if platform.system() == 'Windows':
cam = cv2.VideoCapture(camInput, cv2.CAP_DSHOW)
else:
cam = cv2.VideoCapture(camInput, cv2.CAP_ANY)