The CL Eye Platform SDK Java/Processing SampleAuthor: CLDate: 01-08-2010
A quick introduction to the new Java and Processing.org sample applications provided with the CL-Eye Platform SDK... Allowing artist and designers quick access to video and audio manipulation using simple coding practices.
Processing is an open source programming language and environment for designers who want to program images, animation, and interactions. It was initiated by Ben Fry and Casey Reas and can be downloaded from processing.org. One of the best aspects of processing is the examples it ships with and a very basic OOP based programming language that allows for a lower barrier of entry for new programmers.
With the new CL-Eye Platform SDK we have full access to Multicam API, which allows us to control individual camera paramaters such as brightness, keystone or rotation. We will use this in the example to animate the cameara with the provided camera parameter.
For more advanced Java developers see the source of the library (src/cl/eye/CLCamera.java) which will allow any Java based application to utilize to utilize the Multicam API. For the most direct communications we utilized the Java Native Interface (JNI) which is a programming framework that allows Java code running in a Java Virtual Machine (JVM) to call and to be called by native applications and libraries written in other languages, such as C, C++ and assembly. For this simple example processing sketch we will only need to setup a few steps:
First we import the cl.eye library and setup some variables for the camera objects.
In the "draw" method we loop through available cameras and copy the data to a displayed image.
Then some optional code can manage animation of camera parameters adjustments.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// This file is part of CL-EyeMulticam SDK
//
// Java Processing CLEyeProcessingTest Sketch
//
// It allows the use of multiple CL-Eye cameras in your own Java Processing applications
//
// For updates and file downloads go to: codelaboratories.com/eye
//
// Copyright 2008-2010 (c) Code Laboratories, Inc. All rights reserved.
//
// Dependancies: CLEyeMulticam.dll - CL-Eye Platform Multicam API
// CLEyeMulticam.jar - For processing.org move this into your libraries folder
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Imports
import cl.eye.*;
// Camera Variables
int numCams;
CLCamera myCameras[] = new CLCamera[2];
PImage myImages[] = new PImage[2];
int cameraWidth = 640;
int cameraHeight = 480;
int cameraRate = 30;
// Animation Variables (not required)
boolean animate = true;
float zoomVal, zoomDelta;
float rotateVal, rotateDelta;
void setup(){
// Library loading via native interface (JNI)
// If you see "UnsatisfiedLinkError" then target the library path otherwise leave it commented out.
// CLCamera.loadLibrary("PATH");
// Verifies the native library loaded
if(!setupCameras()) exit();
// Setups animated variables
if(animate) setupAnimation();
}
void draw(){
// Loops through available cameras and updates
for(int i = 0; i < numCams; i++)
{
// --------------------- (image destination, wait timeout)
myCameras[i].getCameraFrame(myImages[i].pixels, (i==0) ? 1000 : 0);
myImages[i].updatePixels();
image(myImages[i], cameraWidth*i, 0);
}
// Updates the animation
if(animate)updateAnimation();
}
boolean setupCameras(){
println("Getting number of cameras");
// Checks available cameras
numCams = CLCamera.cameraCount();
println("Found " + numCams + " cameras");
if(numCams == 0) return false;
// create cameras and start capture
for(int i = 0; i < numCams; i++)
{
// Prints Unique Identifier per camera
println("Camera " + (i+1) + " UUID " + CLCamera.cameraUUID(i));
// New camera instance per camera
myCameras[i] = new CLCamera(this);
// ----------------------(i, CLEYE_GRAYSCALE/COLOR, CLEYE_QVGA/VGA, Framerate)
myCameras[i].createCamera(i, CLCamera.CLEYE_COLOR, CLCamera.CLEYE_VGA, cameraRate);
// Starts camera captures
myCameras[i].startCamera();
myImages[i] = createImage(cameraWidth, cameraHeight, RGB);
}
// resize the output window
size(cameraWidth*numCams, cameraHeight);
println("Complete Initializing Cameras");
return true;
}
void setupAnimation(){
// General Animation Variables
zoomVal = 0;
zoomDelta = TWO_PI/75.0;
rotateVal = 0;
rotateDelta = TWO_PI/125.0;
}
void updateAnimation(){
myCameras[0].setCameraParam(CLCamera.CLEYE_HKEYSTONE, (int)(150 * sin(rotateVal)));
myCameras[0].setCameraParam(CLCamera.CLEYE_VKEYSTONE, (int)(200 * cos(rotateVal)));
if(numCams>1)
{
myCameras[1].setCameraParam(CLCamera.CLEYE_ZOOM, (int)(200 * sin(zoomVal)));
}
rotateVal += rotateDelta;
zoomVal += zoomDelta;
}
Conclusion
In this example we showcase the use of using 2 cameras in Java/Processing.org, you can get the sample source in the CL-Eye Platform SDK