Compare commits
	
		
			No commits in common. "0b7ebfeec0444ec2090477280504f068cb492be4" and "ef7dc000abec67f128d2baefd29d7d66c7781ef2" have entirely different histories.
		
	
	
		
			0b7ebfeec0
			...
			ef7dc000ab
		
	
		|  | @ -4,12 +4,10 @@ import lombok.extern.slf4j.Slf4j; | |||
| import org.aohe.result.R; | ||||
| import org.aohe.webcam.WebCamUtils; | ||||
| import org.java_websocket.WebSocket; | ||||
| import org.java_websocket.framing.Framedata; | ||||
| import org.java_websocket.handshake.ClientHandshake; | ||||
| 
 | ||||
| import java.net.InetSocketAddress; | ||||
| import java.net.UnknownHostException; | ||||
| import java.nio.ByteBuffer; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| 
 | ||||
|  | @ -88,27 +86,5 @@ public class CamSocketServer extends SocketServer { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void broadcastNew(ByteBuffer bytes) { | ||||
|         if (bytes == null){ | ||||
|             return; | ||||
|         } | ||||
|         WebSocket zero = map.get("zero"); | ||||
|         if(zero != null && zero.isOpen()){ | ||||
|             zero.send(bytes); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void broadcastNew(Framedata data) { | ||||
|         if (data == null){ | ||||
|             return; | ||||
|         } | ||||
|         WebSocket zero = map.get("zero"); | ||||
|         if(zero != null && zero.isOpen()){ | ||||
|             zero.sendFrame(data); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -3,13 +3,11 @@ package org.aohe.web; | |||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.aohe.result.R; | ||||
| import org.java_websocket.WebSocket; | ||||
| import org.java_websocket.framing.Framedata; | ||||
| import org.java_websocket.handshake.ClientHandshake; | ||||
| import org.java_websocket.server.WebSocketServer; | ||||
| 
 | ||||
| import java.net.InetSocketAddress; | ||||
| import java.net.UnknownHostException; | ||||
| import java.nio.ByteBuffer; | ||||
| 
 | ||||
| import static org.aohe.control.Operational.selectOperational; | ||||
| 
 | ||||
|  | @ -72,11 +70,4 @@ public class SocketServer extends WebSocketServer { | |||
|     public void broadcastNew(byte[] bytes) { | ||||
|     } | ||||
| 
 | ||||
|     public void broadcastNew(ByteBuffer bytes) { | ||||
|     } | ||||
| 
 | ||||
|     public void broadcastNew(Framedata data) { | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -10,7 +10,6 @@ import javax.imageio.ImageIO; | |||
| import java.awt.*; | ||||
| import java.awt.image.BufferedImage; | ||||
| import java.io.*; | ||||
| import java.nio.ByteBuffer; | ||||
| import java.util.*; | ||||
| import java.util.List; | ||||
| import java.util.stream.Collectors; | ||||
|  | @ -90,19 +89,6 @@ public class WebCamUtils { | |||
|         return webcam.getImage(); | ||||
|     } | ||||
| 
 | ||||
|     public static byte[] getImageByteBuffer(){ | ||||
|         if (!webcam.isOpen()){ | ||||
|             webcam.open(); | ||||
|         } | ||||
|         ByteBuffer imageBytes = webcam.getImageBytes(); | ||||
|         imageBytes.flip(); | ||||
|         System.out.println("imageBytes.remaining():"+imageBytes.remaining()); | ||||
|         byte[] byteArray = new byte[imageBytes.remaining()]; | ||||
|         imageBytes.get(byteArray); | ||||
|         System.out.println("byteArray.length:"+byteArray.length); | ||||
|         return byteArray; | ||||
|     } | ||||
| 
 | ||||
|     public static InputStream getImageInputStream() { | ||||
|         BufferedImage bi = getImage(); | ||||
|         ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||||
|  |  | |||
|  | @ -1,95 +0,0 @@ | |||
| package org.aohe.webcam; | ||||
| 
 | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.aohe.constant.Control; | ||||
| import org.aohe.constant.SocketEnum; | ||||
| import org.aohe.web.SocketUtils; | ||||
| import org.java_websocket.framing.BinaryFrame; | ||||
| 
 | ||||
| import javax.imageio.ImageIO; | ||||
| import java.awt.image.BufferedImage; | ||||
| import java.io.ByteArrayOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.nio.ByteBuffer; | ||||
| import java.util.concurrent.Executors; | ||||
| import java.util.concurrent.ScheduledExecutorService; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| @Slf4j | ||||
| public class WebcamShowTask2 extends Thread { | ||||
| 
 | ||||
|     private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); | ||||
| 
 | ||||
|     @Override | ||||
|     public void run() { | ||||
|         scheduler.scheduleAtFixedRate(() -> { | ||||
|             try { | ||||
|                 while (Control.SHOW_CAMERA) { | ||||
|                     WebCamUtils.open(); | ||||
|                     ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||||
|                     BufferedImage bi = WebCamUtils.getImage(); | ||||
|                     try { | ||||
|                         ImageIO.write(bi, "JPG", baos); | ||||
|                     } catch (IOException e) { | ||||
|                         //log.error(e.getMessage(), e); | ||||
|                     }finally { | ||||
|                         if (bi != null){ | ||||
|                             bi.flush(); | ||||
|                             bi = null; | ||||
|                         } | ||||
|                     } | ||||
| //                    String base64 = null; | ||||
| //                    try { | ||||
| //                        base64 = new String(Base64.getEncoder().encode(baos.toByteArray()), "UTF8"); | ||||
| //                    } catch (UnsupportedEncodingException e) { | ||||
| //                        log.error(e.getMessage(), e); | ||||
| //                    }finally { | ||||
| //                        baos.close(); | ||||
| //                    } | ||||
| 
 | ||||
|                     SocketUtils.get(SocketEnum.CAM_SOCKET.getName()).broadcastNew(WebCamUtils.getImageByteBuffer()); | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
|                 log.error(e.getMessage(), e); | ||||
|             } | ||||
|         }, 0, 100, TimeUnit.MILLISECONDS); | ||||
| 
 | ||||
|         try { | ||||
|             Thread.currentThread().join(); | ||||
|         } catch (InterruptedException e) { | ||||
|             log.error("Main thread interrupted", e); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     public static void main(String[] args) { | ||||
|         SocketUtils.start(SocketEnum.CAM_SOCKET); | ||||
|         WebCamUtils.setWebcam(0); | ||||
|         WebCamUtils.open(); | ||||
|         //File file = new File("\"C:\\Users\\JianGuo\\Pictures\\Screenshots\\abc.png"); | ||||
|         while (true){ | ||||
|             ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||||
|             BufferedImage bi = WebCamUtils.getImage(); | ||||
|             try { | ||||
|                 ImageIO.write(bi, "JPG", baos); | ||||
|             } catch (IOException e) { | ||||
|                 //log.error(e.getMessage(), e); | ||||
|             }finally { | ||||
|                 if (bi != null){ | ||||
|                     bi.flush(); | ||||
|                     bi = null; | ||||
|                 } | ||||
|             } | ||||
| //                    try { | ||||
| //                        base64 = new String(Base64.getEncoder().encode(baos.toByteArray()), "UTF8"); | ||||
| //                    } catch (UnsupportedEncodingException e) { | ||||
| //                        log.error(e.getMessage(), e); | ||||
| //                    }finally { | ||||
| //                        baos.close(); | ||||
| //                    } | ||||
|             BinaryFrame frame = new BinaryFrame(); | ||||
|             frame.setPayload(ByteBuffer.wrap(baos.toByteArray())); | ||||
|             SocketUtils.get(SocketEnum.CAM_SOCKET.getName()).broadcastNew(frame); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue