AndroidCapture For Processing
This library tries to transfer data between Processing and Android.
I make a android app to capture the real-time video from
"Android Camera"and the real-time data from
"Android Sensor"through the socket to the server (processing server) with
WiFi. The users use this lib to get phone camera frame and sensors data in processing, then can do some interesting things.
Welcome to try it and if there is a problem, please contact me or new a issues.
android5.1
Setting IP, then input
the local address of your computer. You must ensure that your mobile phone and your computer in the same Wifi.
local address of your computer
.jarfile in the project. The
.jarfile is set the named
'code'folder.
AndroidProcessingForProcessing.jarfile in it.
getCameraImage()function to get android client phone camera frame and it will return a
PImageobject in processing.
getColor()function to get color from android phone camera and it return a
intobject.
```processing
import com.onlylemi.processing.android.capture.*;
AndroidCamera ac; PImage img;
void setup() { size(720, 480); ac = new AndroidCamera(width, height, 30); ac.start(); }
void draw() { // get android camera frame img = ac.getCameraImage(); image(img, 0, 0); } ```
--
```processing
import com.onlylemi.processing.android.capture.*;
AndroidCamera ac;
void setup() { size(720, 480);
ac = new AndroidCamera(width, height, 20); ac.start(); }
void draw() { background(0); translate(width / 2, height / 2);
// get color from android camera int c = ac.getColor(); fill(c); ellipse(0, 0, 300, 300); } ```
There is a class named
AndroidSensorin this lib. And there are 8 sensors from android phone. The users get sensor type in class named
SensorType.
```processing
import com.onlylemi.processing.android.capture.*;
AndroidSensor as;
void setup() { size(720, 480); background(0);
as = new AndroidSensor(0); as.start(); }
void draw() { background(0); fill(255); textSize(15);
text(SensorType.TYPEACCELEROMETER + " : ", 60, 50); float[] values1 = as.getAccelerometerSensorValues(); //float[] values1 = as.getSensorValues(SensorType.TYPEACCELEROMETER); text("X : " + values1[0], 250, 50); text("Y : " + values1[1], 400, 50); text("Z : " + values1[2], 550, 50);
text(SensorType.TYPEORIENTATION + " : ", 60, 100); float[] values2 = as.getOrientationSensorValues(); //float[] values2 = as.getSensorValues(SensorType.TYPEORIENTATION); text("X : " + values2[0], 250, 100); text("Y : " + values2[1], 400, 100); text("Z : " + values2[2], 550, 100);
text(SensorType.TYPEMAGNETICFIELD + " : ", 60, 150); float[] values3 = as.getMagneticFieldSensorValues(); //float[] values3 = as.getSensorValues(SensorType.TYPEMAGNETICFIELD); text("X : " + values3[0], 250, 150); text("Y : " + values3[1], 400, 150); text("Z : " + values3[2], 550, 150);
text(SensorType.TYPEGYROSCOPE + " : ", 60, 200); float[] values4 = as.getGyroscopeSensorValues(); //float[] values4 = as.getSensorValues(SensorType.TYPEGYROSCOPE); text("X : " + values4[0], 250, 200); text("Y : " + values4[1], 400, 200); text("Z : " + values4[2], 550, 200);
text(SensorType.TYPELIGHT + " : ", 60, 250); float values5 = as.getLightSensorValues(); //float values5 = as.getSensorValues(SensorType.TYPELIGHT)[0]; text("level : " + values5, 250, 250);
text(SensorType.TYPEPROXIMITY + " : ", 60, 300); float values6 = as.getProximitySensorValues(); //float values6 = as.getSensorValues(SensorType.TYPEPROXIMITY)[0]; text("distance : " + values6, 250, 300);
text(SensorType.TYPEPRESSURE + " : ", 60, 350); float values7 = as.getPressureSensorValues(); //float[] values7 = as.getSensorValues(SensorType.TYPEPRESSURE); text("pressure : " + values7, 250, 350);
text(SensorType.TYPETEMPERATURE + " : ", 60, 400); float values8 = as.getTemperatureSensorValues(); //float values8 = as.getSensorValues(SensorType.TYPETEMPERATURE); text("temperature : " + values8, 250, 400); } ```
--
import com.onlylemi.processing.android.capture.*;AndroidSensor as;
void setup() { size(720, 480);
background(0);
as = new AndroidSensor(0); as.start(); }
void draw() { // get accelerometer sensor value //float[] values = as.getSensorValues(SensorType.TYPE_ACCELEROMETER); float[] values = as.getAccelerometerSensorValues(); float x = values[0]; float y = values[1]; float z = values[2];
println(values);
int r = (int) (11.0f * (11.0f + x)); int g = (int) (11.0f * (11.0f + y)); int b = (int) (11.0f * (11.0f + z));
// background noStroke(); fill(r, g, b, 25); rect(0, 0, width, height);
// 3 circles float x1 = ((int) (width / 20 * (9.5f + (1.0f) * y))); float y1 = ((int) (height / 12 * (x + 6.0f))); fill(255, 0, 0); ellipse(x1, y1, 100, 100);
float x2 = ((int) (width / 20 * (9.5f + (-1.0f) * x))); float y2 = ((int) (height / 12 * (y + 6.0f))); fill(0, 255, 0); ellipse(x2, y2, 100, 100);
float x3 = ((int) (width / 20 * (9.5f + (1.0f) * x))); float y3 = ((int) (height / 12 * (y + 6.0f))); fill(0, 0, 255); ellipse(x3, y3, 100, 100); }