We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi
I was working with an android sample code accessing the camera and I notice it is lagging. Is that normal? I am using 5.0.1. and processing 3.0.2 on a Galaxy VI (no emulator). I am hopping to quantify color segments in the screen but the videos seems to skip frames. It feels like is playing one frame every 2 or 3 seconds instead of the desirable 30 fps that you get running in java mode (using an external camera - and not this specific example). Is there anything I could do to have better video rates?
Cheers,
Kf
import android.os.Environment;
import ketai.camera.*;
KetaiCamera cam;
void settings() {
fullScreen();
}
void setup() {
orientation(LANDSCAPE);
imageMode(CENTER);
textSize(45);
}
void draw() {
if(cam != null && cam.isStarted()){
image(cam, width/2, height/2, width, height);
text("Number of cams \n" +
cam.getNumberOfCameras(), 0, 0, width/2-100, height/2);
cam.loadPixels();
int brightestX = 0; // X-coordinate of the brightest video pixel
int brightestY = 0; // Y-coordinate of the brightest video pixel
float brightestValue = 0; // Brightness of the brightest video pixel
int index = 0;
for (int y = 0; y < cam.height; y++) {
for (int x = 0; x < cam.width; x++) {
// Get the color stored in the pixel
int pixelValue = cam.pixels[index];
// Determine the brightness of the pixel
float pixelBrightness = brightness(pixelValue);
// If that value is brighter than any previous, then store the
// brightness of that pixel, as well as its (x,y) location
if (pixelBrightness > brightestValue) {
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
}
index++;
}
}
// Draw a large, yellow circle at the brightest pixel
fill(255, 204, 0, 128);
ellipse(brightestX, brightestY, 200, 200);
}
else
{
background(128);
text("Waiting for camera....touch to activate", 100, height/2);
}
}
void onCameraPreviewEvent()
{
cam.read();
}
// start/stop camera preview by tapping the screen
void mousePressed()
{
//HACK: Instantiate camera once we are in the sketch itself
if(cam == null)
cam = new KetaiCamera(this, 640, 480, 24);
if (cam.isStarted())
{
cam.stop();
}
else
cam.start();
}
void keyPressed() {
if(cam == null)
return;
if (key == CODED) {
if (keyCode == MENU) {
if (cam.isFlashEnabled())
cam.disableFlash();
else
cam.enableFlash();
}
}
}
Answers
maybe you have to do all the frame processing inside the onCameraPreviewEvent() so it only happens when it gets a frame