face_box_camera 0.0.7 copy "face_box_camera: ^0.0.7" to clipboard
face_box_camera: ^0.0.7 copied to clipboard

A package to detect face inside defined a box or not.

example/lib/main.dart

import 'dart:developer';

import 'package:camera/camera.dart';
import 'package:face_box_camera/face_box_camera.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final FaceBoxController faceBoxController = FaceBoxController(
    cameraLensDirection: CameraLensDirection.back,
    options: FaceBoxOptions(
      minOverlapPercent: 0.5,
      requireCenterInside: true,
      throttleDuration: Duration(milliseconds: 0),
    ),
  );

  bool _isFaceInsideBox = false;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: Scaffold(
        body: Stack(
          children: [
            Positioned.fill(
              child: FaceBoxCameraWidget(
                controller: faceBoxController,
                onFaceInsideBox: (face, overlap) {
                  log('Face inside box is called');
                  log("Overlap percent: $overlap");
                  setState(() {
                    _isFaceInsideBox = true;
                  });
                },
                onFaceOutsideBox: () {
                  log('Face outside box is called');
                  setState(() {
                    _isFaceInsideBox = false;
                  });
                },
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 60),
              child: Column(
                children: [
                  // Show measured processing FPS
                  ValueListenableBuilder<double>(
                    valueListenable: faceBoxController.fpsNotifier,
                    builder: (_, fps, __) {
                      log("Log Unique FPS: $fps");
                      return Text(
                        'FPS: ${fps.toStringAsFixed(0)}',
                        style: const TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.bold,
                          color: Colors.white,
                        ),
                      );
                    },
                  ),
                  const SizedBox(height: 8),
                  // Show last frame processing time (ms)
                  ValueListenableBuilder<double>(
                    valueListenable: faceBoxController.processingTimeNotifier,
                    builder: (_, ms, __) {
                      log("Log Unique Proc time: $ms ms");
                      return Text(
                        'Proc time: ${ms.toStringAsFixed(0)} ms',
                        style: const TextStyle(
                          fontSize: 16,
                          color: Colors.white70,
                        ),
                      );
                    },
                  ),
                  if (_isFaceInsideBox)
                    const Text(
                      'Face is inside the box',
                      style: TextStyle(
                        fontSize: 24,
                        fontWeight: FontWeight.bold,
                        color: Colors.green,
                      ),
                    )
                  else
                    const Text(
                      'Face is outside the box',
                      style: TextStyle(
                        fontSize: 24,
                        fontWeight: FontWeight.bold,
                        color: Colors.red,
                      ),
                    ),
                ],
              ),
            ),
            Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    GestureDetector(
                      onTap: () {
                        faceBoxController.switchLense();
                      },
                      child: Container(
                        margin: EdgeInsets.only(bottom: 20),
                        decoration: BoxDecoration(
                          color: Colors.blueAccent.shade100,
                          shape: BoxShape.circle,
                        ),
                        width: 100,
                        height: 100,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
44
downloads

Publisher

verified publisherteguhtriprasetya.com

Weekly Downloads

A package to detect face inside defined a box or not.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

camera, flutter, google_mlkit_face_detection

More

Packages that depend on face_box_camera