视频文件在颤动中传输到图像流
Video file to image stream in flutter
我的资产文件夹中有一个视频文件(如 mp4)。我想将该视频文件作为图像流读取,就像相机包中的图像流 https://pub.dev/documentation/camera/latest/camera/CameraController/startImageStream.html
我想将图像传递给 Tflite 模型。
类似的东西:
controller = loadVideo('assets/example.mp4'); // how to do that?!
controller.startImageStream((CameraImage img) {
Tflite.runPoseNetOnFrame(
bytesList: img.planes.map((plane) {
return plane.bytes;
}).toList(),
imageHeight: img.height,
imageWidth: img.width,
numResults: 1,
threshold: 0.1,
).then((recognitions) {
// ...
}
}
我试图在 image_picker 和 video_player 包中搜索,但没有找到任何东西。
是的,您当然可以通过以下方式之一进行操作:
使用 export_video_frame 插件
使用video_thumbnail插件
您可以通过时间参数指定一个精确的帧。
我做的是将图片分割后保存为文件,然后传给tf模型。它并不快(因为你创建文件然后读取它)但它正在工作,在 android 上测试并且它应该在 IOS 上工作:)
我在包 flutter_export_video_frame, now it have a function in the name of exportImagesFromFile 中做了一个 PR。它以 Stream<File>
.
的形式从视频文件返回图像流
要从资产文件夹中获取视频文件,我使用以下函数:
import 'dart:async';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:path/path.dart';
Future<File> getImageFileFromAssets(String path) async {
final byteData = await rootBundle.load('assets/$path');
final fileName = basename(path);
final file = new File('${(await getTemporaryDirectory()).path}/$fileName');
await file.writeAsBytes(byteData.buffer
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
return file;
}
然后将其移动到 posenet/model,有一个函数将 File
作为输入:
var results = await Tflite.runPoseNetOnImage(
path: path,
numResults: 1,
);
此方法的一个可能改进是使其仅在 RAM 上工作(当然是在您阅读视频之后)
我的资产文件夹中有一个视频文件(如 mp4)。我想将该视频文件作为图像流读取,就像相机包中的图像流 https://pub.dev/documentation/camera/latest/camera/CameraController/startImageStream.html
我想将图像传递给 Tflite 模型。
类似的东西:
controller = loadVideo('assets/example.mp4'); // how to do that?!
controller.startImageStream((CameraImage img) {
Tflite.runPoseNetOnFrame(
bytesList: img.planes.map((plane) {
return plane.bytes;
}).toList(),
imageHeight: img.height,
imageWidth: img.width,
numResults: 1,
threshold: 0.1,
).then((recognitions) {
// ...
}
}
我试图在 image_picker 和 video_player 包中搜索,但没有找到任何东西。
是的,您当然可以通过以下方式之一进行操作:
使用 export_video_frame 插件
使用video_thumbnail插件
您可以通过时间参数指定一个精确的帧。
我做的是将图片分割后保存为文件,然后传给tf模型。它并不快(因为你创建文件然后读取它)但它正在工作,在 android 上测试并且它应该在 IOS 上工作:)
我在包 flutter_export_video_frame, now it have a function in the name of exportImagesFromFile 中做了一个 PR。它以 Stream<File>
.
要从资产文件夹中获取视频文件,我使用以下函数:
import 'dart:async';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:path/path.dart';
Future<File> getImageFileFromAssets(String path) async {
final byteData = await rootBundle.load('assets/$path');
final fileName = basename(path);
final file = new File('${(await getTemporaryDirectory()).path}/$fileName');
await file.writeAsBytes(byteData.buffer
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
return file;
}
然后将其移动到 posenet/model,有一个函数将 File
作为输入:
var results = await Tflite.runPoseNetOnImage(
path: path,
numResults: 1,
);
此方法的一个可能改进是使其仅在 RAM 上工作(当然是在您阅读视频之后)