Skip to content

Commit

Permalink
The Delays should not Possitively Contribute to the Score (#427)
Browse files Browse the repository at this point in the history
* Fixed the metrics. (#424)

* Fixed the metrics. (#424)
  • Loading branch information
ATATC authored Oct 2, 2024
1 parent 92a67b0 commit ad25bc3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions leads_vec/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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


Expand All @@ -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


Expand Down

0 comments on commit ad25bc3

Please sign in to comment.