{"title":"Joe Thomas - Python","link":[{"@attributes":{"href":"https:\/\/jsthomas.github.io\/","rel":"alternate"}},{"@attributes":{"href":"https:\/\/jsthomas.github.io\/feeds\/python.atom.xml","rel":"self"}}],"id":"https:\/\/jsthomas.github.io\/","updated":"2013-12-10T00:00:00-05:00","entry":{"title":"A Camera-Based Virtual Keyboard System","link":{"@attributes":{"href":"https:\/\/jsthomas.github.io\/vkeyboard.html","rel":"alternate"}},"published":"2013-12-10T00:00:00-05:00","updated":"2013-12-10T00:00:00-05:00","author":{"name":"Joe Thomas"},"id":"tag:jsthomas.github.io,2013-12-10:\/vkeyboard.html","summary":"<p>A brief summary of my term project for ECE 532<\/p>","content":"<p>In the Fall of 2013, I developed a camera-based keyboard system as my\nterm project for an image analysis course. This page provides a brief\nsummary of my project.<\/p>\n<p>In my system, a webcam looks down on a user's hands, which rest on a\npaper keyboard template. My program collects images from the webcam to\ndetermine when and where the user touches the keyboard template. When\nthe user touches a key, my program produces the corresponding letter\nas output.<\/p>\n<p>Virtual keyboards are still actively researched in computer science\nand electrical engineering. The system I implemented uses techniques\npublished in [1]-[3] between 2010 and 2013. Camera-based virtual\nkeyboards require a number of interesting image analysis techniques to\nimplement. They are particularly of interest in mobile applications\nand in areas where one would like to avoid the cost of a physical\nkeyboard (for example, projects providing computers to people in the\ndeveloping world).<\/p>\n<h1>Processing Steps<\/h1>\n<p>The virtual keyboard system I implemented needed to solve three main\nproblems:<\/p>\n<ol>\n<li>\n<p>Detect the locations of the user's fingertips.<\/p>\n<\/li>\n<li>\n<p>Detect whether any fingertips are in contact with the tabletop.<\/p>\n<\/li>\n<li>\n<p>When a fingertip touches the tabletop, determine which key was\npressed on the keyboard.<\/p>\n<\/li>\n<\/ol>\n<p>The first problem can be solved by segmenting an input image <span class=\"math\">\\(I\\)<\/span> into\ntwo regions: one representing the hands and another representing the\nbackground. For each connected component of the hand region, we can\nextract a contour <span class=\"math\">\\(\\gamma\\)<\/span> that traverses the boundary\ncounterclockwise. Places where <span class=\"math\">\\(\\gamma\\)<\/span> has high curvature (the\nplaces where <span class=\"math\">\\(\\gamma\\)<\/span> bends the most sharply) typically correspond to\nfingertips.<\/p>\n<p><img alt=\"Virtual keyboard processing steps.\" src=\"https:\/\/jsthomas.github.io\/images\/vkeyboard\/kb_processing.png\"><\/p>\n<p>I addressed the second problem using a technique called <em>shadow\nanalysis<\/em>, which is discussed in [1]. With this technique, we perform\nanother segmentation on <span class=\"math\">\\(I\\)<\/span>, to locate the regions in the image that\nrepresent the shadows of the user's hands. Then, we examine small\nneighborhoods near the user's fingertips. If the proportion of\nshadow-pixels in a given neighborhood is above a certain threshold, we\ninfer that the corresponding fingertip is not in contact with the\ntabletop (because it has a shadow). Otherwise, we declare that\nfingertip to be touching the keyboard.<\/p>\n<p>The last problem is solved by making some assumptions about the\ngeometry of the keyboard and imaging system. I assumed that the\nkeyboard template displays four easily identifiable control points\narranged in a rectangle, and that the front edge of the control\nrectangle is parallel to the <span class=\"math\">\\(x\\)<\/span>-axis of the camera's coordinate\nsystem. With these additional assumptions, it isn't too hard to invert\nthe perspective projection and recover the keyboard-space coordinates\nof each keypress from the image-space coordinates of the fingertips.<\/p>\n<h1>Results<\/h1>\n<p>After implementing my virtual keyboard system in python, I analyzed\nits performance under different lighting and usage conditions. My\ntests suggest that a camera-based user interface that uses shadow\nanalysis will work best under conditions where one has fine control\nover the lighting conditions and the user does not need to enter very\nmuch data at one time. For example, a camera-based user interface\nwould work well in an interactive museum exhibit, but it might not be\na very good tool for word processing in a dark coffee shop. Currently,\ncamera-based keyboards cannot provide the speed and accuracy\nachievable on physical keyboards (but for that matter, neither do\ntouchscreen keyboards).<\/p>\n<h1>Downloads<\/h1>\n<p>Below are links to the paper and code I wrote for the term project. I\nused the code within <a href=\"http:\/\/ipython.org\/\">ipython<\/a> to conduct my\nexperiments, and used the <a href=\"http:\/\/opencv.org\/\">OpenCV<\/a> project to get\ndata from the camera. OpenCV's support for python is still under\ndevelopment, so if you examine my code you may have to adapt it to\nwork with your particular hardware and copy of OpenCV.<\/p>\n<ul>\n<li>\n<p>Paper:\n  <a href=\"https:\/\/jsthomas.github.io\/docs\/vkeyboard\/vkeyboard.pdf\">A Camera Based Virtual Keyboard with Touch Detection by Shadow Analysis<\/a><\/p>\n<\/li>\n<li>\n<p>Project Code: <a href=\"https:\/\/jsthomas.github.io\/docs\/vkeyboard\/vkeyboard.zip\">vkeyboard.zip<\/a><\/p>\n<\/li>\n<\/ul>\n<h2>References<\/h2>\n<ol>\n<li>\n<p>Y. Adajania, J. Gosalia, A. Kanade, H. Mehta, and N. Shekokar. Virtual\nkeyboard using shadow analysis. In Emerging Trends in Engineering and\nTechnology (ICETET), 2010 3rd International Conference on, page 163 to\n165, 2010.<\/p>\n<\/li>\n<li>\n<p>E. Posner, N. Starzicki, and E. Katz. A single camera based floating virtual\nkeyboard with improved touch detection. In Electrical Electronics Engineers\nin Israel (IEEEI), 2012 IEEE 27th Convention of, page 1 to 5, 2012.<\/p>\n<\/li>\n<li>\n<p>M. Hagara and J. Pucik. Fingertip detection for virtual keyboard\nbased on camera. In Radioelektronika (RADIOELEKTRONIKA), 2013 23rd\nInternational Conference, page 356 to 360, 2013.<\/p>\n<\/li>\n<\/ol>\n<script type=\"text\/javascript\">if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {\n    var align = \"center\",\n        indent = \"0em\",\n        linebreak = \"false\";\n\n    if (false) {\n        align = (screen.width < 768) ? \"left\" : align;\n        indent = (screen.width < 768) ? \"0em\" : indent;\n        linebreak = (screen.width < 768) ? 'true' : linebreak;\n    }\n\n    var mathjaxscript = document.createElement('script');\n    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';\n    mathjaxscript.type = 'text\/javascript';\n    mathjaxscript.src = 'https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/mathjax\/2.7.3\/latest.js?config=TeX-AMS-MML_HTMLorMML';\n\n    var configscript = document.createElement('script');\n    configscript.type = 'text\/x-mathjax-config';\n    configscript[(window.opera ? \"innerHTML\" : \"text\")] =\n        \"MathJax.Hub.Config({\" +\n        \"    config: ['MMLorHTML.js'],\" +\n        \"    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } },\" +\n        \"    jax: ['input\/TeX','input\/MathML','output\/HTML-CSS'],\" +\n        \"    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js'],\" +\n        \"    displayAlign: '\"+ align +\"',\" +\n        \"    displayIndent: '\"+ indent +\"',\" +\n        \"    showMathMenu: true,\" +\n        \"    messageStyle: 'normal',\" +\n        \"    tex2jax: { \" +\n        \"        inlineMath: [ ['\\\\\\\\(','\\\\\\\\)'] ], \" +\n        \"        displayMath: [ ['$$','$$'] ],\" +\n        \"        processEscapes: true,\" +\n        \"        preview: 'TeX',\" +\n        \"    }, \" +\n        \"    'HTML-CSS': { \" +\n        \"        availableFonts: ['STIX', 'TeX'],\" +\n        \"        preferredFont: 'STIX',\" +\n        \"        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} },\" +\n        \"        linebreaks: { automatic: \"+ linebreak +\", width: '90% container' },\" +\n        \"    }, \" +\n        \"}); \" +\n        \"if ('default' !== 'default') {\" +\n            \"MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {\" +\n                \"var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;\" +\n                \"VARIANT['normal'].fonts.unshift('MathJax_default');\" +\n                \"VARIANT['bold'].fonts.unshift('MathJax_default-bold');\" +\n                \"VARIANT['italic'].fonts.unshift('MathJax_default-italic');\" +\n                \"VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');\" +\n            \"});\" +\n            \"MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {\" +\n                \"var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;\" +\n                \"VARIANT['normal'].fonts.unshift('MathJax_default');\" +\n                \"VARIANT['bold'].fonts.unshift('MathJax_default-bold');\" +\n                \"VARIANT['italic'].fonts.unshift('MathJax_default-italic');\" +\n                \"VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');\" +\n            \"});\" +\n        \"}\";\n\n    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);\n    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);\n}\n<\/script>","category":{"@attributes":{"term":"Python"}}}}