소스 검색

摄像头拍照

wutt 5 년 전
부모
커밋
e0500b4dc3

+ 0 - 18
KeyMonitorApp/bin/.gitignore

@@ -1,18 +0,0 @@
-/Code.class
-/CodeDao.class
-/JdbcCodeDao.class
-/KeyboardListener.class
-/MyApp$1.class
-/MyApp.class
-/PropertyUtil.class
-/Test.class
-/TestWebCam$1$1.class
-/TestWebCam$1.class
-/TestWebCam.class
-/WindowsKeybordListener$1.class
-/WindowsKeybordListener.class
-/jdbc.properties
-/Test$1$1.class
-/Test$1.class
-/Test$2$1.class
-/Test$2.class

BIN
KeyMonitorApp/bin/Test$1$1.class


BIN
KeyMonitorApp/bin/Test$1.class


BIN
KeyMonitorApp/bin/Test$2.class


BIN
KeyMonitorApp/bin/TestWebCam$1$1.class


BIN
KeyMonitorApp/bin/TestWebCam$1.class


BIN
KeyMonitorApp/bin/TestWebCam$TimerTask$1.class


BIN
KeyMonitorApp/bin/TestWebCam$TimerTask.class


BIN
KeyMonitorApp/bin/TestWebCam.class


BIN
KeyMonitorApp/bin/WebCamTestDemo$1$1.class


BIN
KeyMonitorApp/bin/WebCamTestDemo$1.class


BIN
KeyMonitorApp/bin/WebCamTestDemo.class


+ 71 - 57
KeyMonitorApp/src/TestWebCam.java

@@ -1,6 +1,10 @@
 import java.awt.BorderLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.util.TimerTask;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 import javax.swing.JButton;
 import javax.swing.JFrame;
@@ -14,66 +18,76 @@ import com.github.sarxos.webcam.WebcamUtils;
 import com.github.sarxos.webcam.util.ImageUtils;
 
 /**
- * 相机测试
+ * 相机测试 
  */
 public class TestWebCam {
- 
+
 	private static JFrame window;
- 
+
 	public static void main(String[] args) throws InterruptedException {
- 
-		Webcam webcam = Webcam.getDefault();
-		webcam.setViewSize(WebcamResolution.VGA.getSize());
-//		webcam.open();
- 
-		WebcamPanel panel = new WebcamPanel(webcam);
-		panel.setFPSDisplayed(true);
-		panel.setDisplayDebugInfo(true);
-		panel.setImageSizeDisplayed(true);
-		panel.setMirrored(true);
- 
-		JFrame window = new JFrame("Test webcam panel");
-		window.add(panel);
-		window.setResizable(true);
-		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		window.pack();
-		window.setVisible(true);
- 
- 
- 
-		final JButton button = new JButton("拍照");
-		window.add(panel, BorderLayout.CENTER);
-		window.add(button, BorderLayout.SOUTH);
-		window.setResizable(true);
-		window.pack();
-		window.setVisible(true);
-		button.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent e){
-				//定时模拟触发
-				button.doClick();
-				button.setEnabled(false);  //设置按钮不可点击
- 
- 
-				//实现拍照保存-------start
-				String fileName = "D://" + System.currentTimeMillis();       //保存路径即图片名称(不用加后缀)
-				WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG);
-				SwingUtilities.invokeLater(new Runnable() {
- 
-					@Override
-					public void run(){
-						JOptionPane.showMessageDialog(null, "拍照成功");
-						button.setEnabled(true);    //设置按钮可点击
- 
-						return;
-					}
-				});
-				//实现拍照保存-------end
- 
-			}
-		});
+		//创建定时线程池
+		ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor();
+		TimerTask timerTask = new TimerTask();
+//		while(true) {
+		//开启定时任务 0 延迟秒数,3000 间隔执行的秒数。
+		timer.scheduleAtFixedRate(timerTask, 0,3000, TimeUnit.MILLISECONDS);
+//		}
+//		final JButton button = new JButton("拍照");
+//		window.add(panel, BorderLayout.CENTER);
+//		window.add(button, BorderLayout.SOUTH);
+//		window.setResizable(true);
+//		window.pack();
+//		window.setVisible(true);
+//		button.addActionListener(new ActionListener() {
+//			public void actionPerformed(ActionEvent e){
+//				//定时模拟触发
+////				button.doClick();
+//				button.setEnabled(false);  //设置按钮不可点击
+// 
+// 
+//				//实现拍照保存-------start
+//				String fileName = "D://" + System.currentTimeMillis(); //保存路径即图片名称(不用加后缀)
+//				//实现拍照保存-------end
+// 
+//			}
+//		});
 	}
