+ All Categories
Home > Software > DIY: Computer Vision with GWT.

DIY: Computer Vision with GWT.

Date post: 16-Jul-2015
Category:
Upload: jooink
View: 183 times
Download: 3 times
Share this document with a friend
85
DIY: computer vision with GWT Francesca Tosi Alberto Mancini [email protected] [email protected]
Transcript
Page 1: DIY: Computer Vision with GWT.

DIY: computer vision with GWT

Francesca Tosi Alberto [email protected] [email protected]

Page 2: DIY: Computer Vision with GWT.

Alberto Software Developer & Linux Sysadmin

C/C++ ( since 80’s :/ )GWT ( since 1.6 )

Javascript & Java

[email protected]+AlbertoMancini

Page 3: DIY: Computer Vision with GWT.

FrancescaWeb and mobile developer,software engineer and architect

C/C++, CFD, HPCGWT since 2009

“with a passion for clean code and fine tuned details”

[email protected]@francescatosi+FrancescaTosi

Page 4: DIY: Computer Vision with GWT.

Devfest’s CodeProject

A couple of years(**) ago we started working on a pet project trying to explore how mixing modern WebAPIs and an effective programming approach(*) can enable us to develop complex client-side applications running in a browser.

(*)read: GWT, i.e. a typed language compiled into js

(**)for the 2012’s GDG DevFest season

Page 5: DIY: Computer Vision with GWT.

Anybody knows

Browsers are a good

“execution environnement”

for evoluted web-pages ….

Page 6: DIY: Computer Vision with GWT.

Browsers are

enough ?

Page 7: DIY: Computer Vision with GWT.

I Mean ...

C’mon we are in 2015:

browsers are certainly more than enough

for any kind of application !

GoogleDocs, Inbox, Plus, Scala vm in js, JsDOSBox…

Page 8: DIY: Computer Vision with GWT.

BETting

The right tool(*) is enough to let us to develop

- complex - compute-intensive

browser-based applications ?

(*) GWT of course :)

Page 9: DIY: Computer Vision with GWT.

The RIGHT TOOL

Should (at least) let us:● master the (quite tricky) web platform● code safely … in a type-safe language

(but provide native-like flexibility and performance)

● reuse existing code

… and of course produce a fast and reliable application

Page 10: DIY: Computer Vision with GWT.

NO,no way

Our forecast was

Page 11: DIY: Computer Vision with GWT.

Target

We were working on Augmented Reality and we had an expertize on it so we started trying to realize an AR webApp in order to show that this kind of applications is way too-complex for the performance of a browser.

Page 12: DIY: Computer Vision with GWT.

Augmented Reality (browser based)

Marker BasedAugmented Reality

Page 13: DIY: Computer Vision with GWT.

Marker Based AR

Essentially composed of 3 steps

● Marker detection and identification(finding the marker in a picture)

● Computation of the marker pose(det. six degrees of freedom w.r.t camera, f.i.)

● Syntetic objects collocation (object space to camera space transf)

Page 14: DIY: Computer Vision with GWT.

Marker Based AR

Page 15: DIY: Computer Vision with GWT.

NyARToolkit, do not reinvent the wheel

NyARToolKit is an ARToolKit built with 100% pure Java.

[great performance, featurefull, GPL]

http://nyatla.jp/nyartoolkit/wp/

Page 16: DIY: Computer Vision with GWT.

GWT-NyARToolkit

… given an image we get a 3x4 (3x3 + a translation vector actually) matrix that identifies the marker in the camera space

nyar.update(i_sensor); ← ‘push’ an image

found = nyar.isExistMarker(marker_id); ← query if a marker is detected

mm = nyar.getMarkerMatrix(marker_id); ← compute the collocation matrix

https://code.google.com/p/gwt-nyartoolkit/http://jooink.blogspot.com

Page 17: DIY: Computer Vision with GWT.

Browser Based AR

<video/>

<canvas/>

Ny

HTTP

?

?

Page 18: DIY: Computer Vision with GWT.

GWT … glue

Page 19: DIY: Computer Vision with GWT.

Acquiring Video (and eventually Audio)

Page 20: DIY: Computer Vision with GWT.

WebRTC

Page 21: DIY: Computer Vision with GWT.

Acquiring Video (and eventually Audio)

Acquisition of Audio/Video stream via simple js api.

Page 22: DIY: Computer Vision with GWT.

