Trying to switch automatically between webcams
in
Core Library Questions
•
6 months ago
Im trying to write a processing script that will randomly cycle through a series of webcams, i can get the values to change of random but it doesn't seem to effect the camera changing. I'm a little stuck so any help is appreciated.
- import processing.video.*;
- Capture cam1;
- Capture cam2;
- void setup() {
- size(1000, 1000);
- String[] cameras = Capture.list();
- if (cameras.length == 0) {
- println("There are no cameras available for capture.");
- exit();
- } else {
- println("Available cameras:");
- for (int i = 0; i < cameras.length; i++) {
- println(cameras[i]);
- }
- // The camera can be initialized directly using an
- // element from the array returned by list():
- cam1 = new Capture(this, cameras[6]);
- println(cameras[3]);
- cam2 = new Capture(this, cameras[18]);
- println(cameras[18]);
- }
- }
- void draw() {
- if (cam1.available() == true) {
- cam1.read();
- }
- if (cam2.available() == true) {
- cam2.read();
- }
- image(cam1, 0, 0);
- image(cam2, 320, 0);
- image(cam1, 0, 200);
- image(cam2, 320, 200);
- // The following does the same, and is faster when just drawing the image
- // without any additional resizing, transformations, or tint.
- //set(0, 0, cam);
- int random = int(random(2));
- println(random);
- randomCamera(random);
- }
- void randomCamera(int rand){
- switch(rand) {
- case 0:
- cam1.start();
- cam2.stop();
- break;
- case 1:
- cam2.start();
- cam1.stop();
- break;
- default: // Default executes if the case labels
- println("None"); // don't match the switch parameter
- break;
- }
- }
1