Skip to content

Commit

Permalink
Image transformer example, refs #282
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Dec 2, 2014
1 parent 20fc506 commit a348abb
Show file tree
Hide file tree
Showing 23 changed files with 225 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ target
**/*/.settings
**/*/target
**/*/dependency-reduced-pom.xml
pom.xml~
3 changes: 2 additions & 1 deletion webcam-capture-examples/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-parent</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-examples</artifactId>
Expand All @@ -25,6 +25,7 @@
<module>webcam-capture-manycams</module>
<module>webcam-capture-motiondetector</module>
<module>webcam-capture-painter</module>
<module>webcam-capture-transformer</module>
<module>webcam-capture-qrcode</module>
<module>webcam-capture-swt-awt</module>
<module>webcam-capture-video-recording</module>
Expand Down
2 changes: 1 addition & 1 deletion webcam-capture-examples/webcam-capture-applet/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-applet</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions webcam-capture-examples/webcam-capture-detect-face/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-detect-face</artifactId>
Expand Down Expand Up @@ -139,4 +139,4 @@
</dependency>
</dependencies>

</project>
</project>
2 changes: 1 addition & 1 deletion webcam-capture-examples/webcam-capture-executable/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-executable</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion webcam-capture-examples/webcam-capture-javafx-fxml/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-javafx-fxml</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion webcam-capture-examples/webcam-capture-javafx/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-javafx</artifactId>
Expand Down
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-live-streaming</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions webcam-capture-examples/webcam-capture-manycams/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-manycams</artifactId>
Expand All @@ -22,4 +22,4 @@
</dependency>
</dependencies>

</project>
</project>
4 changes: 2 additions & 2 deletions webcam-capture-examples/webcam-capture-motiondetector/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-motiondetector</artifactId>
Expand All @@ -22,4 +22,4 @@
</dependency>
</dependencies>

</project>
</project>
4 changes: 2 additions & 2 deletions webcam-capture-examples/webcam-capture-onejar/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-onejar</artifactId>
Expand Down Expand Up @@ -43,4 +43,4 @@
</plugins>
</build>

</project>
</project>
4 changes: 2 additions & 2 deletions webcam-capture-examples/webcam-capture-painter/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-painter</artifactId>
Expand Down Expand Up @@ -33,4 +33,4 @@
</dependency>
</dependencies>

</project>
</project>
4 changes: 2 additions & 2 deletions webcam-capture-examples/webcam-capture-qrcode/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-qrcode</artifactId>
Expand All @@ -27,4 +27,4 @@
</dependency>
</dependencies>

</project>
</project>
2 changes: 1 addition & 1 deletion webcam-capture-examples/webcam-capture-swt-awt/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-swt-awt</artifactId>
Expand Down
31 changes: 31 additions & 0 deletions webcam-capture-examples/webcam-capture-transformer/.classpath
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions webcam-capture-examples/webcam-capture-transformer/.project
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>webcam-capture-example-painter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
38 changes: 38 additions & 0 deletions webcam-capture-examples/webcam-capture-transformer/README.md
@@ -0,0 +1,38 @@
# Webcam Capture Custom Painter Example

This simple example show how to use webcam image transformer feature.

## What Is This

This example presents how to use transformation feature to paint a frame on
the image. The goal of this simple application is to draw transparent frame
at the image from the camera video feed. The frame is created from the normal
PNG file with alpha channel. The inner part of the image is completely transparent.

The frame image has been found on [pixabay.com](http://pixabay.com/) and can
be downloaded from [here](http://pixabay.com/pl/rozk%C5%82ad-jazdy-ramki-potw%C3%B3r-183669).
It's redistributed under Creative Commons Deed CC0 license.

### Screenshoots:

The frame only:

![Frame](https://raw.github.com/sarxos/webcam-capture/master/webcam-capture-examples/webcam-capture-transformer/src/main/resources/frame.png "Frame")

And how the application actually works:

![Screenshoot](https://raw.github.com/sarxos/webcam-capture/master/webcam-capture-examples/webcam-capture-transformer/src/etc/resources/screen.png "Screenshoot")

## Frame Image License

[Creative Commons Deed CC0](http://creativecommons.org/publicdomain/zero/1.0/)

## Code License

Copyright (C) 2014 Bartosz Firyn

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 changes: 25 additions & 0 deletions webcam-capture-examples/webcam-capture-transformer/pom.xml
@@ -0,0 +1,25 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-transformer</artifactId>
<packaging>jar</packaging>

<name>Webcam Capture - Image transformer Example</name>
<description>Example of how to use webcam image transformation feature</description>

<dependencies>
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,86 @@
package com.github.sarxos.webcam;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;


/**
* Example demonstrating how to use webcam image transformer feature.
*
* @author Bartosz Firyn (SarXos)
*/
public class WebcamImageTransformerExample extends JFrame implements WebcamImageTransformer {

private static final long serialVersionUID = 1L;

private static final BufferedImage IMAGE_FRAME = getImage("frame.png");

public WebcamImageTransformerExample() {

Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
webcam.setImageTransformer(this);
webcam.open();

JFrame window = new JFrame("Test Transformer");

WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);
panel.setFillArea(true);

window.add(panel);
window.pack();
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

@Override
public BufferedImage transform(BufferedImage image) {

int w = image.getWidth();
int h = image.getHeight();

BufferedImage modified = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

Graphics2D g2 = modified.createGraphics();
g2.drawImage(image, null, 0, 0);
g2.drawImage(IMAGE_FRAME, null, 0, 0);
g2.dispose();

modified.flush();

return modified;
}

private static final BufferedImage getImage(String image) {
try {
return ImageIO.read(WebcamImageTransformerExample.class.getResourceAsStream("/" + image));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static void main(String[] args) throws IOException {

JFrame.setDefaultLookAndFeelDecorated(true);

SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
new WebcamImageTransformerExample();
}
});
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-examples</artifactId>
<version>0.3.10-SNAPSHOT</version>
<version>0.3.11-SNAPSHOT</version>
</parent>

<artifactId>webcam-capture-example-video-recordig</artifactId>
Expand Down

0 comments on commit a348abb

Please sign in to comment.