package version7_3_simu.sensorySystem;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;


public class Webcam{
	 
	private int width = 640, height = 480;
	public BufferedImage bf;
	
	public boolean connected=false;

	public int[][][] image;
 
 
	public Webcam() {
 
		try{
			bf=ImageIO.read(new File(System.getProperty("user.home")+"/Ernest_simulator/simulation_image.jpg"));
		}catch (Exception ex) {System.out.println(ex);}
		
		width = bf.getWidth();
		height = bf.getHeight();
		
		image=new int[width][height][3];
		for (int i=0;i<width;i++){
			for (int j=0;j<height;j++){
				image[i][j][0]=0;
				image[i][j][1]=0;
				image[i][j][2]=0;
			}
		}
	}
 
	// capture an image from the camera
	public void setImage(){
		
		try{
		
			bf=ImageIO.read(new File(System.getProperty("user.home")+"/Ernest_simulator/simulation_image.jpg"));
			
			width = bf.getWidth();
			height = bf.getHeight();
			
			for (int i=1;i<width-1;i++){
				for (int j=1;j<height-1;j++){
					
					int i2=(int)((float)i/2.4);
					int j2=(int)((float)j/2.2)+320;
					
					image[i][j][0]=((bf.getRGB(i2,j2) & 0x00ff0000)>>16);
					image[i][j][1]=((bf.getRGB(i2,j2) & 0x0000ff00)>> 8);
					image[i][j][2]=((bf.getRGB(i2,j2) & 0x000000ff));
				}
			}
		}catch (Exception ex) {System.out.println(ex);}
		
	}

}
