Skip to content

Commit

Permalink
Add basic Google Glass Mirror API app. Not likely to be functional.
Browse files Browse the repository at this point in the history
git-svn-id: https://zxing.googlecode.com/svn/trunk@2926 59b500cc-1b3d-0410-9834-0bbf25fbcc57
  • Loading branch information
[email protected] committed Nov 26, 2013
1 parent 4c64228 commit d1ef2a9
Show file tree
Hide file tree
Showing 20 changed files with 1,256 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,11 @@
- Many ports of Java updates to C++ and C# ports
- Standardize test system image processing and image format for reproducibility

2.3 (XX Dec 2013)
2.3.0 (1 Dec 2013)

- Added clone of Google Chart Server QR code encoder API to zxingorg/, at endpoint /chart
- Updated zxing.appspot.com generator to remove deprecated API usage, use latest GWT / App Engine
- Added skeleton Google Glass Mirror API app
- Improve and standardize Maven build, standardize directories and version naming
- Barcode Scanner Android up requires Android 4 and is updated to use Android 4+ APIs
- javase/ and zxingorg/ modules now use Java 7
Expand Down
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<exclude name="core/src/test/resources/**"/> <!-- included separately below -->
<include name="cpp/**"/>
<include name="csharp/**"/>
<include name="glass-mirror/**"/>
<include name="iphone/**"/>
<include name="javase/**"/>
<include name="jruby/**"/>
Expand Down
145 changes: 145 additions & 0 deletions glass-mirror/pom.xml
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>
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);
}

}
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;
}

}
Loading

0 comments on commit d1ef2a9

Please sign in to comment.