我正在研究一个项目,必须改变一个人的形象的头发颜色,为此,我正在使用华为的头发分割。
这是分析图像的分析仪。
val setting = MLImageSegmentationSetting.Factory()
.setExact(true)
.setAnalyzerType(MLImageSegmentationSetting.HAIR_SEG)
.create()
analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(setting)
// Create an MLFrame by using android.graphics.Bitmap. Recommended image size: large than 224*224.
bitmap = BitmapFactory.decodeResource(this.resources, R.drawable.imgseg_foreground);
val mlFrame = MLFrame.Creator().setBitmap(bitmap).create()
val task: Task<MLImageSegmentation> = analyzer!!.asyncAnalyseFrame(mlFrame)
task.addOnSuccessListener(OnSuccessListener<MLImageSegmentation?> { imageSegmentationResult -> // Processing logic for recognition success.
if (imageSegmentationResult != null) {
[email protected](imageSegmentationResult)
} else {
[email protected]("imageSegmentationResult is null.")
}
})
.addOnFailureListener(OnFailureListener { e -> // Processing logic for recognition failure.
[email protected](e.message!!)
})
这是displaySuccess()的代码
private fun displaySuccess(imageSegmentationResult: MLImageSegmentation) {
if (bitmap == null) {
displayFailure("bitmap is null.")
return
}
// Here I get null value in getMask()
if (imageSegmentationResult.getMasks() == null) {
return
}
var processedBitmap: Bitmap? = null
val pixels: IntArray = byteArrToIntArr(imageSegmentationResult.getMasks())
processedBitmap = Bitmap.createBitmap(
pixels,
0,
bitmap!!.width,
bitmap!!.width,
bitmap!!.height,
Bitmap.Config.ARGB_8888
)
if (processedBitmap != null) {
binding.imgHolder.setImageBitmap(processedBitmap)
} else {
displayFailure("bitmapFore is null.")
}
}
,我在这里获得零值。
if (imageSegmentationResult.getMasks() == null) {
return
}
这是我正在使用的ML Kit SDK版本
// Import the base SDK.
implementation 'com.huawei.hms:ml-computer-vision-segmentation:3.4.0.300'
// Import the multiclass segmentation model package.
implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-multiclass-model:3.4.0.300'
// Import the human body segmentation model package.
implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-body-model:3.4.0.300'
// Import the hair segmentation model package.
implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-hair-model:3.4.0.300'
,这是日志信息
2022-04-29 13:58:31.623 7423-7423/com.android.android.backgroundRemover e/countrycodebean:getVendorCountry =未知 2022-04-29 13:58:31.624 7423-7423/com.android.android.backgroundRemover e/countrycodebean:getsimcountrycode by not enableNetwork,countrycode = pk 2022-04-29 13:58:31.701 7423-8129/com.android.backgroundRemover I/halogprovider:在常见的HA,build_mode中 2022-04-29 13:58:31.702 7423-8129/com.android.backgroundRemover e/halogprovider:forbiddenhilog.getvendercountry =未知 2022-04-29 13:58:31.702 7423-8129/com.android.backgroundRemover E/HalogProvider:Forbiddenhilog OpenHA = false 2022-04-29 13:58:31.702 7423-8129/com.android.backgroundRemover i/imgseg_imagesegimpl:准确性:1,型号,型号:2,时间表:0 2022-04-29 13:58:31.704 7423-8129/com.android.backgroundRemover i/hmsnativate:准确性:1,模型键:2,ISVEDIO:0,ISVEDIO:0,场景:0,场景:0 2022-04-29 13:58:31.704 7423-8129/com.android.backgroundRemover I/Hcljni:[HCL] 202112292在Runnet()中。 new.A。 ELAB:1,MKEY:2,ISVIDEO:0,SET:0 2022-04-29 13:58:31.704 7423-8129/com.android.backgroundRemover I/Hcljni:[HCl] Enter Runnet()。 2022-04-29 13:58:31.707 7423-8129/com.android.backgroundRemover I/hcljni:[HCl] Inputheight,InputWidth:1031,688 2022-04-29 13:58:31.715 7423-8129/com.android.backgroundRemover I/hcljni:[HCl]调整大小后,H:289,W:289。 2022-04-29 13:58:31.721 7423-8129/com.android.backgroundRemover e/hiai_ddk_msg:/general_model_executor.cpp checkInputs(811)::: 2022-04-29 13:58:31.721 7423-8129/com.android.backgroundRemover e/hiai_ddk_msg:/general_model_executor.cpp execute(868)::: 2022-04-29 13:58:31.721 7423-8129/com.android.backgroundRemover e/ai_ddk_msg:/ai_model_executor_manager.cpp execute(698) 2022-04-29 13:58:31.721 7423-8129/com.android.backgroundRemover e/ai_ddk_msg:process(145)::“模型同步过程失败:seg_1c.om” 2022-04-29 13:58:31.722 7423-8129/com.android.backgroundRemover e/hiai_ddk_msg:/hiaimodelmanagerservice.cpp process(374) 2022-04-29 13:58:31.722 7423-8129/com.android.backgroundRemover i/hcljni:[HCL]第1611行,运行1cmodel失败,ret:1。 2022-04-29 13:58:31.722 7423-8129/com.android.backgroundRemover i/hmsnativate:----&gt; Mindsporerunnet时间= 18 2022-04-29 13:58:31.723 7423-8129/com.android.backgroundRemover e/hmsnativate:Runnet Fail 2022-04-29 13:58:31.723 7423-8129/com.android.backgroundRemover e/imagesegimpl:ProcessImage失败的ImageSedeDecteectEorparcel null
I don't know why it's not working as I've extracted this code from the demo app and there它正常工作。
I'm working on a project where I have to change the hair color of a person's image and for this, I'm using Huawei Hair segmentation.
Here is the code of Analyzer which analyze the image.
val setting = MLImageSegmentationSetting.Factory()
.setExact(true)
.setAnalyzerType(MLImageSegmentationSetting.HAIR_SEG)
.create()
analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(setting)
// Create an MLFrame by using android.graphics.Bitmap. Recommended image size: large than 224*224.
bitmap = BitmapFactory.decodeResource(this.resources, R.drawable.imgseg_foreground);
val mlFrame = MLFrame.Creator().setBitmap(bitmap).create()
val task: Task<MLImageSegmentation> = analyzer!!.asyncAnalyseFrame(mlFrame)
task.addOnSuccessListener(OnSuccessListener<MLImageSegmentation?> { imageSegmentationResult -> // Processing logic for recognition success.
if (imageSegmentationResult != null) {
[email protected](imageSegmentationResult)
} else {
[email protected]("imageSegmentationResult is null.")
}
})
.addOnFailureListener(OnFailureListener { e -> // Processing logic for recognition failure.
[email protected](e.message!!)
})
And here is the code of displaySuccess()
private fun displaySuccess(imageSegmentationResult: MLImageSegmentation) {
if (bitmap == null) {
displayFailure("bitmap is null.")
return
}
// Here I get null value in getMask()
if (imageSegmentationResult.getMasks() == null) {
return
}
var processedBitmap: Bitmap? = null
val pixels: IntArray = byteArrToIntArr(imageSegmentationResult.getMasks())
processedBitmap = Bitmap.createBitmap(
pixels,
0,
bitmap!!.width,
bitmap!!.width,
bitmap!!.height,
Bitmap.Config.ARGB_8888
)
if (processedBitmap != null) {
binding.imgHolder.setImageBitmap(processedBitmap)
} else {
displayFailure("bitmapFore is null.")
}
}
and I get the null value here.
if (imageSegmentationResult.getMasks() == null) {
return
}
This is the ml kit sdk version I'm using
// Import the base SDK.
implementation 'com.huawei.hms:ml-computer-vision-segmentation:3.4.0.300'
// Import the multiclass segmentation model package.
implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-multiclass-model:3.4.0.300'
// Import the human body segmentation model package.
implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-body-model:3.4.0.300'
// Import the hair segmentation model package.
implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-hair-model:3.4.0.300'
And this is the log info
2022-04-29 13:58:31.623 7423-7423/com.android.backgroundremover E/CountryCodeBean: getVendorCountry=UNKNOWN
2022-04-29 13:58:31.624 7423-7423/com.android.backgroundremover E/CountryCodeBean: getSimCountryCode by not enableNetwork, countryCode=pk
2022-04-29 13:58:31.701 7423-8129/com.android.backgroundremover I/HaLogProvider: in common ha, BUILD_MODE is: APK
2022-04-29 13:58:31.702 7423-8129/com.android.backgroundremover E/HaLogProvider: forbiddenHiLog.getVenderCountry=UNKNOWN
2022-04-29 13:58:31.702 7423-8129/com.android.backgroundremover E/HaLogProvider: forbiddenHiLog openHa = false
2022-04-29 13:58:31.702 7423-8129/com.android.backgroundremover I/ImgSeg_ImageSegImpl: accuracy:1,model:2,timeType:0
2022-04-29 13:58:31.704 7423-8129/com.android.backgroundremover I/HMSNativate: accuracy:1,modelKey:2,isVedio:0,scene:0
2022-04-29 13:58:31.704 7423-8129/com.android.backgroundremover I/HCLJNI: [HCL] 202112292 in runnet(). new.a. Elab: 1, MKey: 2, isVideo: 0, set: 0
2022-04-29 13:58:31.704 7423-8129/com.android.backgroundremover I/HCLJNI: [HCL] enter runnet().
2022-04-29 13:58:31.707 7423-8129/com.android.backgroundremover I/HCLJNI: [HCL] InputHeight,InputWidth: 1031, 688
2022-04-29 13:58:31.715 7423-8129/com.android.backgroundremover I/HCLJNI: [HCL] after resize, h: 289, w: 289.
2022-04-29 13:58:31.721 7423-8129/com.android.backgroundremover E/HIAI_DDK_MSG: /general_model_executor.cpp CheckInputs(811)::"input size not match:2, 1"
2022-04-29 13:58:31.721 7423-8129/com.android.backgroundremover E/HIAI_DDK_MSG: /general_model_executor.cpp Execute(868)::"check geBaseBuffInput failed"
2022-04-29 13:58:31.721 7423-8129/com.android.backgroundremover E/AI_DDK_MSG: /ai_model_executor_manager.cpp Execute(698)::"aicp::IModelExecutor::Execute failed! ret:0xffffffff."
2022-04-29 13:58:31.721 7423-8129/com.android.backgroundremover E/AI_DDK_MSG: Process(145)::"Model synchrous process failed: seg_1c.om"
2022-04-29 13:58:31.722 7423-8129/com.android.backgroundremover E/HIAI_DDK_MSG: /HiAiModelManagerService.cpp Process(374)::"run seg_1c.om failed"
2022-04-29 13:58:31.722 7423-8129/com.android.backgroundremover I/HCLJNI: [HCL] Line 1611, run 1cModel failed, ret: 1.
2022-04-29 13:58:31.722 7423-8129/com.android.backgroundremover I/HMSNativate: ---> mindSporeRunnet time = 18
2022-04-29 13:58:31.723 7423-8129/com.android.backgroundremover E/HMSNativate: runnet fail
2022-04-29 13:58:31.723 7423-8129/com.android.backgroundremover E/ImageSegImpl: ProcessImage failed imageSliceDecteorParcel is null
I don't know why it's not working as I've extracted this code from the demo app and there it's working perfectly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论