Ask Your Question
0

how to create trackbar in opencv with java API

asked 2015-03-25 06:38:25 -0600

rmae gravatar image

updated 2015-03-25 06:49:42 -0600

berak gravatar image

i want to create a trackbar\sliderbar using opencv2411 with java API. i did not found any class in opencv java docs that does so.

how can i create trackbar in opencv with java API

edit retag flag offensive close merge delete

Comments

1

unfortunately, there is no such thing from the opencv side (it does not handle any gui in java)

but i'm sure, you can do an easy replacement using awt/swing.

berak gravatar imageberak ( 2015-03-25 06:46:54 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-08-25 21:28:31 -0600

There's an example on how to create swing GUI with Java OpenCV. The full source is available here: https://github.com/JavaOpenCVBook/cod... You can compile and run it in a couple minutes using maven and the information here: https://github.com/JavaOpenCVBook/code

You would basically have to put a JSlider to your JFrame, and the code there would be something like this:

    private void setupSlider(JFrame frame) {
    JLabel sliderLabel = new JLabel("Blur level", JLabel.CENTER);
    sliderLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

    int minimum = 0;
    int maximum = 10;
    int initial =0;

    JSlider levelSlider = new JSlider(JSlider.HORIZONTAL,
            minimum, maximum, initial);

    levelSlider.setMajorTickSpacing(2);
    levelSlider.setMinorTickSpacing(1);
    levelSlider.setPaintTicks(true);
    levelSlider.setPaintLabels(true);
    levelSlider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider)e.getSource();
            int level = (int)source.getValue();
            Mat output = imageProcessor.blur(image, level);
            updateView(output);         
        }
    });

    frame.add(sliderLabel);
    frame.add(levelSlider);
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-03-25 06:38:25 -0600

Seen: 1,228 times

Last updated: Mar 25 '15