# Two Cameras in one Sketch

**URL:** https://discourse.processing.org/t/two-cameras-in-one-sketch/3663
**Category:** Electronics (Arduino, etc.)
**Created:** [September 19, 2018, 8:15am UTC](https://discourse.processing.org/t/two-cameras-in-one-sketch/3663 "2018-09-19T08:15:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jorgeeduardojonas](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@jorgeeduardojonas](https://discourse.processing.org/u/jorgeeduardojonas)
#### Post date: [September 19, 2018, 8:15am UTC](https://discourse.processing.org/t/two-cameras-in-one-sketch/3663/1 "2018-09-19T08:15:00Z")

</div>

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:

> **[AGPtEK USB 3.0 HDMI HD Video Capture: Amazon.de: Computer & Zubehör](https://www.amazon.de/Capture-Videoaufnahmekarte-Rekorder-Live-Streaming-Windows/dp/B0749CW81T?psc=1&SubscriptionId=AKIAILSHYYTFIVPWUY6Q&tag=duc03-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B0749CW81T)**
>
> EUR 95,99

and the other is an Endoscope Camera.

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

```auto
  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.

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [September 19, 2018, 9:18am UTC](https://discourse.processing.org/t/two-cameras-in-one-sketch/3663/2 "2018-09-19T09:18:28Z")

</div>

> [@jorgeeduardojonas](#):
>
> `if (cam.available() == true) { cam.read(); cam2.read(); }`

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

Should be

```auto
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)` ! 😄

---

<div class="post-metadata">

### Author: ![jorgeeduardojonas](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@jorgeeduardojonas](https://discourse.processing.org/u/jorgeeduardojonas)
#### Post date: [September 19, 2018, 2:21pm UTC](https://discourse.processing.org/t/two-cameras-in-one-sketch/3663/3 "2018-09-19T14:21:59Z")

</div>

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

all the best!

Jorge.
