Guest User

Untitled

a guest
May 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. package org.libspark.flartoolkit.example {
  2.  
  3. import flash.display.Bitmap;
  4. import flash.display.BitmapData;
  5. import flash.display.PixelSnapping;
  6. import flash.display.Sprite;
  7. import flash.events.Event;
  8. import flash.events.IOErrorEvent;
  9. import flash.events.SecurityErrorEvent;
  10. import flash.media.Camera;
  11. import flash.media.Video;
  12. import flash.net.URLLoader;
  13. import flash.net.URLLoaderDataFormat;
  14. import flash.net.URLRequest;
  15.  
  16. import org.libspark.flartoolkit.core.FLARCode;
  17. import org.libspark.flartoolkit.core.param.FLARParam;
  18. import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
  19. import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
  20.  
  21. [Event(name="init",type="flash.events.Event")]
  22. [Event(name="init",type="flash.events.Event")]
  23. [Event(name="ioError",type="flash.events.IOErrorEvent")]
  24. [Event(name="securityError",type="flash.events.SecurityErrorEvent")]
  25.  
  26. public class ARAppBase extends Sprite {
  27.  
  28. private var _loader:URLLoader;
  29. private var _cameraFile:String;
  30. private var _codeFile:String;
  31. private var _width:int;
  32. private var _height:int;
  33. private var _codeWidth:int;
  34.  
  35. protected var _param:FLARParam;
  36. protected var _code:FLARCode;
  37. protected var _raster:FLARRgbRaster_BitmapData;
  38. protected var _detector:FLARSingleMarkerDetector;
  39.  
  40. protected var _webcam:Camera;
  41. protected var _video:Video;
  42. protected var _capture:Bitmap;
  43.  
  44. public function ARAppBase() {
  45. }
  46.  
  47. protected function init(cameraFile:String, codeFile:String, canvasWidth:int = 320, canvasHeight:int = 240, codeWidth:int = 80):void {
  48. _cameraFile = cameraFile;
  49. _width = canvasWidth;
  50. _height = canvasHeight;
  51. _codeFile = codeFile;
  52. _codeWidth = codeWidth;
  53.  
  54. _loader = new URLLoader();
  55. _loader.dataFormat = URLLoaderDataFormat.BINARY;
  56. _loader.addEventListener(Event.COMPLETE, _onLoadParam);
  57. _loader.addEventListener(IOErrorEvent.IO_ERROR, dispatchEvent);
  58. _loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, dispatchEvent);
  59. _loader.load(new URLRequest(_cameraFile));
  60. }
  61.  
  62. private function _onLoadParam(e:Event):void {
  63. _loader.removeEventListener(Event.COMPLETE, _onLoadParam);
  64. _param = new FLARParam();
  65. _param.loadARParam(_loader.data);
  66. _param.changeScreenSize(_width, _height);
  67.  
  68. _loader.dataFormat = URLLoaderDataFormat.TEXT;
  69. _loader.addEventListener(Event.COMPLETE, _onLoadCode);
  70. _loader.load(new URLRequest(_codeFile));
  71. }
  72.  
  73. private function _onLoadCode(e:Event):void {
  74. _code = new FLARCode(16, 16);
  75. _code.loadARPatt(_loader.data);
  76.  
  77. _loader.removeEventListener(Event.COMPLETE, _onLoadCode);
  78. _loader.removeEventListener(IOErrorEvent.IO_ERROR, dispatchEvent);
  79. _loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, dispatchEvent);
  80. _loader = null;
  81.  
  82. // setup webcam
  83. _webcam = Camera.getCamera();
  84. if (!_webcam) {
  85. throw new Error('No webcam!!!!');
  86. }
  87. _webcam.setMode(_width, _height, 30);
  88. _video = new Video(_width, _height);
  89. _video.attachCamera(_webcam);
  90. _capture = new Bitmap(new BitmapData(_width, _height, false, 0), PixelSnapping.AUTO, true);
  91.  
  92. // setup ARToolkit
  93. _raster = new FLARRgbRaster_BitmapData(_capture.bitmapData);
  94. _detector = new FLARSingleMarkerDetector(_param, _code, _codeWidth);
  95. _detector.setContinueMode(true);
  96.  
  97. dispatchEvent(new Event(Event.INIT));
  98. }
  99.  
  100. protected function onInit():void {
  101. }
  102. }
  103. }
Add Comment
Please, Sign In to add comment