+	
+	private static class TimerTask implements Runnable {
+		static Webcam webcam = Webcam.getDefault();
+		static Integer count = 1;
+		static {
+			webcam.setViewSize(WebcamResolution.VGA.getSize());
+//			webcam.open();
+	 
+			WebcamPanel panel = new WebcamPanel(webcam);
+			panel.setFPSDisplayed(true);
+			panel.setDisplayDebugInfo(true);
+			panel.setImageSizeDisplayed(true);
+			panel.setMirrored(true);
+	 
+			JFrame window = new JFrame("摄像头");
+			window.add(panel);
+			window.setResizable(true);
+			window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+			window.pack();
+			window.setVisible(true);
+		}
+		
+		@Override
+        public void run() {
+			SwingUtilities.invokeLater(new Runnable() {
+				@Override
+				public void run(){
+					String fileName = "D://upload//" + System.currentTimeMillis();
+					WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_JPG);
+//					JOptionPane.showMessageDialog(null, "拍照成功");
+					System.out.println("第"+count+"次拍照成功");
+//					button.setEnabled(true);    //设置按钮可点击
+					count++;
+					return;
+				}
+			});
+        }
+    }
 }
- 
- 
- 
- 

+ 77 - 0
KeyMonitorApp/src/WebCamTestDemo.java

@@ -0,0 +1,77 @@
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
+import com.github.sarxos.webcam.Webcam;
+import com.github.sarxos.webcam.WebcamPanel;
+import com.github.sarxos.webcam.WebcamResolution;
+import com.github.sarxos.webcam.WebcamUtils;
+import com.github.sarxos.webcam.util.ImageUtils;
+
+/**
+ * 相机测试
+ * 需要导入bridj-0.7.0.jar,slf4j-api-1.6.6.jar,webcam-capture-0.3.11.jar
+ */
+public class WebCamTestDemo {
+ 
+	private static JFrame window;
+ 
+	public static void main(String[] args) throws InterruptedException {
+ 
+		Webcam webcam = Webcam.getDefault();
+		webcam.setViewSize(WebcamResolution.VGA.getSize());
+//		webcam.open();
+ 
+		WebcamPanel panel = new WebcamPanel(webcam);
+		panel.setFPSDisplayed(true);
+		panel.setDisplayDebugInfo(true);
+		panel.setImageSizeDisplayed(true);
+		panel.setMirrored(true);
+ 
+		JFrame window = new JFrame("Test webcam panel");
+		window.add(panel);
+		window.setResizable(true);
+		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		window.pack();
+		window.setVisible(true);
+ 
+ 
+ 
+		final JButton button = new JButton("拍照");
+		window.add(panel, BorderLayout.CENTER);
+		window.add(button, BorderLayout.SOUTH);
+		window.setResizable(true);
+		window.pack();
+		window.setVisible(true);
+		//添加按钮点击事件触发拍照
+		button.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e){
+				button.setEnabled(false);  //设置按钮不可点击
+				//实现拍照保存
+				String fileName = "D://" + System.currentTimeMillis();       //保存路径即图片名称(不用加后缀)
+				//执行拍照并设置图片后缀是png
+				WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG);
+				SwingUtilities.invokeLater(new Runnable() {
+ 
+					@Override
+					public void run(){
+						JOptionPane.showMessageDialog(null, "拍照成功");
+						button.setEnabled(true);    //设置按钮可点击
+						return;
+					}
+				});
+				//实现拍照保存-------end
+ 
+			}
+		});
+	}
+}
+ 
+ 
+ 
+ 

BIN
LEDTest/bin/com/fire/LightingTestingTask.class


+ 132 - 85
LEDTest/src/com/fire/LightingTestingTask.java

