SlideShare a Scribd company logo
Exploring the limits of HTML5
The Moustamera edition
What’s the goal?
+ + =
The contents
Accessing the camera
Using the Canvas & Haar.JS
Let’s fix that
Some useful tips
Part I
Accessing the Camera
Accessing the camera in pure HTML5
Just add this to your HTML
<video autoplay controls></video>
Accessing the camera in pure HTML5
And fire up the JavaScript!
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia || false;
if(!!navigator.getUserMedia)
{
navigator.getUserMedia({audio: true, video: true}, function(stream) {
var video = document.querySelector('video');
video.src = ('webkitURL' in window)?
window.webkitURL.createObjectURL(stream):stream;
}, onFailSoHard);
}
else
{
alert("not supported"); // fallback.
}
Accessing the camera in pure HTML5
The results?
Attempt II: Invoking the native camera
Simple
blackberry.invoke.card.invokeCamera(
blackberry.invoke.card.CAMERA_MODE_PHOTO,
function(path)
{
console.log('Picture path is: ' + path);
}, function(reason)
{
console.log('Cancelled for reason: ' + reason);
}, function(error)
{
console.log('Invoke error: ' + error);
}
);
Attempt II: Invoking the native camera
But don’t forget to edit your config.xml file!
<rim:permissions>
<rim:permit>access_shared</rim:permit>
<rim:permit>use_camera</rim:permit>
</rim:permissions>
<feature id="blackberry.invoke" />
<feature id="blackberry.invoke.card" />
<feature id="blackberry.io" />
<access uri="file:///accounts/1000/" />
Part II
Using the Canvas & HAAR.js
What is the HTML5 canvas?
Allows for dynamic, scriptable
rendering of 2D shapes and
bitmap images.
Container for on the fly
generated graphics
How do I create a HTML5 canvas?
<canvas></canvas>
What is HAAR.js?
A feature detection library for
JavaScript
Detect various features using
existing OpenCV cascades
Lets combine them!
new
HAAR.Detector(haarcascade_frontalface_alt).image(image).complete(
function()
{
console.log('Detection finished: ' + this.objects.length + "
Objects found");
drawImageToCanvas(image);
processDetectionResults(this.objects);
}
).detect(1, 1.25, 0.1, 1, true);
Somewhat impressive code block
-baseScale
-scale_inc
-increment
-min_neighbors
-doCannyPruning
Drawing an Image to the Canvas
function drawImageToCanvas(image)
{
var canvas = document.querySelector('canvas');
canvas.width = image.width;
canvas.height = image.height;
canvas.getContext('2d').drawImage(image, 0, 0, image.width,
image.height);
}
function processDetectionResults(objects)
{
for(var i = 0; i < objects.length; i++)
{
var rect = objects[i];
if(rect.width > 200) //Filter out mistakes
{
var moustache = new Image();
moustache.onload = function()
{
var x = rect.x + rect.width/2.0 - moustache.width/2.0;
var y = rect.y + rect.height/8*5;
var scaleFactor = rect.width/2 / moustache.width;
var moustacheHeight = moustache.height * scaleFactor;
canvas.getContext('2d').drawImage(moustache, x, y, rect.width/
2, moustacheHeight);
}
moustache.src = 'images/moustaches/' + selectedMoustache + '.png';
}
}
}
The result?
Part III
Let’s fix that
Why?
Looping several time over all 8MP
In JavaScript...
Solution?
Resize the image before detection!
In JavaScript...
Procedure
Load the picture in an Image object
Draw the picture on a canvas with the approximate size of the screen
Save that picture to the file system
Loading the original image
var image = new Image();
image.onload = function()
{
resizeImage(image, 'file://' + path);
}
image.src = 'file://' + path;
Resizing the image
function resizeImage(img, imagePath)
{
//Calculate the appropriate size
//width = ...;
//height = ...;
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
saveCanvas(canvas);
}
Saving the canvas to a PNG file
<script type="text/javascript" src="js/canvas-toBlob.min.js"></script>
function saveCanvas(canvas)
{
var filePath = blackberry.io.home + '/temp.png'
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(window.TEMPORARY, 5.0 * 1024 * 1024, function (fs)
{
console.log('Got FileSystem access...');
console.log('Trying to get a FileEntry object to ' + filePath + '...');
fs.root.getFile(filePath, {create: true}, function(fileEntry)
{
console.log('Got FileEntry access to ' + filePath + '...');
fileEntry.createWriter(function(fileWriter)
{
console.log('Got FileWriter access...');
fileWriter.onerror = onFileError;
fileWriter.onwriteend = function()
{
console.log('Done writing canvas to file ' + filePath);
};
//Save the image to the file system
canvas.toBlob(function (blob)
{
fileWriter.write(blob);
}, 'image/png');
}, onFileError);
}, onFileError);
}, onFileError);
}
function onFileError(e)
{
var msg = '';
switch (e.code)
{
case FileError.QUOTA_EXCEEDED_ERR:
msg = 'QUOTA_EXCEEDED_ERR';
break;
case FileError.NOT_FOUND_ERR:
msg = 'NOT_FOUND_ERR';
break;
case FileError.SECURITY_ERR:
msg = 'SECURITY_ERR';
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = 'INVALID_MODIFICATION_ERR';
break;
case FileError.INVALID_STATE_ERR:
msg = 'INVALID_STATE_ERR';
break;
default:
msg = 'Unknown Error';
break;
};
console.log('Error: ' + msg);
}
The result?
Part IV
Tips and tricks
Some bugs in WebWorks
2013-02-23 13:41:37 GET /ripple/build_status/8265 200
out: [INFO] java.lang.NullPointerException	at com.qnx.bbt.packager.Asset.setSourcePath(Asset.java:88)	 at com.qnx.bbt.packager.Asset.<init>(Asset.java:75)	 at
com.qnx.bbt.xml.BbtExtensionXml.getAsset(BbtExtensionXml.java:571)	 at com.qnx.bbt.xml.BbtExtensionXml.getAssets(BbtExtensionXml.java:541)	at
com.qnx.bbt.packager.BbtBarValueProvider.getAssets(BbtBarValueProvider.java:202)	 at com.qnx.bbt.bar.BARPackager.getAssets(BARPackager.java:71)	 at
com.qnx.bbt.bar.BARPackager.findAsset(BARPackager.java:233)
out: [INFO] 	 at com.qnx.bbt.bar.BARPackager.associateSourceAssets(BARPackager.java:227)	at
com.qnx.bbt.packager.AbstractPackager.parseDescriptorAndCreateBarManifest(AbstractPackager.java:577)	 at
com.qnx.bbt.packager.AbstractPackager.doRun(AbstractPackager.java:238)	 at com.qnx.bbt.packager.AbstractPackager.runPackager(AbstractPackager.java:164)	 at
com.qnx.bbt.nativepackager.BarNativePackager.main(BarNativePackager.java:61)
out: [ERROR] Error: null
out: [ERROR] Native Packager exception occurred
2013-02-23 13:41:38 GET /ripple/build_status/8265 200
2013-02-23 13:41:38 GET /ripple/build_status/8265 200
out: [INFO] java.lang.NullPointerException
out: [INFO] 	 at com.qnx.bbt.packager.Asset.setSourcePath(Asset.java:88)	 at com.qnx.bbt.packager.Asset.<init>(Asset.java:75)	 at
com.qnx.bbt.xml.BbtExtensionXml.getAsset(BbtExtensionXml.java:571)	 at com.qnx.bbt.xml.BbtExtensionXml.getAssets(BbtExtensionXml.java:541)	at
com.qnx.bbt.packager.BbtBarValueProvider.getAssets(BbtBarValueProvider.java:202)	 at com.qnx.bbt.bar.BARPackager.getAssets(BARPackager.java:71)
[INFO] 	 at com.qnx.bbt.bar.BARPackager.findAsset(BARPackager.java:233)
[INFO] 	 at com.qnx.bbt.bar.BARPackager.associateSourceAssets(BARPackager.java:227)
[INFO] 	 at com.qnx.bbt.packager.AbstractPackager.parseDescriptorAndCreateBarManifest(AbstractPackager.java:577)
[INFO] 	 at com.qnx.bbt.packager.AbstractPackager.doRun(AbstractPackager.java:238)
[INFO] 	 at com.qnx.bbt.packager.AbstractPackager.runPackager(AbstractPackager.java:164)
[INFO] 	 at com.qnx.bbt.nativepackager.BarNativePackager.main(BarNativePackager.java:61)
out: [ERROR] Error: null
out: [ERROR] Native Packager exception occurred
Done build
error response - {"code":1,"msg":"[ERROR] Error: nulln[ERROR] Native Packager exception occurredn[INFO] java.lang.NullPointerExceptionn[INFO] tat
com.qnx.bbt.packager.Asset.setSourcePath(Asset.java:88)tat com.qnx.bbt.packager.Asset.<init>(Asset.java:75)tat com.qnx.bbt.xml.BbtExtensionXml.getAsset(BbtExtensionXml.j
Solution?
Don’t use a folder named src in your WebWorks project!
Conclusion
Too early for HTML5 Camera (even on BB10)
JavaScript is not without limits
Everybody looks cool with a moustache!

More Related Content

What's hot

Brave new world of HTML5
Brave new world of HTML5Brave new world of HTML5
Brave new world of HTML5
Chris Mills
 
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 SederhanaPraktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
Muhammad Yusuf
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
Patrick Chanezon
 
фабрика Blockly
фабрика Blocklyфабрика Blockly
фабрика Blockly
Евгений Белов
 
JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New World
Robert Nyman
 
YUI 3
YUI 3YUI 3
YUI 3
Dav Glass
 
What the heck went wrong?
What the heck went wrong?What the heck went wrong?
What the heck went wrong?
Andy McKay
 
Sperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copySperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copy
Salvatore Iaconesi
 
YouDrup_in_Drupal
YouDrup_in_DrupalYouDrup_in_Drupal
YouDrup_in_Drupal
tutorialsruby
 
To Err Is Human
To Err Is HumanTo Err Is Human
To Err Is Human
Alex Liu
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
Robert Nyman
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
Constantin Titarenko
 
Prototype UI
Prototype UIPrototype UI
Prototype UI
Sébastien Gruhier
 
RicoLiveGrid
RicoLiveGridRicoLiveGrid
RicoLiveGrid
tutorialsruby
 
Web APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existedWeb APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existed
Zeno Rocha
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
What the FUF?
What the FUF?What the FUF?
What the FUF?
An Doan
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
philogb
 
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
Patrick Lauke
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?

What's hot (20)

Brave new world of HTML5
Brave new world of HTML5Brave new world of HTML5
Brave new world of HTML5
 
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 SederhanaPraktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 
фабрика Blockly
фабрика Blocklyфабрика Blockly
фабрика Blockly
 
JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New World
 
YUI 3
YUI 3YUI 3
YUI 3
 
What the heck went wrong?
What the heck went wrong?What the heck went wrong?
What the heck went wrong?
 
Sperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copySperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copy
 
YouDrup_in_Drupal
YouDrup_in_DrupalYouDrup_in_Drupal
YouDrup_in_Drupal
 
To Err Is Human
To Err Is HumanTo Err Is Human
To Err Is Human
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
Prototype UI
Prototype UIPrototype UI
Prototype UI
 
RicoLiveGrid
RicoLiveGridRicoLiveGrid
RicoLiveGrid
 
Web APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existedWeb APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existed
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
What the FUF?
What the FUF?What the FUF?
What the FUF?
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?
WebXR if X = how?
 

Similar to Moustamera

Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
PL dream
 
How to implement camera recording for USB webcam or IP camera in C#.NET
How to implement camera recording for USB webcam or IP camera in C#.NETHow to implement camera recording for USB webcam or IP camera in C#.NET
How to implement camera recording for USB webcam or IP camera in C#.NET
Ozeki Informatics Ltd.
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
Remy Sharp
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
Jussi Pohjolainen
 
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, MoscowJavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
Robert Nyman
 
Android workshop
Android workshopAndroid workshop
Android workshop
Michael Galpin
 
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsWebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
Robert Nyman
 
Web versus Native: round 1!
Web versus Native: round 1!Web versus Native: round 1!
Web versus Native: round 1!
Chris Mills
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
Ankara JUG
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
gerbille
 
Cutting edge HTML5 API you can use today (by Bohdan Rusinka)
 Cutting edge HTML5 API you can use today (by Bohdan Rusinka) Cutting edge HTML5 API you can use today (by Bohdan Rusinka)
Cutting edge HTML5 API you can use today (by Bohdan Rusinka)
Binary Studio
 
Webauthn Tutorial
Webauthn TutorialWebauthn Tutorial
Webauthn Tutorial
FIDO Alliance
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
philogb
 
JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the Platform
Robert Nyman
 
Getting Touchy Feely with the Web
Getting Touchy Feely with the WebGetting Touchy Feely with the Web
Getting Touchy Feely with the Web
Andrew Fisher
 
Vue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapyVue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapy
Darío Blanco Iturriaga
 
webinale2011_Chris Mills_Brave new world of HTML5Html5
webinale2011_Chris Mills_Brave new world of HTML5Html5webinale2011_Chris Mills_Brave new world of HTML5Html5
webinale2011_Chris Mills_Brave new world of HTML5Html5
smueller_sandsmedia
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloJavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
Robert Nyman
 
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
Frédéric Harper
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
Robert Nyman
 

Similar to Moustamera (20)

Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
How to implement camera recording for USB webcam or IP camera in C#.NET
How to implement camera recording for USB webcam or IP camera in C#.NETHow to implement camera recording for USB webcam or IP camera in C#.NET
How to implement camera recording for USB webcam or IP camera in C#.NET
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, MoscowJavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsWebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
 
Web versus Native: round 1!
Web versus Native: round 1!Web versus Native: round 1!
Web versus Native: round 1!
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
 
Cutting edge HTML5 API you can use today (by Bohdan Rusinka)
 Cutting edge HTML5 API you can use today (by Bohdan Rusinka) Cutting edge HTML5 API you can use today (by Bohdan Rusinka)
Cutting edge HTML5 API you can use today (by Bohdan Rusinka)
 
Webauthn Tutorial
Webauthn TutorialWebauthn Tutorial
Webauthn Tutorial
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
 
JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the Platform
 
Getting Touchy Feely with the Web
Getting Touchy Feely with the WebGetting Touchy Feely with the Web
Getting Touchy Feely with the Web
 
Vue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapyVue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapy
 
webinale2011_Chris Mills_Brave new world of HTML5Html5
webinale2011_Chris Mills_Brave new world of HTML5Html5webinale2011_Chris Mills_Brave new world of HTML5Html5
webinale2011_Chris Mills_Brave new world of HTML5Html5
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloJavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
 
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
 

Recently uploaded

Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 

Recently uploaded (20)

Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 

Moustamera

  • 1. Exploring the limits of HTML5 The Moustamera edition
  • 3. The contents Accessing the camera Using the Canvas & Haar.JS Let’s fix that Some useful tips
  • 5. Accessing the camera in pure HTML5 Just add this to your HTML <video autoplay controls></video>
  • 6. Accessing the camera in pure HTML5 And fire up the JavaScript! navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || false; if(!!navigator.getUserMedia) { navigator.getUserMedia({audio: true, video: true}, function(stream) { var video = document.querySelector('video'); video.src = ('webkitURL' in window)? window.webkitURL.createObjectURL(stream):stream; }, onFailSoHard); } else { alert("not supported"); // fallback. }
  • 7. Accessing the camera in pure HTML5 The results?
  • 8. Attempt II: Invoking the native camera Simple blackberry.invoke.card.invokeCamera( blackberry.invoke.card.CAMERA_MODE_PHOTO, function(path) { console.log('Picture path is: ' + path); }, function(reason) { console.log('Cancelled for reason: ' + reason); }, function(error) { console.log('Invoke error: ' + error); } );
  • 9. Attempt II: Invoking the native camera But don’t forget to edit your config.xml file! <rim:permissions> <rim:permit>access_shared</rim:permit> <rim:permit>use_camera</rim:permit> </rim:permissions> <feature id="blackberry.invoke" /> <feature id="blackberry.invoke.card" /> <feature id="blackberry.io" /> <access uri="file:///accounts/1000/" />
  • 10. Part II Using the Canvas & HAAR.js
  • 11. What is the HTML5 canvas? Allows for dynamic, scriptable rendering of 2D shapes and bitmap images. Container for on the fly generated graphics
  • 12. How do I create a HTML5 canvas? <canvas></canvas>
  • 13. What is HAAR.js? A feature detection library for JavaScript Detect various features using existing OpenCV cascades
  • 14. Lets combine them! new HAAR.Detector(haarcascade_frontalface_alt).image(image).complete( function() { console.log('Detection finished: ' + this.objects.length + " Objects found"); drawImageToCanvas(image); processDetectionResults(this.objects); } ).detect(1, 1.25, 0.1, 1, true); Somewhat impressive code block -baseScale -scale_inc -increment -min_neighbors -doCannyPruning
  • 15. Drawing an Image to the Canvas function drawImageToCanvas(image) { var canvas = document.querySelector('canvas'); canvas.width = image.width; canvas.height = image.height; canvas.getContext('2d').drawImage(image, 0, 0, image.width, image.height); }
  • 16. function processDetectionResults(objects) { for(var i = 0; i < objects.length; i++) { var rect = objects[i]; if(rect.width > 200) //Filter out mistakes { var moustache = new Image(); moustache.onload = function() { var x = rect.x + rect.width/2.0 - moustache.width/2.0; var y = rect.y + rect.height/8*5; var scaleFactor = rect.width/2 / moustache.width; var moustacheHeight = moustache.height * scaleFactor; canvas.getContext('2d').drawImage(moustache, x, y, rect.width/ 2, moustacheHeight); } moustache.src = 'images/moustaches/' + selectedMoustache + '.png'; } } }
  • 19. Why? Looping several time over all 8MP In JavaScript...
  • 20. Solution? Resize the image before detection! In JavaScript...
  • 21. Procedure Load the picture in an Image object Draw the picture on a canvas with the approximate size of the screen Save that picture to the file system
  • 22. Loading the original image var image = new Image(); image.onload = function() { resizeImage(image, 'file://' + path); } image.src = 'file://' + path;
  • 23. Resizing the image function resizeImage(img, imagePath) { //Calculate the appropriate size //width = ...; //height = ...; var canvas = document.createElement("canvas"); canvas.width = width; canvas.height = height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0, width, height); saveCanvas(canvas); }
  • 24. Saving the canvas to a PNG file <script type="text/javascript" src="js/canvas-toBlob.min.js"></script>
  • 25. function saveCanvas(canvas) { var filePath = blackberry.io.home + '/temp.png' window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; window.requestFileSystem(window.TEMPORARY, 5.0 * 1024 * 1024, function (fs) { console.log('Got FileSystem access...'); console.log('Trying to get a FileEntry object to ' + filePath + '...'); fs.root.getFile(filePath, {create: true}, function(fileEntry) { console.log('Got FileEntry access to ' + filePath + '...'); fileEntry.createWriter(function(fileWriter) { console.log('Got FileWriter access...'); fileWriter.onerror = onFileError; fileWriter.onwriteend = function() { console.log('Done writing canvas to file ' + filePath); }; //Save the image to the file system canvas.toBlob(function (blob) { fileWriter.write(blob); }, 'image/png'); }, onFileError); }, onFileError); }, onFileError); }
  • 26. function onFileError(e) { var msg = ''; switch (e.code) { case FileError.QUOTA_EXCEEDED_ERR: msg = 'QUOTA_EXCEEDED_ERR'; break; case FileError.NOT_FOUND_ERR: msg = 'NOT_FOUND_ERR'; break; case FileError.SECURITY_ERR: msg = 'SECURITY_ERR'; break; case FileError.INVALID_MODIFICATION_ERR: msg = 'INVALID_MODIFICATION_ERR'; break; case FileError.INVALID_STATE_ERR: msg = 'INVALID_STATE_ERR'; break; default: msg = 'Unknown Error'; break; }; console.log('Error: ' + msg); }
  • 29. Some bugs in WebWorks 2013-02-23 13:41:37 GET /ripple/build_status/8265 200 out: [INFO] java.lang.NullPointerException at com.qnx.bbt.packager.Asset.setSourcePath(Asset.java:88) at com.qnx.bbt.packager.Asset.<init>(Asset.java:75) at com.qnx.bbt.xml.BbtExtensionXml.getAsset(BbtExtensionXml.java:571) at com.qnx.bbt.xml.BbtExtensionXml.getAssets(BbtExtensionXml.java:541) at com.qnx.bbt.packager.BbtBarValueProvider.getAssets(BbtBarValueProvider.java:202) at com.qnx.bbt.bar.BARPackager.getAssets(BARPackager.java:71) at com.qnx.bbt.bar.BARPackager.findAsset(BARPackager.java:233) out: [INFO] at com.qnx.bbt.bar.BARPackager.associateSourceAssets(BARPackager.java:227) at com.qnx.bbt.packager.AbstractPackager.parseDescriptorAndCreateBarManifest(AbstractPackager.java:577) at com.qnx.bbt.packager.AbstractPackager.doRun(AbstractPackager.java:238) at com.qnx.bbt.packager.AbstractPackager.runPackager(AbstractPackager.java:164) at com.qnx.bbt.nativepackager.BarNativePackager.main(BarNativePackager.java:61) out: [ERROR] Error: null out: [ERROR] Native Packager exception occurred 2013-02-23 13:41:38 GET /ripple/build_status/8265 200 2013-02-23 13:41:38 GET /ripple/build_status/8265 200 out: [INFO] java.lang.NullPointerException out: [INFO] at com.qnx.bbt.packager.Asset.setSourcePath(Asset.java:88) at com.qnx.bbt.packager.Asset.<init>(Asset.java:75) at com.qnx.bbt.xml.BbtExtensionXml.getAsset(BbtExtensionXml.java:571) at com.qnx.bbt.xml.BbtExtensionXml.getAssets(BbtExtensionXml.java:541) at com.qnx.bbt.packager.BbtBarValueProvider.getAssets(BbtBarValueProvider.java:202) at com.qnx.bbt.bar.BARPackager.getAssets(BARPackager.java:71) [INFO] at com.qnx.bbt.bar.BARPackager.findAsset(BARPackager.java:233) [INFO] at com.qnx.bbt.bar.BARPackager.associateSourceAssets(BARPackager.java:227) [INFO] at com.qnx.bbt.packager.AbstractPackager.parseDescriptorAndCreateBarManifest(AbstractPackager.java:577) [INFO] at com.qnx.bbt.packager.AbstractPackager.doRun(AbstractPackager.java:238) [INFO] at com.qnx.bbt.packager.AbstractPackager.runPackager(AbstractPackager.java:164) [INFO] at com.qnx.bbt.nativepackager.BarNativePackager.main(BarNativePackager.java:61) out: [ERROR] Error: null out: [ERROR] Native Packager exception occurred Done build error response - {"code":1,"msg":"[ERROR] Error: nulln[ERROR] Native Packager exception occurredn[INFO] java.lang.NullPointerExceptionn[INFO] tat com.qnx.bbt.packager.Asset.setSourcePath(Asset.java:88)tat com.qnx.bbt.packager.Asset.<init>(Asset.java:75)tat com.qnx.bbt.xml.BbtExtensionXml.getAsset(BbtExtensionXml.j
  • 30. Solution? Don’t use a folder named src in your WebWorks project!
  • 32. Too early for HTML5 Camera (even on BB10) JavaScript is not without limits Everybody looks cool with a moustache!