Take the value of a variable in Seekbar - Java / Android

Asked

Viewed 541 times

0

I am a beginner in Java / Android and I am developing an application with image processing. I already have the application working with the necessary filters.

In case I have:

Canny(edges, edges, thresholdCanny, thresholdCanny2);

I would like to apply a Seekbar to change the values of the variables thresholdCanny and thresholdCanny2 directly in the running application, that is, adjust the intensity of the filters.

Follow my role already with Seekbar implemented:

    public Mat onCameraFrame(final CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    // Image Processing
    Mat rgba = inputFrame.rgba();
    Mat edges = new Mat(rgba.size(), CV_8UC1);
    final int thresholdCanny = 80, thresholdCanny2 = 100;

    // SeekBar change value
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });


    try {
        Imgproc.cvtColor(rgba, edges, Imgproc.COLOR_RGB2GRAY, 4);
        Imgproc.GaussianBlur(edges, edges, new Size(5,5), 30, 50);
        Canny(edges, edges, thresholdCanny, thresholdCanny2);
    } catch (Exception e) {
        Log.i(TAG, e.toString());
        e.printStackTrace();
    }



    return edges;
}

It is possible to capture the current value of thresholdCanny and thresholdCanny2 within the onProgressChanged and replace the values of these variables according to the Seekbar movement? How can I do this?

Thank you in advance!

1 answer

1


For you to get the value of Seekbar:

seekBar.getProgress();

And within the method onProgressChanged(SeekBar seekBar, int progress, boolean b) progress is the second parameter int progress

And to exchange the values of final int thresholdCanny = 80, thresholdCanny2 = 100; you can create these variables in the class scope:

private int thresholdCanny = 80;
private int thresholdCanny2 = 100;
  • Should I use thresholdCanny = seekBar.getProgress(); ? Another doubt, it is possible to make this variable assume a value with some other calculation? example: thresholdCanny - 20 // Thank you

  • Can do thresholdCanny = Progress;

  • In this case you can create a method setThresholdCanny(int thresholdCanny) and do the calculation in the method. And instead of using thresholdCanny = progress; you do setThresholdCanny(progress);. So it becomes more flexible to create calculations etc.

  • Got it, thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.