SlideShare uma empresa Scribd logo
1 de 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!

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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?
 

Semelhante a 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
 

Semelhante a 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
 

Último

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
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
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Último (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
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
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

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!