Unable to use both cameras of Evo 4G using OpenCV4Android

让人想犯罪 __ 提交于 2019-11-30 16:19:45

The stereoscopic camera ID in Android changed from 2 to 100 with the ICS upgrade. This is the constant used by the Android Camera.open call. I don't think there was ever any official way to get one camera or the other. You can only get one image or both images.

As the above answer suggests, I used 100 as the Camera Index, but it didn't work with OpenCV, so I tried using Android's Camera SDK, but got some errors. But as this is a part of HTC Open Sense SDK, I downloaded it on my Eclipse and used http://www.htcdev.com/devcenter/opensense-sdk/stereoscopic-3d/s3d-sample-code/ . I used the base file of S3D Camera Demo and added few more functions so that I could access the Camera image data and convert it to OpenCV Mat.

So I made few changes in onTouchEvent function in that code, and more code there.

@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    //  toggle();
        //Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
        //startActivityForResult(cameraIntent, 1337);
        int bufferSize = width * height * 3;
        byte[] mPreviewBuffer = null;

        // New preview buffer.
        mPreviewBuffer = new byte[bufferSize + 4096];

        // with buffer requires addbuffer.
        camera.addCallbackBuffer(mPreviewBuffer);
        camera.setPreviewCallbackWithBuffer(mCameraCallback);
        break;
    default:
        break;
    }
    return true;
}



private final Camera.PreviewCallback mCameraCallback = new Camera.PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera c) {
    Log.d(TAG, "ON Preview frame");
    img = new Mat(height, width, CvType.CV_8UC1);
    gray = new Mat(height, width, CvType.CV_8UC1);
    img.put(0, 0, data);        



    Imgproc.cvtColor(img, gray, Imgproc.COLOR_YUV420sp2GRAY);
    String pixvalue = String.valueOf(gray.get(300, 400)[0]);
    String pixval1 = String.valueOf(gray.get(300, 400+width/2)[0]);
    Log.d(TAG, pixvalue);
    Log.d(TAG, pixval1);
        // to do the camera image split processing using "data"
}
};

The Image that you get from the camera is in YUV420s mode and I was initially having problems accessing the data as I had created a 4 channel Mat. Actually, it needs only 1 channel Mat.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!