Skip to content

Instantly share code, notes, and snippets.

@NSLog0
Created May 7, 2019 10:55
Show Gist options
  • Save NSLog0/07b3451ce1e5daa0c72f4afffe418fc5 to your computer and use it in GitHub Desktop.
Save NSLog0/07b3451ce1e5daa0c72f4afffe418fc5 to your computer and use it in GitHub Desktop.
import argparse
import io
import time
import numpy as np
from edgetpu.detection.engine import DetectionEngine
import cv2
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--model', help='File path of Tflite model.', required=True)
parser.add_argument(
'--input', help='File path of the input image.', required=True)
parser.add_argument(
'--output', help='File path of the output image.')
args = parser.parse_args()
if not args.output:
output_name = 'object_detection_result.jpg'
else:
output_name = args.output
img = cv2.imread(args.input,0)
img = cv2.resize(img, dsize=(299, 299), interpolation = cv2.INTER_CUBIC)
img = np.asarray(img, dtype=np.float32)
engine = DetectionEngine(args.model)
ans = engine.DetectWithImage(img, threshold=0.05, keep_aspect_ratio=True,
relative_coord=False, top_k=10)
print(ans)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment