Control the FPS of a video input OpenCV Android

asked 2017-09-22 15:18:11 -0600

miller619 gravatar image

I am making an application where the camera takes a video and shows the average RGB value per frame. I am able to get the RGB value of each frame with good accuracy. I am also able to see the FPS with enableFpsMeter(). The problem is that i want to plot a graph of the R value against time for which i need to store the FPS in a variable. I have been trying to figure that out for a few days now. I know that OpenCV for android does not have any inbuilt methods in its library which will allow me to do that. I have tried the following ways, 1. Tried to create own methods in the JavaCameraView class. 2. Tried making a class which extends JavaCameraView and define a method to find the FPS. Both of which i failed.

What i want is to control the FPS. i want to set the FPS within a range of 8-16. and also plot a graph of the R value against time or FPS (i guess once i get the fps i cant change it easily to time domain).

My Class

package com.example.virus.bloodpressurereader;
import android.hardware.Camera;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log; 
import android.view.SurfaceView;
import android.view.View;

import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.Viewport;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.JavaCameraView;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;

import static org.opencv.core.Core.getTickCount;
import static org.opencv.core.Core.getTickFrequency;
import static org.opencv.core.Core.inRange;


public class VideoRecordingActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2{

 //custom toolbar
private Toolbar toolbar;

//java camera view
JavaCameraView javaCameraView;

Mat mRgba, mHsv;

GraphView graph;
LineGraphSeries<DataPoint> series;

CustomizableCameraView customizableCameraView;

//callback loader
BaseLoaderCallback mCallBackLoader = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status){
            case BaseLoaderCallback.SUCCESS:
                javaCameraView.enableView();
                break;
            default:
                super.onManagerConnected(status);
                break;
        }
    }
};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_recording);

    //custom toolbar
    toolbar = (Toolbar)findViewById(R.id.nav_action);
    setSupportActionBar(toolbar);

    //connect the camera
    javaCameraView = (JavaCameraView)findViewById(R.id.java_camera_view);

    //set visibility
    javaCameraView.setVisibility(View.VISIBLE);
    javaCameraView.setMaxFrameSize(320, 240);



    javaCameraView.enableFpsMeter();
    javaCameraView.clearFocus();

    //set callback function
    javaCameraView.setCvCameraViewListener(this);

    /*Graph*/
    graph = (GraphView)findViewById(R.id.graphView);
    Viewport graphView = graph.getViewport();
    graphView.setScrollable(true);



}

@Override
protected void onPause() {
    super.onPause();
    //if java camera view not = null
    if(javaCameraView!=null){
        javaCameraView.disableView();
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    //check if java camera view not = null
    if (javaCameraView!=null){
        javaCameraView.disableView();
    }
}

@Override
protected void onResume() {
    super.onResume();

    if (OpenCVLoader.initDebug()){
        Log.d("openCV", "Connected");

        //display when the activity resumed,, callback loader
        mCallBackLoader.onManagerConnected(LoaderCallbackInterface.SUCCESS);


    }else ...
(more)
edit retag flag offensive close merge delete