Android OpenCV - CameraBridgeViewBase take picture?

user3546879

Please, can anybody help me with this?
I have a project using CameraBridgeViewBase and I want to take a picture and save a file, but CameraBridgeViewBase doesn't implement the function takePicture.

user3546879

Result: I implemented a new class extends JavaCameraView and implemented myself the function takePicture.

import org.opencv.android.JavaCameraView;

import java.io.FileOutputStream;
import java.util.List;

import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.Size;
import android.util.AttributeSet;
import android.util.Log;

public class MyCameraView extends JavaCameraView implements PictureCallback {

    private static final String TAG = "myCameraView";
    private String mPictureFileName;

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

    public List<String> getEffectList() {
        return mCamera.getParameters().getSupportedColorEffects();
    }

    public boolean isEffectSupported() {
        return (mCamera.getParameters().getColorEffect() != null);
    }

    public String getEffect() {
        return mCamera.getParameters().getColorEffect();
    }

    public void setEffect(String effect) {
        Camera.Parameters params = mCamera.getParameters();
        params.setColorEffect(effect);
        mCamera.setParameters(params);
    }

    public List<Size> getResolutionList() {
        return mCamera.getParameters().getSupportedPreviewSizes();
    }

    public void setResolution(Size resolution) {
        disconnectCamera();
        mMaxHeight = resolution.height;
        mMaxWidth = resolution.width;
        connectCamera(getWidth(), getHeight());
    }

    public Size getResolution() {
        return mCamera.getParameters().getPreviewSize();
    }

    public void takePicture(final String fileName) {
        Log.i(TAG, "Taking picture");
        this.mPictureFileName = fileName;
        // Postview and jpeg are sent in the same buffers if the queue is not empty when performing a capture.
        // Clear up buffers to avoid mCamera.takePicture to be stuck because of a memory issue
        mCamera.setPreviewCallback(null);

        // PictureCallback is implemented by the current class
        mCamera.takePicture(null, null, this);
    }

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        Log.i(TAG, "Saving a bitmap to file");
        // The camera preview was automatically stopped. Start it again.
        mCamera.startPreview();
        mCamera.setPreviewCallback(this);

        // Write the image in a file (in jpeg format)
        try {
            FileOutputStream fos = new FileOutputStream(mPictureFileName);

            fos.write(data);
            fos.close();

        } catch (java.io.IOException e) {
            Log.e("PictureDemo", "Exception in photoCallback", e);
        }

    }
}

-

    private MyCameraView mOpenCvCameraView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        mOpenCvCameraView = (MyCameraView) view.findViewById(R.id.fd_activity_surface_view);
        mOpenCvCameraView.setCvCameraViewListener(this);

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        mOpenCvCameraView.enableView();

        String filename = "teste.jpg";
        mOpenCvCameraView.takePicture(filename);
        mOpenCvCameraView.disableView();
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Take picture from CameraGLSurfaceView in Android with Opencv

From Dev

OpenCV Android - color issue using CameraBridgeViewBase

From Dev

Android - Take picture without preview

From Dev

Take new picture action on Android

From Dev

Take picture continuously with autofocus in android

From Dev

Android - take picture - pass uri to camera app

From Dev

Android using front facing camera to take a picture

From Dev

Android - take picture - onActivityResult returns immediately

From Dev

Android - take picture - pass uri to camera app

From Dev

Take picture with front camera in android service

From Dev

Android - take picture - onActivityResult returns immediately

From Dev

Take Picture and Upload to Android Firebase Error

From Dev

ANDROID STUDIO: Take picture with Camera API -> Send this picture to another activity

From Dev

Getting Mat picture from camera in OpenCV for Android

From Dev

Activity extended from CameraBridgeViewBase (OpenCV) doesn't make camera connection

From Dev

How to take a picture without an Intent and without any view window in Android

From Dev

Android: take camera picture intent remove confirmation dialog

From Dev

Take picture only with android camera intent in Kotlin, not video

From Dev

How to take a picture without an Intent and without any view window in Android

From Dev

Android Tablet Take Picture Camera Intent Activity Restarts

From Dev

Android Camera2 : can't take picture with front camera

From Java

Take the color avarage of each column of a picture using OpenCV with C++ on Visual Studio 2019

From Dev

Take picture with volume button

From Dev

How to take a picture in Xamarin?

From Dev

Application will take a picture, but will not save it

From Dev

Take a picture from terminal

From Dev

How to take a picture to show in a `ImageView` and save the picture?

From Dev

How To Use AVCaptureStillImageOutput To Take Picture

From Dev

Take a picture with mobile using javascript

Related Related

  1. 1

    Take picture from CameraGLSurfaceView in Android with Opencv

  2. 2

    OpenCV Android - color issue using CameraBridgeViewBase

  3. 3

    Android - Take picture without preview

  4. 4

    Take new picture action on Android

  5. 5

    Take picture continuously with autofocus in android

  6. 6

    Android - take picture - pass uri to camera app

  7. 7

    Android using front facing camera to take a picture

  8. 8

    Android - take picture - onActivityResult returns immediately

  9. 9

    Android - take picture - pass uri to camera app

  10. 10

    Take picture with front camera in android service

  11. 11

    Android - take picture - onActivityResult returns immediately

  12. 12

    Take Picture and Upload to Android Firebase Error

  13. 13

    ANDROID STUDIO: Take picture with Camera API -> Send this picture to another activity

  14. 14

    Getting Mat picture from camera in OpenCV for Android

  15. 15

    Activity extended from CameraBridgeViewBase (OpenCV) doesn't make camera connection

  16. 16

    How to take a picture without an Intent and without any view window in Android

  17. 17

    Android: take camera picture intent remove confirmation dialog

  18. 18

    Take picture only with android camera intent in Kotlin, not video

  19. 19

    How to take a picture without an Intent and without any view window in Android

  20. 20

    Android Tablet Take Picture Camera Intent Activity Restarts

  21. 21

    Android Camera2 : can't take picture with front camera

  22. 22

    Take the color avarage of each column of a picture using OpenCV with C++ on Visual Studio 2019

  23. 23

    Take picture with volume button

  24. 24

    How to take a picture in Xamarin?

  25. 25

    Application will take a picture, but will not save it

  26. 26

    Take a picture from terminal

  27. 27

    How to take a picture to show in a `ImageView` and save the picture?

  28. 28

    How To Use AVCaptureStillImageOutput To Take Picture

  29. 29

    Take a picture with mobile using javascript

HotTag

Archive