Ask Your Question
1

Android: How to set capture resolution for NativeCameraView?

asked 2013-05-06 15:48:48 -0500

AAZZ gravatar image

updated 2013-05-06 15:49:12 -0500

I use NativeCameraView and want to take pictures with camera resolutions. But I can take pictures only in preview resolution. mRgba.cols() and mRgba.rows() get resolution of display but I want to capture with camera resolution and I want the user to choose camera resolution.

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    // TODO Auto-generated method stub

    /*
    mRgba = inputFrame.rgba();
    Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_RGB2HSV_FULL);
    return mRgba;
    */

    // http://answers.opencv.org/question/12265/how-to-display-a-mat-in-imageview/
    if (take_pic)
    {
        take_pic = false;

        mRgba = inputFrame.rgba();
        bitmap = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(),Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(mRgba, bitmap);

        // http://stackoverflow.com/questions/5776684/how-can-i-convert-a-view-to-a-drawable
        //v.setDrawingCacheEnabled(true);
        //bitmap = Bitmap.createBitmap(v.getDrawingCache());

        //Log.i(TAG,"onTouch event");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
        String currentDateandTime = sdf.format(new Date());
        String fileName = Environment.getExternalStorageDirectory().getPath() +
                               "/camera" + currentDateandTime + ".jpg";

        //mOpenCvCameraView.takePicture(fileName); //***

        // http://stackoverflow.com/questions/4989182/converting-java-bitmap-to-byte-array
        ByteArrayOutputStream stream = new ByteArrayOutputStream();;
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byteArray = stream.toByteArray();

        try {
             FileOutputStream fos = new FileOutputStream(fileName);

             fos.write(byteArray);
             fos.close();

          //mCamera.startPreview();
        } catch (java.io.IOException e) {
          Log.e("PictureDemo", "Exception in photoCallback", e);
        }
          return mRgba;
    }

How can I use display resolution for preview and capture with camera resolution using NativeCameraView?

And how can I find out camera resolutions for NativeCameraView (it hasn't a setResolution method like the JavaCameraView)?

edit retag flag offensive close merge delete

Comments

Please be aware that the OpenCV native camera isn't intended to making still pictures (but for preview only), I' suggest you use Java camera for taking pictures like shown in the Tutorial-3.

Andrey Pavlenko gravatar imageAndrey Pavlenko ( 2013-05-11 04:40:55 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-05-07 02:06:55 -0500

JavaCameraView does not have its own setResolution method. There is JavaCameraView subclass in tutorial-3 that implements this method. If you want to implement the same behavior with Native Camera you need to subclass NativeCameraView and add the same setResolution method to it. Also you can override calculateCameraFrameSize method to select proper frame resolution. See CameraBridgeViewBase class for details. It is base class for NativeCameraView and JavaCameraView.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-06 15:48:48 -0500

Seen: 4,231 times

Last updated: May 07 '13