Class PreviewDetectionRegion
DetectionRegion
for restricting detection within a camera preview. A PreviewDetectionRegion
must be created by the PreviewDetectionRegion.Builder
. To construct a PreviewDetectionRegion.Builder
a RectF
is needed to describe the percentage of the frame that is visible in the camera preview.
A PreviewDetectionRegion is useful for apps that display a camera preview. The visible image within a camera preview
is often a cropped region of the full camera frame. This class allows apps to restrict detection within this visible area.
To further restrict the detection region within a sub-region of the visible image, such as a targeting area, apps can
construct a PreviewDetectionRegion.Builder
with PreviewDetectionRegion.Builder.setRegionOfInterest(RectF)
.
PreviewDetectionRegion is designed to accept regions relative to the display's orientation. Internally PreviewDetectionRegion
will apply the rotation needed to project regions onto input frames. The majority of use cases should use the default values
described in PreviewDetectionRegion.Builder.setDisplayRotation(int)
and PreviewDetectionRegion.Builder.setCameraRotation(int)
.
Apps using a display other than default or a camera source other than CameraHelper
should provide rotation information via
the relevant builder methods.
Apps using CameraHelper
to stream the preview can access the percentage of visible camera frame by calling
CameraHelper.getRectForVisibleSurface()
within a CameraRegionListener.onVisibleRegionChanged()
callback.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionBuilder
(android.graphics.RectF visiblePreview) Creates a Builder based on the visible region of the camera image.
-
Method Details
-
Builder
@NonNull public static PreviewDetectionRegion.Builder Builder(@NonNull android.graphics.RectF visiblePreview) Creates a Builder based on the visible region of the camera image.Apps using
CameraHelper
to stream camera preview can use the value ofCameraHelper.getRectForVisibleSurface()
to restrict detection to the visible portion of the camera frame. Further restrictions can be set relative to the visible region withPreviewDetectionRegion.Builder.setRegionOfInterest(RectF)
.- Parameters:
visiblePreview
- The percentage of the camera frame that should be used to define the detection region. The region is expected to be in normalized coordinates (0..1).See also:
CameraHelper.getRectForVisibleSurface()
- Returns:
- Builder for visible preview region
-