Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Opencv Android: FPS and RGB values

hi, i am learning to use opencv in android application. I am trying to create an app that captures video. the purpose of it is that when i point my camera to a color, it should show me the rgb values separately and also show the fps at which it is capturing. i would also like to change the fps according to the device its used on. I have done tutorials and I know how to change RGB image to GREY scale and so on. However, i cannot understand that once i declare "inputFrame.rgba()" how the break it up and store the R, G and B values separately to show it on the log/screen and also display the fps at which the video is being captured.

  public class VideoRecordingActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2{

//custom toolbar
private Toolbar toolbar;

//java camera view
JavaCameraView javaCameraView;

Mat mRgba, hsv_scale;





//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;
        }
    }
};


public static String TAG="VideoRecordingActivity";
public static String TAG2="Video";


@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(SurfaceView.VISIBLE);
    javaCameraView.setMaxFrameSize(1024,768);
    javaCameraView.clearFocus();

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


}

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

    if(javaCameraView!=null){
        javaCameraView.disableView();
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (javaCameraView!=null){
        javaCameraView.disableView();
    }
}

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

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

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


    }else{
        Log.d(TAG, "Not connected");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_3_0, this, mCallBackLoader);
    }
}

@Override
public void onCameraViewStarted(int width, int height) {
    //4 channel
    mRgba = new Mat(height, width, CvType.CV_8UC4);
    hsv_scale = new Mat(height, width, CvType.CV_8UC1);


}

@Override
public void onCameraViewStopped() {
    //release
    mRgba.release();
}

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    //camera setup

    //get each frame from camera
    mRgba = inputFrame.rgba();

    Vector<Mat> channels = null;

    Core.split(mRgba, channels);

    int rows = mRgba.rows();
    int cols = mRgba.cols();

    double R=0,G=0,B=0;

    for (int i=0; i<rows; i++)
    {
        for (int j=0; j<cols; j++)
        {
            double[] data = mRgba.get(i, j); //Stores element in an array
            R = data[0];
            G= data[1];
            B = data[2];
        }
    }
    Imgproc.putText(mRgba,"R:"+R + "G:"+G +"B:"+B,new Point(10,52),Core.FONT_HERSHEY_COMPLEX,.7,new Scalar(5,255,255), 2,8,false );
    return mRgba;

}

This is my camera class. In the onCameraFrame class you may notice that i have declared rows and columns to break this color space into RGB and this works fine. Except it drastically decrees the FPS of my video.

What am i missing. I would like to have suggestions/direction on how to achieve what im trying to get.

Thank you

Opencv Android: FPS and RGB values

hi, i am learning to use opencv in android application. I am trying to create an app that captures video. the purpose of it is that when i point my camera to a color, it should show me the rgb values separately and also show the fps at which it is capturing. i would also like to change the fps according to the device its used on. I have done tutorials and I know how to change RGB image to GREY scale and so on. However, i cannot understand that once i declare "inputFrame.rgba()" how the break it up and store the R, G and B values separately to show it on the log/screen and also display the fps at which the video is being captured.

  public class VideoRecordingActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2{

//custom toolbar
private Toolbar toolbar;

//java camera view
JavaCameraView javaCameraView;

Mat mRgba, hsv_scale;





//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;
        }
    }
};


public static String TAG="VideoRecordingActivity";
public static String TAG2="Video";


@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(SurfaceView.VISIBLE);
    javaCameraView.setMaxFrameSize(1024,768);
    javaCameraView.clearFocus();

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


}

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

    if(javaCameraView!=null){
        javaCameraView.disableView();
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (javaCameraView!=null){
        javaCameraView.disableView();
    }
}

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

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

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


    }else{
        Log.d(TAG, "Not connected");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_3_0, this, mCallBackLoader);
    }
}

@Override
public void onCameraViewStarted(int width, int height) {
    //4 channel
    mRgba = new Mat(height, width, CvType.CV_8UC4);
    hsv_scale = new Mat(height, width, CvType.CV_8UC1);


}

@Override
public void onCameraViewStopped() {
    //release
    mRgba.release();
}

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    //camera setup

    //get each frame from camera
    mRgba = inputFrame.rgba();

    Vector<Mat> channels = null;

    Core.split(mRgba, channels);

    int rows = mRgba.rows();
    int cols = mRgba.cols();

    double R=0,G=0,B=0;

    for (int i=0; i<rows; i++)
    {
        for (int j=0; j<cols; j++)
        {
            double[] data = mRgba.get(i, j); //Stores element in an array
            R = data[0];
            G= data[1];
            B = data[2];
        }
    }
    Imgproc.putText(mRgba,"R:"+R + "G:"+G +"B:"+B,new Point(10,52),Core.FONT_HERSHEY_COMPLEX,.7,new Scalar(5,255,255), 2,8,false );
    return mRgba;

}

This is my camera class. In the onCameraFrame class you may notice that i have declared rows and columns to break this color space into RGB and this works fine. Except it drastically decrees the FPS of my video.

What am i missing. I would like to have suggestions/direction on how to achieve what im trying to get.

Thank you

Opencv Android: FPS and RGB valuesvalues [Solved]

hi, i am learning to use opencv in android application. I am trying to create an app that captures video. the purpose of it is that when i point my camera to a color, it should show me the rgb values separately and also show the fps at which it is capturing. i would also like to change the fps according to the device its used on. I have done tutorials and I know how to change RGB image to GREY scale and so on. However, i cannot understand that once i declare "inputFrame.rgba()" how the break it up and store the R, G and B values separately to show it on the log/screen and also display the fps at which the video is being captured.

  public class VideoRecordingActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2{

//custom toolbar
private Toolbar toolbar;

//java camera view
JavaCameraView javaCameraView;

Mat mRgba, hsv_scale;





//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;
        }
    }
};


public static String TAG="VideoRecordingActivity";
public static String TAG2="Video";


@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(SurfaceView.VISIBLE);
    javaCameraView.setMaxFrameSize(1024,768);
    javaCameraView.clearFocus();

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


}

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

    if(javaCameraView!=null){
        javaCameraView.disableView();
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (javaCameraView!=null){
        javaCameraView.disableView();
    }
}

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

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

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


    }else{
        Log.d(TAG, "Not connected");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_3_0, this, mCallBackLoader);
    }
}

@Override
public void onCameraViewStarted(int width, int height) {
    //4 channel
    mRgba = new Mat(height, width, CvType.CV_8UC4);
    hsv_scale = new Mat(height, width, CvType.CV_8UC1);


}

@Override
public void onCameraViewStopped() {
    //release
    mRgba.release();
}

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    //camera setup

    //get each frame from camera
    mRgba = inputFrame.rgba();

    Vector<Mat> channels = null;

    Core.split(mRgba, channels);

    int rows = mRgba.rows();
    int cols = mRgba.cols();

    double R=0,G=0,B=0;

    for (int i=0; i<rows; i++)
    {
        for (int j=0; j<cols; j++)
        {
            double[] data = mRgba.get(i, j); //Stores element in an array
            R = data[0];
            G= data[1];
            B = data[2];
        }
    }
    Imgproc.putText(mRgba,"R:"+R + "G:"+G +"B:"+B,new Point(10,52),Core.FONT_HERSHEY_COMPLEX,.7,new Scalar(5,255,255), 2,8,false );
    return mRgba;

}

This is my camera class. In the onCameraFrame class you may notice that i have declared rows and columns to break this color space into RGB and this works fine. Except it drastically decrees the FPS of my video.

What am i missing. I would like to have suggestions/direction on how to achieve what im trying to get.

Thank you