[v4,2/3] libcamera: Add face detection controls
diff mbox series

Message ID 20240903104018.3289112-3-chenghaoyang@chromium.org
State Superseded
Headers show
Series
  • Add Face Detection Controls
Related show

Commit Message

Harvey Yang Sept. 3, 2024, 10:39 a.m. UTC
From: Yudhistira Erlandinata <yerlandinata@chromium.org>

Add FaceDetectMode, FaceDetectFaceRectangles, FaceDetectFaceScores,
and FaceDetectFaceLandmark. Also add ControlTypePoint for supporting
FaceDetectFaceLandmark.

Signed-off-by: Yudhistira Erlandinata <yerlandinata@chromium.org>
Co-developed-by: becker hsieh <beckerh@chromium.org>
Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
---
 include/libcamera/controls.h         |  6 ++
 src/libcamera/control_ids_draft.yaml | 85 ++++++++++++++++++++++++++++
 src/libcamera/controls.cpp           |  6 ++
 3 files changed, 97 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 7c2bb2872..bf1b8609c 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -34,6 +34,7 @@  enum ControlType {
 	ControlTypeString,
 	ControlTypeRectangle,
 	ControlTypeSize,
+	ControlTypePoint,
 };
 
 namespace details {
@@ -87,6 +88,11 @@  struct control_type<Size> {
 	static constexpr ControlType value = ControlTypeSize;
 };
 
+template<>
+struct control_type<Point> {
+	static constexpr ControlType value = ControlTypePoint;
+};
+
 template<typename T, std::size_t N>
 struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {
 };
diff --git a/src/libcamera/control_ids_draft.yaml b/src/libcamera/control_ids_draft.yaml
index 9bef5bf15..c0cf53207 100644
--- a/src/libcamera/control_ids_draft.yaml
+++ b/src/libcamera/control_ids_draft.yaml
@@ -227,4 +227,89 @@  controls:
             value. All of the custom test patterns will be static (that is the
             raw image must not vary from frame to frame).
 
+  - FaceDetectMode:
+      type: uint8_t
+      description: |
+        Reporting mode of face detection.
+
+        The number of faces in each list must be the same.
+
+        Currently identical to ANDROID_STATISTICS_FACE_DETECT_MODE.
+
+        \sa FaceDetectFaceRectangles
+        \sa FaceDetectFaceScores
+        \sa FaceDetectFaceLandmarks
+        \sa FaceDetectFaceIds
+
+      enum:
+        - name: FaceDetectModeOff
+          value: 0
+          description: |
+            Pipeline should not report face detection result.
+        - name: FaceDetectModeSimple
+          value: 1
+          description: |
+            Pipeline should at least report FaceDetectFaceRectangles and
+            FaceDetectFaceScores for each detected faces.
+            FaceDetectFaceLandmarks and FaceDetectFaceIds is optional.
+
+        - name: FaceDetectModeFull
+          value: 2
+          description: |
+            Pipeline should report all face controls, including
+            FaceDetectFaceRectangles, FaceDetectFaceScores,
+            FaceDetectFaceLandmarks, and FaceDeteceFaceIds.
+
+  - FaceDetectFaceRectangles:
+      type: Rectangle
+      description: |
+        Boundary rectangles of the detected faces.
+        The number of values should be the number of faces.
+
+        The FaceDetectFaceRectangles control can only be returned in metadata.
+
+        Currently identical to ANDROID_STATISTICS_FACE_RECTANGLES.
+
+      size: [n]
+
+  - FaceDetectFaceScores:
+      type: uint8_t
+      description: |
+        Confidence score of each of the detected faces by face detector.
+        The range of score is [0, 100].
+        The FaceDetectFaceScores control can only be returned in metadata.
+        The number of values should be the number of faces.
+
+        Currently identical to ANDROID_STATISTICS_FACE_SCORES.
+
+      size: [n]
+
+  - FaceDetectFaceLandmarks:
+      type: Point
+      description: |
+        Array of human face landmark coordinates in format:
+        [..., left_eye_i, right_eye_i, mouth_i, left_eye_i+1, ...],
+        with i = index of face.
+        The number of values should be 3 * the number of faces.
+
+        The FaceDetectFaceLandmarks control can only be returned in metadata.
+
+        Currently identical to ANDROID_STATISTICS_FACE_LANDMARKS.
+
+      size: [n]
+
+  - FaceDetectFaceIds:
+      type: int32_t
+      description: |
+        Each detected face is given a unique ID that is valid for as long as
+        the face is visible to the camera device. A face that leaves the field
+        of view and later returns may be assigned a new ID.
+        The number of values should be the number of faces.
+
+        The FaceDetectFaceIds control can only be returned in metadata.
+
+        Currently identical to ANDROID_STATISTICS_FACE_IDS.
+
+      size: [n]
+
 ...
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 11d35321c..ce73ae9d7 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -61,6 +61,7 @@  static constexpr size_t ControlValueSize[] = {
 	[ControlTypeString]		= sizeof(char),
 	[ControlTypeRectangle]		= sizeof(Rectangle),
 	[ControlTypeSize]		= sizeof(Size),
+	[ControlTypePoint]		= sizeof(Point),
 };
 
 } /* namespace */
@@ -255,6 +256,11 @@  std::string ControlValue::toString() const
 			str += value->toString();
 			break;
 		}
+		case ControlTypePoint: {
+			const Point *value = reinterpret_cast<const Point *>(data);
+			str += value->toString();
+			break;
+		}
 		case ControlTypeNone:
 		case ControlTypeString:
 			break;