Search in sources :

Example 11 with ZoomData

use of android.hardware.camera2.legacy.ParameterUtils.ZoomData in project android_frameworks_base by AOSPA.

the class ParameterUtils method convertFaceFromLegacy.

/**
     * Convert an api1 face into an active-array based api2 face.
     *
     * <p>Out-of-ranges scores and ids will be clipped to be within range (with a warning).</p>
     *
     * @param face a non-{@code null} api1 face
     * @param activeArraySize active array size of the sensor (e.g. max jpeg size)
     * @param zoomData the calculated zoom data corresponding to this request
     *
     * @return a non-{@code null} api2 face
     *
     * @throws NullPointerException if the {@code face} was {@code null}
     */
public static Face convertFaceFromLegacy(Camera.Face face, Rect activeArray, ZoomData zoomData) {
    checkNotNull(face, "face must not be null");
    Face api2Face;
    Camera.Area fakeArea = new Camera.Area(face.rect, /*weight*/
    1);
    WeightedRectangle faceRect = convertCameraAreaToActiveArrayRectangle(activeArray, zoomData, fakeArea);
    Point leftEye = face.leftEye, rightEye = face.rightEye, mouth = face.mouth;
    if (leftEye != null && rightEye != null && mouth != null && leftEye.x != -2000 && leftEye.y != -2000 && rightEye.x != -2000 && rightEye.y != -2000 && mouth.x != -2000 && mouth.y != -2000) {
        leftEye = convertCameraPointToActiveArrayPoint(activeArray, zoomData, leftEye, /*usePreviewCrop*/
        true);
        rightEye = convertCameraPointToActiveArrayPoint(activeArray, zoomData, leftEye, /*usePreviewCrop*/
        true);
        mouth = convertCameraPointToActiveArrayPoint(activeArray, zoomData, leftEye, /*usePreviewCrop*/
        true);
        api2Face = faceRect.toFace(face.id, leftEye, rightEye, mouth);
    } else {
        api2Face = faceRect.toFace();
    }
    return api2Face;
}
Also used : Area(android.hardware.Camera.Area) Area(android.hardware.Camera.Area) Camera(android.hardware.Camera) Point(android.graphics.Point) Face(android.hardware.camera2.params.Face)

Example 12 with ZoomData

use of android.hardware.camera2.legacy.ParameterUtils.ZoomData in project android_frameworks_base by ResurrectionRemix.

the class ParameterUtils method convertFaceFromLegacy.

/**
     * Convert an api1 face into an active-array based api2 face.
     *
     * <p>Out-of-ranges scores and ids will be clipped to be within range (with a warning).</p>
     *
     * @param face a non-{@code null} api1 face
     * @param activeArraySize active array size of the sensor (e.g. max jpeg size)
     * @param zoomData the calculated zoom data corresponding to this request
     *
     * @return a non-{@code null} api2 face
     *
     * @throws NullPointerException if the {@code face} was {@code null}
     */
public static Face convertFaceFromLegacy(Camera.Face face, Rect activeArray, ZoomData zoomData) {
    checkNotNull(face, "face must not be null");
    Face api2Face;
    Camera.Area fakeArea = new Camera.Area(face.rect, /*weight*/
    1);
    WeightedRectangle faceRect = convertCameraAreaToActiveArrayRectangle(activeArray, zoomData, fakeArea);
    Point leftEye = face.leftEye, rightEye = face.rightEye, mouth = face.mouth;
    if (leftEye != null && rightEye != null && mouth != null && leftEye.x != -2000 && leftEye.y != -2000 && rightEye.x != -2000 && rightEye.y != -2000 && mouth.x != -2000 && mouth.y != -2000) {
        leftEye = convertCameraPointToActiveArrayPoint(activeArray, zoomData, leftEye, /*usePreviewCrop*/
        true);
        rightEye = convertCameraPointToActiveArrayPoint(activeArray, zoomData, leftEye, /*usePreviewCrop*/
        true);
        mouth = convertCameraPointToActiveArrayPoint(activeArray, zoomData, leftEye, /*usePreviewCrop*/
        true);
        api2Face = faceRect.toFace(face.id, leftEye, rightEye, mouth);
    } else {
        api2Face = faceRect.toFace();
    }
    return api2Face;
}
Also used : Area(android.hardware.Camera.Area) Area(android.hardware.Camera.Area) Camera(android.hardware.Camera) Point(android.graphics.Point) Face(android.hardware.camera2.params.Face)

