Last active
July 31, 2021 14:11
-
-
Save daiki1003/b4b10b69f623f0720ce2660b12a023a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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