We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there !
I have made simple code which is performing a blue filter. It adds some value to R value and substract something from GB values in two for() loops. It works great on PC but on mobile the performance is really slow. You can see the stuttering on the screen below. Ofc. changing the size of capture image helps but it is not a solution I am looking. How can you improve the performance, what's the best way to do image proccesing on mobile ?
Code:
import ketai.camera.*;
PImage prev;
float threshold = 60;
color currentColor;
color lastColor;
float r1 = 0;
float g1 = 0;
float b1 = 0;
KetaiCamera cam;
void setup() {
orientation(LANDSCAPE);
imageMode(CENTER);
cam = new KetaiCamera(this, 320, 240, 24);
prev = createImage(320, 240, RGB);
cam.start();
}
void onCameraPreviewEvent(){
cam.read();
}
void draw() {
image(prev, width/2, height/2);
cam.loadPixels();
prev.loadPixels();
loadPixels();
for (int y = 0; y < cam.height; y++ )
{
for (int x = 0; x < cam.width; x++ )
{
int loc = x + y * cam.width;
currentColor = cam.pixels[loc]; //current values, taken from cam
lastColor = prev.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float b1 = blue(currentColor);
//pixels[loc] = color(r1+30,g1-35,b1-35);
//float r2 = red(lastColor);
//float g2 = green(lastColor);
//float b2 = blue(lastColor);
prev.pixels[loc] = color(r1-40,g1-40,b1+40);
//prev.pixels[loc] = lerpColor(lastColor, currentColor, 0.9);
}
}
prev.updatePixels();
//image(prev, width/2, height/2);
updatePixels();
}
Answers
@Rakerson===
dont'use ketai which is very slow; use the android camera API for the same.
@akenaton Thx, I will try your tip below but I dont exactly understand how you turn your frame to PImage. https://forum.processing.org/two/discussion/14312/launch-native-camera-with-camera-menu#latest
@Rakerson===
in the post you arre linking i was answering to somebody who asked not for video but for image capture. That s why i only explained that onActivityResult you call your images folder, get the image (many ways to do that) and put it on screen.
@akenaton Could you send me some examples how to use default library for capture video ? Something like this with ketai: http://blog.rhesoft.com/2014/05/11/tutorial-how-to-use-camera-on-android-with-processing-ide-and-ketai/ I have been looking for something like this but I can't find.
@Rakerson===
i am working now; i 'll post ASAP some code snippet
Thx alot, no need to hurry, I am doing this in free time.