-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image transformer example, refs #282
- Loading branch information
Showing
23 changed files
with
225 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ target | |
**/*/.settings | ||
**/*/target | ||
**/*/dependency-reduced-pom.xml | ||
pom.xml~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
webcam-capture-examples/webcam-capture-transformer/.classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
23
webcam-capture-examples/webcam-capture-transformer/.project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
38
webcam-capture-examples/webcam-capture-transformer/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
25
webcam-capture-examples/webcam-capture-transformer/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Binary file added
BIN
+354 KB
webcam-capture-examples/webcam-capture-transformer/src/etc/resources/screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions
86
...ure-transformer/src/main/java/com/github/sarxos/webcam/WebcamImageTransformerExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
}); | ||
} | ||
} |
Binary file added
BIN
+86.5 KB
webcam-capture-examples/webcam-capture-transformer/src/main/resources/frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.