Problem using Ketai function savePhoto();

edited January 2016 in Android Mode

I'm making a timeLapse app for capturing photos with a 10 seconds interval, but everytime I use the savePhoto() function with a boolean the sketch crashes. Strangely, when I use the same code but with the savePhoto() inside a void mousePressed it works nicely. Here is the code and the error message below.

`/** *

Ketai Sensor Library for Android: http://KetaiProject.org

* *

<

p>Ketai Camera Features: *

    *
  • Interface for built-in camera
  • *
  • TODO: fix HACK of camera registration that currently exceptions in setup() at the moment.
  • *
  • Updated: 2012-10-21 Daniel Sauter/j.duran

*/

import ketai.camera.*;

KetaiCamera video;

Boolean shoot = false;

void setup() {

size(640, 480, P2D);

orientation(LANDSCAPE); video = new KetaiCamera(this, 640,480, 30);

println("camerasId" + video.list());

video.setCameraID(0);

video.setSaveDirectory("/storage/sdcard0/Movies/");

video.setPhotoSize(1280,720);

video.autoSettings();

}

void onCameraPreviewEvent() {

video.read();

}

void draw() {

video.start();

background(0);

if(second()%10 == 0) { shoot = true; }

if (shoot) { video.savePhoto("foto_teste.jpg");

}

}

void onSavePhotoEvent( String filename) {

video.addToMediaLibrary(filename); println("ok"); shoot = false;

}`

ERROR: Calculated camera parameters as (w,h,fps):640,480,30 Face detection supported! Using preview format: 17 Preview size: 640x480,30 Photo size: 1280x720 Calculated photo path: /storage/emulated/0/Pictures/storage/sdcard0/Movies/foto_teste.jpg Calculated photo path: /storage/emulated/0/Pictures/storage/sdcard0/Movies/foto_teste.jpg FATAL EXCEPTION: GLThread 4041 Process: processing.test.timelapse_v4_savphoto_debug, PID: 8494 java.lang.RuntimeException: takePicture failed at android.hardware.Camera.native_takePicture(Native Method) at android.hardware.Camera.takePicture(Camera.java:1266) at android.hardware.Camera.takePicture(Camera.java:1211) at ketai.camera.KetaiCamera.savePhoto(KetaiCamera.java:708) at processing.test.timelapse_v4_savphoto_debug.timeLapse_v4_savPhoto_DEBUG.draw(timeLapse_v4_savPhoto_DEBUG.java:79) at processing.core.PApplet.handleDraw(Unknown Source) at processing.opengl.PGLES$AndroidRenderer.onDrawFrame(Unknown Source) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Answers

  • Answer ✓

    @jrmasiero===

    i have tested (P3X) your code as it was && got the same error && same difference with mousePressed(); i think that it is a problem with picture call back. In order to solve that i have done some modify to the code and now it works. Consider also that for other reasons i have changed the save directory path but you can change that easily and go back to your code.

            import ketai.camera.*;
            import android.os.Environment;
    
            KetaiCamera video;
    
            Boolean shoot = false;
            String directory;
    
            void setup() {
    
            size(640, 480, P2D);
    
            orientation(LANDSCAPE); video = new KetaiCamera(this, 640,480, 30);
    
            println("camerasId" + video.list());
            directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath());
    
            video.setCameraID(0);
    
            video.setSaveDirectory(directory);
    
            video.setPhotoSize(1280,720);
    
            video.autoSettings();
    
            }
    
            void onCameraPreviewEvent() {
    
            video.read();
    
            }
    
            void draw() {
    
            video.start();
    
            background(0);
            println(shoot);
    
            if(second()%10 == 0) { shoot = true; }
    
            if (shoot) { video.savePhoto("foto_teste.jpg");
            noLoop();
    
            }else{
              loop();
            }
    
            }
    
            void onSavePhotoEvent( String filename) {
    
            //video.addToMediaLibrary(filename); 
            println("ok"); 
            shoot = false;
            loop();
    
            }
    
            public void mousePressed(){
              video.savePhoto("foto_teste.jpg");
              println("je sauve=====================");
            }
    
  • edited January 2016

    And now, we have a working time-lapse app. Thank you. Also, I have learned about loop and noLoop(). Nice!

  • edited January 2016

    @jrmasiero===

    ...Yet this loop/noLoop is only a kind of workaround...As i cannot see the ketai src i dont know how to get the callback after the photo has been successfully taken but it is quite sure that this is possible. Working with native android code there are a lot of better solutions like this one with startActivityForResult:::

    Intent takePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePhoto.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePhoto, REQUEST_IMAGE_CAPTURE);
        }
    
  • Yeah. The native way is always better, but in my case your solution is enough.

  • edited June 2

    Hi guys, I have another problem in saving the image using ketai lib. I followed the exact procedure that akenaton has suggested but still the camera clicks the photo only when I close the application. For example when I click on the screen I am suppose to save current image from the camera but instead the camera clicks the images only when i exist the application. What could be the reason for it. My code is similar to akenaton.

    I am not sure if I should have created a new thread for this question. But If I has to let me know kindly. Thanks in advance

  • Can you share your code?

Sign In or Register to comment.