Wednesday 12 September 2012

Using two web cams with Open CV


From the archive Discourse for the Processing (ALPHA) software: "I am trying to use two web cams. In theory, OpenCV allows us to address different cameras. I have two cameras in two USB ports, and Amcap can show either one. The OpenCV capture command can take three args, the last one being the camera index. However, the code below does not seem to work. I'm not sure what indexs to put in the third arg, and chose -1 only because I found this on a java thread about OpenCV." http://processing.org/discourse/beta/num_1237253804.html "It appears to me that the video library in processing currently only supports reading a stream from one camera. Am I correct or does anyone know of a way to read from multiple cameras within the processing environment? " http://www.processing.org/discourse/alpha/board_VideoCamera_action_display_num_1081365206.html from http://forum.processing.org/search/multiple%20cameras Multiple Cameras with JMyron and/or video library: http://forum.processing.org/topic/multiple-cameras-with-jmyron-and-or-video-library key-words: multiple cameras example: Re: 2 Webcams... Individual function 1 year ago I managed to take an image from both camera by mixing some of my own code with some I found from another user. import processing.video.*; Capture cam1; Capture cam2; int currX, currY; int capWidth, capHeight; boolean isCapturing; PFont font; void setup() { size(640,240); String[] devices = Capture.list(); println(devices); currX = 0; currY = 0; capWidth = 320; capHeight = 240; cam1 = new Capture(this, 320, 240, devices[0]); cam2 = new Capture(this, 320, 240, devices[1]); isCapturing = true; } void draw() { image(cam1, currX, currY); image(cam2, 320, currY); } void captureEvent(Capture c) { c.read(); } void keyPressed() { if (key == ' ') { isCapturing = !isCapturing; saveFrame("####.jpg"); } } This creates one image using a capture from both webcams when one button is pressed. Does anyone know how I could make it that each camera has an individual button, and when it is pressed it captures an image from just that webcam?

No comments: