OpenKinect AS3 API
Class: as3kinect
Description:
- Constant definitions
Public variables:
- SUCCESS - Value returned by the library when method was successfully executed (Default: 0)
- ERROR- Value returned by the library when method was not successfully executed (Default: -1)
- SERVER_IP – The ip address where as3server is running (Default: “loalhost”)
- SOCKET_PORT – The socket where as3server is listening (Server default: 6001)
- CAMERA_ID – Value for camera for the first byte command (Server default: 0)
- MOTOR_ID – Value for motor for the first byte command (Server default: 1)
- MIC_ID – Value for microphone for the first byte command (Server default: 2)
- GET_DEPTH – Value for camera -> getDepth for the second byte command (Server default: 0)
- GET_VIDEO - Value for camera -> getVideo for the second byte command (Server default: 1)
- MIRROR_DEPTH - Value for camera -> mirrorDepth for the second byte command (Server default: 2)
- MIRROR_VIDEO - Value for camera -> mirrorVideo for the second byte command (Server default: 3)
- MOVE_MOTOR - Value for motor -> moveMotor for the second byte command (Server default: 0)
- LED_COLOR - Value for motor -> ledColor for the second byte command (Server default: 1)
- ACCEL_DATA - Value for motor -> accelerometerData for the second byte command (Server default: 2)
- IMG_WIDTH – Width of the received image and depth frames (Default: 640)
- IMG_HEIGHT – Height of the received image and depth frames (Default: 480)
- RAW_IMG_SIZE – Size in bytes of the raw image and depth data (Default: IMG_WIDTH * IMG_HEIGHT * 4)
- COMMAND_SIZE – Size in bytes of the command sent (Server default: 6)
- MAX_BLOBS – Max number of blobs to be detected by the library (Default: 15)
- BLOB_MASK – Mask used for blob detection (Default: 0xFFFFFFFF)
- BLOB_COLOR – Color of the blobs that will be searched (Default: 0xFFFFFFFF)
- BLOB_FILL_COLOR – Fill the first detected blob with this color to proces its rect (Default: 0xFF0000FF)
- BLOB_PROCESSED_COLOR – Fill already processed blobs with this color (Default: 0x00FF00FF)
- BLOB_MIN_WIDTH – Minium width for a blob to be detected as a blob (Default: 30)
- BLOB_MAX_WIDTH – Maximum width for a blob to be detected as a blob (Default: 120)
- BLOB_MIN_HEIGHT – Minium height for a blob to be detected as a blob (Default: 30)
- BLOB_MAX_HEIGHT - Maximum height for a blob to be detected as a blob (Default: 120)
Class: as3kinectUtils
Description:
- Utilities for processing images and data, this are useful static methods that may or may not have a direct relation with the as3kinect library.
Public methods:
- static function byteArrayToBitmapData(bytes:ByteArray, _canvas:BitmapData):void
- Draw a byteArray (bytes) of ARGB bytes into a BitmapData object (_canvas)
- static function getBlobs(r:BitmapData, _w:Number = 0, _h:Number = 0):Array
- Get an array of blobs from a BitmapData (r), if _w and _h are set they will be converted to that specific resolution. If not IMG_WIDTH and IMG_HEIGHT constants will be used as the resolution.
- static function setBlackWhiteFilter(obj:BitmapData, threshold:int = 128):void
- Convert an BitmapData object (obj) into a Black / White BitmapData with a desired threshold.
- static function fireTouchEvent(id:int, point:Point,_lastTouched:Array, _stage:Stage):void
- Fire touch events over the desired Point (point). lastTouched is used for storing touches history.
Class: as3kinectWrapper
Description:
- Main Wrapper Class.
Public variables:
- motor – as3kinectMotor instantiated object reference.
- depth – as3kinectDepth instantiated object reference.
- video – as3kinectVideo instantiated object reference.
Public methods:
- function as3kinectWrapper():void
- Constructor.
Class: as3kinectDepth
Description:
- Depth control class.
Public variables:
- bitmap – Depth BitmapData object.
- mirrored – (set/get) if the image is sent mirrored or not from the server <Bool>
- minDistance – (set/get) the minium distance sent by the depth camera from the server <int>
- maxDistance – (set/get) the maximum distance sent by the depth camera from the server <int>
Public methods:
- function getBuffer():void
- Send the camera->getDepth command to the server.
Class: as3kinectVideo
Description:
- Video control class.
Public variables:
- bitmap – Video BitmapData object.
- mirrored – (set/get) if the image is sent mirrored or not from the server <Bool>
Public methods:
- function getBuffer():void
- Send the camera->getVideo command to the server.
Class: as3kinectMotor
Description:
- Motor control class.
Public variables:
- data – (get/set) motorData object.
- position – (set) set position in degrees <-31 to 31>
- ledColor – (set) set led color <0 – 6>
Public methods:
- function getData():void
- Send the camera->getData command to the server.
- function updateDataFromBytes(bytes:ByteArray):void
- Generate motorData object from byteArray object (bytes)
Sample code:
Importing the classes:
//as3kinect (OpenKinect) libraries import org.as3kinect.as3kinect; import org.as3kinect.as3kinectWrapper; import org.as3kinect.as3kinectUtils; import org.as3kinect.events.as3kinectWrapperEvent; import org.as3kinect.objects.motorData;
Variable definition:
private var _as3w :as3kinectWrapper;
Code initialization:
//Instanciating the wrapper library _as3w = new as3kinectWrapper(); //Add as3kinectWrapper events (depth, video and acceleration data) _as3w.addEventListener(as3kinectWrapperEvent.ON_DEPTH, got_depth); _as3w.addEventListener(as3kinectWrapperEvent.ON_VIDEO, got_video); _as3w.addEventListener(as3kinectWrapperEvent.ON_ACCELEROMETER, got_motor_data); //Add depth BitmapData to depth_cam MovieClip _canvas_depth = _as3w.depth.bitmap; _bmp_depth = new Bitmap(_canvas_depth); depth_cam.addChild(_bmp_depth); //Add video BitmapData to rgb_cam MovieClip _canvas_video = _as3w.video.bitmap; _bmp_video = new Bitmap(_canvas_video); rgb_cam.addChild(_bmp_video); //On every frame call the update method this.addEventListener(Event.ENTER_FRAME, update);
Update method:
//UPDATE METHOD (This is called each frame)
private function update(event:Event){
_as3w.video.getBuffer();
_as3w.depth.getBuffer();
_as3w.motor.getData();
}
Depth received:
//GOT DEPTH METHOD
private function got_depth(event:as3kinectWrapperEvent):void{
//Convert Received ByteArray into BitmapData
as3kinectUtils.byteArrayToBitmapData(event.data, _canvas_depth);
}
Video received:
//GOT VIDEO METHOD
private function got_video(event:as3kinectWrapperEvent):void{
//Convert Received ByteArray into BitmapData
as3kinectUtils.byteArrayToBitmapData(event.data, _canvas_video);
}
Motor data received:
//GOT MOTOR DATA (Accelerometer info)
function got_motor_data(event:as3kinectWrapperEvent):void
{
var object:motorData = event.data;
info.text = "raw acceleration:\n\tax: " + object.ax + "\n\tay: " + object.ay;
info.appendText("\n\taz: " + object.az + "\n\n");
info.appendText("mks acceleration:\n\tdx: " + object.dx + \n\tdy: " + object.dy);
info.appendText("\n\tdz: " + object.dz + "\n");
}
-
http://twitter.com/trippedout Anthony Tripaldi
-
Jasper
-
Eric Jacobsson
-
Wheelchair_cop