forked from zxing/zxing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic Google Glass Mirror API app. Not likely to be functional.
git-svn-id: https://zxing.googlecode.com/svn/trunk@2926 59b500cc-1b3d-0410-9834-0bbf25fbcc57
- Loading branch information
1 parent
4c64228
commit d1ef2a9
Showing
20 changed files
with
1,256 additions
and
1 deletion.
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
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,145 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2013 ZXing authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License 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. | ||
--> | ||
<!-- Author: Sean Owen --> | ||
<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> | ||
|
||
<artifactId>glass-mirror</artifactId> | ||
<version>2.3.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>com.google.apis</groupId> | ||
<artifactId>google-api-services-mirror</artifactId> | ||
<version>v1-rev28-1.17.0-rc</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.http-client</groupId> | ||
<artifactId>google-http-client-jackson2</artifactId> | ||
<version>1.17.0-rc</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.apis</groupId> | ||
<artifactId>google-api-services-oauth2</artifactId> | ||
<version>v2-rev51-1.17.0-rc</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.zxing</groupId> | ||
<artifactId>core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.zxing</groupId> | ||
<artifactId>javase</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- Update dependencies --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
<version>2.2.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
<version>1.8</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.3.1</version> | ||
<scope>runtime</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpcore</artifactId> | ||
<version>4.3</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>15.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-jdk14</artifactId> | ||
<version>1.7.5</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<version>1.7.5</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-web-api</artifactId> | ||
<version>6.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<parent> | ||
<groupId>com.google.zxing</groupId> | ||
<artifactId>zxing-parent</artifactId> | ||
<version>2.3.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>7</source> | ||
<target>7</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<name>ZXing Google Glass Mirror API app</name> | ||
<description>Experimental Barcode Scanner app for Google Glass Mirror API</description> | ||
|
||
</project> |
86 changes: 86 additions & 0 deletions
86
glass-mirror/src/main/java/com/google/zxing/client/glass/AuthUtil.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 @@ | ||
/* | ||
* Copyright (C) 2013 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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. | ||
*/ | ||
|
||
/* | ||
* Copyright 2013 ZXing authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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.google.zxing.client.glass; | ||
|
||
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; | ||
import com.google.api.client.auth.oauth2.Credential; | ||
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; | ||
import com.google.api.client.http.javanet.NetHttpTransport; | ||
import com.google.api.client.json.jackson2.JacksonFactory; | ||
import com.google.api.client.util.store.DataStoreFactory; | ||
import com.google.api.client.util.store.MemoryDataStoreFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
/** | ||
* A collection of utility functions that simplify common authentication and | ||
* user identity tasks | ||
* | ||
* @author Sean Owen | ||
* @author Google | ||
*/ | ||
final class AuthUtil { | ||
|
||
private static final Collection<String> SCOPES = | ||
Arrays.asList("https://www.googleapis.com/auth/glass.timeline", | ||
"https://www.googleapis.com/auth/userinfo.profile"); | ||
|
||
private final DataStoreFactory dataStoreFactory; | ||
private final String clientID; | ||
private final String clientSecret; | ||
|
||
AuthUtil(String clientID, String clientSecret) { | ||
dataStoreFactory = new MemoryDataStoreFactory(); | ||
this.clientID = clientID; | ||
this.clientSecret = clientSecret; | ||
} | ||
|
||
/** | ||
* Creates and returns a new {@link AuthorizationCodeFlow} for this app. | ||
*/ | ||
public AuthorizationCodeFlow newAuthorizationCodeFlow() throws IOException { | ||
return new GoogleAuthorizationCodeFlow.Builder(new NetHttpTransport(), | ||
new JacksonFactory(), | ||
clientID, | ||
clientSecret, | ||
SCOPES) | ||
.setAccessType("offline").setDataStoreFactory(dataStoreFactory).build(); | ||
} | ||
|
||
public Credential getCredential(String userId) throws IOException { | ||
return userId == null ? null : newAuthorizationCodeFlow().loadCredential(userId); | ||
} | ||
|
||
} |
114 changes: 114 additions & 0 deletions
114
glass-mirror/src/main/java/com/google/zxing/client/glass/DecodeHelper.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,114 @@ | ||
/* | ||
* Copyright 2013 ZXing authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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.google.zxing.client.glass; | ||
|
||
import com.google.zxing.BarcodeFormat; | ||
import com.google.zxing.BinaryBitmap; | ||
import com.google.zxing.DecodeHintType; | ||
import com.google.zxing.LuminanceSource; | ||
import com.google.zxing.MultiFormatReader; | ||
import com.google.zxing.Reader; | ||
import com.google.zxing.ReaderException; | ||
import com.google.zxing.Result; | ||
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; | ||
import com.google.zxing.common.GlobalHistogramBinarizer; | ||
import com.google.zxing.common.HybridBinarizer; | ||
|
||
import java.awt.color.CMMException; | ||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.EnumMap; | ||
import java.util.EnumSet; | ||
import java.util.Map; | ||
|
||
import javax.imageio.ImageIO; | ||
|
||
/** | ||
* @author Sean Owen | ||
*/ | ||
final class DecodeHelper { | ||
|
||
// No real reason to deal with more than maybe 8.3 megapixels | ||
private static final int MAX_PIXELS = 1 << 23; | ||
private static final Map<DecodeHintType,Object> HINTS; | ||
|
||
static { | ||
HINTS = new EnumMap<>(DecodeHintType.class); | ||
HINTS.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); | ||
HINTS.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class)); | ||
} | ||
|
||
private DecodeHelper() { | ||
} | ||
|
||
static Collection<Result> processStream(InputStream is) throws IOException { | ||
BufferedImage image; | ||
try { | ||
image = ImageIO.read(is); | ||
} catch (CMMException | IllegalArgumentException e) { | ||
throw new IOException(e); | ||
} | ||
if (image == null) { | ||
throw new IOException("No image"); | ||
} | ||
if (image.getHeight() <= 1 || image.getWidth() <= 1 || | ||
image.getHeight() * image.getWidth() > MAX_PIXELS) { | ||
throw new IOException("Dimensions out of bounds: " + image.getWidth() + 'x' + image.getHeight()); | ||
} | ||
|
||
return processImage(image); | ||
} | ||
|
||
private static Collection<Result> processImage(BufferedImage image) { | ||
|
||
Reader reader = new MultiFormatReader(); | ||
LuminanceSource source = new BufferedImageLuminanceSource(image); | ||
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source)); | ||
Collection<Result> results = new ArrayList<>(1); | ||
|
||
if (results.isEmpty()) { | ||
try { | ||
// Look for normal barcode in photo | ||
Result theResult = reader.decode(bitmap, HINTS); | ||
if (theResult != null) { | ||
results.add(theResult); | ||
} | ||
} catch (ReaderException re) { | ||
// continue | ||
} | ||
} | ||
|
||
if (results.isEmpty()) { | ||
try { | ||
// Try again with other binarizer | ||
BinaryBitmap hybridBitmap = new BinaryBitmap(new HybridBinarizer(source)); | ||
Result theResult = reader.decode(hybridBitmap, HINTS); | ||
if (theResult != null) { | ||
results.add(theResult); | ||
} | ||
} catch (ReaderException re) { | ||
// continue | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
} |
Oops, something went wrong.