Skip to content

Commit

Permalink
Update two_step.py to current setup
Browse files Browse the repository at this point in the history
Updated this script to changes in config file parameters names and in
the way the package was organized.  Made the logging a tad more
informative.
  • Loading branch information
iingram committed Aug 16, 2021
1 parent c7274e6 commit a5d9cbe
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions two_step.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# grabs stills, inferring on each, going as fast as it can
"""Runs detector on frame, then classifier on detected boxes
"""
import logging
import io
import argparse
import yaml

import picamera

import vision
from scrubcam import vision

logging.basicConfig(level='INFO',
format='[%(levelname)s] %(message)s (%(name)s)')
log = logging.getLogger('main')

parser = argparse.ArgumentParser()
parser.add_argument('config',
Expand All @@ -18,34 +24,34 @@
configs = yaml.load(f, Loader=yaml.SafeLoader)

RECORD = configs['RECORD']
FILTER_CLASS = configs['FILTER_CLASS']
FILTER_CLASSES = configs['FILTER_CLASSES']

detector = vision.ObjectDetectionSystem(configs)
classifier = vision.ImageClassificationSystem(configs)

stream = io.BytesIO()

camera = picamera.PiCamera()
camera.rotation = configs['CAMERA_ANGLE']
camera.rotation = configs['CAMERA_ROTATION']
if configs['PREVIEW_ON']:
camera.start_preview()

for _ in camera.capture_continuous(stream, format='jpeg'):
stream.truncate()
stream.seek(0)

log.info('Running detector.')
detector.infer(stream)
detector.print_report(5)
for box in detector.labeled_boxes:
# if detector.top_class() == FILTER_CLASS:
if detector.class_of_box(box) in FILTER_CLASS:
# x, y, w, h = detector.top_box()
if detector.class_of_box(box) in FILTER_CLASSES:
x, y, w, h = box['box']

cropped_frame = detector.frame[y:y+h, x:x+w]
label = box['class_name']
log.info(f'Running classifier on filtered box with label {label}')
classifier.infer_on_frame(cropped_frame)
classifier.print_report()


if RECORD:
classifier.save_image_of_anything_but('background')

0 comments on commit a5d9cbe

Please sign in to comment.