Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用camera2 API使用后置摄像头进行人脸检测时工作不正常_Java_Android_Face Detection - Fatal编程技术网

Java 使用camera2 API使用后置摄像头进行人脸检测时工作不正常

Java 使用camera2 API使用后置摄像头进行人脸检测时工作不正常,java,android,face-detection,Java,Android,Face Detection,我正在使用camre2 api进行人脸检测。这对前置摄像头来说可以正常工作,但对后置摄像头则不起作用。 有人能为后置摄像头提供人脸检测矩阵吗 前摄像头人脸检测矩阵为 if (facing == CameraCharacteristics.LENS_FACING_FRONT) { StreamConfigurationMap map = mCameraCharacteristics.get(

我正在使用camre2 api进行人脸检测。这对前置摄像头来说可以正常工作,但对后置摄像头则不起作用。 有人能为后置摄像头提供人脸检测矩阵吗

前摄像头人脸检测矩阵为

 if (facing == CameraCharacteristics.LENS_FACING_FRONT) {


                        StreamConfigurationMap map = mCameraCharacteristics.get(
                                CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
                        if (map == null) {
                            continue;
                        }

                        // For still image captures, we use the largest available size.
                        Size largest = Collections.max(
                                Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                                new CompareSizesByArea());
                        /*maxImages = mCameraCharacteristics.get(
                                CameraCharacteristics.STATISTICS_INFO_MAX_FACE_COUNT);*/
                        mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),
                                ImageFormat.JPEG, 1);
                        mImageReader.setOnImageAvailableListener(
                                mOnImageAvailableListener, mBackgroundHandler);

                        // Find out if we need to swap dimension to get the preview size relative to sensor
                        // coordinate.
                        int displayRotation = this.getWindowManager().getDefaultDisplay().getRotation();
                        //noinspection ConstantConditions
                        mSensorOrientation = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
                        mSwappedDimensions = false;

                        switch (displayRotation) {
                            case Surface.ROTATION_0:
                            case Surface.ROTATION_180:
                                if (mSensorOrientation == 90 || mSensorOrientation == 270) {
                                    mSwappedDimensions = true;
                                }
                                break;
                            case Surface.ROTATION_90:
                            case Surface.ROTATION_270:
                                if (mSensorOrientation == 0 || mSensorOrientation == 180) {
                                    mSwappedDimensions = true;
                                }
                                break;
                            default:
                                Log.e(TAG, "Display rotation is invalid: " + displayRotation);
                        }

                        Point displaySize = new Point();
                        this.getWindowManager().getDefaultDisplay().getSize(displaySize);
                        int rotatedPreviewWidth = width;
                        int rotatedPreviewHeight = height;
                        int maxPreviewWidth = displaySize.x;
                        int maxPreviewHeight = displaySize.y;

                        if (mSwappedDimensions) {
                            rotatedPreviewWidth = height;
                            rotatedPreviewHeight = width;
                            maxPreviewWidth = displaySize.y;
                            maxPreviewHeight = displaySize.x;
                        }

                        if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
                            maxPreviewWidth = MAX_PREVIEW_WIDTH;
                        }

                        if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
                            maxPreviewHeight = MAX_PREVIEW_HEIGHT;
                        }

                        // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
                        // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
                        // garbage capture data.
                        mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
                                rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
                                maxPreviewHeight, largest);

                        // We fit the aspect ratio of TextureView to the size of preview we picked.
                        int orientation = getResources().getConfiguration().orientation;
                        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                            textureView.setAspectRatio(
                                    mPreviewSize.getWidth(), mPreviewSize.getHeight());
                        } else {
                            textureView.setAspectRatio(
                                    mPreviewSize.getHeight(), mPreviewSize.getWidth());
                        }

                        // Check if the flash is supported.
                        Boolean available = mCameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
                        FlashSupported = available == null ? false : available;

                        this.cameraId = "0";

                        int orientationOffset = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
                        Rect activeArraySizeRect = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);

                        // Face Detection Matrix
                        mFaceDetectionMatrix = new Matrix();
                        // TODO - I guess that is not enough if we have a landscape layout too...
                        mFaceDetectionMatrix.setRotate(orientationOffset);

                        Log.i("Test", "activeArraySizeRect1: (" + activeArraySizeRect + ") -> " + activeArraySizeRect.width() + ", " + activeArraySizeRect.height());
                        Log.i("Test", "activeArraySizeRect2: " + mPreviewSize.getWidth() + ", " + mPreviewSize.getHeight());
                        float s1 = mPreviewSize.getWidth() / (float)activeArraySizeRect.width();
                        float s2 = mPreviewSize.getHeight() / (float)activeArraySizeRect.height();
                        //float s1 = mOverlayView.getWidth();
                        //float s2 = mOverlayView.getHeight();
                        boolean mirror = true; // we always use front face camera
                        boolean weAreinPortrait = true;
                        mFaceDetectionMatrix.postScale(mirror ? -s1 : s1, s2);
                        if (mSwappedDimensions) {
                            mFaceDetectionMatrix.postTranslate(mPreviewSize.getHeight(), mPreviewSize.getWidth());
                        } else {
                            // TODO - ...

                           // here i am using same code just making mirror 
                           //value false.
                        }

                    }

这对前置摄像头来说很好用。任何一个都可以为后置摄像头人脸检测矩阵提供解决方案。

在if(facing==CameraCharacteristics.LENS\u facing\u FRONT)中对else条件使用布尔镜像=false)

任何一个都可以解决此问题吗