diff --git a/providers/base/bin/camera_quality_test.py b/providers/base/bin/camera_quality_test.py index 1a73f74ee..41984af1f 100755 --- a/providers/base/bin/camera_quality_test.py +++ b/providers/base/bin/camera_quality_test.py @@ -31,7 +31,7 @@ THRESHOLD = 60 -def brisque(device: str = "video0"): +def brisque(device: str = "video0", file: str = "", save: bool = False): """ Captures an image to a file and computes the quality using the Blinded/Unreferenced Spatial Image Quality Evaluator (BRISQUE). If the @@ -58,14 +58,17 @@ def brisque(device: str = "video0"): print("Cannot read from the selected device", file=sys.stderr) return 1 - # Save it in a temporary file + # Create a temporary file f = NamedTemporaryFile(prefix='camera_test_brisque_%s_' % device, - suffix='.jpg', delete=False) + suffix='.jpg', delete=not save) cv2.imwrite(f.name, image) - print("Image saved to %s" % f.name) + if save: + print("Image saved to %s" % f.name) # Compute the BRISQUE score score = brisque.score(f.name) + f.close() + if isnan(score): print("Unable to compute BRISQUE score", file=sys.stderr) return 1 @@ -81,6 +84,10 @@ def brisque(device: str = "video0"): parser = argparse.ArgumentParser(description="Run the image quality test") parser.add_argument("-d", "--device", default="video0", help="Device for the webcam to use") + parser.add_argument("-f", "--file", default="", + help="Parse a file instead of a device") + parser.add_argument("-s", "--save", action="store_true", + help="Keep the image file after the test") args = parser.parse_args() - sys.exit(brisque(args.device)) + sys.exit(brisque(args.device, args.file, not args.save))