Example 13 with ZoomData

use of android.hardware.camera2.legacy.ParameterUtils.ZoomData in project android_frameworks_base by ResurrectionRemix.

the class LegacyFaceDetectMapper method mapResultFaces.

/**
     * Update the {@code result} camera metadata map with the new value for the
     * {@code statistics.faces} and {@code statistics.faceDetectMode}.
     *
     * <p>Face detect callbacks are processed in the background, and each call to
     * {@link #mapResultFaces} will have the latest faces as reflected by the camera1 callbacks.</p>
     *
     * <p>If the scene mode was set to {@code FACE_PRIORITY} but face detection is disabled,
     * the camera will still run face detection in the background, but no faces will be reported
     * in the capture result.</p>
     *
     * @param result a non-{@code null} result
     * @param legacyRequest a non-{@code null} request (read-only)
     */
public void mapResultFaces(CameraMetadataNative result, LegacyRequest legacyRequest) {
    checkNotNull(result, "result must not be null");
    checkNotNull(legacyRequest, "legacyRequest must not be null");
    Camera.Face[] faces, previousFaces;
    int fdMode;
    boolean fdScenePriority;
    synchronized (mLock) {
        fdMode = mFaceDetectReporting ? STATISTICS_FACE_DETECT_MODE_SIMPLE : STATISTICS_FACE_DETECT_MODE_OFF;
        if (mFaceDetectReporting) {
            faces = mFaces;
        } else {
            faces = null;
        }
        fdScenePriority = mFaceDetectScenePriority;
        previousFaces = mFacesPrev;
        mFacesPrev = faces;
    }
    CameraCharacteristics characteristics = legacyRequest.characteristics;
    CaptureRequest request = legacyRequest.captureRequest;
    Size previewSize = legacyRequest.previewSize;
    Camera.Parameters params = legacyRequest.parameters;
    Rect activeArray = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    ZoomData zoomData = ParameterUtils.convertScalerCropRegion(activeArray, request.get(CaptureRequest.SCALER_CROP_REGION), previewSize, params);
    List<Face> convertedFaces = new ArrayList<>();
    if (faces != null) {
        for (Camera.Face face : faces) {
            if (face != null) {
                convertedFaces.add(ParameterUtils.convertFaceFromLegacy(face, activeArray, zoomData));
            } else {
                Log.w(TAG, "mapResultFaces - read NULL face from camera1 device");
            }
        }
    }
    if (DEBUG && previousFaces != faces) {
        // Log only in verbose and IF the faces changed
        Log.v(TAG, "mapResultFaces - changed to " + ListUtils.listToString(convertedFaces));
    }
    result.set(CaptureResult.STATISTICS_FACES, convertedFaces.toArray(new Face[0]));
    result.set(CaptureResult.STATISTICS_FACE_DETECT_MODE, fdMode);
    // Override scene mode with FACE_PRIORITY if the request was using FACE_PRIORITY
    if (fdScenePriority) {
        result.set(CaptureResult.CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_FACE_PRIORITY);
    }
}
Also used : Rect(android.graphics.Rect) Size(android.util.Size) ArrayList(java.util.ArrayList) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) ZoomData(android.hardware.camera2.legacy.ParameterUtils.ZoomData) CaptureRequest(android.hardware.camera2.CaptureRequest) Camera(android.hardware.Camera) Face(android.hardware.camera2.params.Face)

Example 14 with ZoomData

use of android.hardware.camera2.legacy.ParameterUtils.ZoomData in project android_frameworks_base by ResurrectionRemix.

the class LegacyResultMapper method getMeteringRectangles.

