我正在使用华为图像分割从图像中去除背景。此代码在debug build上工作得很好,但在release build上不起作用。我不明白可能是什么情况。
代码:
private fun imageSegmentation(bitmap: Bitmap?) {
if (bitmap == null) {
dialog.dismiss()
Toast.makeText(requireContext(), "Something went wrong. Try again!", Toast.LENGTH_LONG).show()
return
}
val setting =
MLImageSegmentationSetting.Factory()
.setAnalyzerType(MLImageSegmentationSetting.BODY_SEG)
.setExact(true)
.create()
val analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(setting)
val mlFrame = MLFrame.Creator().setBitmap(bitmap).create()
val task = analyzer?.asyncAnalyseFrame(mlFrame)
task?.addOnSuccessListener { mlImageSegmentationResults ->
if (mlImageSegmentationResults != null) {
removalFlag = true
removalBitmap = mlImageSegmentationResults.foreground
} else
Toast.makeText(context, "No human body is detected!", Toast.LENGTH_LONG).show()
dialog.dismiss()
}?.addOnFailureListener {
Toast.makeText(context, "No human body is detected!", Toast.LENGTH_LONG).show()
dialog.dismiss()
}
}
依赖项:
implementation 'com.huawei.hms:ml-computer-vision-segmentation:2.2.0.300'
implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-body-model:2.2.0.300'
注意:根据我的理解,task?.addOnSuccessListener
调用但mlImageSegmentationResults
返回null。