140 likes | 311 Vues
AS3 で画像処理して QR コードを読んだ話. 自己紹介. 名前:上野 賢一. 所属:ロゴスウェア株式会社. Twitter : @keno42. 今日の内容. 大まかな手順. カメラ画像 → ビット配列(画像処理) ビット配列 → 文字列(デコード) 参考: JIS X 0510:2004. 画像処理 1. グレー化 ColorMatrixFilter. var conGray:Array = [constnum*0.3, constnum*0.59, constnum*0.11];
E N D
自己紹介 • 名前:上野 賢一 • 所属:ロゴスウェア株式会社 • Twitter:@keno42
大まかな手順 • カメラ画像 → ビット配列(画像処理) • ビット配列 → 文字列(デコード) • 参考: JIS X 0510:2004
画像処理 1 • グレー化 ColorMatrixFilter var conGray:Array = [constnum*0.3, constnum*0.59, constnum*0.11]; var cmfGray:ColorMatrixFilter = new ColorMatrixFilter( [conGray[0], conGray[1], conGray[2], 0, 0, conGray[0], conGray[1], conGray[2], 0, 0, conGray[0], conGray[1],conGray[2], 0, 0, 0, 0, 0, 0, 255] ); bmp_dst.applyFilter( bmp_src, rect, point, cmfGray );
画像処理 2 • 2値化 BitmapData.threshold bmp.threshold(bmp, bmp.rect, new Point(0, 0), "<", threshold, 0xFF000000, 0xFFFFFFFF ); bmp.threshold(bmp, bmp.rect, new Point(0, 0), ">=", threshold, 0xFFFFFFFF, 0xFFFFFFFF );
画像処理 3 • ラベリング BitmapData.getColorBoundRect BitmapData.copyPixels BitmapData.floodFill var rect:Rectangle = bmp.getColorBoundsRect( 0xFFFFFFFF, pickcolor ); while ((rect.width > 0) && (rect.height> 0)){ var tempBmp:BitmapData = new BitmapData( rect.width, 1 ); tempBmp.copyPixels( bmp, new Rectangle(rect.topLeft.x, rect.topLeft.y, rect.width, 1 ), new Point(0, 0) ); var rect2:Rectangle = tempBmp.getColorBoundsRect( 0xFFFFFFFF, pickcolor ); bmp.floodFill( rect2.topLeft.x + rect.topLeft.x, rect2.topLeft.y + rect.topLeft.y, fillcolor ); _fillColor --; rect = bmp.getColorBoundsRect( 0xFFFFFFFF, pickcolor ); }
画像処理 4 • 切り出しシンボルを探す ラベリングした矩形の中央を縦横に走査し、 黒:白:黒:白:黒=1:1:3:1:1 になっていたら当たり
画像処理 5 • コードを切り出して向きを直す Math.atan Matrix.translate Matrix.rotate matrix2.translate( - topLeftObj.topleft.x, -topLeftObj.topleft.y ); var theta:Number = 0.0; if ( tempPoint1.x != 0.0 ) { theta = -Math.atan( tempPoint1.y / tempPoint1.x ); } matrix2.rotate( theta ); matrix2.translate( 10, 10 );
画像処理 6 • タイミングパターンからバージョン検出 BitmapData.copyPixels BitmapData.getPixels 白と黒のパターン数をがんばって読む 縦横のパターン数が一致したらOK
画像処理 7 • 位置合わせパターンを使ってグリッド作成 BitmapData.getPixel BitmapData.getColorBoundRect BitmapData.floodfill 正方形からのズレは線形に補間する
画像処理 8 • いざ読み取り BitmapData.getPixel →デコーダーへ
完成品サンプル • labs.logosware.com