Two Cameras in one Sketch

Hello!
I’m trying to control a fade between two cameras in the same application, the following code works, however, the first camera has some jitter (the endoscope), am I missing something?
One camera is a Go Pro going through an AGPtEK USB 3.0 HDMI HD Video capture:

and the other is an Endoscope Camera.

Any help would be much appreciated!
here is the code:

  import processing.video.*;
  
  Capture cam;
  Capture cam2;
  int selMode = REPLACE;
  String name = "REPLACE";
  int picAlpha = 255;
  
  void setup() {
  blendMode(BLEND);
     fullScreen(P3D);
   // size(1920, 1080);
  
    String[] cameras = Capture.list();
  
    if (cameras == null) {
      println("Failed to retrieve the list of available cameras, will try the default...");
      cam = new Capture(this, 1920, 1080);
    } 
    if (cameras.length == 0) {
      println("There are no cameras available for capture.");
      exit();
    } else {
      println("Available cameras:");
      printArray(cameras);
  
      cam = new Capture(this, cameras[0]);
      cam.start();
      
      cam2 = new Capture(this, cameras[1]);
      cam2.start();
    }
  }
  
  void draw() {
    
    picAlpha = int(map(mouseX, 0, width, 0, 255));
    background(0);
    
    if (cam.available() == true) {
      cam.read();
      cam2.read();
    }
  
    tint(255, 255);
    image(cam, 0, 0, width, height);
    
    tint(255, picAlpha);
    image(cam2, 0, 0, width, height);
    
    // println(name);
 }
  
void mouseDragged() {
  if (height - 50 < mouseY) {
    picAlpha = int(map(mouseX, 0, width, 0, 255));
  }
}

All the best!

Jorge.

1 Like

You’re only reading from cam2 if cam has a new frame!

Should be

if (cam.available()) {
  cam.read();
}
if (cam2.available()) {
  cam2.read();
}

There’s never a need to use == true. if (true == true) is the same as if(true) ! :smile:

1 Like

oh!! overlooked that completely,
thank you very much Neil!

all the best!

Jorge.