Skip to content

Commit

Permalink
Merge pull request #22 from bdhandap/release_1.0.4
Browse files Browse the repository at this point in the history
Release 1.0.4
  • Loading branch information
bdhandap authored Apr 19, 2018
2 parents cdd9015 + b811f79 commit 0017a7d
Show file tree
Hide file tree
Showing 42 changed files with 2,826 additions and 76 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ with the AWS SDK for the Kinesis Video. This example provides examples for
* It has been tested not only for streams ingested by `PutMediaWorker` but also streams sent to Kinesis Video Streams using GStreamer Demo application (https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp)
## Release Notes
### Release 1.0.4 (April 2018)
* Add example for KinesisVideo Streams integration with Rekognition and draw Bounding Boxes for every sampled frame.
* Fix for stream ending before reporting tags visited.
* Same test data file for parsing and rendering example.
* Known Issues: In `KinesisVideoRekognitionIntegrationExample`, the decode/renderer sample using JCodec may not be able to decode all mkv files.
### Release 1.0.3 (Februrary 2018)
* In OutputSegmentMerger, make sure that the lastClusterTimecode is updated for the first fragment.
If timecode is equal to that of a previous cluster, stop merging
Expand Down
18 changes: 17 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<artifactId>amazon-kinesis-video-streams-parser-library</artifactId>
<packaging>jar</packaging>
<name>Amazon Kinesis Video Streams Parser Library</name>
<version>1.0.3</version>
<version>1.0.4</version>
<description>The Amazon Kinesis Video Streams Parser Library for Java enables Java developers to parse the streams
returned by GetMedia calls to Amazon Kinesis Video.
</description>
Expand Down Expand Up @@ -47,11 +47,27 @@
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.289</version>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.289</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-kinesisvideo</artifactId>
<version>1.11.247</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>amazon-kinesis-client</artifactId>
<version>1.9.0</version>
</dependency>

<!-- Frame Decode/View -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
A copy of the License is located at
http://aws.amazon.com/apache2.0/
or in the "license" file accompanying this file.
This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
*/
package com.amazonaws.kinesisvideo.parser.examples;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import com.amazonaws.kinesisvideo.parser.rekognition.pojo.BoundingBox;
import com.amazonaws.kinesisvideo.parser.rekognition.pojo.FaceType;
import com.amazonaws.kinesisvideo.parser.rekognition.pojo.MatchedFace;
import com.amazonaws.kinesisvideo.parser.rekognition.pojo.RekognizedOutput;

/**
* Panel which is used for rendering frames and embedding bounding boxes on the frames.
*/
class BoundingBoxImagePanel extends ImagePanel {
private static final String DELIMITER = "-";
private RekognizedOutput rekognizedOutput;

@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
super.paintComponent(g);

if (rekognizedOutput != null) {

// Draw bounding boxes for faces.
if (rekognizedOutput.getFaceSearchOutputs() != null) {
for (RekognizedOutput.FaceSearchOutput faceSearchOutput: rekognizedOutput.getFaceSearchOutputs()) {
FaceType detectedFaceType;
String title;
if (!faceSearchOutput.getMatchedFaceList().isEmpty()) {
// Taking First match as Rekognition returns set of matched faces sorted by confidence level
MatchedFace matchedFace = faceSearchOutput.getMatchedFaceList().get(0);
String externalImageId = matchedFace.getFace().getExternalImageId();
// Rekognition doesn't allow any extra attributes/tags to be associated with the 'Face'.
// External Image Id is used here to draw title on top of the bounding box and change color
// of the bounding box (based on the FaceType). External Image Id needs to be specified in
// below format in order get this working.
// Eg: PersonName1-Criminal, PersonName2-Trusted, PersonName3-Intruder etc.
if (externalImageId == null) {
// If the external image id is not specified, then draw confidence level as title.
title = matchedFace.getFace().getConfidence() + "";
detectedFaceType = FaceType.NOT_RECOGNIZED;
} else {
String[] imageIds = externalImageId.split(DELIMITER);
if (imageIds.length > 1) {
title = imageIds[0];
detectedFaceType = FaceType.valueOf(imageIds[1].toUpperCase());
} else {
title = "No prefix";
detectedFaceType = FaceType.NOT_RECOGNIZED;
}
}
} else {
detectedFaceType = FaceType.NOT_RECOGNIZED;
title = "Not recognized";
}
drawFaces(g2, faceSearchOutput.getDetectedFace().getBoundingBox(),
title, detectedFaceType.getColor());
}
}
}
}

