vision_flow 0.0.1
vision_flow: ^0.0.1 copied to clipboard
A Flutter plugin for real-time vision tasks
example/lib/main.dart
import 'dart:async';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:signify_vision/signify_vision.dart';
late List<CameraDescription> cameras;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late CameraController controller;
StreamSubscription? landmarkSubscription;
@override
void initState() {
super.initState();
listenForLandmarks();
initCamera();
}
void listenForLandmarks() {
SignifyVision.landmarksStream.listen((landmarks) {
print("Features received: ${landmarks.length}");
print("Landmarks: ${landmarks}");
});
}
Future<void> initCamera() async {
controller = CameraController(
cameras[0],
ResolutionPreset.medium,
enableAudio: false,
);
await controller.initialize();
bool isProcessing = false;
await controller.startImageStream((CameraImage image) async {
if (isProcessing) return;
isProcessing = true;
await SignifyVision.processFrame(
yPlane: image.planes[0].bytes,
uPlane: image.planes[2].bytes,
vPlane: image.planes[1].bytes,
width: image.width,
height: image.height,
yRowStride: image.planes[0].bytesPerRow,
uvRowStride: image.planes[1].bytesPerRow,
uvPixelStride: image.planes[1].bytesPerPixel ?? 1,
);
isProcessing = false;
});
setState(() {});
}
@override
Widget build(BuildContext context) {
if (!controller.value.isInitialized) {
return const MaterialApp(
home: Scaffold(body: Center(child: CircularProgressIndicator())),
);
}
return MaterialApp(home: Scaffold(body: CameraPreview(controller)));
}
}