/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Cam1.java
*
* Created on 18 Jan, 2011, 12:26:13 PM
*/
package webcam;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import javax.media.control.FrameGrabbingControl;
import javax.media.*;
import javax.media.protocol.*;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.util.Date;
import webcam.ImageCompare;
import javax.media.control.FormatControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
/**
*
* @author MOHIT
*/
public class Cam2 extends javax.swing.JInternalFrame {
private FrameGrabbingControl frameGrabber;
/** Creates new form Cam1 */
public Cam2() {
initComponents();
getCam();
}
public void getCam() {
try {
/* Grab the default web cam*/
MediaLocator ml = new MediaLocator("vfw://0");
/* Create my data source */
DataSource ds = Manager.createDataSource(ml);
requestFormatResolution(ds);
/* Create & start my player */
Player p = Manager.createRealizedPlayer(ds);
p.start();
Thread.currentThread().sleep(1000);
/* code for creating a JFrame and adding the visual component to it */
if (p.getVisualComponent() != null) {
Component comp = p.getVisualComponent();
comp.setSize(panel1.getWidth(), panel1.getHeight());
this.panel1.add(comp);
}
if (p.getControlPanelComponent() != null) {
this.panel1.add(p.getControlPanelComponent(), BorderLayout.SOUTH);
}
this.pack();
this.setVisible(true);
frameGrabber = (FrameGrabbingControl) p.getControl(FrameGrabbingControl.class.getName());
int i = 1,j=1;
ImageCompare ic = new ImageCompare();
Thread.sleep(5000);
/*while (true) {
grab(i);
if (i >= 2) {
String f1 = "E:\\" + (i - 1) + ".jpg";
String f2 = "E:\\" + i + ".jpg";
ic.ImageCompare_stage_1(f1, f2);
ic.setParameters(10, 10, 10, 10);
if (!ic.match()) {
count++;
if (count >= 2) {
ic.saveJP(ic.getChangeIndicator(), "e:\\changes"+i+".jpg");
//File file = new File("C:\\DeadRing.wav");
//SimpleAudioPlayer sap = new SimpleAudioPlayer(file)
}
}
}
i = i + 1;
}*/
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean requestFormatResolution(DataSource ds) {
if (ds instanceof CaptureDevice) {
FormatControl[] fcs = ((CaptureDevice) ds).getFormatControls();
for (FormatControl fc : fcs) {
Format[] formats = ((FormatControl) fc).getSupportedFormats();
for (Format format : formats) {
if ((format instanceof VideoFormat)
&& (((VideoFormat) format).getSize().getHeight() <= 480)
&& (((VideoFormat) format).getSize().getWidth() <= 640)) {
((FormatControl) fc).setFormat(format);
return true;
}
}
}
}
return false;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
panel1 = new javax.swing.JPanel();
setClosable(true);
setIconifiable(true);
javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
panel1.setLayout(panel1Layout);
panel1Layout.setHorizontalGroup(
panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 440, Short.MAX_VALUE)
);
panel1Layout.setVerticalGroup(
panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 376, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(panel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(panel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel panel1;
// End of variables declaration//GEN-END:variables
}