ANDROID MODE 4+ support to Keitai camera, or other ways to access camera?

edited January 2017 in Android Mode

Hey, how is it going?

Im working on an app that needs to get videos from the mobile`s camera in real time. Before downloading version 4+ of android mode it was working fine, but I had to get 4+ because its gonna be a virtual reality (cardboard) app.

I was using android 7.0 (API 24) and it was working, i could access the camera using the CameraGettingStarted from ketai, but the recommended android SDK for android mode 4+ is the 6.0 (API 23) and since ive installed it the example doesnt work, it crashes when I click to start the camera. One thing ive noticed is that it doesnt crash until i click, so i tried putting the line:

cam = new KetaiCamera(this, width, height, 24);

inside setup, and then it crashes when it starts, suggesting that this is the part when something wrong happens.

Anyone tried accessing camera using the same android mode and sdk versions? Any suggestions?

One other solution would be getting the images from the camera without the library, but I have no idea how to do that.

Basically i need to get the camera in real time to do some image processing to the frames and display them. Here`s an example code, what i get is: gray screen with "Waiting for camera....touch to activate" working with cardboard features, when i click the screen it crashes, if i put that line on setup it crashes when it starts. Its basically the getting started example from ketai with cardboard added

import processing.cardboard.*;
import ketai.camera.*;

KetaiCamera cam;

void setup() {
  fullScreen(PCardboard.STEREO);
  orientation(LANDSCAPE);
  imageMode(CENTER);
  textSize(45);

  //cam = new KetaiCamera(this, 640, 480, 24); //this is the line that crashes when app starts if not commented
}

void draw() {
  background(0);
  if (cam != null && cam.isStarted())
    image(cam, width/2, height/2, width, height);
  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();
    }
  }
}

any tips or ideas welcome! thanks in advance!

Tagged:

