Closed iamaz007 closed 1 year ago
@iamaz007 Please provide the following contents:
@xuxiapu
Logs
I/HMSSDK_HianalyticsExist( 4809): In isHianalyticsExist, Failed to find class HiAnalyticsConfig. I/HMSSDK_HianalyticsExist( 4809): hianalytics exist: false I/HMSSDK_HiAnalyticsUtils( 4809): Enable Log I/FormalHASDK( 4809): ======================================= I/FormalHASDK( 4809): FormalHASDK_2.2.0.313 I/FormalHASDK( 4809): ======================================= I/HMSSDK_HMSBIInitializer( 4809): Builder->biInitFlag :false I/NetworkKit_CountryCodeBean( 4809): main|null|com.huawei.hms.framework.network.grs.local.model.CountryCodeBean|getVendorCountryCode|39|countryCode by ro.hw.country is: UNKNOWN I/NetworkKit_CountryCodeBean( 4809): main|null|com.huawei.hms.framework.network.grs.local.model.CountryCodeBean|getSimCountryCode|74|countryCode by SimCountryIso is: us I/NetworkKit_CountryCodeBean( 4809): main|null|com.huawei.hms.framework.network.grs.local.model.CountryCodeBean|init|32|get issue_country code from SIM_COUNTRY I/HMSSDK_AnalyticsSwitchHolder( 4809): not ChinaROM I/HMSSDK_AnalyticsSwitchHolder( 4809): Get OOBE failed D/HMSLogger( 4809): HMS Plugin Dotting is Enabled! I/MLApplication( 4809): initialize one para I/AgConnectInfo( 4809): AGConnectServicesConfig: com.huawei.agconnect.config.impl.c@9bb2bf9context: android.app.Application@7adc73e I/AgConnectInfo( 4809): AGConnectServicesConfig: com.huawei.agconnect.config.impl.c@9bb2bf9region: null I/AgConnectInfo( 4809): signature is not null I/AgConnectInfo( 4809): AGConnectServicesConfig: com.huawei.agconnect.config.impl.c@9bb2bf9certFingerprint: certFingerprint is secret I/AgConnectInfo( 4809): AGConnectServicesConfig: com.huawei.agconnect.config.impl.c@9bb2bf9project_id: null I/AgConnectInfo( 4809): AGConnectServicesConfig: com.huawei.agconnect.config.impl.c@9bb2bf9processing_location_policy/mlkit: null I/MLApplication( 4809): initialize two para E/CountryCodeBean( 4809): getVendorCountry=UNKNOWN E/CountryCodeBean( 4809): getSimCountryCode by not enableNetwork, countryCode=us E/CountryCodeBean( 4809): getVendorCountry=UNKNOWN E/CountryCodeBean( 4809): getSimCountryCode by not enableNetwork, countryCode=us E/ActivityThread( 4809): Failed to find provider info for com.huawei.hms W/dynamic-api_DynamicModule( 4809): 4809-4809|null|com.huawei.hms.feature.dynamic.DynamicModule|getRemoteVersion|80|Query remote module:huawei_module_mlkit_imgseg exception:com.huawei.hms.feature.dynamic.DynamicModule$g: failed to Query remote version. I/PreferHighestOrRemote( 4809): localVersion is: 30700302 I/PreferHighestOrRemote( 4809): remoteVersion is: 0 I/PreferHighestOrRemote( 4809): use local ML ability, the localVersion is: 30700302 E/AbstractInitializer( 4809): huawei_module_mlkit_imgseg -> No need to switch because the context of the dynamic module is null or the context of full sdk E/AbstractInitializer( 4809): huawei_module_mlkit_imgseg -> The context of the dynamic module belongs to LOCAL I/HaLogProvider( 4809): init timer, timer=java.util.Timer@959df6d,moduleName=MLKitImgSeg E/HMSNativate( 4809): load model failed: dlopen failed: library "libmlkit-segmentation.so" not found I/HMSNativate( 4809): isMatting = true E/tersforpicture( 4809): No implementation found for long com.huawei.hms.mlkit.imgseg.HMSNativateImageSegmentation.loadModel(android.content.res.AssetManager, java.nio.ByteBuffer, java.nio.ByteBuffer, int, int, int) (tried Java_com_huawei_hms_mlkit_imgseg_HMSNativateImageSegmentation_loadModel and Java_com_huawei_hms_mlkit_imgseg_HMSNativateImageSegmentation_loadModel__Landroid_content_res_AssetManager_2Ljava_nio_ByteBuffer_2Ljava_nio_ByteBuffer_2III) I/TimerAssist( 4809): unlock time = 596398 I/HMSNativate( 4809): isMatting = true E/tersforpicture( 4809): No implementation found for long com.huawei.hms.mlkit.imgseg.HMSNativateImageSegmentation.loadModel(android.content.res.AssetManager, java.nio.ByteBuffer, java.nio.ByteBuffer, int, int, int) (tried Java_com_huawei_hms_mlkit_imgseg_HMSNativateImageSegmentation_loadModel and Java_com_huawei_hms_mlkit_imgseg_HMSNativateImageSegmentation_loadModel__Landroid_content_res_AssetManager_2Ljava_nio_ByteBuffer_2Ljava_nio_ByteBuffer_2III) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): Failed to handle method call E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at com.huawei.hms.flutter.mlimage.utils.Commons.bitmapToByteArray(Commons.java:54) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at com.huawei.hms.flutter.mlimage.handlers.SegmentationMethodHandler.segListMap(SegmentationMethodHandler.java:96) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at com.huawei.hms.flutter.mlimage.handlers.SegmentationMethodHandler.syncSegmentation(SegmentationMethodHandler.java:125) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at com.huawei.hms.flutter.mlimage.handlers.SegmentationMethodHandler.onMethodCall(SegmentationMethodHandler.java:63) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at android.os.Handler.handleCallback(Handler.java:938) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at android.os.Looper.loop(Looper.java:223) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at android.app.ActivityThread.main(ActivityThread.java:7656) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/MethodChannel#huawei.hms.flutter.ml.image.segmentation( 4809): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) I/tersforpicture( 4809): Background concurrent copying GC freed 929(98KB) AllocSpace objects, 6(9256KB) LOS objects, 49% free, 11MB/23MB, paused 694us total 119.784ms I/flutter ( 4809): PlatformException(error, Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference I/flutter ( 4809): at com.huawei.hms.flutter.mlimage.utils.Commons.bitmapToByteArray(Commons.java:54) I/flutter ( 4809): at com.huawei.hms.flutter.mlimage.handlers.SegmentationMethodHandler.segListMap(SegmentationMethodHandler.java:96) I/flutter ( 4809): at com.huawei.hms.flutter.mlimage.handlers.SegmentationMethodHandler.syncSegmentation(SegmentationMethodHandler.java:125) I/flutter ( 4809): at com.huawei.hms.flutter.mlimage.handlers.SegmentationMethodHandler.onMethodCall(SegmentationMethodHandler.java:63) I/flutter ( 4809): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) I/flutter ( 4809): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessen
Code
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:huawei_ml_image/huawei_ml_image.dart';
import 'package:image_picker/image_picker.dart';
class ImageSegmentation extends StatefulWidget {
const ImageSegmentation({Key? key}) : super(key: key);
@override
ImageSegmentationState createState() => ImageSegmentationState();
}
class ImageSegmentationState extends State<ImageSegmentation> {
MLImageSegmentationAnalyzer? analyzer;
MLImageSegmentationAnalyzerSetting? setting;
List<MLImageSegmentation>? result;
PickedFile? _pickedFile;
File? _imageFile;
File? _imageFile1;
String? _imagePath;
String? _imagePath1;
final String _foregroundUri = "Foreground Uri";
final String _grayscaleUri = "Grayscale Uri";
final String _originalUri = "Original Uri";
@override
void initState() {
analyzer = MLImageSegmentationAnalyzer();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
const SizedBox(height: 15),
Container(
padding: const EdgeInsets.all(16.0),
child: Column(
children: const [
// _setImageView(_imageFile!),
// const SizedBox(width: 15),
// _setImageView(_imageFile1!),
// const SizedBox(width: 15),
],
)),
// SizedBox(height: 15),
// _setText(),
const SizedBox(height: 15),
_showImagePickingOptions(),
],
));
}
Widget _showImagePickingOptions() {
return Expanded(
child: Align(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 20.0, right: 20.0),
child: MaterialButton(
color: Colors.blue,
textColor: Colors.white,
child: const Text("PICK FROM GALLERY"),
onPressed: () async {
final String path = await getImage(ImageSource.gallery);
_startRecognition(path);
},
),
),
],
),
),
);
}
Widget _setImageView(File? imageFile) {
if (imageFile != null) {
return Image.file(imageFile, width: 200, height: 200);
} else {
return const Text(" ");
}
}
_startRecognition(String path) async {
print(path);
setting = MLImageSegmentationAnalyzerSetting.create(
path: path,
analyzerType: MLImageSegmentationAnalyzerSetting.BODY_SEG,
// scene: MLImageSegmentationAnalyzerSetting.FOREGROUND_ONLY,
exactMode: true,
);
try {
result = await analyzer!.analyseFrame(setting!);
print(result!.first.foreground);
// _foregroundUri = result!.first.foreground;
// _grayscaleUri = result!.first.grayscale;
// _originalUri = result!.first.original;
// _imagePath = await FlutterAbsolutePath.getAbsolutePath(_grayscaleUri);
// _imagePath1 = await FlutterAbsolutePath.getAbsolutePath(_originalUri);
// setState(() {
// _imageFile = File(_imagePath);
// _imageFile1 = File(_imagePath1);
// });
} on Exception catch (e) {
// print('error');
print(e.toString());
}
}
Future<String> getImage(ImageSource imageSource) async {
final picker = ImagePicker();
XFile? temp = await picker.pickImage(source: imageSource);
_pickedFile = PickedFile(temp!.path);
return _pickedFile!.path;
}
}
@iamaz007 The log shows countryCode=us, but the Flutter does not support this region. It is recommended to try another region.
@xuxiapu I tested on real device it is working. issue is on android emulator while development. Where I have to change region?
@iamaz007 What can be determined at present is that the coverage region does not support the United States. And sorry, we can't answer the question about android emulator changing region. You can try another path to solve it.If you have any other questions, please contact us.
Description I'm testing on android emulator, When I select image from gallery for segmentation. it gives error as you can see in logs. Tried with adding/removing
agconnect-services.json
in app directory but not workingEdit: working on real device, tested on Xiaomi Redmi 5 plus
Logs View Logs
Screenshots
android/build.gradle
android/app/build.gradle
proguard-rules.pro
pubspec.yaml
Tried using both pub.dev package and locally importing of package, none of them workingSource code View Code
Environment