简体   繁体   English

显示在 flutter 应用程序中的图像帧上运行 tflite 的相机活动

[英]Show a Camera Activity which runs tflite on image frames in a flutter app

I have an android app having a CameraActivity which runs a tflite classifier periodically on image frames from the preview stream.我有一个 android 应用程序,它有一个CameraActivity ,它定期在预览 stream 的图像帧上运行tflite 分类器。 The implementation of the Camera and tflite works great in the Android part and gives a good FPS. Camera 和 tflite 的实现在 Android 部分效果很好,并提供了良好的 FPS。

I want to show this CameraActivity in my Flutter App as a Screen.我想在我的 Flutter 应用程序中将这个CameraActivity显示为屏幕。 The Flutter app has all the Frontend and UI part implemented already. Flutter 应用程序已经实现了所有前端和 UI 部分。

I've already tried using the official Flutter Camera plugin to implement the same by using camera.startImageStream but was unable to get matching FPS and the Camera Preview lags when calling the tflite model asynchronously using methodChannel .我已经尝试使用官方 Flutter相机插件通过使用camera.startImageStream来实现相同的功能,但是在使用methodChannel异步调用 tflite model 时无法获得匹配的 FPS 和相机预览滞后。

I also came across AndroidView which embeds an Android view in the Widget hierarchy but the docs say it is an expensive operation and should be avoided when a Flutter equivalent is possible.我还遇到了AndroidView ,它在 Widget 层次结构中嵌入了 Android 视图,但文档说这是一项昂贵的操作,当 Flutter 等效项可能时应该避免。

Is there a way to write a plugin for showing the CameraActivity (ie the UI) on the Flutter end similar to the way methodChannel is used for exchanging data between the Flutter and the Native codes.有没有办法编写一个插件来显示 Flutter 端的CameraActivity (即 UI),类似于使用方法通道在 Flutter 和本机代码之间交换数据的方式。 Or if there's another possible way of achieving this, please let me know.或者,如果有另一种可能的方式来实现这一点,请告诉我。

Thanks in advance!提前致谢!

//Flutter side
Future<Null> showNativeView() async {

  
  if (Platform.isAndroid) {//check if platform is android
    var methodChannel = MethodChannel("methodchannelname");//create a method channel name 
    await methodChannel.invokeMethod('showNativeCameraView');//create method name
  }
}

Container(
child: InkWell(
onTap: () {
showNativeView();//call to open native android activity
},
child: Center(
child: new Text("takeimage"))))

//Android side 


//inside mainactivity on create
var channel: MethodChannel? = null


channel = MethodChannel(flutterView, "methodchannelname");
MethodChannel(flutterView, "methodchannelname")//same as flutterside 
    .setMethodCallHandler { call, result ->
if (call.method == "showNativeCameraView") {//same methodname as flutterside
val intent = Intent(this, ActivityCamera::class.java)//native camera activity code can be added in the android folder of the flutter application
startActivity(intent)
result.success(true)
} else {
result.notImplemented()
}

}
         

This link will help u further https://medium.com/@Chetan/flutter-communicate-with-android-activity-or-ios-viewcontroller-through-method-channel-c11704429cd0此链接将帮助您进一步https://medium.com/@Chetan/flutter-communicate-with-android-activity-or-ios-viewcontroller-through-method-channel-c11704429cd0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM