Ciao 访客, welcome back to old school! :p
import processing.video.*; import java.awt.Frame; ////////////////////////PFrame f;SecondApplet s;//////////////////////// Capture cam1; //camera 1 of present windowCapture cam2; //camera 2 of present windowCapture Scam1; //camera 1 of 2nd windowCapture Scam2; //camera 2 of 2nd window void setup(){ size(600,600); PFrame f = new PFrame(); String[] cameras = Capture.list(); if (cameras == null) { println("Failed to retrieve the list of available cameras, will try the default..."); cam1 = new Capture(this, 720, 576); cam2 = new Capture(this, 720, 576); Scam1 = new Capture(this, 720, 576); Scam2 = new Capture(this, 720, 576); } 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[3]); cam2 = new Capture(this, cameras[3]); Scam1 = new Capture(this, cameras[3]); Scam2 = new Capture(this, cameras[3]); // Start capturing the images from the camera cam1.start(); cam2.start(); Scam1.start(); Scam2.start(); } } void draw(){ if ((cam1.available() == true)) { cam1.read(); cam2.read(); Scam1.read(); Scam2.read(); } image(cam1, 0,0,300,300 ); image(cam2, 150,150, 300,300 ); s.image(Scam1, 0,0,300,300 ); s.image(Scam2, 50,50, 300,300 ); } public class PFrame extends Frame { public PFrame() { setBounds(0, 0, 600, 600); s = new SecondApplet(); add(s); s.init(); show(); } } /////////////////////////Second Windows///////////////////////////////////////////////////////Second Windows////////////////////////////// public class SecondApplet extends PApplet { public void setup() { } public void draw() { } }
在SecondApplet 类内建立一个PImage 对象。每次把主窗口的cam 包含的像素数据更新给这个PImage 对象。https://processing.org/reference/copy_.html
public class SecondApplet extends PApplet { PImage img; public void setup() { } public void draw() { } }
class SecondApplet extends PApplet { int w, h; PImage camDup; SecondApplet(int w, int h) { this.w = w; this.h = h; camDup = createImage(w, h, RGB); } void setup() { size(w, h, P3D); } void draw() { image(camDup, 0, 0); } void update(Capture cam){ camDup.copy(cam, 0, 0, cam.width, cam.height, 0, 0, w, h); }}
程序代码class SecondApplet extends PApplet { int w, h; PImage camDup; SecondApplet(int w, int h) { this.w = w; this.h = h; camDup = createImage(w, h, RGB); } void setup() { size(w, h, P3D); } void draw() { image(camDup, 0, 0); } void update(Capture cam){ camDup.copy(cam, 0, 0, cam.width, cam.height, 0, 0, w, h); }}这样应该就明朗了,其实算是基本帮你写掉了。。。
类的构造函数。恩,大致了解你的基础了,建议你循序渐进,可以先看一下官网关于OOP 的教程。https://processing.org/tutorials/objects/