Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example how to read QR code with web camera
- Loading branch information
Showing
9 changed files
with
237 additions
and
5 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
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,26 @@ | ||
<?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 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> |
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-qrcode</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> |
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,35 @@ | ||
# Webcam Capture QR Code Reader Example | ||
|
||
This example show how to read QR codes with Webcam Capture. | ||
|
||
## What Is This | ||
|
||
This example show how to process QR codes with your webcam using | ||
[Webcam Capture](https://github.com/sarxos/webcam-capture) | ||
project together with [ZXing](https://github.com/zxing/zxing) library. | ||
|
||
### Screenshoots: | ||
|
||
First I took a picture of some sample QR code I found on Google | ||
([link](http://www.google.pl/imgres?um=1&hl=pl&client=firefox-a&sa=N&tbo=d&rls=org.mozilla:en-US:official&biw=1366&bih=552&tbm=isch&tbnid=ZnVvKF0A2BGNTM:&imgrefurl=http://www.qrstuff.com/&docid=1A-zeI71ulZS1M&imgurl=http://www.qrstuff.com/images/sample.png&w=3000&h=3000&ei=yLSwUNTdCIOC4gS1xIGIBQ&zoom=1&iact=hc&vpx=154&vpy=141&dur=1160&hovh=225&hovw=225&tx=124&ty=78&sig=117284320547613276213&page=1&tbnh=149&tbnw=159&start=0&ndsp=24&ved=1t:429,r:1,s:0,i:87)) | ||
and then put it opposite to my build-in PC web camera. | ||
|
||
This is picture from my cell phone: | ||
|
||
![QR Code](https://raw.github.com/sarxos/webcam-capture/master/webcam-capture-examples/webcam-capture-qrcode/src/etc/resources/20121124.jpg "QR Code") | ||
|
||
In the application window webcam image is displayed on the left side, and on the right | ||
side there is a text area containing QR code data. In this case this is just a link | ||
to the web page from where I took my QR code example. | ||
|
||
![QR Code Example Application](https://raw.github.com/sarxos/webcam-capture/master/webcam-capture-examples/webcam-capture-qrcode/src/etc/resources/qrcode-zxing.png "QR Code Example Application") | ||
|
||
## License | ||
|
||
Copyright (C) 2012 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. |
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,30 @@ | ||
<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.5</version> | ||
</parent> | ||
|
||
<artifactId>webcam-capture-example-qrcode</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Webcam Capture - QR Code Example</name> | ||
<description>Example of how to read QR codes with your PC webcam</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.sarxos</groupId> | ||
<artifactId>webcam-capture</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.zxing</groupId> | ||
<artifactId>javase</artifactId> | ||
<version>2.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Binary file added
BIN
+53.3 KB
webcam-capture-examples/webcam-capture-qrcode/src/etc/resources/20121124.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+188 KB
webcam-capture-examples/webcam-capture-qrcode/src/etc/resources/qrcode-zxing.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions
104
...les/webcam-capture-qrcode/src/main/java/com/github/sarxos/webcam/WebcamQRCodeExample.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,104 @@ | ||
package com.github.sarxos.webcam; | ||
|
||
import java.awt.FlowLayout; | ||
import java.awt.image.BufferedImage; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ThreadFactory; | ||
|
||
import javax.swing.JFrame; | ||
import javax.swing.JTextArea; | ||
|
||
import com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice; | ||
import com.google.zxing.BinaryBitmap; | ||
import com.google.zxing.LuminanceSource; | ||
import com.google.zxing.MultiFormatReader; | ||
import com.google.zxing.NotFoundException; | ||
import com.google.zxing.Result; | ||
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; | ||
import com.google.zxing.common.HybridBinarizer; | ||
|
||
|
||
public class WebcamQRCodeExample extends JFrame implements Runnable, ThreadFactory { | ||
|
||
private static final long serialVersionUID = 6441489157408381878L; | ||
|
||
private Executor executor = Executors.newSingleThreadExecutor(this); | ||
|
||
private Webcam webcam = null; | ||
private WebcamPanel panel = null; | ||
private JTextArea textarea = null; | ||
|
||
public WebcamQRCodeExample() { | ||
super(); | ||
|
||
setLayout(new FlowLayout()); | ||
setTitle("Read QR Code With Webcam"); | ||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
|
||
webcam = Webcam.getDefault(); | ||
webcam.setViewSize(WebcamDefaultDevice.SIZE_QVGA); | ||
|
||
panel = new WebcamPanel(webcam); | ||
panel.setPreferredSize(WebcamDefaultDevice.SIZE_QVGA); | ||
|
||
textarea = new JTextArea(); | ||
textarea.setEditable(false); | ||
textarea.setPreferredSize(WebcamDefaultDevice.SIZE_QVGA); | ||
|
||
add(panel); | ||
add(textarea); | ||
|
||
pack(); | ||
setVisible(true); | ||
|
||
executor.execute(this); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
|
||
do { | ||
try { | ||
Thread.sleep(100); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
Result result = null; | ||
BufferedImage image = null; | ||
|
||
if (webcam.isOpen()) { | ||
|
||
if ((image = webcam.getImage()) == null) { | ||
continue; | ||
} | ||
|
||
LuminanceSource source = new BufferedImageLuminanceSource(image); | ||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); | ||
|
||
try { | ||
result = new MultiFormatReader().decode(bitmap); | ||
} catch (NotFoundException e) { | ||
// fall thru, it means there is no QR code in image | ||
} | ||
} | ||
|
||
if (result != null) { | ||
textarea.setText(result.getText()); | ||
} | ||
|
||
} while (true); | ||
} | ||
|
||
@Override | ||
public Thread newThread(Runnable r) { | ||
Thread t = new Thread(r, "example-runner"); | ||
t.setDaemon(true); | ||
return t; | ||
} | ||
|
||
public static void main(String[] args) { | ||
new WebcamQRCodeExample(); | ||
} | ||
} |
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