/* * @(#) WebCamSample.java * * Tangible Object Placement Codes (TopCodes) * Copyright (c) 2007 Michael S. Horn * * Michael S. Horn (michael.horn@tufts.edu) * Tufts University Computer Science * 161 College Ave. * Medford, MA 02155 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License (version 2) as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ import webcam.*; import topcodes.*; import java.util.List; import java.awt.Font; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.BasicStroke; import java.awt.Dimension; import java.awt.RenderingHints; import java.awt.geom.Area; import java.awt.geom.GeneralPath; import java.awt.geom.RoundRectangle2D; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.awt.event.*; import javax.swing.*; /** * This is a sample application that integrates the webcam library * with the TopCode scanner. This code will only work on windows * machines--I tested with XP, but it should work fine with * Vista as well. * * To run this sample, you will need a webcamera with VGA (640x480) * resolution. A Logitech QuickCam is a good choice. Plug in your * camera, and then use this command to launch the demo: *
* $ java -cp lib/topcodes.jar WebCamSample ** * @author Michael Horn * @version $Revision: 1.1 $, $Date: 2008/02/04 15:00:59 $ */ public class WebCamSample extends JPanel implements ActionListener, WindowListener { /** The main app window */ protected JFrame frame; /** Camera Manager dialog */ protected WebCam webcam; /** TopCode scanner */ protected Scanner scanner; /** Animates display */ protected Timer animator; public WebCamSample() { super(true); this.frame = new JFrame("TopCodes Webcam Sample"); this.webcam = new WebCam(); this.scanner = new Scanner(); this.animator = new Timer(100, this); // 10 frames / second //-------------------------------------------------- // Set up the application frame //-------------------------------------------------- setOpaque(true); setPreferredSize(new Dimension(640, 480)); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.setContentPane(this); frame.addWindowListener(this); frame.pack(); frame.setVisible(true); //-------------------------------------------------- // Connect to the webcam (this might fail if the // camera isn't connected yet). //-------------------------------------------------- try { this.webcam.initialize(); //--------------------------------------------- // This can be set to other resolutions like // (320x240) or (1600x1200) depending on what // your camera supports //--------------------------------------------- this.webcam.openCamera(640, 480); } catch (Exception x) { x.printStackTrace(); } requestFocusInWindow(); animator.start(); } protected void paintComponent(Graphics graphics) { Graphics2D g = (Graphics2D)graphics; List