Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter for mCamera in JavaCameraView class #16759

Closed
wants to merge 1 commit into from

Conversation

StidOfficial
Copy link

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under OpenCV (BSD) License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Example usage :

private JavaCameraView cameraView;
...
Camera.Parameters params = cameraView.getCamera().getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cameraView.getCamera().setParameters(params);

@asmorkalov
Copy link
Contributor

Could you provide some reason why you want to expose camera object? The protect ed camera object guarantees that application has predictable lifecycle and camera settings are done in proper state. You can use inheritance and implement own class for specific behaviour, there is no need to modify original code.

@StidOfficial
Copy link
Author

StidOfficial commented Mar 8, 2020

It's more complex to create a extends class :

public class JavaCameraViewAdvanced extends JavaCameraView {

    public JavaCameraViewAdvanced(Context context, int cameraId) {
        super(context, cameraId);
    }

    public JavaCameraViewAdvanced(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void enableTorch() {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
        mCamera.setParameters(parameters);
    }

    public void disableTorch() {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
        mCamera.setParameters(parameters);
    }
}

Replace JavaCameraView component in xml layout and use it in normal code juste for enable/disable flash torch.
Than add getter and use it in normal code.

@asmorkalov
Copy link
Contributor

Theoretically yes, but in practice even with flash you need to check flash mode availability (there is no flash for frontal camera), handle view events (turn it of, when camera view is closed), etc. So the amount of extra code lines for real use case is very small.

@asmorkalov
Copy link
Contributor

@alalek What do you think about the patch?

@asmorkalov
Copy link
Contributor

The solution was discussed with @alalek @VadimLevin @vpisarev and the team decided to reject the patch. There are several reasons for that:

  • It's not safe to expose camera for manipulations, because particular camera options should be sent during particular camera stages. User has to handle the events and inheritance is treated as better solution, see discussion above.
  • There are JavaCamera2View and it should be consistent.

@asmorkalov asmorkalov closed this Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants