0

i would like to set frame rate to 1 fps using JavaCameraView. When i turn on camera the frame rate is about 20 fps. My purpose is to change this value to 1 fps after click on the button.

Could someone help me ? I've searched a lot on the Internet, but i could not find nothing interesting ( in the documentation also http://docs.opencv.org/java/org/opencv/android/JavaCameraView.html). I'm using JavaCameraView because i am working with openCV.

michael
  • 3
  • 3
  • 5

1 Answers1

2

You can manipulate camera preview fps by creating class that extends JavaCameraView and change parameters of mCamera Object:

public class CustomizableCameraView extends JavaCameraView {

    public CustomizableCameraView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setPreviewFPS(double min, double max){
        Camera.Parameters params = mCamera.getParameters();
        params.setPreviewFpsRange((int)(min*1000), (int)(max*1000));
        mCamera.setParameters(params);
    }
}

similar to OpenCV Tutorial 3 - Camera Control.

But you have to check if fps range you will set is in mCamera.getSupportedPreviewFpsRange() - reference. In my case [min:10000, max:31000], so theoretically minimum is 10fps.

reynev
  • 326
  • 2
  • 5
  • Thanks for reply, but how to handle with situations when i already extend class (ActionBarACtivity) ? For example i'd like to change fps after click to the button (i can add listener but what next? inner class inside this listener ?) – michael Oct 11 '14 at 16:24
  • There is no problem because `ActionBarACtivity` is Activity and `JavaCameraView` is View, do you know the difference? Activity 'handles' your application, and View is component to display content. So you extend JavaCameraView as above and add this child class to layout xml together with button to change FPS. Creating custom Views is explained here: [How to add custom view to the layout?](http://stackoverflow.com/questions/10410616/how-to-add-custom-view-to-the-layout) – reynev Oct 12 '14 at 10:32
  • Ok, but what to do when i want to use two view - org.opencv.android.JavaCameraView all the time and CustomizableCameraView after click on the menu button (they both are defined in the layout file) ? – michael Oct 14 '14 at 07:39
  • Why use two views? Besides `CustomizableCameraView` is extended `JavaCameraView` and the difference is only with method that allows you to set FPS. You want to change FPS `onClick`, not View. So you can have `CustomizableCameraView` which behaves like `JavaCameraView` and `onClick` you invokes `setPreviewFPS` which sets FPS with your value. This is the idea of inheritance you extends class so it behaves like superclass always but the methods you write in subclass. – reynev Oct 15 '14 at 08:44
  • Hi @reynev hope i can reach you.. I have been trying to implement this in my app. I want to set a fixed fps which i believe can be achieved with `params.setPreviewRangeFps(x, x)`. I have created the class extending the JavaCameraView class and can access the all methods accordingly. EX: `customizableCameraView.enableFpsMeter()` etc. However, when i try to access the `customizableCameraView.setPreviewFps(x,x)` my app crash without any error report. I have tried to create other methods like the one for resolution in the example. But it still crash when ever i try to access. What am i missing? – Mill3r Sep 23 '17 at 05:23
  • `Attempt to invoke virtual method 'android.hardware.Camera$Parameters android.hardware.Camera.getParameters()' on a null object reference` I am getting this error. – Mill3r Sep 23 '17 at 05:57
  • Maybe camerais not initialized yet in time you want to set FPS range? – reynev Sep 25 '17 at 07:11