Skip to content

Commit

Permalink
Merge pull request #983 from pointcontrols/master
Browse files Browse the repository at this point in the history
Add windows support for Pupil Cam2
  • Loading branch information
mkassner authored Dec 12, 2017
2 parents 0c5ccd8 + e837130 commit 8126d89
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
18 changes: 13 additions & 5 deletions pupil_src/launchables/eye.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ def on_drop(window, count, paths):
g_pool.capture_manager = manager_class_by_name[manager_class_name](g_pool,**manager_settings)

if eye_id == 0:
cap_src = ["Pupil Cam1 ID0", "HD-6000", "HD USB Camera", "USB 2.0 Camera"]
cap_src = ["Pupil Cam2 ID0", "Pupil Cam1 ID0", "HD-6000"]
else:
cap_src = ["Pupil Cam1 ID1", "HD-6000"]
cap_src = ["Pupil Cam2 ID1", "Pupil Cam1 ID1"]

# Initialize capture
default_settings = ('UVC_Source', {
'preferred_names': cap_src,
'frame_size': (640, 480),
'frame_size': (320, 240),
'frame_rate': 90
})

Expand Down Expand Up @@ -309,8 +309,14 @@ def toggle_general_settings(collapsed):
# Initialize glfw
glfw.glfwInit()
title = "Pupil Capture - eye {}".format(eye_id)

width, height = g_pool.capture.frame_size
width *= 2
height *= 2
width += icon_bar_width

width, height = session_settings.get(
'window_size', g_pool.capture.frame_size)
'window_size', (width, height))
main_window = glfw.glfwCreateWindow(width, height, title, None, None)
window_pos = session_settings.get(
'window_position', window_position_default)
Expand Down Expand Up @@ -344,7 +350,9 @@ def set_scale(new_scale):

def set_window_size():
f_width, f_height = g_pool.capture.frame_size
f_width += int(icon_bar_width*g_pool.gui.scale)
f_width *= 2
f_height *= 2
f_width += int(icon_bar_width * g_pool.gui.scale)
glfw.glfwSetWindowSize(main_window, f_width, f_height)
general_settings.append(ui.Button('Reset window size', set_window_size))
general_settings.append(ui.Switch('flip',g_pool,label='Flip image display'))
Expand Down
41 changes: 37 additions & 4 deletions pupil_src/shared_modules/video_capture/uvc_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def verify_drivers(self):
import os
import subprocess

DEV_HW_IDS = [(0x05A3, 0x9230, "Pupil Cam1 ID0"), (0x05A3, 0x9231, "Pupil Cam1 ID1"), (0x05A3, 0x9232, "Pupil Cam1 ID2"), (0x046D, 0x0843, "Logitech Webcam C930e"), (0x17EF,0x480F, "Lenovo Integrated Camera")]
DEV_HW_IDS = [(0x05A3, 0x9230, "Pupil Cam1 ID0"), (0x05A3, 0x9231, "Pupil Cam1 ID1"), (0x05A3, 0x9232, "Pupil Cam1 ID2"), (0x046D, 0x0843, "Logitech Webcam C930e"), (0x17EF,0x480F, "Lenovo Integrated Camera"), (0x0C45, 0x64AB, "Pupil Cam2 ID0")]
ids_present = 0;
ids_to_install = [];
for id in DEV_HW_IDS:
Expand Down Expand Up @@ -131,6 +131,9 @@ def configure_capture(self, frame_size, frame_rate, uvc_controls):
# UVC setting quirks:
controls_dict = dict([(c.display_name, c) for c in self.uvc_capture.controls])

if ("Pupil Cam2" in self.uvc_capture.name) and frame_size == (320, 240):
frame_size = (192, 192)

self.frame_size = frame_size
self.frame_rate = frame_rate
for c in self.uvc_capture.controls:
Expand All @@ -144,8 +147,7 @@ def configure_capture(self, frame_size, frame_rate, uvc_controls):
except KeyError:
pass

if ("Pupil Cam1" in self.uvc_capture.name or
"USB2.0 Camera" in self.uvc_capture.name):
if ("Pupil Cam1" in self.uvc_capture.name):

if ("ID0" in self.uvc_capture.name or "ID1" in self.uvc_capture.name):

Expand Down Expand Up @@ -173,6 +175,18 @@ def configure_capture(self, frame_size, frame_rate, uvc_controls):
self.uvc_capture.bandwidth_factor = 2.0
try: controls_dict['Auto Exposure Priority'].value = 1
except KeyError: pass

elif ("Pupil Cam2" in self.uvc_capture.name):

try: controls_dict['Auto Exposure Mode'].value = 1
except KeyError: pass

try:controls_dict['Saturation'].value = 0
except KeyError: pass

try: controls_dict['Gamma'].value = 200
except KeyError: pass

else:
self.uvc_capture.bandwidth_factor = 2.0
try: controls_dict['Auto Focus'].value = 0
Expand Down Expand Up @@ -232,7 +246,7 @@ def recent_events(self, events):
time.sleep(0.02)
self._restart_logic()
else:
if self.ts_offset: #c930 timestamps need to be set here. The camera does not provide valid pts from device
if self.ts_offset: # c930 timestamps need to be set here. The camera does not provide valid pts from device
frame.timestamp = uvc.get_time_monotonic() + self.ts_offset
frame.timestamp -= self.g_pool.timebase.value
self._recent_frame = frame
Expand Down Expand Up @@ -284,6 +298,7 @@ def frame_size(self, new_size):

self._intrinsics = load_intrinsics(self.g_pool.user_dir, self.name, self.frame_size)


@property
def frame_rate(self):
if self.uvc_capture:
Expand All @@ -303,6 +318,14 @@ def frame_rate(self, new_rate):
self.uvc_capture.frame_rate = rate
self.frame_rate_backup = rate

if ("Pupil Cam2" in self.uvc_capture.name):

controls_dict = dict([(c.display_name, c) for c in self.uvc_capture.controls])

special_settings = {200: 28, 180: 31}
try: controls_dict['Absolute Exposure Time'].value = special_settings.get(new_rate, 32)
except KeyError: pass

@property
def jpeg_support(self):
return True
Expand Down Expand Up @@ -362,9 +385,19 @@ def frame_rate_getter():
return (self.uvc_capture.frame_rates, [str(fr) for fr in self.uvc_capture.frame_rates])
sensor_control.append(ui.Selector('frame_rate', self, selection_getter=frame_rate_getter, label='Frame rate'))

if ("Pupil Cam" in self.uvc_capture.name):
blacklist = ['Auto Focus', 'Absolute Focus', 'Absolute Iris ',
'Scanning Mode ', 'Zoom absolute control', 'Pan control',
'Tilt control', 'Roll absolute control',
'Privacy Shutter control']
else:
blacklist = []

for control in self.uvc_capture.controls:
c = None
ctl_name = control.display_name
if ctl_name in blacklist:
continue

# now we add controls
if control.d_type == bool:
Expand Down

0 comments on commit 8126d89

Please sign in to comment.