private void drawFaces(Graphics2D g2, BoundingBox boundingBox, String personName, Color color) {
Color c = g2.getColor();

g2.setColor(color);
// Draw bounding box
drawBoundingBox(g2, boundingBox);

// Draw title
drawFaceTitle(g2, boundingBox, personName);
g2.setColor(c);
}

private void drawFaceTitle(Graphics2D g2, BoundingBox boundingBox, String personName) {
int left = (int) (boundingBox.getLeft() * image.getWidth());
int top = (int) (boundingBox.getTop() * image.getHeight());
g2.drawString(personName, left, top);
}

private void drawBoundingBox(Graphics2D g2, BoundingBox boundingBox) {
int left = (int) (boundingBox.getLeft() * image.getWidth());
int top = (int) (boundingBox.getTop() * image.getHeight());
int width = (int) (boundingBox.getWidth() * image.getWidth());
int height = (int) (boundingBox.getHeight() * image.getHeight());

// Draw bounding box
g2.drawRect(left, top, width, height);
}

public void setImage(BufferedImage bufferedImage, RekognizedOutput rekognizedOutput) {
this.image = bufferedImage;
this.rekognizedOutput = rekognizedOutput;
repaint();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
A copy of the License is located at
http://aws.amazon.com/apache2.0/
or in the "license" file accompanying this file.
This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
*/
package com.amazonaws.kinesisvideo.parser.examples;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

/**
* Panel for rendering buffered image.
*/
class ImagePanel extends JPanel {
protected BufferedImage image;

@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
if (image != null) {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.clearRect(0, 0, image.getWidth(), image.getHeight());
g2.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
}
}

public void setImage(BufferedImage bufferedImage) {
image = bufferedImage;
repaint();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
A copy of the License is located at
http://aws.amazon.com/apache2.0/
or in the "license" file accompanying this file.
This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
*/
package com.amazonaws.kinesisvideo.parser.examples;

import java.awt.image.BufferedImage;

import com.amazonaws.kinesisvideo.parser.rekognition.pojo.RekognizedOutput;

public class KinesisVideoBoundingBoxFrameViewer extends KinesisVideoFrameViewer {

public KinesisVideoBoundingBoxFrameViewer(int width, int height) {
super(width, height, "KinesisVideo Embedded Frame Viewer");
panel = new BoundingBoxImagePanel();
addImagePanel(panel);
}

public void update(BufferedImage image, RekognizedOutput rekognizedOutput) {
((BoundingBoxImagePanel) panel).setImage(image, rekognizedOutput);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,42 @@
*/
package com.amazonaws.kinesisvideo.parser.examples;

import javax.swing.*;

import java.awt.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;

import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;
import javax.swing.JFrame;

public class KinesisVideoFrameViewer extends JFrame {
private final ImagePanel panel;
private final int width;
private final int height;
private final String title;

public KinesisVideoFrameViewer(int width, int height) {
this.setTitle("Kinesis Video Frame Viewer Sample");
protected ImagePanel panel;

protected KinesisVideoFrameViewer(int width, int height, String title) {
this.width = width;
this.height = height;
this.title = title;
this.setTitle(title);
this.setBackground(Color.BLACK);
}

public KinesisVideoFrameViewer(int width, int height) {
this(width, height, "Kinesis Video Frame Viewer ");
panel = new ImagePanel();
addImagePanel(panel);
}

protected void addImagePanel(final ImagePanel panel) {
panel.setPreferredSize(new Dimension(width, height));
this.add(panel);
this.pack();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.out.println("Kinesis video viewer frame closed");
System.out.println(title + " closed");
System.exit(0);
}
});
Expand All @@ -48,21 +59,3 @@ public void update(BufferedImage image) {
}
}

class ImagePanel extends JPanel {
private BufferedImage image;

@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
if (image != null) {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.clearRect(0, 0, image.getWidth(), image.getHeight());
g2.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
}
}

public void setImage(BufferedImage bufferedImage) {
image = bufferedImage;
repaint();
}
}
Loading

0 comments on commit 0017a7d

Please sign in to comment.