Connect USB webcam to Processing Android with Ketai

please format code with </> button * homework policy * asking questions

Hi everyone,
Can someone send me the code needed to connect a webcam to an android device? I am using Processing Android Mode obviously and I’ve tried using Ketai Camera and setting cam.setCameraID(); to 2 and -1 but neither works. How can I access a usb webcam connected (via usb) to my android device. I’ll paste my code below.

import ketai.camera.*;

KetaiCamera cam;

import processing.sound.*;
SqrOsc soundRed;
Pulse soundGreen;
SinOsc soundBlue;
int gameState = 0;
int count = 0;
float rAmp = 0;
float gAmp = 0;
float bAmp = 0;
boolean sounds = false;
float tempRed = 0;
float tempGreen = 0;
float tempBlue = 0;
float mapRed = 0;
float mapGreen = 0;
float mapBlue = 0;
float soundSpace = 0;

int countThruCameras;
void setup() {

textSize(20);
fullScreen();
orientation(PORTRAIT);

soundRed = new SqrOsc(this);
soundRed.amp(0.05);
soundGreen = new Pulse(this);
soundGreen.amp(0.05);
soundBlue = new SinOsc(this);
soundBlue.amp(0.2);

cam = new KetaiCamera(this, 1000, 1500, 60);
cam.setCameraID(2);
textAlign(CENTER, CENTER);
}

void draw() {

if(gameState == 0){
count++;
if(count >= 200){
gameState = 1;
cam.start();
}
background(255);

}

if (gameState==1) {

print(cam.getCameraID());
soundRed.amp(rAmp);
soundGreen.amp(gAmp);
soundBlue.amp(bAmp);


background(0);

translate(width/2, height/2);
pushMatrix();
rotate(HALF_PI);
image(cam, 0,0);
popMatrix();
tempRed = red(get(width/2, height/2));
tempGreen = green(get(width/2, height/2)); 
tempBlue = blue(get(width/2, height/2));
mapRed = map(tempRed, 0, 255, 1, 200);
mapGreen = map(tempGreen, 0, 255, 0, 450);
mapBlue = map(tempBlue, 0, 255, 1, 500);
rAmp = map(mapRed, 0, 200, 0, .05);
gAmp = map(mapGreen, 0, 450, 0, .05);
bAmp = map(mapBlue, 0, 200, 0, .07);
soundRed.freq(mapRed);
soundGreen.freq(mapGreen);
soundBlue.freq(mapBlue);
stroke(255);
strokeWeight(2);
noFill();
ellipse(0, 0, 40, 40);
if (sounds) {
  soundRed.play();
  soundGreen.play();
  soundBlue.play();
} else {
  soundRed.stop();
  soundGreen.stop();
  soundBlue.stop();
  fill(0, 0, 0, 180);
  stroke(0);
  //rect((-width/2)-5, 170, width+5, 60);
  fill(0, 200, 255);
  text("Click screen to hear color", 0, (height/3)+(height/13));
  stroke(255);
}

}
}

void onCameraPreviewEvent()
{
cam.read();
}

void mousePressed() {

if(gameState==1){
sounds = !sounds;

}
}

Hi @flotowcameron
Are you using a webcam with an OTG cable?

I’m using a webcam. To be specific, I have this one: https://www.target.com/p/logitech-c270-3-0mp-webcam-black-960-000694/-/A-13252212#lnk=sametab

Should be possible with an OTG cable in series. Here is an android driver code. I can not test this because I don’t have a usb webcam.

I’m newish to Processing Android. How would I use this android driver code in my program? I’ve never done that before.