{"id":204,"date":"2013-02-18T11:29:33","date_gmt":"2013-02-18T16:29:33","guid":{"rendered":"https:\/\/peterabeles.com\/blog\/?p=204"},"modified":"2013-02-21T20:13:29","modified_gmt":"2013-02-22T01:13:29","slug":"boofcv-android-demo-application","status":"publish","type":"post","link":"https:\/\/peterabeles.com\/blog\/?p=204","title":{"rendered":"BoofCV Android Demo Application"},"content":{"rendered":"<p>I recently wrote an application to demonstrate some of the capabilities BoofCV on Android.\u00a0 BoofCV is an open source computer vision library that I&#8217;m working on written entirely in Java.\u00a0 The v0.13 update to BoofCV added functions for converting NV21 images (camera preview format) into BoofCV data types and provided Android specific visualization code.\u00a0 The end result is that it is now easier to write fast real-time image processing applications on Android using BoofCV.\u00a0 The source code for the demo application has also be released without restrictions.<\/p>\n<ul>\n<li><a href=\"https:\/\/play.google.com\/store\/apps\/details?id=org.boofcv.android\">Application on Android Store<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/lessthanoptimal\/BoofAndroidDemo\">Source code on GitHub<\/a><\/li>\n<\/ul>\n<h3>General Tips<\/h3>\n<ul>\n<li>Cell phone cameras are poor quality and suffer from motion blur and rolling shutters.<\/li>\n<li>Everything will work better when viewed with good lighting, allowing for faster shutter speeds.<\/li>\n<li>When selecting images for association you can swipe to remove previous selection.\u00a0 Also try tapping and double tapping.<\/li>\n<li>Image mosaic and stabilization work best when viewing far away objects, pure rotations, and planar surfaces.<\/li>\n<li>When tapping the screen to capture an image, do so gently or else the image will be blurred.<\/li>\n<li>On slower devices, pressing the back button to leave a slow process can crash the app and require you to manually kill it.<\/li>\n<li>Changing the camera preview size to &#8220;large&#8221; images can cause out of memory exceptions.<\/li>\n<\/ul>\n<h2>Camera Calibration<\/h2>\n<div id=\"attachment_208\" style=\"width: 330px\" class=\"wp-caption alignright\"><a href=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_detect_calib.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-208\" class=\" wp-image-208 \" title=\"Detected Pattern\" alt=\"Detected square grid pattern.  Red dots show calibration points.\" src=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_detect_calib.jpg\" width=\"320\" height=\"180\" srcset=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_detect_calib.jpg 400w, https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_detect_calib-300x168.jpg 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><p id=\"caption-attachment-208\" class=\"wp-caption-text\">Detected square grid pattern. Red dots show calibration points.<\/p><\/div>\n<p>Camera calibration is required for 3D vision applications.\u00a0 It will allow radial lens distortion to be removed and other intrinsic camera parameters to be known.\u00a0 To calibrate the camera print out a calibration grid and follow the general instructions from the link below.\u00a0 Note that the printed image can be rescaled for this application.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/boofcv.org\/index.php?title=Tutorial_Camera_Calibration\">http:\/\/boofcv.org\/index.php?title=Tutorial_Camera_Calibration<\/a><\/p>\n<p>After you have printed the calibration target, take pictures of it (by <strong>gently<\/strong> tapping the screen) from at least 5 different views and angles.\u00a0 Most of the pictures should be taken from about 30 degree angle.\u00a0 When you are done taking pictures, press the &#8220;Compute&#8221; button to find the intrinsic parameters.\u00a0 When taking pictures it is recommended that you are sitting down on the ground holding your Android device with both hands.\u00a0 This is more stable and reduces motion blur, greatly reducing the frustration factor.\u00a0 Try to fill as much of the screen as possible with the calibration target and if one looks like it might be blurred click the remove button.\u00a0 On my Sampson Galaxy S3 and Droid 2 I get about 0.2 pixels mean error on good runs and more than a pixel error when things go badly.<\/p>\n<h2>Stereo<\/h2>\n<div id=\"attachment_211\" style=\"width: 330px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_stereo.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-211\" class=\" wp-image-211 \" title=\"Stereo Depth Image\" alt=\"android_stereo\" src=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_stereo.jpg\" width=\"320\" height=\"180\" srcset=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_stereo.jpg 400w, https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_stereo-300x168.jpg 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><p id=\"caption-attachment-211\" class=\"wp-caption-text\">Stereo depth image computed from two views of the same object. Warmer colors indicate closer objects and color farther away.<\/p><\/div>\n<p style=\"text-align: left;\">Stereo vision allows the scene&#8217;s 3D structure to be computed.\u00a0 This is accomplished using a single camera using taking pictures of the same object two times from two different points of view.\u00a0 Camera calibration is required before stereo vision can be computed since lens distortion must be removed.\u00a0 On a Droid 2 cell phone (phone from around 2010\/2011) the whole process can take 25 seconds or so, but on a Galaxy S3 (phone from 2012) it only takes four seconds.<\/p>\n<p>To compute a stereo depth image first tap the screen to take a picture. Then move the camera left or right with a little rotation, up\/down, and forwards\/backwards motion as possible.\u00a0 How far you should move the camera depends on how far away the objects are.\u00a0 For close objects 1cm is often good and for objects a few feet away (1 meter) 3cm\/1inch works well.\u00a0 Moving the camera too much tends to be a more common mistake than moving it too little.\u00a0 It will probably take you a few tries to get a good image.\u00a0 Also make sure the scene has good texture or else it won&#8217;t work.<\/p>\n<h2>\u00a0Video Mosaic<\/h2>\n<div id=\"attachment_212\" style=\"width: 330px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_mosaic.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-212\" class=\" wp-image-212  \" alt=\"Mosaic created by moving the camera over a flat table top.\" src=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_mosaic.jpg\" width=\"320\" height=\"180\" srcset=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_mosaic.jpg 400w, https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2013\/02\/android_mosaic-300x168.jpg 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><p id=\"caption-attachment-212\" class=\"wp-caption-text\">Mosaic created by moving the camera over a flat table top.<\/p><\/div>\n<p>Creating a good mosaic can be difficult, with motion blur being the primary culprit.\u00a0 There is a reason why image stitching software on Android devices use still images.\u00a0 However with some practice and the right environment you can get some good results.\u00a0 See the image above.<\/p>\n<p>Remember that it won&#8217;t work if you are close up to a complex 3D scene and translating the camera.\u00a0 Instead try pivoting the camera or working off of far away objects.\u00a0 Slowly moving the camera also helps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently wrote an application to demonstrate some of the capabilities BoofCV on Android.\u00a0 BoofCV is an open source computer vision library that I&#8217;m working on written entirely in Java.\u00a0 The v0.13 update to BoofCV added functions for converting NV21 images (camera preview format) into BoofCV data types and provided Android specific visualization code.\u00a0 The [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[17,12],"tags":[],"class_list":["post-204","post","type-post","status-publish","format-standard","hentry","category-android","category-computer-vision"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=204"}],"version-history":[{"count":10,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions\/216"}],"wp:attachment":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}