Wrote flow for here. (Written in Japanese)
private val surfaceTextureListener = object : TextureView.SurfaceTextureListener {
override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) {
imageReader = ImageReader.newInstance(width, height, ImageFormat.JPEG, /*maxImages*/ 2);
imageReader?.setOnImageAvailableListener(mOnImageAvailableListener, backgroundHandler)
openCamera()
}
}
private val mOnImageAvailableListener = ImageReader.OnImageAvailableListener {
val bitmap = textureView.bitmap
val visionImage = FirebaseVisionImage.fromBitmap(bitmap)
val options = FirebaseVisionFaceDetectorOptions.Builder()
.setModeType(FirebaseVisionFaceDetectorOptions.FAST_MODE)
.setLandmarkType(FirebaseVisionFaceDetectorOptions.ALL_LANDMARKS)
.setClassificationType(FirebaseVisionFaceDetectorOptions.ALL_CLASSIFICATIONS)
.setMinFaceSize(0.15f)
.setTrackingEnabled(true)
.build()
val detector = FirebaseVision.getInstance().getVisionFaceDetector(options)
detector.detectInImage(visionImage)
.addOnSuccessListener {
print("good job")
}
.addOnFailureListener {
it.printStackTrace()
}
}
Actually, my codes have something wrong, so this listener never called...😇