Hello,
I’m new in Processing, and I try to create some funny pixelator app on Android APDE using camera on my Phone. To solve this task I’m using a Ketai library. Problem is when I try to get image from camera using get() method^ I got only one frame as an image, not a video stream from my camera. But I need a realtime video stream from my camera. Who can help me to understand how can I do it. The code is here:
import ketai.camera.*;
KetaiCamera cam;
color bg = #f1f1f1;
color fg = #111111;
PImage img;
void setup() {
requestPermission("android.permission.WRITE_EXTERNAL_STORAGE", "checkPermission");
size(displayWidth, displayHeight);
orientation(LANDSCAPE);
imageMode(CENTER);
cam = new KetaiCamera(this, displayWidth, displayHeight, 24);
cam.setCameraID(0);
background(bg);
}
void draw() {
background(bg);
fill(fg);
if (mousePressed == true) {
cam.start();
} else {
cam.stop();
}
img = cam.get();
float tileX = map(mouseY, 0, height, 10, 100);
//float tileY = ratio * tileX;
float tileSize = width / tileX;
for (int y = 0; y < img.height; y += tileSize) {
for (int x = 0; x < img.width; x += tileSize) {
color c = img.get(x, y);
float b = map(brightness(c), 0, 255, 1, 0);
pushMatrix();
translate(x, y);
rect(0, 0, b * tileSize, b* tileSize);
popMatrix();
}
}
}
void checkPermission(boolean wasPermissionGranted) {
if (wasPermissionGranted) println("Hooray! I can now write to the local file system!");
else println("Oh no! I was not granted write permission =(");
}
void onCameraPreviewEvent() {
cam.read();
}
// start/stop camera preview by tapping the screen
/*
void mousePressed() {
if (cam.isStarted()) {
cam.stop();
} else cam.start();
}
*/
void keyPressed() {
if (key == CODED) {
if (keyCode == MENU) {
if (cam.isFlashEnabled()) cam.disableFlash();
else cam.enableFlash();
}
}
}
Thank you)