Fiz uma tela pra capturar imagens, um painel com botões, segui a documentação. Só que não abre webcam, e pior que não da erro.
identar texto pré-formatado por 4 espaços
public class Reconhecimento extends javax.swing.JInternalFrame {
public Reconhecimento() {
initComponents();
}
private DaemonThread trend = null;
int count = 0;
VideoCapture webSource = null;
Mat frame = new Mat();
MatOfByte mem = new MatOfByte();
class DaemonThread implements Runnable {
protected volatile boolean runnable = false;
@Override
public void run() {
synchronized (this) {
while (runnable) {
if (webSource.grab()) {
try {
webSource.retrieve(frame);
Imgcodecs.imencode(".bmp", frame, mem);
Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
BufferedImage buff = (BufferedImage) im;
Graphics g = jPanel1.getGraphics();
if (g.drawImage(buff, 0, 0, getWidth(), getHeight() - 150, 0, 0, buff.getWidth(), buff.getHeight(), null)) {
if (runnable == false) {
System.out.println("Going to wait()");
this.wait();
}
}
} catch (Exception ex) {
System.out.println("Error");
}
}
}
}
}
}
ONDE CHAMO NO BOTÃO INICIAR
webSource = new VideoCapture();
trend = new DaemonThread();
Thread t = new Thread(trend);
t.setDaemon(true);
trend.runnable = true;
t.start();
inicio.setEnabled(false); //start button
pause.setEnabled(true);