1. def main():
2. interpreter_classify, labels_classity = init_models("classify")
3. interpreter_obj_detect, labels_obj_detect = init_models("obj_detection")
4.
5. with picamera.PiCamera(resolution=(CAMERA_WIDTH, CAMERA_HEIGHT), framerate=30) as camera:
6. camera.start_preview()
7. try:
8. stream = io.BytesIO()
9. annotator = Annotator(camera)
10.
11. # Получение потока видео в виде jpeg снимков
12. for _ in camera.capture_continuous(stream, format='jpeg', use_video_port=True):
13. stream.seek(0)
14. # Конвертируем кадр в цветовое пространство RGB без альфа канала
15. image = Image.open(stream).convert('RGB').resize(
16. (input_width, input_height),
17. Image.ANTIALIAS
18. )
19. start_time = time.monotonic()
20.
21. # Поиск объектов на фотографии - лица людей
22. objects = detect_objects(interpreter_obj_detect, image, args.threshold)
23. results = list()
24. for obj in objects:
25. ymin, xmin, ymax, xmax = obj['bounding_box']
26. XY = (
27. int(xmin * CAMERA_WIDTH),
28. int(xmax * CAMERA_WIDTH),
29. int(ymin * CAMERA_HEIGHT),
30. int(ymax * CAMERA_HEIGHT),
31. )
32.
33. # По каждому найденному объекту определяем наличие маски
34. results.append({
35. "XY": XY,
36. "class_img": classify_image(interpreter_classify, image.crop(XY))
37. })
38.
39. elapsed_ms = (time.monotonic() - start_time) * 1000
40. annotator.clear()
41. annotate_objects(annotator, results, ["with_mask", "without_mask"])
42. annotator.text([5, 0], '%.1fms' % (elapsed_ms))
43. annotator.update()
44.
45. stream.seek(0)
46. stream.truncate()
47.
48. finally:
49. camera.stop_preview()
Отличная подача материала. Спасибо . Какого уровня ошибки смогли достичь? Освещение / расположение камеры тестировали?
Andrey, добрый день, спасибо! Освещение, положение камер не тестировали. На нашей маленькой обучающей модели мы смогли достичь точности чуть лучше, чем случайное угадывание (около 60%). Для лучших результатов модель нужно дообучать.