Skip to content

Commit

Permalink
doublicated eye process, implemented selection of muliple webcams wit…
Browse files Browse the repository at this point in the history
…h same name
  • Loading branch information
mkassner committed Oct 9, 2013
1 parent 4e867b7 commit 1107210
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 50 deletions.
17 changes: 6 additions & 11 deletions pupil_src/capture/eye.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from pupil_detectors import Canny_Detector
import shelve

def eye(g_pool):
def eye(g_pool,cap_src, cap_size,cap_special_id = 0, side='mono'):
"""
this needs a docstring
this needs a docstring...
"""

# Callback functions World
Expand Down Expand Up @@ -72,8 +72,6 @@ def on_close(window):





# Helper functions called by the main atb bar
def start_roi():
bar.display.value = 1
Expand Down Expand Up @@ -101,7 +99,7 @@ def save(var_name,var):
session_settings[var_name] = var

# Initialize capture
cap = autoCreateCapture(g_pool.eye_src, g_pool.eye_size)
cap = autoCreateCapture(cap_src,cap_size,special_id = cap_special_id)
if cap is None:
print "EYE: Error could not create Capture"
return
Expand Down Expand Up @@ -224,7 +222,7 @@ def save(var_name,var):

# fine pupil ellipse detection
result = pupil_detector.detect(frame,u_roi=u_r,p_roi=p_r,visualize=bar.display.value == 2)

result['side']=side
g_pool.pupil_queue.put(result)
# Work with detected ellipses

Expand Down Expand Up @@ -285,17 +283,14 @@ def save(var_name,var):
save('bar.record_eye',bar.record_eye.value)
session_settings.close()

#flushing queue incase world process did not exit gracefully
while not g_pool.pupil_queue.empty():
g_pool.pupil_queue.get()

g_pool.pupil_queue.close()

cap.close()
atb.terminate()
glfwDestroyWindow(window)
glfwTerminate()

print "EYE Process closed"
print "%s EYE Process closed" %side

def eye_profiled(g_pool):
import cProfile,subprocess,os
Expand Down
35 changes: 20 additions & 15 deletions pupil_src/capture/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ def main():
os.mkdir(user_dir)
if not os.path.isdir(rec_dir):
os.mkdir(rec_dir)



# To assign by name: put string(s) in list
eye_src = ["Microsoft", "6000"]
eye_left_src = ["Microsoft", "6000"]
eye_right_src = ["Microsoft", "6000"]
world_src = ["Logitech Camera","B525", "C525","C615","C920","C930e"]

# to assign cameras directly, using integers as demonstrated below
Expand All @@ -70,7 +71,7 @@ def main():
# world_src = "/Users/mkassner/Pupil/pupil_google_code/wiki/videos/eye_simple_filter.avi"

# Camera video size in pixels (width,height)
eye_size = (640,360)
eye_size = (320,240)
world_size = (1280,720)

# Create and initialize IPC
Expand All @@ -79,28 +80,32 @@ def main():
g_pool.eye_rx, g_pool.eye_tx = Pipe(False)
g_pool.quit = RawValue(c_bool,0)
# make constants avaiable
g_pool.eye_src = eye_src
g_pool.eye_size = eye_size
g_pool.world_src = world_src
g_pool.world_size = world_size
g_pool.user_dir = user_dir
g_pool.rec_dir = rec_dir
g_pool.version = version
# set up subprocesses
p_eye = Process(target=eye, args=(g_pool,))
sleep(0.5)
p_eye_left = Process(target=eye, args=(g_pool,eye_right_src,eye_size,0,'left'))
p_eye_right = Process(target=eye, args=(g_pool,eye_left_src,eye_size,1,'right'))

# spawn subprocesse
p_eye.start()
p_eye_left.start()
# On Linux, we need to give the camera driver some time before requesting another camera.
sleep(0.5)
# on MacOS, when using some cameras (like our current logitech worldcamera)
# you can't run the world camera grabber in its own process
# it must reside in the main process when you run on MacOS.
world(g_pool)
p_eye_right.start()
sleep(0.5)
world(g_pool,world_src,world_size)

# Exit / clean-up
p_eye.join()
p_eye_left.join()
p_eye_right.join()


# flushing queue incase world process did not exit gracefully
while not g_pool.pupil_queue.empty():
g_pool.pupil_queue.get()
g_pool.pupil_queue.close()
print "Pupil Queue empty, Exit"


if __name__ == '__main__':
main()
18 changes: 2 additions & 16 deletions pupil_src/capture/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from pupil_server import Pupil_Server


def world(g_pool):
def world(g_pool,cap_src,cap_size):
"""world
"""

Expand Down Expand Up @@ -95,7 +95,7 @@ def save(var_name,var):


# Initialize capture, check if it works
cap = autoCreateCapture(g_pool.world_src, g_pool.world_size,24)
cap = autoCreateCapture(cap_src, cap_size,24)
if cap is None:
print "WORLD: Error could not create Capture"
return
Expand Down Expand Up @@ -159,20 +159,6 @@ def toggle_show_calib_result():
new_plugin = Show_Calibration(g_pool,frame.img.shape)
g.plugins.append(new_plugin)

def show_calib_result():
# first kill old if any
for p in g.plugins:
if isinstance(p,Show_Calibration):
p.alive = False
g.plugins = [p for p in g.plugins if p.alive]
# then make new
calib = Show_Calibration(g_pool,frame.img.shape)
g.plugins.append(calib)

def hide_calib_result():
for p in g.plugins:
if isinstance(p,Show_Calibration):
p.alive = False

def toggle_server():
for p in g.plugins:
Expand Down
18 changes: 10 additions & 8 deletions pupil_src/shared_modules/uvc_capture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def close(self):
pass


def autoCreateCapture(src,size=(640,480),fps=30):
def autoCreateCapture(src,size=(640,480),fps=30,special_id = 0):
# checking src and handling all cases:
src_type = type(src)

Expand All @@ -109,12 +109,17 @@ def autoCreateCapture(src,size=(640,480),fps=30):
matching_devices.append(device)

if len(matching_devices) >1:
print "Warning: found",len(matching_devices),"devices that match the src string pattern. Using the first one."
if len(matching_devices) ==0:
print "Found",len(matching_devices),"devices that match any of %s. Using the %s one." %(src,('first','second','third')[special_id])
elif len(matching_devices) ==0:
print "ERROR: No device found that matched",src,
return
else:
#found just one
if special_id:
print "ERROR: Did not find %i devices that match %s" %(special_id+1,src)
return

cap = Camera_Capture(matching_devices[0],size,fps)
cap = Camera_Capture(matching_devices[special_id],size,fps)
print "camera selected: %s with id: %s" %(cap.name,cap.src_id)
return cap

Expand Down Expand Up @@ -143,7 +148,4 @@ def autoCreateCapture(src,size=(640,480),fps=30):


if __name__ == '__main__':
cap = autoCreateCapture(1,(1280,720),30)
if cap:
print cap.controls
print "done"
pass

0 comments on commit 1107210

Please sign in to comment.