private static MeteringRectangle[] getMeteringRectangles(Rect activeArray, ZoomData zoomData, List<Camera.Area> meteringAreaList, String regionName) {
    List<MeteringRectangle> meteringRectList = new ArrayList<>();
    if (meteringAreaList != null) {
        for (Camera.Area area : meteringAreaList) {
            WeightedRectangle rect = ParameterUtils.convertCameraAreaToActiveArrayRectangle(activeArray, zoomData, area);
            meteringRectList.add(rect.toMetering());
        }
    }
    if (DEBUG) {
        Log.v(TAG, "Metering rectangles for " + regionName + ": " + ListUtils.listToString(meteringRectList));
    }
    return meteringRectList.toArray(new MeteringRectangle[0]);
}
Also used : WeightedRectangle(android.hardware.camera2.legacy.ParameterUtils.WeightedRectangle) ArrayList(java.util.ArrayList) MeteringRectangle(android.hardware.camera2.params.MeteringRectangle) Camera(android.hardware.Camera)

Example 15 with ZoomData

use of android.hardware.camera2.legacy.ParameterUtils.ZoomData in project android_frameworks_base by crdroidandroid.

the class LegacyRequestMapper method convertMeteringRegionsToLegacy.

private static List<Camera.Area> convertMeteringRegionsToLegacy(Rect activeArray, ParameterUtils.ZoomData zoomData, MeteringRectangle[] meteringRegions, int maxNumMeteringAreas, String regionName) {
    if (meteringRegions == null || maxNumMeteringAreas <= 0) {
        if (maxNumMeteringAreas > 0) {
            return Arrays.asList(ParameterUtils.CAMERA_AREA_DEFAULT);
        } else {
            return null;
        }
    }
    // Add all non-zero weight regions to the list
    List<MeteringRectangle> meteringRectangleList = new ArrayList<>();
    for (MeteringRectangle rect : meteringRegions) {
        if (rect.getMeteringWeight() != MeteringRectangle.METERING_WEIGHT_DONT_CARE) {
            meteringRectangleList.add(rect);
        }
    }
    if (meteringRectangleList.size() == 0) {
        Log.w(TAG, "Only received metering rectangles with weight 0.");
        return Arrays.asList(ParameterUtils.CAMERA_AREA_DEFAULT);
    }
    // Ignore any regions beyond our maximum supported count
    int countMeteringAreas = Math.min(maxNumMeteringAreas, meteringRectangleList.size());
    List<Camera.Area> meteringAreaList = new ArrayList<>(countMeteringAreas);
    for (int i = 0; i < countMeteringAreas; ++i) {
        MeteringRectangle rect = meteringRectangleList.get(i);
        ParameterUtils.MeteringData meteringData = ParameterUtils.convertMeteringRectangleToLegacy(activeArray, rect, zoomData);
        meteringAreaList.add(meteringData.meteringArea);
    }
    if (maxNumMeteringAreas < meteringRectangleList.size()) {
        Log.w(TAG, "convertMeteringRegionsToLegacy - Too many requested " + regionName + " regions, ignoring all beyond the first " + maxNumMeteringAreas);
    }
    if (DEBUG) {
        Log.v(TAG, "convertMeteringRegionsToLegacy - " + regionName + " areas = " + ParameterUtils.stringFromAreaList(meteringAreaList));
    }
    return meteringAreaList;
}
Also used : ArrayList(java.util.ArrayList) MeteringRectangle(android.hardware.camera2.params.MeteringRectangle)

Aggregations

Camera (android.hardware.Camera)25 ArrayList (java.util.ArrayList)20 Rect (android.graphics.Rect)15 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)15 CaptureRequest (android.hardware.camera2.CaptureRequest)15 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)15 Size (android.util.Size)15 Parameters (android.hardware.Camera.Parameters)10 ZoomData (android.hardware.camera2.legacy.ParameterUtils.ZoomData)10 Face (android.hardware.camera2.params.Face)10 Point (android.graphics.Point)5 Area (android.hardware.Camera.Area)5 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)5 WeightedRectangle (android.hardware.camera2.legacy.ParameterUtils.WeightedRectangle)5 Location (android.location.Location)5 Range (android.util.Range)5 List (java.util.List)5