[Tutorial] How to use camera on Android with Processing IDE and Ketai

Welcome!! I’m going to show you how to use camera with Android + Processing + Ketai.

First of all, check if your Processing IDE is ready for Ketai and Android development.

If everything is fine, let’s start.  

Create a new Android project, and import the lib:

  import ketai.camera.*;

On the menu Android -> Sketch Permissions, select the Camera option.

Create the camera instance and configure your application in the setup():

KetaiCamera cam;
void setup() {
orientation(LANDSCAPE);
imageMode(CENTER);
cam = new KetaiCamera(this, 950, 540, 24);
}

I’m using landscape orientation and the image on the center of the screen. With the resolution 950x540, with 24 FPS. Now, you can code the onCameraPreviewEvent, to read camera data:

void onCameraPreviewEvent(){
cam.read();
}

And finally, the draw() method, to draw the image on the screen:

void draw() {
if(cam.isStarted())
   image(cam, width/2, height/2);
else
cam.start();
}

That’s it, this application will take 24 pictures per second and show it on the screen.

Full source:

import ketai.camera.*;

KetaiCamera cam;

void setup() {
orientation(LANDSCAPE);
imageMode(CENTER);
cam = new KetaiCamera(this, 950, 540, 24);
}

void draw() {
if(cam.isStarted())
image(cam, width/2, height/2);
else
cam.start();
}

void onCameraPreviewEvent(){
cam.read();
}

That’s all, as you can see, Processing IDE is completely simple. Take a look in my blog, you can find more tutorial here. Thx for reading.

Aron Bordin

Aron Bordin
Computer Science Student and AI researcher. Always coding something fun :)

[Tutorial] Developing Android Background Services

### Welcome!In this post, I'll show you how to develop background services on Android Studio. We'll see two type of services: `Service` a...… Continue reading