How To Using Image Adjustment (Brightness, Contrast) in UVCCamera Library on Android Studio

1.3k views Asked by At

I'm trying to build an apps to capture picture from usb camera, using UVCCamera from https://github.com/saki4510t/UVCCamera But, i didn't know, how to implement image adjustment setting (like Adjust Brightness, Contrast, White Balance) in this library. I've tried to using seekbar to adjust brightness setting, and this is my code :

final UVCCamera camera = new UVCCamera();

private final OnSeekBarChangeListener mSeekBarChangeListener = new OnSeekBarChangeListener()
{
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) 
    {
        if (mCameraHandler.isOpened()) //When USB Camera, Connected
        {       
            camera.setBrightness(progress);
        }
    }
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) 
    {
    }
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) 
    {
    }
};

And, if i try to change value of seekbar, the value has changed, but it doesn't change the brightness level. Can anybody explain me, how to change the image adjustment in this library or give me correction about my code? Any answers will be apreciate from me

Regards, and have a good day everyone :)

1

There are 1 answers

0
iS_Tom On

I updated the files in my project from the new version of the library (libuvccamera, usbCameraCommon) and modified the code from the example 8. I gave a sample code. Here is an example of the code that I got.

    private SeekBar.OnSeekBarChangeListener seekBarChangeListener =
            new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress,
                                              boolean fromUser) {
                    // TODO Auto-generated method stub
                    br = progress;

                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    if (isActive()) {

                                setValue(seekBar.getProgress());

                        }
                    }
                    // TODO Auto-generated method stub
                };

    private int setValue( final int value) {
            return mCameraHandler != null ? mCameraHandler.setValue(value) : 0;
        }
private boolean isActive() {
        return mCameraHandler != null && mCameraHandler.isOpened();
    }

And edit AbstractUVCCameraHandler.java

public int setValue( final int value) {
        checkReleased();
        final CameraThread thread = mWeakThread.get();
        final UVCCamera camera = thread != null ? thread.mUVCCamera : null;
        if (camera != null) {

                camera.setBrightness(value);
                return camera.getBrightness();
        }
    throw new IllegalStateException();
}