/*
 * 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 com.seniorproject.augmentedreality.utils;

import com.github.sarxos.webcam.Webcam;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;

/**
 *
 * @author RainWhileLoop
 */
public class TestWebcam {

    public static void main(String[] args) {
        Webcam webcam = Webcam.getDefault();
        webcam.open();
        System.out.println("\n\n\n-----------" + webcam.getDevice().getName());
        JFrame frame = new JFrame("TestWebcam");
        MyCanvas canvas = new MyCanvas();
        while (true) {
            BufferedImage bufferedImage = webcam.getImage();
            int width = bufferedImage.getWidth();
            int height = bufferedImage.getHeight();
            Image image = bufferedImage.getScaledInstance(width, height, Image.SCALE_DEFAULT);
            canvas.setImage(image);
            canvas.setSize(width, height);
            canvas.paint(bufferedImage.getGraphics());
            frame.add(canvas);

            frame.setSize(800, 600);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);

        }
    }
}

@@ -740,185 +740,294 @@
     
-while (true) %7B%0D%0A            BufferedImage bufferedImage = webcam.getImage();%0D%0A            int width = bufferedImage.getWidth();%0D%0A            int height = bufferedImage.getHeight
+canvas.setSize(640, 480);%0D%0A%0D%0A        frame.setSize(320, 240);%0D%0A        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);%0D%0A        frame.setVisible(true);%0D%0A        frame.add(canvas);%0D%0A        BufferedImage bufferedImage;%0D%0A        Image image;%0D%0A        bufferedImage = webcam.getImage
 ();%0D
@@ -1034,26 +1034,16 @@
 %0A       
-     Image
  image =
@@ -1075,29 +1075,24 @@
 nstance(
-width, height
+320, 240
 , Image.
@@ -1108,36 +1108,32 @@
 AULT);%0D%0A        
-    
 canvas.setImage(
@@ -1145,56 +1145,8 @@
 );%0D%0A
-            canvas.setSize(width, height);%0D%0A    
     
@@ -1205,34 +1205,64 @@
     
-    frame.add(canvas
+do %7B%0D%0A            bufferedImage = webcam.getImage(
 );%0D%0A
-%0D%0A
+  
     
@@ -1271,99 +1271,145 @@
     
-  frame.setSize(800, 600);%0D%0A            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
+image = bufferedImage.getScaledInstance(320, 240, Image.SCALE_DEFAULT);%0D%0A            canvas.setImage(image);%0D%0A            canvas.repaint(
 );%0D%0A
@@ -1416,37 +1416,41 @@
         
-    
+%7D while (
 frame.
+i
 s
-et
 Visible(
 true);%0D%0A
@@ -1445,26 +1445,21 @@
 ble(
-true
+)
 );%0D%0A
-%0D%0A
         
 %7D%0D%0A 
@@ -1454,17 +1454,31 @@
         
-%7D
+webcam.close();
 %0D%0A    %7D%0D

add test webcam