Image processing on Android - poor permormance.

edited December 2017 in Android Mode

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();
  }

filtr

Answers

Sign In or Register to comment.