Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webcam support for mac #912

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion PYTHON/utils/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ class Signals:
def __init__(self) -> None:
self.signal_states = {}
self.signal_iterations = {}
self.all_node_signals = {} # {child_id -> {(parent_id, direction)] -> signal_id}
self.all_node_signals = (
{}
) # {child_id -> {(parent_id, direction)] -> signal_id}

def update_child_signals(self, child_id, node_id, direction):
child_signals = self.all_node_signals.get(child_id, {})
Expand Down
1 change: 1 addition & 0 deletions captain/routes/devices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from fastapi import APIRouter
from captain.services.hardware import get_device_finder
from captain.types.devices import DeviceInfo
Expand Down
27 changes: 26 additions & 1 deletion captain/services/hardware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import subprocess
from sys import platform

if platform in ["darwin"]:
import AVFoundation
import os

import cv2
Expand Down Expand Up @@ -96,7 +99,29 @@ def get_cameras(self) -> list[CameraDevice]:
return cameras


class MacDeviceFinder(LinuxDeviceFinder):
def __init__(self):
if platform not in ["darwin"]:
raise Exception("MacDeviceFinder should only be used on macOS")

def get_cameras(self) -> list[CameraDevice]:
devices = AVFoundation.AVCaptureDevice.devices()
video_devices = [
device
for device in devices
if device.hasMediaType_(AVFoundation.AVMediaTypeVideo)
]
cameras = []
for device in video_devices:
cameras.append(
CameraDevice(name=device.localizedName(), id=device.uniqueID())
)
return cameras


def get_device_finder():
if platform in ["win32", "darwin"]:
if platform in ["win32"]:
return DefaultDeviceFinder()
if platform in ["darwin"]:
return MacDeviceFinder()
return LinuxDeviceFinder()
Loading
Loading