{"id":30150,"date":"2017-05-11T03:01:20","date_gmt":"2017-05-10T17:01:20","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=30150"},"modified":"2017-07-15T19:31:37","modified_gmt":"2017-07-15T09:31:37","slug":"webcam-photobooth-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/webcam-photobooth-tutorial\/","title":{"rendered":"Webcam Photobooth Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/webcamtest\/index.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Webcam Photobooth Tutorial\" src=\"https:\/\/www.rjmprogramming.com.au\/webcamtest\/webcamtest.png\" title=\"Webcam Photobooth Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Webcam Photobooth Tutorial<\/p><\/div>\n<p>The <a target=_blank href='https:\/\/en.wikipedia.org\/wiki\/Webcam' title='Webcam information from Wikipedia ... thanks'>webcam<\/a> of a computer device can be like a video selfie except that when filming something it can be flipped horizontally, like when dealing with mirrors, on occasions, especially after a heavy night!  And that&#8217;s where the Mac OS X (and iOS) <a target=_blank title='Mac OS X apps out of the box' href='https:\/\/support.apple.com\/kb\/PH18738'>Photobooth<\/a> desktop (or mobile &#8220;desktop&#8221;) application comes to our thinking.  It has a very useful option <i>Edit &gt; Auto Flip New Items<\/i>, a simulation of functionality we&#8217;d like to add onto the web application of our previous <a title='Webcam Primer Tutorial' href='#wpt'>Webcam Primer Tutorial<\/a> as shown below.  The thought of doing all this to the implicit video of the Webcam sounds daunting, but the clue to this being easier than expected came from the &#8220;bowels&#8221; of that previous tutorial, basing itself on the help of a few excellent links you can link into below too, and its use of an HTML(5) canvas element to be an intermediary between the webcam (video) and your dear little selves.  And it is on this canvas (sounds apt to say &#8220;palette&#8221; today) that there are tremendous HTML5 &#8220;goodies&#8221; functionality-wise to call on to be able to &#8230;<\/p>\n<ul>\n<li><a target=_blank href='https:\/\/www.w3schools.com\/tags\/canvas_scale.asp' title='HTML(5) canvas element scale method information from w3schools'>scale<\/a><\/li>\n<li><a target=_blank href='https:\/\/www.w3schools.com\/tags\/canvas_rotate.asp' title='HTML(5) canvas element rotate method information from w3schools'>rotate<\/a><\/li>\n<li><a target=_blank href='https:\/\/www.w3schools.com\/tags\/canvas_translate.asp' title='HTML(5) canvas element translate method information from w3schools'>translate<\/a><\/li>\n<\/ul>\n<p> &#8230; and so, effectively (horizontally) &#8220;flip&#8221; (or also today&#8217;s &#8220;we didn&#8217;t know&#8221; flop (meaning vertically flip)) the canvas right there in the middle of the action, doing twirls and triple pikes just for you gals and guys &#8230; awwwww, shucks!  This ability of our Webcam application was precisely what was missing as we lamented in yesterday&#8217;s <a title='Windows Memory Stick Research Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/windows-memory-stick-research-primer-tutorial\/'>Windows Memory Stick Research Primer Tutorial<\/a> &#8230;<\/p>\n<blockquote cite='https:\/\/www.rjmprogramming.com.au\/ITblog\/windows-memory-stick-research-primer-tutorial\/'><p>\nThe YouTube\u2019s genesis was from the Mac OS X desktop application PhotoBooth, mainly done this way because of its excellent Edit -&gt; Auto Flip New Items option, otherwise we\u2019d have used our recent Webcam web application.\n<\/p><\/blockquote>\n<p>We&#8217;d like to thank <a target=_blank title='Useful link, thanks' href='http:\/\/stackoverflow.com\/questions\/3129099\/how-to-flip-images-horizontally-with-html5'>this webpage<\/a> for a great Javascript function to manipulate our HTML(5) canvas element this way.<\/p>\n<p>This opens our web application up to allowing you to use a Webcam to show a &#8220;filmed&#8221; thing in an unmirrored context, and so, if you, as we did today with our YouTube video &#8230;<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/kpMSroD06ys\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p> &#8230; <i>record<\/i> this from afar, as we did with an iPad Camera app&#8217;s Video mode, it will appear the correct way around, as the Photobooth application can also do, and was the genesis of our inspiration to do today.<\/p>\n<p>We&#8217;ll leave you the HTML and Javascript code we&#8217;ve got those <strike>three<\/strike> four links <strike>above<\/strike> to thank for, mainly.  The code can be downloaded and\/or perused via the <a target=_blank title='webcamtest.html' href='http:\/\/www.rjmprogramming.com.au\/webcamtest\/webcamtest.html-GETME'>webcamtest.html<\/a> (https:) source code link, that changed for today&#8217;s purposes in <a target=_blank title='webcamtest.html' href='http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/webcamtest\/webcamtest.html-GETME'>this way<\/a>. To try it out for yourself, if your computer device suits, try this <a target=_blank title='Click picture' href='https:\/\/www.rjmprogramming.com.au\/webcamtest\/webcamtest.html'>live run<\/a> link.<\/p>\n<hr>\n<p id='wpt'>Previous relevant <a target=_blank title='Webcam Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/webcam-primer-tutorial\/'>Webcam Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/webcamtest\/index.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Webcam Primer Tutorial\" src=\"https:\/\/www.rjmprogramming.com.au\/webcamtest\/webcamtest.jpg\" title=\"Webcam Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Webcam Primer Tutorial<\/p><\/div>\n<p>The <a target=_blank href='https:\/\/en.wikipedia.org\/wiki\/Webcam' title='Webcam information from Wikipedia ... thanks'>webcam<\/a> of a computer device can be a very useful piece of hardware.  We&#8217;ve written an &#8220;entry level&#8221; web application using your device&#8217;s webcam, should it have one, and should you give permission for the web application to access it, and if the web browser and platform combination you use suits some or all of the functionality offered in this first draft.  We would like to thank three great online resources for the code stitched together for this first draft web application, those being &#8230;<\/p>\n<ol>\n<li><a target=_blank title='https:\/\/www.kirupa.com\/html5\/accessing_your_webcam_in_html5.htm' href='https:\/\/www.kirupa.com\/html5\/accessing_your_webcam_in_html5.htm'>www.kirupa.com<\/a> link taught us about the getUserMedia method of the navigator object &#8230;<\/li>\n<li><a target=_blank title='https:\/\/software.intel.com\/en-us\/html5\/hub\/blogs\/using-the-getusermedia-api-with-the-html5-video-and-canvas-elements' href='https:\/\/software.intel.com\/en-us\/html5\/hub\/blogs\/using-the-getusermedia-api-with-the-html5-video-and-canvas-elements'>software.intel.com<\/a> link helped us with code and event logic allowing for a 33mS refresh of the webcam&#8217;s underlying <a target=_blank href='https:\/\/www.w3schools.com\/html\/html5_video.asp' title='HTML video element information from w3schools'>video<\/a> to an HTML(5) <a target=_blank href='https:\/\/www.w3schools.com\/html\/html5_canvas.asp' title='HTML(5) canvas element information from w3schools'>canvas<\/a> element, along with a greyscale manipulation of that canvas element&#8217;s &#8220;snapshot in time&#8221; contents<\/li>\n<li><a target=_blank href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Canvas_API\/Tutorial\/Pixel_manipulation_with_canvas' title='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Canvas_API\/Tutorial\/Pixel_manipulation_with_canvas'>developer.mozilla.org<\/a> link helped us with some other image within canvas pixel level functionalities such as colour reversal, and zooming in ((like a magnifier) as you see often on eCommerce product pages) and an individual canvas pixel rgba(r,g,b,opacity) report<\/li>\n<\/ol>\n<p>None of this functionality calls on anything else but HTML(5) and Javascript &#8220;smarts&#8221;, and is eye opening in that way, no doubt.<\/p>\n<p>And so today&#8217;s first draft is mainly about the webcam (hardware) &#8220;capture&#8221; capabilities, its &#8220;conduit&#8221; to the outside world &#8230; that being you user gals and guys &#8230; say hello &#8230; is that curious and exciting notion that you capture the webcam video <a target=_blank href='https:\/\/en.wikipedia.org\/wiki\/Streaming_media' title='Media streaming information from Wikipedia ... thanks'>streaming<\/a> &#8220;snapshot&#8221; fast enough into a canvas element, it looks like you are just dealing with a &#8220;magical&#8221; canvas, though the (usually green) webcam light on your device (and the web browser tab (usually red) light, and any other web browser webcam icons shown) should be the giveaway that a webcam underpins the goings on.<\/p>\n<p>There are cross-platform and cross-browser issues with webcams, that is for sure.  Maybe you&#8217;ve gone and clicked the <a target=_blank title='Click picture' href='https:\/\/www.rjmprogramming.com.au\/webcamtest\/webcamtest.html'>live run<\/a> equivalent of clicking the tutorial&#8217;s picture, already, above, and noticed a slightly different pattern of arrangement to our usual.  We direct you to an https: URL, because the Google Chrome web browser asks for this type of URL to go with allowing permission to access the device&#8217;s webcam.<\/p>\n<p>And so that leaves us to show you the HTML and Javascript code we&#8217;ve got those three links above to thank for, mainly.  The code can be downloaded and\/or perused via the <a target=_blank title='webcamtest.html' href='https:\/\/www.rjmprogramming.com.au\/webcamtest\/webcamtest.html_GETME'>webcamtest.html<\/a> (https:) source code link.  We also direct you to a video we made for you to visualize all this, below &#8230;<\/p>\n<p><video controls><source type='video\/mp4' src=\"https:\/\/www.rjmprogramming.com.au\/webcamtest\/webcamtest.m4v\"><\/source><\/video><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d29927' onclick='var dv=document.getElementById(\"d29927\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/webcam\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d29927' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d30150' onclick='var dv=document.getElementById(\"d30150\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/photobooth\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d30150' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The webcam of a computer device can be like a video selfie except that when filming something it can be flipped horizontally, like when dealing with mirrors, on occasions, especially after a heavy night! And that&#8217;s where the Mac OS &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/webcam-photobooth-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,18,37],"tags":[183,184,275,278,375,2188,520,576,578,590,630,652,2189,927,1918,997,1065,1071,1094,1300,1319,1369,1413,1498],"class_list":["post-30150","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-hardware","category-tutorials","tag-camera","tag-canvas","tag-cross-browser","tag-cross-platform","tag-ecommerce","tag-getusermedia","tag-google-chrome","tag-html","tag-html5","tag-image","tag-ipad","tag-javascript","tag-navigator","tag-photobooth","tag-pixel","tag-programming","tag-rgb","tag-rotate","tag-scale","tag-translate","tag-tutorial","tag-video","tag-webcam","tag-zoom"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/30150"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=30150"}],"version-history":[{"count":15,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/30150\/revisions"}],"predecessor-version":[{"id":31486,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/30150\/revisions\/31486"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=30150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=30150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=30150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}