Skip to content

Commit ad25bc3

Browse files
authored
The Delays should not Possitively Contribute to the Score (#427)
* Fixed the metrics. (#424) * Fixed the metrics. (#424)
1 parent 92a67b0 commit ad25bc3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

leads_vec/benchmark.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from PIL.Image import open
77
from customtkinter import CTkLabel, DoubleVar
8-
from cv2 import VideoCapture, imencode, IMWRITE_JPEG_QUALITY
8+
from cv2 import VideoCapture, imencode, IMWRITE_JPEG_QUALITY, CAP_PROP_FPS
99

1010
from leads import L, require_config
1111
from leads_gui import RuntimeData, Window, ContextManager, Speedometer
@@ -26,6 +26,7 @@ def video_tester(container: Callable[[], None]) -> float:
2626
def video_test() -> dict[str, float]:
2727
r = {}
2828
vc = VideoCapture(require_config().get("benchmark_camera_port", 0))
29+
r["camera fps"] = vc.get(CAP_PROP_FPS)
2930
if not vc.isOpened():
3031
L.error("No camera available")
3132
return r
@@ -45,12 +46,13 @@ def test3() -> None:
4546
def test4() -> None:
4647
_, frame = vc.read()
4748
im = imencode(".jpg", frame, (IMWRITE_JPEG_QUALITY, 90))[1].tobytes()
49+
b64encode(im)
4850
open(BytesIO(im))
4951

50-
r["video capture"] = video_tester(test1) * 1000
51-
r["video capture and encoding"] = video_tester(test2) * 1000
52-
r["video capture and Base64 encoding"] = video_tester(test3) * 1000
53-
r["video capture and PIL"] = video_tester(test4) * 1000
52+
r["video capture"] = 1 / video_tester(test1)
53+
r["video capture + encoding"] = 1 / video_tester(test2)
54+
r["video capture + Base64 encoding"] = 1 / video_tester(test3)
55+
r["video capture + PIL"] = 1 / video_tester(test4)
5456
return r
5557

5658

@@ -73,23 +75,23 @@ def main() -> int:
7375
w = Window(800, 256, 30, rd, callbacks.on_refresh, "Benchmark", no_title_bar=False)
7476
callbacks.speed = DoubleVar(w.root())
7577
uim = ContextManager(w)
76-
uim.layout([[CTkLabel(w.root(), text="Benchmark Ongoing", height=240),
78+
uim.layout([[CTkLabel(w.root(), text="Do NOT close the window", height=240),
7779
Speedometer(w.root(), height=240, variable=callbacks.speed)]])
7880
uim.show()
7981
L.info("GUI test complete")
8082
L.info("Video test starting, this takes about 40 seconds")
81-
report["frame rate"] = w.frame_rate()
82-
report["net delay"] = w.net_delay() * 1000
83+
report["gui"] = w.frame_rate()
8384
report.update(video_test())
8485
L.info("Video test complete")
8586
for k, v in report.items():
8687
L.info(f"{k}: {v:.3f}")
87-
baseline = {"frame rate": 30, "net delay": 1.062, "video capture": 17.898, "video capture and encoding": 16.657,
88-
"video capture and Base64 encoding": 16.658, "video capture and PIL": 16.668}
88+
camera_fps = report.pop("camera fps")
89+
baseline = {"gui": 30, "video capture": camera_fps, "video capture + encoding": camera_fps,
90+
"video capture + Base64 encoding": camera_fps, "video capture + PIL": camera_fps}
8991
score = 0
9092
for k, v in report.items():
9193
score += v / baseline[k]
92-
L.info("Score:", str(score / len(report)))
94+
L.info(f"Score: {100 * score / len(report):.2f}%")
9395
return 0
9496

9597

0 commit comments

Comments
 (0)