1 package com.neuronrobotics.sdk.bowlercam.device;
5 import java.awt.Graphics2D;
6 import java.awt.image.BufferedImage;
7 import java.io.ByteArrayInputStream;
8 import java.io.IOException;
9 import java.net.MalformedURLException;
11 import java.util.ArrayList;
13 import javax.imageio.ImageIO;
15 import com.neuronrobotics.sdk.commands.neuronrobotics.bowlercam.BlobCommand;
16 import com.neuronrobotics.sdk.commands.neuronrobotics.bowlercam.ImageCommand;
17 import com.neuronrobotics.sdk.commands.neuronrobotics.bowlercam.ImageURLCommand;
18 import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
19 import com.neuronrobotics.sdk.common.BowlerDatagram;
20 import com.neuronrobotics.sdk.common.ByteList;
21 import com.neuronrobotics.sdk.common.Log;
22 import com.neuronrobotics.sdk.util.ThreadUtil;
35 private ArrayList<IWebcamImageListener>
imageListeners =
new ArrayList<IWebcamImageListener>();
38 private ArrayList<highSpeedAutoCapture>
captures=
new ArrayList<highSpeedAutoCapture> ();
41 private ArrayList<BufferedImage>
images =
new ArrayList<BufferedImage>();
44 private ArrayList<String>
urls =
new ArrayList<String> ();
47 private ArrayList<ItemMarker>
mark =
new ArrayList<ItemMarker> ();
71 l.onNewImage(camera,im);
101 if(
urls.get(cam) ==
null){
109 long start = System.currentTimeMillis();
110 while(((System.currentTimeMillis()-start)<200) && ir.
isDone()==
false){
115 }
catch(Exception ex) {
146 images.set(cam,ImageIO.read(
new URL(
urls.get(cam))));
147 }
catch (Exception e) {
148 Log.
error(
"Image Read threw an exception: "+e.getMessage());
167 if(data.
getRPC().contains(
"_img")){
173 Log.
info(
"Got image chunk\n"+data+
"\nindex: "+index+
", total: "+total+
", len: "+imgData.length);
177 if(index == (total)){
179 BufferedImage image=
null;
184 }
catch (IOException e1) {
186 e1.printStackTrace();
192 images.set(camera, image);
198 if(data.
getRPC().contains(
"blob")){
202 if(x==0 && y == 0 && r == 0){
233 if(
urls.get(chan) !=
null)
234 return urls.get(chan);
237 return urls.get(chan);
274 }
catch (Exception e){}
287 public boolean updateFilter(Color c,
int threshhold,
boolean within,
int minBlobSize,
int maxBlobSize){
288 boolean back =
false;
290 back =
send(
new BlobCommand(c, threshhold, within, minBlobSize, maxBlobSize))==
null;
291 }
catch (Exception e){
308 }
catch (InterruptedException e) {
331 boolean running =
true;
347 mspf = (int)(1000.0/((
double)fps));
356 long st = System.currentTimeMillis();
362 if(scale>1.01||scale<.99)
369 }
catch (Exception e) {
373 long diff = System.currentTimeMillis() - st;
378 Thread.sleep(mspf-diff);
379 }
catch (InterruptedException e) {
382 st = System.currentTimeMillis() ;
403 public BufferedImage
resize(BufferedImage image,
double scale) {
408 int width = (int)(((
double)image.getWidth())*scale);
409 int height = (int)(((
double)image.getHeight())*scale);
410 BufferedImage resizedImage =
new BufferedImage(width, height,image.getType());
411 Graphics2D g = resizedImage.createGraphics();
412 g.drawImage(image, 0, 0, width, height,
null);
425 BufferedImage image =
null;
426 image = ImageIO.read(
new ByteArrayInputStream(array));
highSpeedAutoCapture(int cam, double scale, int fps)
BufferedImage getImage(int chan)
ArrayList< ItemMarker > mark
BufferedImage getHighSpeedImage(int cam)
String getImageServerURL(int chan)
void onAsyncResponse(BowlerDatagram data)
BufferedImage ByteArrayToImage(byte[] array)
void fireIWebcamImageListenerEvent(int camera, BufferedImage im)
void stopAutoCapture(int cam)
void onAllResponse(BowlerDatagram data)
void addWebcamImageListener(IWebcamImageListener l)
ArrayList< ItemMarker > getBlobs()
boolean updateFilter(Color c, int threshhold, boolean within, int minBlobSize, int maxBlobSize)
ArrayList< IWebcamImageListener > imageListeners
boolean updateImage(int chan, double scale)
BufferedImage resize(BufferedImage image, double scale)
void startHighSpeedAutoCapture(int cam, double scale, int fps)
ArrayList< BufferedImage > images
ArrayList< highSpeedAutoCapture > captures
BowlerDatagram send(BowlerAbstractCommand command)
byte[] popList(int index)
synchronized boolean add(byte data)
static final int convertToInt(byte[] b)
static void info(String message)
static void error(String message)
static void wait(int time)