Problems with camera size and orientation ANDROID

asked 2014-03-04 14:23:49 -0600

ARL1990 gravatar image

updated 2014-03-04 14:26:28 -0600

Hi all

I am having problems with the camera despite of I am using an example code (image_manipulation). This:

package com.lsi.lsiappdet;

import java.util.Arrays;

import; import; import; import; import org.opencv.core.Core; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.MatOfFloat; import org.opencv.core.MatOfInt; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.core.Size; import; import; import org.opencv.imgproc.Imgproc;

import; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.WindowManager;

public class OpenCVactivity extends Activity implements CvCameraViewListener2 { private static final String TAG = "OCVSample::Activity";

public static final int      VIEW_MODE_RGBA      = 0;
public static final int      VIEW_MODE_HIST      = 1;
public static final int      VIEW_MODE_CANNY     = 2;
public static final int      VIEW_MODE_SEPIA     = 3;
public static final int      VIEW_MODE_SOBEL     = 4;
public static final int      VIEW_MODE_ZOOM      = 5;
public static final int      VIEW_MODE_PIXELIZE  = 6;
public static final int      VIEW_MODE_POSTERIZE = 7;

private MenuItem             mItemPreviewRGBA;
private MenuItem             mItemPreviewHist;
private MenuItem             mItemPreviewCanny;
private MenuItem             mItemPreviewSepia;
private MenuItem             mItemPreviewSobel;
private MenuItem             mItemPreviewZoom;
private MenuItem             mItemPreviewPixelize;
private MenuItem             mItemPreviewPosterize;
private CameraBridgeViewBase mOpenCvCameraView;

private Size                 mSize0;

private Mat                  mIntermediateMat;
private Mat                  mMat0;
private MatOfInt             mChannels[];
private MatOfInt             mHistSize;
private int                  mHistSizeNum = 25;
private MatOfFloat           mRanges;
private Scalar               mColorsRGB[];
private Scalar               mColorsHue[];
private Scalar               mWhilte;
private Point                mP1;
private Point                mP2;
private float                mBuff[];
private Mat                  mSepiaKernel;

public static int           viewMode = VIEW_MODE_RGBA;

private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
                Log.i(TAG, "OpenCV loaded successfully");
            } break;
            } break;

public OpenCVactivity() {
    Log.i(TAG, "Instantiated new " + this.getClass());

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");


    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(;

public void onPause()
    if (mOpenCvCameraView != null)

public void onResume()
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);

public void onDestroy() {
    if (mOpenCvCameraView != null)

public boolean onCreateOptionsMenu(Menu menu) {
    Log.i(TAG, "called onCreateOptionsMenu");
    mItemPreviewRGBA  = menu.add("Preview RGBA");
    mItemPreviewHist  = menu.add("Histograms");
    mItemPreviewCanny = menu.add("Canny");
    mItemPreviewSepia = menu.add("Sepia");
    mItemPreviewSobel = menu.add("Sobel");
    mItemPreviewZoom  = menu.add("Zoom");
    mItemPreviewPixelize  = menu.add("Pixelize");
    mItemPreviewPosterize = menu.add("Posterize");
    return true;

public boolean onOptionsItemSelected(MenuItem item) {
    Log.i(TAG, "called onOptionsItemSelected; selected item: " + item);
    if (item == mItemPreviewRGBA)
        viewMode = VIEW_MODE_RGBA;
    if (item == mItemPreviewHist)
        viewMode = VIEW_MODE_HIST;
    else if (item == mItemPreviewCanny)
        viewMode = VIEW_MODE_CANNY;
    else if (item == mItemPreviewSepia)
        viewMode = VIEW_MODE_SEPIA;
    else if (item == mItemPreviewSobel)
        viewMode = VIEW_MODE_SOBEL;
    else if (item == mItemPreviewZoom)
        viewMode = VIEW_MODE_ZOOM;
    else if (item == mItemPreviewPixelize)
        viewMode = VIEW_MODE_PIXELIZE;
    else if (item == mItemPreviewPosterize)
        viewMode = VIEW_MODE_POSTERIZE;
    return true;

public void onCameraViewStarted(int width, int height) {
    mIntermediateMat = new Mat();
    mSize0 = new Size();
    mChannels = new ...
edit retag flag offensive close merge delete



ARL1990 gravatar imageARL1990 ( 2014-03-04 15:44:35 -0600 )edit