From 65f163dd7075cbea6df961792a0ed75edc025c34 Mon Sep 17 00:00:00 2001 From: niten Date: Mon, 5 Jun 2023 13:14:34 -0700 Subject: [PATCH] Only keep images if there's an object detected --- src/objectifier.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/objectifier.py b/src/objectifier.py index 3c23ab7..c271e22 100644 --- a/src/objectifier.py +++ b/src/objectifier.py @@ -110,12 +110,16 @@ def analyze_image(request: Request, image: UploadFile): print ("writing " + str(buffer_size) + " bytes") f.write(chunk) chunk = image.file.read(buffer_size) - result = detector.detect_objects( + dectect_result = detector.detect_objects( infile, detection_timeout, str(outgoing_dir / (file_hash.hexdigest() + ".png"))) remove(infile) - return result_to_dict(result, base_url) + result = result_to_dict(detect_result, base_url) + if not result.labels: + # There were no objects detected + remove(detect_result.outfile) + return result @app.get("/analyzed_images/{image_name}", response_class=FileResponse) def get_analyzed_image(image_name: str):