OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Azure Face API SDK get photo in android after verify

  • Thread starter Thread starter Woton Sampaio
  • Start date Start date
W

Woton Sampaio

Guest
I'm implementing the liveness system but I need to get the photo taken at the time of verification, but I didn't find a way to do this, I even tried to get a "print" of the preview on Android but it is displayed on a surfaceview, every attempt I make I did always return a blank image.

Is there any way to get this image still on android while checking this?

In the examples they do it like this:

Code:
open class LivenessActivity : AppCompatActivity() {
...
    override fun onResume() {
            super.onResume()
            if (mFaceAnalyzer == null) {
                initializeConfig()
                val visionSourceOptions = VisionSourceOptions(this, this as LifecycleOwner)
                // preview on surfaceView
                visionSourceOptions.setPreview(mSurfaceView)
                mVisionSource = VisionSource.fromDefaultCamera(visionSourceOptions)
                displayCameraOnLayout()
                createFaceAnalyzer()
    
            }
            startAnalyzeOnce()
        }

    private fun displayCameraOnLayout() {
        val previewSize = mVisionSource?.cameraPreviewFormat
        val params = mCameraPreviewLayout.layoutParams as ConstraintLayout.LayoutParams
        params.dimensionRatio = previewSize?.height.toString() + ":" + previewSize?.width
        params.width = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT
        params.matchConstraintDefaultWidth = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT_PERCENT
        params.matchConstraintPercentWidth = 0.8f
        mCameraPreviewLayout.layoutParams = params
    }

    private fun createFaceAnalyzer() {
        FaceAnalyzerCreateOptions().use { createOptions ->
            createOptions.setFaceAnalyzerMode(FaceAnalyzerMode.TRACK_FACES_ACROSS_IMAGE_STREAM)

            mFaceAnalyzer = FaceAnalyzerBuilder()
                .serviceOptions(mServiceOptions)
                .source(mVisionSource)
                .createOptions(createOptions)
                .build().get()
        }

        mFaceAnalyzer?.apply {
            this.analyzed.addEventListener(analyzedListener)
            this.analyzing.addEventListener(analyzingListener)
            this.stopped.addEventListener(stoppedListener)
        }
    }
...
}

I tried several ways to "print" the surfaceview since I didn't have direct access to the camera object but none of them worked:

Code:
private fun usePixelCopy(view: SurfaceView, callback: (String) -> Unit) {
    val bmp = Bitmap.createBitmap(view.width, view.width, Bitmap.Config.ARGB_8888)

    PixelCopy.request(view, bmp, {
        callback(bitmapToBase64(bmp))
    }, Handler(Looper.getMainLooper()))
}

Source: Link
<p>I'm implementing the liveness system but I need to get the photo taken at the time of verification, but I didn't find a way to do this, I even tried to get a "print" of the preview on Android but it is displayed on a surfaceview, every attempt I make I did always return a blank image.</p>
<p>Is there any way to get this image still on android while checking this?</p>
<p>In the examples they do it like this:</p>
<pre><code>open class LivenessActivity : AppCompatActivity() {
...
override fun onResume() {
super.onResume()
if (mFaceAnalyzer == null) {
initializeConfig()
val visionSourceOptions = VisionSourceOptions(this, this as LifecycleOwner)
// preview on surfaceView
visionSourceOptions.setPreview(mSurfaceView)
mVisionSource = VisionSource.fromDefaultCamera(visionSourceOptions)
displayCameraOnLayout()
createFaceAnalyzer()

}
startAnalyzeOnce()
}

private fun displayCameraOnLayout() {
val previewSize = mVisionSource?.cameraPreviewFormat
val params = mCameraPreviewLayout.layoutParams as ConstraintLayout.LayoutParams
params.dimensionRatio = previewSize?.height.toString() + ":" + previewSize?.width
params.width = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT
params.matchConstraintDefaultWidth = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT_PERCENT
params.matchConstraintPercentWidth = 0.8f
mCameraPreviewLayout.layoutParams = params
}

private fun createFaceAnalyzer() {
FaceAnalyzerCreateOptions().use { createOptions ->
createOptions.setFaceAnalyzerMode(FaceAnalyzerMode.TRACK_FACES_ACROSS_IMAGE_STREAM)

mFaceAnalyzer = FaceAnalyzerBuilder()
.serviceOptions(mServiceOptions)
.source(mVisionSource)
.createOptions(createOptions)
.build().get()
}

mFaceAnalyzer?.apply {
this.analyzed.addEventListener(analyzedListener)
this.analyzing.addEventListener(analyzingListener)
this.stopped.addEventListener(stoppedListener)
}
}
...
}
</code></pre>
<p>I tried several ways to "print" the surfaceview since I didn't have direct access to the camera object but none of them worked:</p>
<pre><code>private fun usePixelCopy(view: SurfaceView, callback: (String) -> Unit) {
val bmp = Bitmap.createBitmap(view.width, view.width, Bitmap.Config.ARGB_8888)

PixelCopy.request(view, bmp, {
callback(bitmapToBase64(bmp))
}, Handler(Looper.getMainLooper()))
}
</code></pre>
<p>Source: <a href="https://github.com/Azure-Samples/az...example/FaceAnalyzerSample/AnalyzeActivity.kt" rel="nofollow noreferrer">Link</a></p>
Continue reading...
 

Latest posts

Top