人脸识别demo部分手机出现黑白,没有彩色
廖水生545 发布于2019-02-11 浏览:1032 回复:3
0
收藏

兄弟们有遇到 人脸识别demo部分手机预览头像出现黑白,没有彩色

收藏
点赞
0
个赞
共3条回复 最后由xi0214xi回复于2019-03-12
#4xi0214xi回复于2019-03-12

试试修改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
#3xi0214xi回复于2019-03-12

我也遇到了

0
#2彦丶子凡回复于2019-02-12

是不是你手机有问题?

0
TOP
切换版块