Skip to content

AsynctaskCoffee/BackgroundRemove-HMS-Core

Repository files navigation

BackgroundRemove-HMS-Core

BackgroundErase with image-segmentation model HMS Core

Methods

fun onStartProcess()
fun onEndProcess()
fun onResultReady(bitmap: Bitmap?)
fun onError(exception: Exception?)

Lib usage

companion object {
        private var mAnalyzer: MLImageSegmentationAnalyzer

        init {
            val analyzerSetting = MLImageSegmentationSetting.Factory()
                .setExact(true)
                .setAnalyzerType(MLImageSegmentationSetting.BODY_SEG)
                .setScene(MLImageSegmentationScene.FOREGROUND_ONLY)
                .create()

            MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(analyzerSetting).also {
                mAnalyzer = it
            }
        }

        @JvmStatic
        fun eraseAndReturnResult(bitmap: Bitmap, eraserListener: EraserListener?) {
            val mlFrame = MLFrame.fromBitmap(bitmap)
            mAnalyzer.asyncAnalyseFrame(mlFrame)
                .addOnSuccessListener { returnImageSegmentation ->
                    eraserListener?.onResultReady(returnImageSegmentation.foreground)
                }
                .addOnFailureListener { exception ->
                    eraserListener?.onError(exception)
                }
        }
}

Releases

No releases published

Packages

No packages published

Languages