小米8相机黑白显示
szyuandao 发布于2018-08 浏览:1907 回复:6
1
收藏

下载了安卓端的人脸识别sdk,小米8相机人脸识别时黑白显示

收藏
点赞
1
个赞
共6条回复 最后由xi0214xi回复于2019-03
#7xi0214xi回复于2019-03

试试修改demo中,Camera1Control 中 startCamera() 方法

 private void startCamera() {
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {
            if (permissionCallback != null) {
                permissionCallback.onRequestPermission();
            }
            return;
        }
        if (mCamera == null) {
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
            for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
                Camera.getCameraInfo(i, cameraInfo);
                if (cameraInfo.facing == cameraFacing) {
                    cameraId = i;
                }
            }
            mCamera = Camera.open(cameraId);
        }
        if (parameters == null) {
            parameters = mCamera.getParameters();
            // parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        }

        List focusModes = parameters.getSupportedFocusModes();
        if(focusModes!=null){
            L.i("getSupportedFocusModes = "+focusModes.toString());
        }
        if(parameters!=null){
            L.i("getFocusMode = "+parameters.getFocusMode());
        }
        if(focusModes!=null && focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)){
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        }

        surfaceTexture = new SurfaceTexture(11);
        parameters.setRotation(90); // TODO
        int rotation = ORIENTATIONS.get(displayOrientation);

        mCamera.setDisplayOrientation(rotation);
        try {
            mCamera.setPreviewCallback(new Camera.PreviewCallback() {
                @Override
                public void onPreviewFrame(byte[] data, Camera camera) {
//                    Log.e("onPreviewFrame", "onPreviewFrame");
                    Camera.Size size = camera.getParameters().getPreviewSize();

                    int rotation = getSurfaceOrientation();
                    if (cameraFacing == ICameraControl.CAMERA_FACING_FRONT) {
                        // android自带的摄像头和接usb摄像头,图片有180旋转,用usb摄像头注释下面的代码
                        if (!usbCamera) {
                            if (rotation == 90 || rotation == 270) {
                                rotation = (rotation + 180) % 360;
                            }
                        }
                    }

                    if (rotation % 180 == 90) {
                        previewView.setPreviewSize(size.height, size.width);
                    } else {
                        previewView.setPreviewSize(size.width, size.height);
                    }

                    onFrameListener.onPreviewFrame(data, rotation, size.width, size.height);
                }
            });
            mCamera.setPreviewTexture(surfaceTexture);
            if (textureView != null) {
                surfaceTexture.detachFromGLContext();
                textureView.setSurfaceTexture(surfaceTexture);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        opPreviewSize(preferredWidth, preferredHeight);
    }
0
#6szyuandao回复于2018-11
#4 江苏信新回复
这是什么啊,能帮忙发一下整个Camera1Control的代码吗

你看下我的解决方案

0
#5szyuandao回复于2018-11

List focusModes = parameters.getSupportedFocusModes();
if(focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)){
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);//r如果
}

相机设置parameters失败了他是写死的。

0
#4江苏信新回复于2018-10
#2 littergang回复
[图片]可以修改下试试

这是什么啊,能帮忙发一下整个Camera1Control的代码吗

0
#3江苏信新回复于2018-10

我也遇到了这个问题,尴尬的一米

0
#2littergang回复于2018-08

可以修改下试试

0
TOP
切换版块