Why WebRTC ?

Page 23: DIY: Computer Vision with GWT.

Why WebRTC ?Plugins for IE

e.g.Temasys provides ad ad hoc craftedreplacement ofadapter.js

Page 24: DIY: Computer Vision with GWT.

Audio/Video

Acqusition Audio/Video stream via simple js apis.

navigator.getUserMedia(constraints,successCallBack,errorCallBack)

Page 25: DIY: Computer Vision with GWT.

WebRTC with GWT

GWT (Elemental at the beginning)

At the beginning elemental, but right now (using jnsi and now jsinterop) we are able to do all the operation without dependencies GWT.

https://code.google.com/p/elemental-getusermedia-demo

https://github.com/jooink/gwt-getusermedia

Page 26: DIY: Computer Vision with GWT.

Browser Based AR

<video/>

the video stream

can (has to be) be played in a <video/> tag

“native” (jsni)

video.src = URL.createObjectURL(stream);

Page 27: DIY: Computer Vision with GWT.

Browser Based AR

<canvas/>

<video/>

canvasCtx2D.drawImage(video, ...);

Page 28: DIY: Computer Vision with GWT.

Browser Based AR

<canvas/>

<video/>

canvasCtx2D.drawImage(video, ...);

canvasCtx2D.getImageData(sx, sy, sw, sh)

Page 29: DIY: Computer Vision with GWT.

Browser Based AR

<video/>Ny

<canvas/>

Page 30: DIY: Computer Vision with GWT.

Browser Based AR

<video/>

<canvas/>

Ny

3D models to be shown on the marker

after the recognition

Page 31: DIY: Computer Vision with GWT.

Browser Based AR

<video/>

<canvas/>

Ny

HTTP

Page 32: DIY: Computer Vision with GWT.

