Skip to content

Commit

Permalink
Accept null data in Frames
Browse files Browse the repository at this point in the history
  • Loading branch information
husaynhakeem committed Jun 27, 2018
1 parent 0e7c7ee commit d3eafa6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 80 deletions.
69 changes: 0 additions & 69 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
implementation "com.otaliastudios:cameraview:1.5.1"

// Android face detector
implementation 'com.github.husaynhakeem:android-face-detector:v1.0'
implementation 'com.github.husaynhakeem:android-face-detector:v1.1'
}

apply plugin: 'com.google.gms.google-services'
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ class FaceDetector(private val faceBoundsOverlay: FaceBoundsOverlay) {
}

private fun detectFacesIn(frame: Frame) {
firebaseFaceDetectorWrapper.process(
image = convertFrameToImage(frame),
onSuccess = {
faceBoundsOverlay.updateFaces(convertToListOfFaceBounds(it))
},
onError = {
Toast.makeText(faceBoundsOverlay.context, "Error processing images: $it", Toast.LENGTH_LONG).show()
})
frame.data?.let {
firebaseFaceDetectorWrapper.process(
image = convertFrameToImage(frame),
onSuccess = {
faceBoundsOverlay.updateFaces(convertToListOfFaceBounds(it))
},
onError = {
Toast.makeText(faceBoundsOverlay.context, "Error processing images: $it", Toast.LENGTH_LONG).show()
})
}
}

private fun convertFrameToImage(frame: Frame) =
FirebaseVisionImage.fromByteArray(frame.data, extractFrameMetadata(frame))
FirebaseVisionImage.fromByteArray(frame.data!!, extractFrameMetadata(frame))

private fun extractFrameMetadata(frame: Frame): FirebaseVisionImageMetadata =
FirebaseVisionImageMetadata.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.graphics.Rect
data class FaceBounds(val id: Int, val box: Rect)

data class Frame(
val data: ByteArray,
val data: ByteArray?,
val rotation: Int,
val size: Size,
val format: Int,
Expand Down

0 comments on commit d3eafa6

Please sign in to comment.