@@ -1,85 +1,132 @@
-package com.fire;
-
-import java.awt.Color;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
-
-import javax.imageio.ImageIO;
-
-public class LightingTestingTask {
-
-	public static void main(String[] args) {
-		String fileName = "D://tt.jpg";
-		LightingTestingTask t = new LightingTestingTask();
-		t.readImage(fileName);
-	}
-	
-	public void readImage(String path) {
-		try {
-//			driver.manage().window().maximize();
-			int[] rgb = new int[3];
-			BufferedImage img = ImageIO.read(new File(path));
-			int width = img.getWidth();
-			int height = img.getHeight();
-			int minx = img.getMinX();
-			int miny = img.getMinY();
-			
-			System.out.println("width=" + width + ",height=" + height + ".");
-			System.out.println("minx=" + minx + ",miniy=" + miny + ".");
-			for (int i = minx; i < width; i++) {
-				for (int j = miny; j < height; j++) {
-//					System.out.println(i+":"+j);
-					int w=20;
-					int h=20;
-//					if(height-j<=h && width-i>=w) {
-//						//高度超出图片范围,但是宽度未超出
-//						
-//					}else {
-//						BufferedImage rect = img.getSubimage(i, j, w, h);
-//					}
-					
-					
-					int pixel = img.getRGB(i, j); // 下面三行代码将一个数字转换为RGB数字
-//					Color c = new Color(pixel);
-//			        int r = c.getRed();
-//			        int g = c.getGreen();
-//			        int b = c.getBlue();
-//			        System.out.println(c + "\t红=" + r + "\t绿" + g + "\t蓝" + b);
-//					int r1 = (pixel >> 16) & 0xFF;
-//			        int g1 = (pixel >> 8) & 0xFF;
-//			        int b1 = (pixel >> 0) & 0xFF;
-//					System.out.println("红="+r1+"\t绿="+g1+"\t蓝="+b1);
-					rgb[0] = (pixel & 0xff0000) >> 16;
-					rgb[1] = (pixel & 0xff00) >> 8;
-					rgb[2] = (pixel & 0xff);
-//					if(i==539 && j==569) {
-//						System.out.println("红="+rgb[0]+"\t绿="+rgb[1]+"\t蓝="+rgb[2]);
-//					}
-					
-					if (rgb[0] != 255 || rgb[1] != 255 || rgb[2] != 255) {
-						
-						//红色判断
-						if (rgb[0]>=230 && rgb[1] <=150 && rgb[2] <= 178) {
-							System.out.println("红色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
-									+ rgb[1] + "," + rgb[2] + ")");
-						} else if (rgb[0] <= 50 && rgb[1] >= 200 && rgb[2] <= 50) {
-							System.out.println("绿色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
-									+ rgb[1] + "," + rgb[2] + ")");
-						} else if (rgb[0] <= 50 && rgb[1] <= 50 && rgb[2] >= 200) {
-							System.out.println("蓝色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
-									+ rgb[1] + "," + rgb[2] + ")");
-						}else if(rgb[0] >= 250 && rgb[1] <= 228 && rgb[2] <=200) {
-							System.out.println("黄色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
-									+ rgb[1] + "," + rgb[2] + ")");
-						}
-					}
-				}
-			}
-			System.out.println("跑完了...");
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
-}
+package com.fire;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+public class LightingTestingTask {
+
+	public static void main(String[] args) {
+		String fileName = "D://yellow.jpg";
+		LightingTestingTask t = new LightingTestingTask();
+		t.readImage(fileName);
+	}
+	
+	public void readImage(String path) {
+		try {
+//			driver.manage().window().maximize();
+			int[] rgb = new int[3];
+			BufferedImage img = ImageIO.read(new File(path));
+			int width = img.getWidth();
+			int height = img.getHeight();
+			int minx = img.getMinX();
+			int miny = img.getMinY();
+			
+			System.out.println("width=" + width + ",height=" + height + ".");
+			System.out.println("minx=" + minx + ",miniy=" + miny + ".");
+			int red = 0;
+			int yellow = 0;
+			int green = 0;
+			for (int i = minx; i < width; i++) {
+				for (int j = miny; j < height; j++) {
+//					System.out.println(i+":"+j);
+					int w=20;
+					int h=20;
+//					if(height-j<=h && width-i>=w) {
+//						//高度超出图片范围,但是宽度未超出
+//						
+//					}else {
+//						BufferedImage rect = img.getSubimage(i, j, w, h);
+//					}
+					
+					
+					int pixel = img.getRGB(i, j); // 下面三行代码将一个数字转换为RGB数字
+//					Color c = new Color(pixel);
+//			        int r = c.getRed();
+//			        int g = c.getGreen();
+//			        int b = c.getBlue();
+//			        System.out.println(c + "\t红=" + r + "\t绿" + g + "\t蓝" + b);
+//					int r1 = (pixel >> 16) & 0xFF;
+//			        int g1 = (pixel >> 8) & 0xFF;
+//			        int b1 = (pixel >> 0) & 0xFF;
+//					System.out.println("红="+r1+"\t绿="+g1+"\t蓝="+b1);红=254	绿=167	蓝=186
+					rgb[0] = (pixel & 0xff0000) >> 16;
+					rgb[1] = (pixel & 0xff00) >> 8;
+					rgb[2] = (pixel & 0xff);
+					//黄  红=255	绿=250	蓝=194   红=255	绿=246	蓝=191  
+					//红=250	 绿=248	蓝=191    红=247	绿=215	蓝=174   红=254	绿=216	蓝=179  
+					//绿 红=119	绿=255	蓝=191  红=152	绿=222	蓝=188  红=141	绿=223	蓝=177  红=117	绿=253	蓝=189 红=136	绿=211	蓝=168
+					
+//							绿色i=251,j=203:(117,116,114)
+//							绿色i=251,j=204:(116,115,113)
+//							绿色i=251,j=205:(115,114,112)
+//							绿色i=251,j=206:(115,114,112)
+//							绿色i=251,j=207:(115,114,112)
+//							绿色i=251,j=208:(116,115,113)
+//							绿色i=251,j=209:(115,114,112)
+//							绿色i=251,j=210:(115,114,112)
+//							绿色i=251,j=211:(115,114,112)
+//							绿色i=251,j=212:(115,114,112)
+//							绿色i=251,j=213:(116,115,113)
+//							绿色i=251,j=214:(117,116,114)
+//							绿色i=251,j=215:(119,118,116)
+					
+					if(i==543 && j==483) {
+						System.out.println("红="+rgb[0]+"\t绿="+rgb[1]+"\t蓝="+rgb[2]);
+					}
+					if (rgb[0] != 255 || rgb[1] != 255 || rgb[2] != 255) {
+						
+//						红色判断
+						if (rgb[0]>=244 && rgb[1] <=170 && rgb[2] <= 186) {
+							red++;
+//							System.out.println("红色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
+//									+ rgb[1] + "," + rgb[2] + ")");
+						} else if (rgb[0] <= 50 && rgb[1] >= 200 && rgb[2] <= 50) {
+//							System.out.println("蓝色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
+//									+ rgb[1] + "," + rgb[2] + ")");
+						} else if (rgb[0] >= 135 && rgb[1] >= 200 && rgb[2] >=165) {
+							green++;
+//							System.out.println("绿色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
+//									+ rgb[1] + "," + rgb[2] + ")");
+						}else if(rgb[0] >= 244 && rgb[1] >= 215 && rgb[2] >=190) {
+							yellow++;
+							System.out.println("黄色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
+									+ rgb[1] + "," + rgb[2] + ")");
+						}
+					}
+				}
+			}
+			System.out.println("red: "+red+"yellow: "+yellow+"green: "+green);
+			String maxColor = getMaxColor(red, yellow,green);
+			if("".equals(maxColor)) {
+				return ;
+			}else if("red".equals(maxColor)) {
+				//此时是红色
+				System.out.println(maxColor);
+			}else if("yellow".equals(maxColor)){
+				System.out.println(maxColor);
+			}else if("green".equals(maxColor)){
+				System.out.println(maxColor);
+			}
+			System.out.println("跑完了...");
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+	
+	private String getMaxColor(int red,int yellow,int green){
+		String color = "";
+		if(red>yellow && red>green) {
+			color = "red";
+		}else if(yellow>red && yellow>green) {
+			color = "yellow";
+		}else if(green>red && green>yellow) {
+			color = "green";
+		}
+        return color;
+    }
+}

+ 0 - 4
equipment-control-system/build/classes/.gitignore

@@ -1,5 +1 @@
-/applicationContext.xml
 /com/
-/context-dispatcher.xml
-/jdbc.properties
-/log4j.properties