[SOLVED] Getting preview image from Ketai

Hi!
I’m color-blind and I made a small android app to exchange colors in a realtime image in order to distinguish red from black.

But the app runs slowly and gets just one frame from the camera.

After many attempts (I initially blamed on my filters, but they took less than 40 microseconds to run), I discovered that this code shows a camera preview image:

ketaiCamera cam;
cam.start();

image (cam,width/2, height/2);

While this code produces no image at all:

ketaiCamera cam;
PImage img;
cam.start();
....
img=cam.get();
image (img,width/2, height/2);

What can I do to get the preview frame into a PImage so I can apply a filter to its pixels[] ?

Yours,

José.

1 Like

We would need to see a complete code demonstrating your problem so we can see your approach. Related to your slow image observation, I have experience that before a while ago when I was using Ketai in Android. Two things I did to speed up the display process were:

  1. To use the P3D renderer as it would be more efficient displaying your images
  2. When creating a camera, I would choose a smaller image dimensions when instantiating the camera and then I would scale the image when I displayed it. This might not be good in your case if you need the resolution. It is worth to give it a shot if you can get a better responsive video.

Another option would be to use native Android libraries in your Processing code which would require some effort from your side to get it going unless you find some samples and demos on the net.

Kf

SOLVED.

I reviewed other sketches made by me and I saw I ketaiCamera.get() worked after displaying the preview frame. It seems the camera preview frame is only refreshed when displayed on the app surface, regardless of onCameraPreviewEvent and ketaiCamera.read();

So, even when you don’t want to show the preview frame in your sketch, you must do something like this:

ketaiCamera cam;
PImage mypimage;
void setup(){
    cam.start();
}

void draw(){

// Assuming you have a cam.read() on the appropriate 
// onCameraPreviewEvent()

//We don't want to display cam, but mypimage. 
//... BUT ...
// if you comment this out, mypimage will be a blank image: 
//
image(cam,somex,somey);
//
//luckily, the user won't see that image.

mypimage=cam.get()

//some filter function that is applied over mypimage.pixels[];
myfilterfunction();

image(mypimage(width/2,height/2, width,height));
}

Yours,

José

1 Like

Thank you for sharing your solution. This is worth to report as a tix in ketai github. I would say this is a workaround but not a desirable final solution. May I suggest you try using the P3D renderer by calling fullScreen(P3D); in setup?

Kf

Hi!
Excuse me for not replying before.

I don’t want to use P3D since my app does not use 3D at all. I don’t know if adding P3D to my project would add an implicit uses-feature.

Since I’m already having trouble for the stores detecting implicit features and not being able to remove them via <uses-feature … android:required=“false”>, since APDE removes the AndroidManifest file and desktop processing gives strange errors.

Yours,

JGMY