SlideShare ist ein Scribd-Unternehmen logo
1 von 32
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!

Weitere ähnliche Inhalte

Was ist angesagt?

Brave new world of HTML5
Brave new world of HTML5Brave new world of HTML5
Brave new world of HTML5Chris 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 SederhanaMuhammad 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
 
JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldRobert Nyman
 
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 copySalvatore Iaconesi
 
To Err Is Human
To Err Is HumanTo Err Is Human
To Err Is HumanAlex 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 meansRobert Nyman
 
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 existedZeno 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 2KThomas 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 - BogotaJSphilogb
 
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
 

Was ist angesagt? (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?
 

Ähnlich wie Moustamera

Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL 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#.NETOzeki 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 anymoreRemy Sharp
 
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, MoscowRobert Nyman
 
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsWebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsRobert 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 todaygerbille
 
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
 
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 Datosphilogb
 
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 PlatformRobert Nyman
 
Getting Touchy Feely with the Web
Getting Touchy Feely with the WebGetting Touchy Feely with the Web
Getting Touchy Feely with the WebAndrew 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 therapyDarí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 HTML5Html5smueller_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 PauloRobert 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-07Fré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, ChileRobert Nyman
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

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!