Skip to content
Open
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion robot/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import threading
import queue
import subprocess as sp

from datetime import datetime
from typing import NamedTuple, Any
Expand Down Expand Up @@ -209,13 +210,29 @@ class RoboConUSBCamera(Camera):
def __init__(self,
start_res=(1296, 736),
focal_lengths=None):
self._cv_capture = cv2.VideoCapture(0)
self._source = self.find_usb_cam()
if self._source == None:
raise Exception("No USB camera detected")
self._cv_capture = cv2.VideoCapture(self._source)
self._res = start_res
self.focal_lengths = (LOGITECH_C270_FOCAL_LENGTHS
if focal_lengths is None
else focal_lengths)
self._update_camera_params(self.focal_lengths)

def find_usb_cam(self):
indicator_string = "bm2835" # if this string is present in the output then it is a pi cam
options = ["/dev/video0", "/dev/video1"] # Only two options so this is hardcoded
for option in options:
try:
output = sp.check_output(["v4l2-ctl", "-d", option, "-D"]).decode()
except sp.CalledProcessError:
continue

if indicator_string not in output:
return option
return None

@property
def res(self):
return self._res
Expand Down