WebGLWe had to reinvent the wheel :(

three.js, BabylonJS

parallax (GWT !)

awesome shading rendering and lighting

tend to mix webgl-interaction with 3D graphics

Page 33: DIY: Computer Vision with GWT.

WebGL, gwt-webgl

<video/>Ny

<canvas/>

https://code.google.com/p/gwt-webgl

based on Elemental with some modifications

damn thin wrapper around webgl standard

Page 34: DIY: Computer Vision with GWT.

Tiny3D

● 3D geometry (4x4 & affine matrices)

● Lambertian and Phong lighting

● Polygons, Polyhedra, normals etc..Wavefront OBJ import

Page 35: DIY: Computer Vision with GWT.

Browser Based AR

<video/>

<canvas/>

Ny

HTTP

Page 36: DIY: Computer Vision with GWT.

picshareWe lost the BET

http://picshare.jooink.com

Page 37: DIY: Computer Vision with GWT.

Browsers are enough!

Page 38: DIY: Computer Vision with GWT.

GWT is more than enough!

Page 39: DIY: Computer Vision with GWT.

mGWT

GWT Widgets & morefor mobile

Page 40: DIY: Computer Vision with GWT.

FirefoxOS

Web developerspreferredmobile OS?

B2G

Page 41: DIY: Computer Vision with GWT.
Page 42: DIY: Computer Vision with GWT.

Browser Based AR

<video/>

<canvas/>

Ny

HTTP

Page 43: DIY: Computer Vision with GWT.

Browser Based AR

<video/>

<canvas/>

Ny

HTTP

Page 44: DIY: Computer Vision with GWT.

Computer Vision

Computer Vision

As told by Alberto, after a while we needed to have some more complex features on this tool for image recognition, in order to have more information on the image we are working with.

Page 45: DIY: Computer Vision with GWT.

Computer Vision

Computer Vision

There exists a lot of CV libs (complete, tested and fine tuned) for example:

- OpenCV- VLFeat- VLX- …

C/C++

Page 46: DIY: Computer Vision with GWT.

Computer Vision

Computer Vision

There exists a lot of CV libs (complete, tested and fine tuned) for example:

- OpenCV- VLFeat- VLX- …

- BoofCV

C/C++

Java

Page 47: DIY: Computer Vision with GWT.

Computer Vision

Computer Vision by BoofCV

There is a great library for Computer Vision interely written in Pure Java: BoofCV → we decided to adapt BoofCV for GWT.

Page 48: DIY: Computer Vision with GWT.

BoofCV

BoofCV is a complete & complex project

BoofCV is an opensource Java library for computer vision & robotics applications.

BoofCV is organized into several packages: image processing, features, geometric vision, calibration, recognition, visualize and IO.

Page 49: DIY: Computer Vision with GWT.

BoofCV

Written by Peter Abeles

www.boofcv.org

Link to the source code:

https://github.com/lessthanoptimal/BoofCV

Page 50: DIY: Computer Vision with GWT.

BoofCV

Adapting an entire big & complex library is not is a funny game.

BoofCV depends on other Java libs, so we must adapt all the dependencies

Page 51: DIY: Computer Vision with GWT.

BoofCV

- DDogLeg: Java numerical lib for non-linear optimization, robust model-fitting, polynomial root finding, sorting and more;

- GeoRegression: open source java geometry lib for scientific computing;

- EJML: dense matrix linear algebra library written in Java

Page 52: DIY: Computer Vision with GWT.

BoofCV- GWT-DDogLeg:

https://github.com/jooink/gwt-ddogleg

http://gwtddogleg.appspot.com/

- GWT-GeoRegression: https://github.com/jooink/gwt-georegressionhttp://gwtgeoregression.appspot.com/

- GWT-EJML: https://github.com/jooink/gwt-ejml

http://gwtejml.appspot.com/

Page 53: DIY: Computer Vision with GWT.

EJML

- EJML: dense matrix linear algebra library written in Java

https://github.com/lessthanoptimal/ejml

Page 54: DIY: Computer Vision with GWT.

GWT-EJML

GWT-EJML

is an adapter-project around EJML that let us to use the original library:

- provides .gwt.xml files - supersources many classes - contains running examples

Page 55: DIY: Computer Vision with GWT.

GWT-EJML

GWT-EJML

published on github

https://github.com/jooink/gwt-ejml

Page 56: DIY: Computer Vision with GWT.

GWT-EJML

org.EJML.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.6.1.rc1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.6.1.rc1/distro-source/core/src/gwt-module.dtd">

<module>

<source path="ejml"/>

</module>

Page 57: DIY: Computer Vision with GWT.

GWT-EJML

.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"

"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">

<module rename-to='gwtejml'>

<inherits name='org.EJML'/>

...

<super-source path="jre" />

...

</module>

Page 58: DIY: Computer Vision with GWT.

GWT-EJML

The Strategy

we decided to use the SuperSourcing in order to change/adapt the class of the basic lib and leave the ejml project unchanged

→ the maintainability is easier

Page 59: DIY: Computer Vision with GWT.

GWT-EJML

SuperSourcing

We added the super source path in the gwt.xml config file

<super-source path="jre" />

and we created the file to modify in that directory (using the right path of the file in the main project).

Page 60: DIY: Computer Vision with GWT.

GWT-EJML

.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"

"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">

<module rename-to='gwtejml'>

<inherits name='org.EJML'/>

...

<super-source path="jre" />

...

</module>

Page 61: DIY: Computer Vision with GWT.

GWT-EJML

Supersourced parts of JRE

java.io.ByteArrayOutputStream

public class ByteArrayOutputStream extends OutputStream {

public ByteArrayOutputStream() { … }

public void write(int arg0) { … }

}

Page 62: DIY: Computer Vision with GWT.

GWT-EJML

Supersourced parts of EJMLorg.ejml.ops.MatrixIO;

public class MatrixIO { … }

org.ejml.alg.dense.decomposition

.eig.symm.SymmetricQREigenHelper

org.ejml.alg.dense.decomposition

.svd.implicitqr.SvdImplicitQrAlgorithm

java.io.PrintStream

printf()

Page 63: DIY: Computer Vision with GWT.

GWT-EJML

Supersourced parts of EJML

java.io.PrintStream does not have printf() in the gwt emulated jre

We could not supersource the PrintStream because already exist on emulated jre and we cannot super-sourcing just a method.

Page 64: DIY: Computer Vision with GWT.

GWT-EJML

Link

https://github.com/jooink/gwt-ejml

http://gwtejml.appspot.com/

Page 65: DIY: Computer Vision with GWT.

DDogLeg

- DDOGLEG: Java numerical lib for non-linear optimization, robust model-fitting, polynomial root finding, sorting and more;

https://github.com/lessthanoptimal/ddogleg

Page 66: DIY: Computer Vision with GWT.

GWT-DDogLeg

.gwt.xml <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"

"http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">

<module rename-to='gwtddogleg'>

<inherits name='org.DDOGLEG'/>

<inherits name='com.jooink.gwtejml.gwtEJML_lib'/>

...

<super-source path="jre" />

...

</module>

Page 67: DIY: Computer Vision with GWT.

GWT-DDogLeg

Supersourced parts of DDOGLEG:

java.lang.OutOfMemoryError

Unchecked Exception …

Page 68: DIY: Computer Vision with GWT.

GWT-DDogLeg

Supersourced parts of DDOGLEG:

org.ddogleg.struct.FastQueue

org.ddogleg.struct.FastQueueList

→ Reflection (not supported by gwt-jre)

Page 69: DIY: Computer Vision with GWT.

GWT-DDogLeg

Link

https://github.com/jooink/gwt-ddogleg

http://gwtddogleg.appspot.com/

Page 70: DIY: Computer Vision with GWT.

GEOREGRESSION

- GEOREGRESSION: open source java geometry lib for scientific computing;

https://github.com/lessthanoptimal/georegression

Page 71: DIY: Computer Vision with GWT.

GWT-GEOREGRESSION

- GWT-GEOREGRESSION: minor modifications

Page 72: DIY: Computer Vision with GWT.

GWT-GEOREGRESSION

.gwt.xml <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN" "http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">

<module rename-to='gwtgeoregression'>

<inherits name='georegression.GEOREGRESSION'/>

<inherits name='com.jooink.gwtejml.gwtEJML_lib'/>

<inherits name='com.jooink.gwtddogleg.gwtDDogLeg_lib'/>

...

</module>

Page 73: DIY: Computer Vision with GWT.

GWT-GEOREGRESSION

Link

https://github.com/jooink/gwt-georegression

http://gwtgeoregression.appspot.com/

Page 74: DIY: Computer Vision with GWT.

BoofCV

- BOOFCV: fast computer vision library written entirely in Java;

https://github.com/lessthanoptimal/boofcv

Page 75: DIY: Computer Vision with GWT.

.gwt.xml <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN" "http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">

<module rename-to='gwtboofcv'>

<inherits name='boofcv.BOOFCV'/>

<inherits name='com.jooink.gwtejml.gwtEJML_lib'/>

<inherits name='com.jooink.gwtddogleg.gwtDDogLeg_lib'/>

<inherits name='com.jooink.gwtGeoRegression.gwtGeoRegression_lib'/>

...

<super-source path="jre" />

...

</module>

Page 76: DIY: Computer Vision with GWT.

BoofCV

GWT-BOOFCV:

● Reflection

● Image managment

Page 77: DIY: Computer Vision with GWT.

BoofCV

GWT-BOOFCV:

● Reflection: ○ used mostly to handle Arrays of primitive

types○ probably unneeded upstream

working with Peter to understand if can be avoided through, for instance, a few of factories.

● Image managment

Page 78: DIY: Computer Vision with GWT.

BoofCV

Reflection:

java.lang.reflect.Array

Array.newInstance( … )

Array.getLength( … )

...

Page 79: DIY: Computer Vision with GWT.

BoofCV

GWT-BOOFCV:

● Reflection

● Image managment

Page 80: DIY: Computer Vision with GWT.

BoofCV

Image managment:

of course we had to work-out the different point of view about Images:

Browser → (<img/> <video/>)

BoofCV → array of values

→ we used <canvas/> (also in this case);

canvas.getContext2d().getImageData( … );

Page 81: DIY: Computer Vision with GWT.

BoofCV

EXAMPLES:

- Interest Point detection

- Interest point association

Page 82: DIY: Computer Vision with GWT.

BoofCV

EXAMPLE 1

Interest Point detection:

ImageFloat32

DetectDescribePoint<ImageFloat32,SurfFeature>detDesc.detect(boofImage);

Page 83: DIY: Computer Vision with GWT.

BoofCV

- Interest point

detection

http://static.jooink.com/experiments/boofcv-gwt/interest-points/

Page 84: DIY: Computer Vision with GWT.

BoofCV

- Interest point

association

Page 85: DIY: Computer Vision with GWT.

Questions? Contact us :

Francesca TosiR&D at Jooink [email protected]

Alberto ManciniDev at Jooink [email protected]

Thanks !Please rate this presentation http://gwtcreate.com/agenda


Recommended