使用OpenCv

时间:2017-05-11 08:32:04

标签: android opencv camera

我需要通过使用OpenCv在我的应用程序中的Android相机连接的帮助..我尝试一切,我的项目在android工作室编译没有任何错误,但当我打开应用程序它总是崩溃与相机断开连接,任何身体的想法如何解决它? 我在Android监视器中得到错误就像:  CameraService :: connect X(pid 2279)被拒绝(cameraId 98无效)。 相机#98无法打开:无法连接到相机服务

清单:      

<supports-screens android:resizeable="true"
                  android:smallScreens="true"
                  android:normalScreens="true"
                  android:largeScreens="true"
                  android:anyDensity="true"/>

<uses-sdk android:minSdkVersion="15"/>

<uses-permission android:name="android.permission.CAMERA"/>

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>

public abstract class MyCameraBridgeViewBase extends SurfaceView implements SurfaceHolder.Callback {

private static final String TAG = "MyCameraBridge";
private static final int MAX_UNSPECIFIED = -1;
private static final int STOPPED = 0;
private static final int STARTED = 1;

private int mState = STOPPED;
private Bitmap mCacheBitmap;
private MyCameraBridgeViewBase.CvCameraViewListener2 mListener;
private boolean mSurfaceExist;
private Object mSyncObject = new Object();

protected int mFrameWidth;
protected int mFrameHeight;
protected int mMaxHeight;
protected int mMaxWidth;
protected float mScale = 1;
protected int mPreviewFormat = Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA;
protected int mCameraIndex = -1;
protected boolean mEnabled;
protected FpsMeter mFpsMeter = null;

public MyCameraBridgeViewBase(Context context, int cameraId) {
    super(context);
    mCameraIndex = cameraId;
    getHolder().addCallback(this);
    mMaxWidth = MAX_UNSPECIFIED;
    mMaxHeight = MAX_UNSPECIFIED;
}

public MyCameraBridgeViewBase(Context context, AttributeSet attrs) {
    super(context, attrs);

    int count = attrs.getAttributeCount();
    Log.d(TAG, "Attr count: " + Integer.valueOf(count));

    TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
    if (styledAttrs.getBoolean(R.styleable.CameraBridgeViewBase_show_fps, false))
        enableFpsMeter();

    mCameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);

    getHolder().addCallback(this);
    mMaxWidth = MAX_UNSPECIFIED;
    mMaxHeight = MAX_UNSPECIFIED;
}

0 个答案:

没有答案