<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>transmote speaks... &#187; notes</title>
	<atom:link href="http://words.transmote.com/wp/tag/notes/feed/" rel="self" type="application/rss+xml" />
	<link>http://words.transmote.com/wp</link>
	<description>design + art + code</description>
	<lastBuildDate>Tue, 28 Jun 2011 23:37:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>san flashcisco 09.04.16</title>
		<link>http://words.transmote.com/wp/20090416/san-flashcisco-090416/</link>
		<comments>http://words.transmote.com/wp/20090416/san-flashcisco-090416/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 23:49:53 +0000</pubDate>
		<dc:creator>ericsoco</dc:creator>
				<category><![CDATA[to do]]></category>
		<category><![CDATA[to see]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[augmented reality]]></category>
		<category><![CDATA[computer vision]]></category>
		<category><![CDATA[flarmanager]]></category>
		<category><![CDATA[flartoolkit]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[notes]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[slides]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://words.transmote.com/wp/?p=127</guid>
		<description><![CDATA[notes from my talk, &#8220;computer vision with flash&#8221;, at the San Flashcisco user group meeting. no slides, as this presentation is mainly demo- and code- focused, but plenty of links and text. motion tracking via subtractive analysis this demo uses code developed by Justin Windle. find the source on his blog, here. main loop happens [...]]]></description>
			<content:encoded><![CDATA[<p>notes from my talk, &#8220;computer vision with flash&#8221;, at the <a href="http://sanflashcisco.com/event/18" target="_blank">San Flashcisco user group meeting</a>.</p>
<p>no slides, as this presentation is mainly demo- and code- focused, but plenty of links and text.<br />
<br />
<span id="more-127"></span></p>
<hr />
<h3>motion tracking via subtractive analysis</h3>
<p>this demo uses code developed by <a href="http://blog.soulwire.co.uk/" target="_blank">Justin Windle</a>.  find the source on his blog, <a href="http://blog.soulwire.co.uk/flash/actionscript-3/webcam-motion-detection-tracking/" target="_blank">here</a>.</p>
<p><strong>main loop</strong><br />
happens in <tt>MotionTracker.track()</tt>:</p>
<p><i>subtractive analysis:</i><br />
previous frame (BitmapData) is drawn into current frame (BitmapData) with a difference filter;  this results in an image that shows only changed pixels.<br />
(difference pixel = lighter pixel &#8211; darker pixel; if pixels are ==, difference pixel is black.)</p>
<p>apply contrast filter to push nearly black (little-to-no motion) pixels to black, and bring brighter pixels (areas of motion) closer to white.</p>
<p>apply blur filter to blur out noise and blob-ify areas of more motion.</p>
<p>apply threshold to isolate all pixels that are not near-black (in this case, all pixels above 0xFF333333), and map to a new color (in this case, 0xFFFFFF).</p>
<p><i>motion tracking</i>:<br />
<tt>BitmapData.getColorBoundsRect()</tt> returns rect that contains all pixels detected as moved, colored white in the previous step.</p>
<p>verify area of rect is above a constant value (in this case, 10% of source width/height), to ignore noise.</p>
<hr />
<h3>FLARToolkit</h3>
<p>download source here:<br />
<a href="http://www.libspark.org/wiki/saqoosha/FLARToolKit/en" target="_blank">http://www.libspark.org/wiki/saqoosha/FLARToolKit/en</a></p>
<p>FLARToolkit is an AS3 marker-tracking engine, derived from NYARToolkit (Java), derived from <a href="http://www.hitl.washington.edu/artoolkit" target="_blank">ARToolkit</a> (C++).</p>
<p>ARToolkit detection algorithm explanation and diagram:<br />
<a href="http://www.hitl.washington.edu/artoolkit/documentation/vision.htm" target="_blank">http://www.hitl.washington.edu/artoolkit/documentation/vision.htm</a></p>
<p><strong>(FL)ARToolkit core algorithm</strong> (runs every frame)</p>
<p>create BitmapData snapshot of Video, and send to <tt>FLARMultiMarkerDetector.detectMarkerLite()</tt>, where the core tracking algorithm is implemented.</p>
<p><tt>FLARRasterFilter_BitmapDataThreshold</tt><br />
snapshot is reduced to brightness, by applying a luminance filter.<br />
(luminance relies more on green channel than red/blue; for more info see comments on <a href="http://www.quasimondo.com/archives/000565.php" target="_blank">this post</a>.)<br />
brightness greyscale image is then thresholded, resulting in a B/W image.</p>
<p><tt>FLARSquareDetector</tt><br />
finds all possible outline areas (not clear on algorithm here).<br />
video image distortion on each area is inverted according to information within a camera calibration file (camera_para.dat / FLARParams.dat).<br />
returns a list of FLARSquare candidates.<br />
each candidate is defined primarily by its four corners.</p>
<p><tt>FLARColorPatt_O3</tt><br />
attempt to extract image, formatted as a pattern, from the area within each detected outline.</p>
<p><tt>FLARMultiMarkerDetector</tt> (continued)<br />
match the extracted image against each loaded pattern.<br />
create a FLARMultiMarkerDetectorResult for the best match.<br />
each FLARMultiMarkerDetectorResult contains information about the quality of the match (&#8220;confidence&#8221;), pattern id, a FLARSquare instance that describes the detected pattern&#8217;s<br />
contour, and cardinal direction (U, R, D, L).</p>
<p>also calculate transformation matrix, based on FLARSquare for each detected marker.</p>
<p><strong>camera_para.dat / FLARParams.dat</strong><br />
the camera parameters file is used to correct distortion caused by the camera lens that might adversely affect marker tracking (particularly with wide-angle lenses).  info on how to create your own is <a href="http://www.hitl.washington.edu/artoolkit/documentation/usercalibration.htm" target="_blank">here</a>.</p>
<p><strong>pattern generation</strong><br />
<a href="http://flash.tarotaro.org/blog/2008/12/14/artoolkit-marker-generator-online-released/" target="_blank">this marker generator</a>, created by <a href="http://flash.tarotaro.org/" target="_blank">tarotaro</a>, can generate pattern files from either a live camera feed or a loaded image.  use the latter for a more reliable pattern file.  tarotaro&#8217;s marker generator allows for patterns of varying resolution and % marker width (patternToBorderRatio in FLARManager &gt; FLARPattern).</p>
<p><strong>FLARToolkit forum</strong><br />
is <a href="http://groups.google.com/group/flartoolkit-userz" target="_blank">here</a>.</p>
<p><strong>(FL)ARToolkit license</strong><br />
<a href="http://www.gnu.org/licenses/gpl.html" target="_blank">GNU GPL</a>: all derivative works must adopt the GPL.<br />
<a href="http://www.hitl.washington.edu/artoolkit/license.html" target="_blank">ARToolkit commercial licenses are available</a>;<br />
at the time of this writing, options include a single-use license and a multi-use, year-long license.  i believe each has an up-front fee and a royalty.</p>
<h3>FLARManager</h3>
<p><a href="http://transmote.com/flar" target="_blank">FLARManager</a> is a framework, written by <a href="http://transmote.com" target="_blank">Eric Socolofsky</a> (that&#8217;s me!), that makes developing FLARToolkit applications simpler.</p>
<p><strong>FLARManager overview</strong><br />
<tt>FLARManager</tt> constructor:<br />
pass in <tt>cameraParamsPath</tt>, list of <tt>FLARPattern</tt> instances, <tt>IFLARSource</tt>.<br />
<tt>cameraParamsPath</tt>: path to camera_para.dat / FLARParams.dat<br />
<tt>FLARPattern</tt>s are containers for information about each pattern FLARToolkit should attempt to detect<br />
<tt>IFLARSource</tt> will provide BitmapData object to FLARToolkit marker detector.</p>
<p><tt>FLARManager</tt> initialization:</p>
<ul>
<li>loads camera params file and all pattern files,</li>
<li>creates default source (<tt>FLARCameraSource</tt>) if none provided,</li>
<li>inits <tt>FLARRgbRaster_BitmapData</tt> (source for detection),</li>
<li>inits <tt>FLARMultiMarkerDetector</tt> (detector),</li>
<li>self-activates (begins detection on <tt>ENTER_FRAME</tt>).</li>
</ul>
<p>main loop:</p>
<ul>
<li>update source (redraw BitmapData)</li>
<li>get list of detected markers via FLARMultiMarkerDetector.detectMarkerLite()</li>
<li>manage detected markers (dispatch FLARMarkerEvents):
<ul>
<li>if no markers found, remove all active markers</li>
<li>check marker confidence against corresponding FLARPattern.minConfidence</li>
<li>compare detected markers against stored active markers; if distance is within MARKER_UPDATE_THRESHOLD, detected marker is just an updated marker; else, it&#8217;s a new marker</li>
<li>remove any stored (previously) active markers that didn&#8217;t get updated</li>
</ul>
</li>
</ul>
<p>a FLARManager application can use <tt>FLARCameraSource</tt> or <tt>FLARLoaderSource</tt> as a source.  can also simulate input with a mouse+keyboard, using <tt>FLARProxy</tt>.</p>
<p>at the time of this writing, FLARManager comes with four example files:<br />
<tt>FLARManagerExample_2D.as</tt>: simple 2D marker detection<br />
<tt>FLARManagerExample_PV3D.as</tt>: 3D detection for &#8220;augmented reality&#8221;<br />
<tt>onAdded</tt>:</p>
<ul>
<li>store FLARMarker</li>
<li>hash DisplayObject3D containers by pattern id (pattern id determined by load order)</li>
</ul>
<p>on <tt>ENTER_FRAME</tt>:</p>
<ul>
<li>loop through stored FLARMarkers,</li>
<li>get each FLARMarker.transformMatrix,</li>
<li>convert from ARToolkit format to PV3D format,</li>
<li>apply to DisplayObject3D.</li>
</ul>
<p><tt>FLARManagerExample_Flash3D.as</tt>: similar, but different transformation matrix conversion; still a bit glitchy.<br />
<tt>FLARManagerExample_2D_Loader.as</tt>: load source from a swf instead of camera.  useful for debugging.</p>
<hr />
<h3>Marilena</h3>
<p><a href="http://www.libspark.org/wiki/mash/Marilena" target="_blank">Marilena</a> is a partial port of <a href="http://opencv.willowgarage.com/wiki/" target="_blank">OpenCV</a>, a computer vision library written in C++.<br />
Marilena uses &#8220;Haar Cascades&#8221; to detect objects in an image, in particular faces.<br />
my understanding is that Haar Cascades are data structures that specify a branching series of descriptions of graphic regions, that can be traversed in order to match with a desired object. i think the face-tracking Haar Cascades start with eyes, then move out from there.</p>
<p>i could be totally wrong about all of this though.  it&#8217;s complicated stuff.</p>
<p>the code i have here is modified from <a href="http://squidder.com" target="_blank">squidder</a>&#8216;s <tt>WebcamFaceDetection</tt> example, from here:<br />
<a href="http://www.squidder.com/2009/02/26/realtime-face-detection-in-flash/" target="_blank">http://www.squidder.com/2009/02/26/realtime-face-detection-in-flash/</a></p>
<p>found that mario klingemann also did some optimization:<br />
<a href="http://www.quasimondo.com/archives/000687.php" target="_blank">http://www.quasimondo.com/archives/000687.php</a></p>
<p>mario&#8217;s magic mirror:<br />
<a href="http://incubator.quasimondo.com/flash/manic_mirror.php" target="_blank">http://incubator.quasimondo.com/flash/manic_mirror.php</a></p>
<p>mr. doob&#8217;s face-driven 3D:<br />
<a href="http://mrdoob.com/lab/webcam/face_driven_3d/" target="_blank">http://mrdoob.com/lab/webcam/face_driven_3d/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://words.transmote.com/wp/20090416/san-flashcisco-090416/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

