This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ARAppBase.as
97 lines (90 loc) · 3.64 KB
/
ARAppBase.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package
{
import ARAppBase.*;
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import org.libspark.flartoolkit.core.*;
import org.libspark.flartoolkit.core.param.*;
import org.libspark.flartoolkit.core.raster.rgb.*;
import org.libspark.flartoolkit.detector.*;
public class ARAppBase extends Sprite
{
private var _loader:URLLoader;
private var _cameraFile:String;
private var _codeFile:String;
private var _width:int;
private var _height:int;
private var _codeWidth:int;
protected var _param:FLARParam;
protected var _code:FLARCode;
protected var _raster:FLARRgbRaster_BitmapData;
protected var _detector:FLARSingleMarkerDetector;
protected var _webcam:Camera;
protected var _video:Video;
protected var _capture:Bitmap;
protected var _nowebcam:Sprite;
public function ARAppBase()
{
_nowebcam = new nowebcam();
return;
}// end function
protected function init(param1:String, param2:String, param3:int = 320, param4:int = 240, param5:int = 80) : void
{
_cameraFile = param1;
_width = param3;
_height = param4;
_codeFile = param2;
_codeWidth = param5;
_loader = new URLLoader();
_loader.dataFormat = URLLoaderDataFormat.BINARY;
_loader.addEventListener(Event.COMPLETE, _onLoadParam);
_loader.addEventListener(IOErrorEvent.IO_ERROR, dispatchEvent);
_loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, dispatchEvent);
_loader.load(new URLRequest(_cameraFile));
return;
}// end function
private function _onLoadParam(event:Event) : void
{
_loader.removeEventListener(Event.COMPLETE, _onLoadParam);
_param = new FLARParam();
_param.loadARParam(_loader.data);
_param.changeScreenSize(_width, _height);
_loader.dataFormat = URLLoaderDataFormat.TEXT;
_loader.addEventListener(Event.COMPLETE, _onLoadCode);
_loader.load(new URLRequest(_codeFile));
return;
}// end function
private function _onLoadCode(event:Event) : void
{
_code = new FLARCode(16, 16);
_code.loadARPatt(_loader.data);
_loader.removeEventListener(Event.COMPLETE, _onLoadCode);
_loader.removeEventListener(IOErrorEvent.IO_ERROR, dispatchEvent);
_loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, dispatchEvent);
_loader = null;
_webcam = Camera.getCamera();
if (!_webcam)
{
_nowebcam.x = 320;
_nowebcam.y = 240;
addChild(_nowebcam);
throw new Error("No webcam!!!!");
}
_webcam.setMode(_width, _height, 30);
_video = new Video(_width, _height);
_video.attachCamera(_webcam);
_capture = new Bitmap(new BitmapData(_width, _height, false, 0), PixelSnapping.AUTO, true);
_raster = new FLARRgbRaster_BitmapData(_capture.bitmapData);
_detector = new FLARSingleMarkerDetector(_param, _code, _codeWidth);
_detector.setContinueMode(true);
dispatchEvent(new Event(Event.INIT));
return;
}// end function
protected function onInit() : void
{
return;
}// end function
}
}