-
-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor facedetection and add autoclose parameter to camera2 imageli…
…stener
- Loading branch information
Showing
12 changed files
with
96 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
encoder/src/main/java/com/pedro/encoder/input/video/facedetector/Face.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.pedro.encoder.input.video.facedetector | ||
|
||
import android.graphics.Point | ||
import android.graphics.Rect | ||
|
||
/** | ||
* Created by pedro on 10/10/23. | ||
*/ | ||
data class Face( | ||
val id: Int?, //depend if device support it, if not supported the value could be -1 | ||
val leftEye: Point?, //depend if device support it | ||
val rightEye: Point?, //depend if device support it | ||
val mouth: Point?, //depend if device support it | ||
val rect: Rect, | ||
val score: Int //range 1 to 100 | ||
) |
10 changes: 10 additions & 0 deletions
10
encoder/src/main/java/com/pedro/encoder/input/video/facedetector/FaceDetectorCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.pedro.encoder.input.video.facedetector | ||
|
||
import android.graphics.Rect | ||
|
||
/** | ||
* Created by pedro on 10/10/23. | ||
*/ | ||
interface FaceDetectorCallback { | ||
fun onGetFaces(faces: Array<Face>, scaleSensor: Rect?, sensorOrientation: Int) | ||
} |
44 changes: 44 additions & 0 deletions
44
encoder/src/main/java/com/pedro/encoder/input/video/facedetector/Utils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@file:Suppress("DEPRECATION") | ||
|
||
package com.pedro.encoder.input.video.facedetector | ||
|
||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
import android.hardware.Camera.Face as Camera1Face | ||
import android.hardware.camera2.params.Face as Camera2Face | ||
|
||
/** | ||
* Created by pedro on 10/10/23. | ||
*/ | ||
|
||
fun Camera1Face.toFace(): Face { | ||
return Face( | ||
id = id, | ||
leftEye = leftEye, | ||
rightEye = rightEye, | ||
mouth = mouth, | ||
rect = rect, | ||
score = score | ||
) | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) | ||
fun Camera2Face.toFace(): Face { | ||
return Face( | ||
id = id, | ||
leftEye = leftEyePosition, | ||
rightEye = rightEyePosition, | ||
mouth = mouthPosition, | ||
rect = bounds, | ||
score = score | ||
) | ||
} | ||
|
||
fun mapCamera1Faces(faces: Array<Camera1Face>): Array<Face> { | ||
return faces.map { it.toFace() }.toTypedArray() | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) | ||
fun mapCamera2Faces(faces: Array<Camera2Face>): Array<Face> { | ||
return faces.map { it.toFace() }.toTypedArray() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters