Only keep images if there's an object detected

This commit is contained in:
niten 2023-06-05 13:14:34 -07:00
parent 3ab9a2faa6
commit 65f163dd70
1 changed files with 6 additions and 2 deletions

View File

@ -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):