Answers

  • Processing 3.2.1 Asus Zenphone 2 Laser Android 5.0.2

  • Are you able to get a crash log? Not an Android developer, but if you have the specific crash message it might help people advise you.

  • thanks for your reply jeremy, but, no error messages (app or processing console, the app just closes.

    For the people reading, any help on how to access the camera without ketai is also more than welcome

    =)

  • Remove the line related the cardboard library to start. I have seen some recent posting that people have had problems with the cardboard lib recently.

    Just to clarify, your program still runs with API 23? In the processing menu, go to Android >> Select target SDK >> and choose API 23.

    Your example runs in my phone Galaxy S4 and P 3.1.2. What processing version are you running on?

    Lastly, Please copy and paste the error code that you are getting from the processing console.

    Kf

  • edited September 2016

    @kfrajer thanks for the answer

    how did it run? with cardboard? Without cardboard It was also working on my phone using API24 and Android Mode 3.0.1. But not now, ive changed android mode and API.

    I have only API23 installed, here`s a screenshot of my sdk tools screen

    Image and video hosting by TinyPic

    Im using the 4+ version of android mode, it is a pre-release, and you have to install manually, according to this

    http://android.processing.org/install.html

    wich sends you here to download and manually install

    https://github.com/processing/processing-android/releases

    Before using it I had this option of Select target SDK, but when I installed the pre-release version it asked me for the sdk (at the time i was using API24). The pre-release versions needs the API 23 to run, so i downloaded it, and deleted API 24, and now even if i install another API version i dont have the option to change it inside processing, heres how the menu looks like

    Image and video hosting by TinyPic

    It does not give any error messages at console, the app just closes suddenly.

    Its the same if i try only the example from ketai, without marking the CARDBOARD option at the Android menu, leaving the APP option marked, wich seems to be something new to this Android Mode version. The app starts, when i click somewhere at the screen it crashes. If i put that line on the setup, it crashes when it opens. If I mark CARDBOARD import the library and put

    fullScreen(PCardboard.STEREO);
    

    on setup, it does open the app with the silver screen waiting for me to click and initialize the camera, with all cardboard features working, but when I do click it closes suddenly.

    One last note, all examples (except the one with shaders, but i think it has nothing to do with this thread) from the cardboard tutorial works, this tutorial:

    http://android.processing.org/tutorials/cardboard_intro/index.html

    the problem seems to be when i try to initialize ketai`s camera

  • I tried running cardboard recently from the processing library but it didn't work. From my little research on the web, there were some steps and manual installs to get it working. However I never got to do it. I don't have the latest android mode at at the moment so I won't be able to help. Thanks for adding the screenshots as it help understanding what you are going through.

    I will post later if I find more info. For now I have to say I do not like the latest android mode release and to remove the options to choose what API to run on.

    Kf

  • edited September 2016

    @krajer

    I also found strange and didn't like that the option to chose API was removed but its probably because its beta and may be working better with this api, just a guess.. i hope they give back the option to chose api.

    thanks for your help

    hope someone can find whats wrong or knows how to access camera without ketai

  • edited September 2016

    @mraeclo && @ kfrager===

    it is very simple to acceed to camera, front or back, without ketai:: you just have to use the android api camera class that ketai tries to wrap....

  • Hi guys, Just got this running on my phone. This is a little checklist for you. I hope it helps.

    Make sure you have all this installed, First a a test try and get the basis Android mode 4+ working

    Android mode 0255 https://github.com/processing/processing-android/releases Cardboard library https://github.com/codeanticode/processing-cardboard/releases/tag/latest And processing-cardboard Libary https://github.com/codeanticode/processing-cardboard

    I followed this great tutorial on the processing android website.

    http://android.processing.org/tutorials/cardboard_intro/index.html

    Hope that helps Sabba

  • edited January 2017

    Facing the same problem with the ketai camera. Does work on stable Android Mode, not on 4 beta.

    This is the logcat:

    01-20 12:18:28.978 17532-17563/? E/AndroidRuntime: FATAL EXCEPTION: Animation Thread Process: processing.test.cardboard0, PID: 17532 java.lang.NoSuchMethodError: No virtual method getActivity()Landroid/app/Activity; in class Lprocessing/core/PApplet; or its super classes (declaration of 'processing.core.PApplet' appears in /data/app/processing.test.cardboard0-1/base.apk) at ketai.camera.KetaiCamera.(KetaiCamera.java:130) at processing.test.cardboard0.cardboard0.setup(cardboard0.java:30) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PSurfaceNone.callDraw(Unknown Source) at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source) 01-20 12:18:28.978 17532-17563/? E/AndroidRuntime: FATAL EXCEPTION: Animation Thread Process: processing.test.cardboard0, PID: 17532 java.lang.NoSuchMethodError: No virtual method getActivity()Landroid/app/Activity; in class Lprocessing/core/PApplet; or its super classes (declaration of 'processing.core.PApplet' appears in /data/app/processing.test.cardboard0-1/base.apk) at ketai.camera.KetaiCamera.(KetaiCamera.java:130) at processing.test.cardboard0.cardboard0.setup(cardboard0.java:30) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PSurfaceNone.callDraw(Unknown Source) at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source)

  • Can you post the example code you are using? i also suggest to try only ketai examples before working with cardboard.

    Kf

  • edited January 2017

    Sure. I was actually not doing cardboard, work, but the project had that name because I had previously been testing Cardboard stuff earlier. This is all the code needed to reproduce the crash (I created a new project to make sure previous tests were not creating conflict):

    import ketai.camera.*;
    
     KetaiCamera cam;
    
     void setup() {
         //fullScreen();
          orientation(LANDSCAPE);
         //imageMode(CENTER);
         cam = new KetaiCamera(this, 950, 540, 24);
         //background(0);
     }
    
     void onCameraPreviewEvent(){
       //cam.read();
     }
    
     void draw() {
    
     }
    

    (I'm trying to format this right, but not sure how to do it on this forum) ok, CONTROL-O if anyone wonders.

    And here's the crash again:

    01-22 22:10:33.978 30783-30814/processing.test.sketch_170122a E/AndroidRuntime: FATAL EXCEPTION: Animation Thread Process: processing.test.sketch_170122a, PID: 30783 java.lang.NoSuchMethodError: No virtual method getActivity()Landroid/app/Activity; in class Lprocessing/core/PApplet; or its super classes (declaration of 'processing.core.PApplet' appears in /data/app/processing.test.sketch_170122a-2/base.apk) at ketai.camera.KetaiCamera.(KetaiCamera.java:130) at processing.test.sketch_170122a.sketch_170122a.setup(sketch_170122a.java:29) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PSurfaceNone.callDraw(Unknown Source) at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source) 01-22 22:10:33.978 30783-30814/processing.test.sketch_170122a E/AndroidRuntime: FATAL EXCEPTION: Animation Thread Process: processing.test.sketch_170122a, PID: 30783 java.lang.NoSuchMethodError: No virtual method getActivity()Landroid/app/Activity; in class Lprocessing/core/PApplet; or its super classes (declaration of 'processing.core.PApplet' appears in /data/app/processing.test.sketch_170122a-2/base.apk) at ketai.camera.KetaiCamera.(KetaiCamera.java:130) at processing.test.sketch_170122a.sketch_170122a.setup(sketch_170122a.java:29) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PSurfaceNone.callDraw(Unknown Source) at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source)

  • @Kajuna

    No virtual method getActivity()Landroid/app/Activity

    I was doing some testing with Android mode v4 and ketai lib and I found out that ketai is not working anymore. There was a recent change in the way to access the current activity object in a sketch. In the new mode, one needs to call suface.getActivity() so i believe that all ketai libraries need to be updated to take into account this change. @codeanticode might be able to provide more info about this issue and maybe he could tell us what is the best way to get ketai running in the new mode version while still supporting the old version.

    For now, if you want to use the ketai library, you need to downgrade your android mode or write the code yourself which is not too difficult, just few extra lines.

    Kf

  • Thanks. Will downgrade for now, and maybe later implement Android's Camera2 instead of using Ketai

  • I have tried to include KetaiCamera.java file in my project, and while that works in Android Mode 3 and I can modify the library's code, in Android 4 I get "no library found for ketai.camera". It happens with any library I add this way. I also tried compiling and including the modified library as a JAR, but I have never done that before... so I failed.

  • What steps did you use to compile your code?

  • I followed this guide, but couldn't get the javac -d part to work. Tried referencing the project libraries before applying the javac to the .java files but got plenty of errors

    https://github.com/processing/processing/wiki/Library-Basics#creating-jar-files-for-your-library

Sign In or Register to comment.