fastestdet-imx / example.py
gbahlnxp's picture
Initial release
e0ee8f9
Raw History Blame Contribute Delete
1.74 kB
#!/usr/bin/env python3
# Copyright 2024-2026 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
import cv2
import argparse
from dperson import dperson
def parse_args():
parser = argparse.ArgumentParser(
description='FastestDet person detection example',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
'-m', '--model',
dest='model',
required=False,
type=str,
default='assets/quantized_tflite_model_mcu/persondetect_220_220.tflite',
help='path to the .tflite model'
)
parser.add_argument(
'-i', '--input',
dest='input',
required=False,
type=str,
default='example_input.jpg',
help='path to the input image'
)
parser.add_argument(
'-o', '--output',
dest='output',
required=False,
type=str,
default='example_output.jpg',
help='path to write the annotated output image'
)
parser.add_argument(
'--thresh',
dest='thresh',
required=False,
type=float,
default=0.6,
help='detection score threshold'
)
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
# instantiate detector model
detector = dperson(args.model)
# run inference on the input image
img = cv2.imread(args.input)
if img is None:
raise FileNotFoundError(f"could not read input image: {args.input}")
bboxes = detector.detect(img, args.thresh)
print(f"detected {len(bboxes)} person(s)")
# draw bounding boxes and save the result
detector.show(img)
cv2.imwrite(args.output, img)
print(f"annotated image written to {args.output}")