thegouger / ResistorScanner

Android app using OpenCV that scans resistor colour bands to determine their values
MIT License
151 stars 52 forks source link

Enable macro mode #4

Open f4grx opened 9 years ago

f4grx commented 9 years ago

Hello

on the S3 jellybean detection does not work because camera can not focus close enough.

Here I added a checkbox in the main view after Seekbar

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Macro"
        android:id="@+id/btnMacro"
        android:layout_above="@+id/CameraZoomControls"
        android:layout_centerHorizontal="true" />

Then I added code in CameraView to handle the checkbox

    public void setMacroControl(CheckBox macroControl)
    {
        _macroControl = macroControl;
        _macroControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Camera.Parameters params = mCamera.getParameters();
                List<String> FocusModes = params.getSupportedFocusModes();
                if (isChecked) {
                    if (FocusModes != null && FocusModes.contains(Camera.Parameters.FOCUS_MODE_MACRO)) {
                        params.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
                    }
                } else {
                    if (FocusModes != null && FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
                        params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
                    } else if (FocusModes != null && FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
                        params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
                    }

                }
                mCamera.setParameters(params);
            }
        });
    }

it is enabled in main activity with:

_resistorCameraView.setMacroControl((CheckBox) findViewById(R.id.btnMacro));

It will be very useful.

thegouger commented 9 years ago

Nice! If you make a pull request, I can merge these changes in.

f4grx commented 9 years ago

you can also use some old fashioned copy-paste! I dont want to fork and all for 10 code lines :)

This code just has to be added, there is nothing to remove.

thegouger commented 9 years ago

Heh, touché