From ad25bc34dc3f640c0c973f2a11cf0cd32a1e498b Mon Sep 17 00:00:00 2001 From: "Tianhao (Terry) Fu" Date: Wed, 2 Oct 2024 14:04:35 -0400 Subject: [PATCH] The Delays should not Possitively Contribute to the Score (#427) * Fixed the metrics. (#424) * Fixed the metrics. (#424) --- leads_vec/benchmark.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/leads_vec/benchmark.py b/leads_vec/benchmark.py index 7604ef7..76d631d 100644 --- a/leads_vec/benchmark.py +++ b/leads_vec/benchmark.py @@ -5,7 +5,7 @@ from PIL.Image import open from customtkinter import CTkLabel, DoubleVar -from cv2 import VideoCapture, imencode, IMWRITE_JPEG_QUALITY +from cv2 import VideoCapture, imencode, IMWRITE_JPEG_QUALITY, CAP_PROP_FPS from leads import L, require_config from leads_gui import RuntimeData, Window, ContextManager, Speedometer @@ -26,6 +26,7 @@ def video_tester(container: Callable[[], None]) -> float: def video_test() -> dict[str, float]: r = {} vc = VideoCapture(require_config().get("benchmark_camera_port", 0)) + r["camera fps"] = vc.get(CAP_PROP_FPS) if not vc.isOpened(): L.error("No camera available") return r @@ -45,12 +46,13 @@ def test3() -> None: def test4() -> None: _, frame = vc.read() im = imencode(".jpg", frame, (IMWRITE_JPEG_QUALITY, 90))[1].tobytes() + b64encode(im) open(BytesIO(im)) - r["video capture"] = video_tester(test1) * 1000 - r["video capture and encoding"] = video_tester(test2) * 1000 - r["video capture and Base64 encoding"] = video_tester(test3) * 1000 - r["video capture and PIL"] = video_tester(test4) * 1000 + r["video capture"] = 1 / video_tester(test1) + r["video capture + encoding"] = 1 / video_tester(test2) + r["video capture + Base64 encoding"] = 1 / video_tester(test3) + r["video capture + PIL"] = 1 / video_tester(test4) return r @@ -73,23 +75,23 @@ def main() -> int: w = Window(800, 256, 30, rd, callbacks.on_refresh, "Benchmark", no_title_bar=False) callbacks.speed = DoubleVar(w.root()) uim = ContextManager(w) - uim.layout([[CTkLabel(w.root(), text="Benchmark Ongoing", height=240), + uim.layout([[CTkLabel(w.root(), text="Do NOT close the window", height=240), Speedometer(w.root(), height=240, variable=callbacks.speed)]]) uim.show() L.info("GUI test complete") L.info("Video test starting, this takes about 40 seconds") - report["frame rate"] = w.frame_rate() - report["net delay"] = w.net_delay() * 1000 + report["gui"] = w.frame_rate() report.update(video_test()) L.info("Video test complete") for k, v in report.items(): L.info(f"{k}: {v:.3f}") - baseline = {"frame rate": 30, "net delay": 1.062, "video capture": 17.898, "video capture and encoding": 16.657, - "video capture and Base64 encoding": 16.658, "video capture and PIL": 16.668} + camera_fps = report.pop("camera fps") + baseline = {"gui": 30, "video capture": camera_fps, "video capture + encoding": camera_fps, + "video capture + Base64 encoding": camera_fps, "video capture + PIL": camera_fps} score = 0 for k, v in report.items(): score += v / baseline[k] - L.info("Score:", str(score / len(report))) + L.info(f"Score: {100 * score / len(report):.2f}%") return 0