X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=blobdiff_plain;f=benchmarks%2FJava%2FSmartLightsController%2FMotionDetection.java;fp=benchmarks%2FJava%2FSmartLightsController%2FMotionDetection.java;h=4aa0dc8810aeffa23a59016ea0fb90990385202b;hp=bd473501808d433f35e2263220414c48e2c9f63c;hb=5bc160f4449b52e721b72b091e1b0c1f1362579b;hpb=d070515f3c8da074210342cebfddbd5769cebe89 diff --git a/benchmarks/Java/SmartLightsController/MotionDetection.java b/benchmarks/Java/SmartLightsController/MotionDetection.java index bd47350..4aa0dc8 100644 --- a/benchmarks/Java/SmartLightsController/MotionDetection.java +++ b/benchmarks/Java/SmartLightsController/MotionDetection.java @@ -257,13 +257,16 @@ class MotionDetection implements CameraCallback { * * @return [void] None. */ - public void newCameraFrameAvailable(byte[] latestFrame, long timeStamp) { + //public void newCameraFrameAvailable(byte[] latestFrame, long timeStamp) { + public void newCameraFrameAvailable(CameraSmart _camera) { BufferedImage img = null; + // Parse the byte array into a Buffered Image + byte[] newImg = _camera.getLatestFrame(); try { - // Parse the byte array into a Buffered Image //InputStream in = new ByteArrayInputStream(_camera.getLatestFrame()); - InputStream in = new ByteArrayInputStream(latestFrame); + //InputStream in = new ByteArrayInputStream(latestFrame); + InputStream in = new ByteArrayInputStream(newImg); img = ImageIO.read(in); } catch (RemoteException e) { @@ -281,7 +284,9 @@ class MotionDetection implements CameraCallback { latestImage = img; // image into image buffer // timestamp from camera into timestamp buffer - long dateLong = timeStamp; + //long dateLong = timeStamp; + long dateLong = _camera.getTimestamp(); + //System.out.println("dateLong: " + dateLong + " - newImage size: " + newImg.length); possibleDate = new Date(dateLong); imageWriteLock.unlock(); // Never forget to unlock @@ -367,13 +372,16 @@ class MotionDetection implements CameraCallback { // calculate the percentage of the image that was in motion double percentMotion = (countMotion / count) * 100.0; + System.out.println("countMotion: " + countMotion); + System.out.println("count: " + count); + System.out.println("Percent motion: " + percentMotion); // Check if a high enough percentage of the image was in motion to say that there was motion in this frame of data if (percentMotion > MOTION_DETECTED_THRESHOLD_PERCENTAGE) { // Motion detected so save timestamp of this frame to another buffer timestampWriteLock.lock(); - timestampOfLastMotion = (Date)tmpDate.clone(); // clone to a different buffer + timestampOfLastMotion = (Date)tmpDate.clone();// clone to a different buffer timestampWriteLock.unlock(); System.out.println("Motion Detected (with percentage: " + Double.toString(percentMotion) + "%)");