Skip to content

Instantly share code, notes, and snippets.

@daiki1003
Last active July 31, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daiki1003/b4b10b69f623f0720ce2660b12a023a2 to your computer and use it in GitHub Desktop.
Save daiki1003/b4b10b69f623f0720ce2660b12a023a2 to your computer and use it in GitHub Desktop.
class SampleScreen extends StatefulWidget {
const SampleScreen({
Key? key,
}) : super(key: key);
@override
_SampleScreenState createState() => _SampleScreenState();
}
class _SampleScreenState extends State<SampleScreen> {
File? _file;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'顔認識 by google_ml_kit',
style: context.theme.appBarTheme.titleTextStyle,
),
),
body: Center(
child: Column(
children: [
if (_file != null) Image.file(_file!),
TextButton(
onPressed: () async {
final file =
await ImagePicker().pickImage(source: ImageSource.camera);
if (file == null) {
return;
}
setState(() {
_file = File(file.path);
});
},
child: const Text('カメラを起動する'),
),
if (_file != null)
TextButton(
onPressed: () async {
const options = FaceDetectorOptions(
mode: FaceDetectorMode.accurate,
enableLandmarks: true,
enableClassification: true,
);
final image = InputImage.fromFile(_file!);
final detector = GoogleMlKit.vision.faceDetector(options);
final faces = await detector.processImage(image);
print(faces);
for (final face in faces) {
print(face.boundingBox);
}
},
child: const Text('顔認識する'),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment