Use external cam instead of integrated webcam in Processing 2.1.1

Hi guys , when i run the following code , it uses my integrated laptop webcam instead of the external webcam (Logitech QuickCam C9000 ) . How do i modify the code such that it uses the external webcam instead of my laptop's integrated one ?

import gab.opencv.*;
import processing.video.*;
import java.awt.*;

Capture video;
OpenCV opencv;

void setup() {
  size(640, 480);
  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();
}

void draw() {
  scale(2);
  opencv.loadImage(video);

  image(video, 0, 0 );

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i < faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
  }
}

void captureEvent(Capture c) {
  c.read();
}

My external webcam is under /dev/video1 and running lsusb gives me the following :

Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 011: ID 04b3:310c IBM Corp. Wheel Mouse
Bus 002 Device 004: ID 04f2:b18a Chicony Electronics Co., Ltd 
Bus 002 Device 015: ID 046d:0990 Logitech, Inc. QuickCam Pro 9000

Thanks in advance !

Answers

  • You should be able to use Capture.list() to get the cameras available to Processing, which you can then initialise with cam = new Capture(this, cameras[x]);, where x is the index of the camera you want. This example shows how to do it.

    Hope that helps.

  • After you did what velvetkevorkian said you could use cam = new Capture(this, String);.

    For me for example:

    cam = new Capture(this, "name=FaceTime HD Camera (Built-in),size=1280x720,fps=30");

    For me it's really slow to call Capture.list() every time. Then it takes around 12+ seconds to start the sketch, else it takes around 4.

    For some reason it takes a lot longer in processing 2.x to retrieve the list.

  • When you use this section you will come up your problem, I try it and I get result :). It is so late maybe some one see my code:). (Note: Processing 1.5.1)

    void setup(){ //some code block

    String[] devices = GSCapture.list() //I own this lib, so if you use Capture lib, shuffle with "no GS, only Capture" //println(devices) if you wanna get cam's id.

    video = new GSCapture(this, 640, 480, devices[1]); //That's my phone cam Id video.start();

    //some code block

    } // setup

    public void draw() {

    if (video.available() == true) { video.read(); image(video,640,0); } }

Sign In or Register to comment.