Permalink
Browse files

added parameter video device index for selecting a specific camera

  • Loading branch information...
1 parent 4d205b9 commit b15313b7fa2fbf47fc2e023a38a5681179c78031 @Dfred Dfred committed Jan 24, 2011
Showing with 8 additions and 4 deletions.
  1. +4 −3 HRI/vision/__init__.py
  2. +4 −1 control/main.py
View
@@ -21,15 +21,15 @@ class CaptureVideo(threading.Thread):
""" captures video stream from camera and performs various detections (face, edge, circle)
"""
- def __init__(self, comm = None):
+ def __init__(self, videoDevice_index, comm = None):
""" initiate variables"""
threading.Thread.__init__(self)
self.comm = comm
self.current_colour = None
self.face_detector = CascadeDetector(cascade_name=config.haar_casc,min_size=(50,50), image_scale=0.5)
- self.webcam = Webcam()
+ self.webcam = Webcam(videoDevice_index)
if config.use_gui: # create windows
cv.NamedWindow('Camera', cv.CV_WINDOW_AUTOSIZE)
@@ -436,6 +436,7 @@ def main_loop(self):
if __name__ == "__main__":
config.haar_casc = "haarcascade_frontalface_alt.xml" # change path for compatibility
- cap = CaptureVideo()
+ import sys
+ cap = CaptureVideo(len(sys.argv) > 1 and sys.argv[1] or 0)
cap.start()
View
@@ -35,6 +35,8 @@ def main():
parser.add_option("-c", "--control", dest="control",
default="keyboard", type="string",
help="specifies type of control. Options are: " + str(config.control_options) )
+ parser.add_option("-v", "--video-device", type="int", dest="videoDev_index",
+ default=0, help="set index of video device to use.")
parser.add_option("-g", "--gui",
action="store_true", dest="gui", default=True,
help="specifies if a GUI is used")
@@ -47,6 +49,7 @@ def main():
"Options are: " + str(config.control_options)
exit(1)
config.use_gui = options.gui
+ config.videoDev_idx = options.videoDev_index
# create appropriate connections
comm_express, comm_features = connect()
@@ -76,7 +79,7 @@ class RobotControl(threading.Thread):
def __init__(self, expression_comm):
threading.Thread.__init__(self)
self.comm = expression_comm
- self.camera = vision.CaptureVideo(self.comm)
+ self.camera = vision.CaptureVideo(config.videoDev_idx, self.comm)
self.camera.start()
self.camera_ball = None
self.learning_agent = agent.Agent("agent", "learner")

0 comments on commit b15313b

Please sign in to comment.