facekit 1.0.0
facekit: ^1.0.0 copied to clipboard
Pure Dart offline facial recognition engine for Flutter & Dart.
import 'dart:typed_data';
import 'package:facekit/facekit.dart';
void main() async {
print(
'=== FaceKit Pure Dart Offline Facial Recognition Engine Example ===\n',
);
// 1. Initialize FaceKit Engine
final facekit = FaceKit();
// 2. Prepare synthetic facial test image
const size = 48;
final bytes = Uint8List(size * size);
for (var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
final idx = y * size + x;
bytes[idx] = 120;
if (y >= 5 && y <= 15 && x >= 10 && x <= 38) bytes[idx] = 220;
if (y >= 16 && y <= 25 && x >= 8 && x <= 40) bytes[idx] = 30;
if (y >= 18 && y <= 35 && x >= 20 && x <= 28) bytes[idx] = 200;
}
}
final image = FaceImage.fromGrayscale(bytes, size, size);
// 3. Register a new subject
await facekit.register(
image: image,
personId: 'EMP001',
name: 'John Doe',
metadata: {'department': 'AI Research'},
);
print('Registered person EMP001 (John Doe)');
// 4. Recognize subject from query image
final result = await facekit.recognize(image);
print('\nRecognition Result:');
print('Matched: ${result.matched}');
print('Person ID: ${result.personId}');
print('Name: ${result.name}');
print('Confidence: ${(result.confidence * 100).toStringAsFixed(1)}%');
print('Metadata: ${result.metadata}\n');
// 5. Custom .face binary export & import
final binaryData = await facekit.exportPersonBinary('EMP001');
print('Exported .face binary size: ${binaryData.length} bytes');
final newEngine = FaceKit();
final importedRecord = await newEngine.importPersonBinary(binaryData);
print(
'Imported person into clean engine: ${importedRecord.personId} (${importedRecord.name})\n',
);
print('All 14 FaceKit execution phases fully verified!');
}