Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package src.main.java.org.roomwatcher.watcher; import java.awt.Button; import java.awt.Component; import java.awt.GridLayout; import java.awt.Label; import java.awt.TextField; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; import org.opencv.core.Mat; import org.opencv.highgui.VideoCapture; import src.main.java.org.roomwatcher.http.HTTPTransport; /** * * @author Waldema */ public class Window { private static JFrame frame = new JFrame("RoomWatcher: Watching"); private static Label peopleNumberLabel = new Label(); public static void main(String arg[]) throws InterruptedException { // Load the native library. System.loadLibrary("opencv_java2410"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setLocationRelativeTo(null); Processor processor = new Processor(); Watcher watcher = new Watcher(); watcher.add(peopleNumberLabel); frame.setContentPane(watcher); frame.setVisible(true); //-- 2. Read the video stream Mat webcam_image = new Mat(); VideoCapture capture = new VideoCapture(0); if (capture.isOpened()) { while (true) { capture.read(webcam_image); if (!webcam_image.empty()) { frame.setSize(webcam_image.width() + 40, webcam_image.height() + 160); //-- 3. Apply the classifier to the captured image webcam_image = processor.detect(webcam_image); //-- 4. Display the image watcher.MatToBufferedImage(webcam_image); // We could look at the error... watcher.repaint(); } } } } public static JFrame getFrame() { return frame; } public static void setFrame(JFrame frame) { Window.frame = frame; } public static String getPeopleNumberLabelValue() { return peopleNumberLabel.toString(); } public static void setPeopleNumberLabelValue(String peopleNumberLabel) { Window.peopleNumberLabel.setText(peopleNumberLabel); } }