2026-05-18-19-56-47 重构双视频同步与单帧对比
This commit is contained in:
@@ -21,6 +21,10 @@ def test_health_and_methods():
|
||||
samples = client.get("/api/samples")
|
||||
assert samples.status_code == 200
|
||||
assert "samples" in samples.json()
|
||||
if samples.json()["samples"]:
|
||||
sample = samples.json()["samples"][0]
|
||||
assert "version" in sample
|
||||
assert "?v=" in sample["url"]
|
||||
|
||||
|
||||
def test_segment_image(tmp_path: Path):
|
||||
@@ -36,3 +40,47 @@ def test_segment_image(tmp_path: Path):
|
||||
payload = response.json()
|
||||
assert payload["kind"] == "image"
|
||||
assert payload["frames"][0]["metrics"]["mask_pixels"] > 0
|
||||
assert payload["frames"][0]["source_time"] == 0.0
|
||||
assert payload["frames"][0]["result_time"] == 0.0
|
||||
|
||||
|
||||
def test_segment_video_and_compare_frame(tmp_path: Path):
|
||||
video_path = tmp_path / "sample.mp4"
|
||||
writer = cv2.VideoWriter(str(video_path), cv2.VideoWriter_fourcc(*"mp4v"), 12.0, (320, 220))
|
||||
for index in range(18):
|
||||
writer.write(make_frame(index, 320, 220))
|
||||
writer.release()
|
||||
|
||||
with video_path.open("rb") as handle:
|
||||
response = client.post(
|
||||
"/api/segment",
|
||||
files={"file": ("sample.mp4", handle, "video/mp4")},
|
||||
data={"method": "fusion", "sensitivity": "0.58", "frame_stride": "6", "max_frames": "3"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
payload = response.json()
|
||||
assert payload["kind"] == "video"
|
||||
assert payload["video_url"].endswith(".mp4")
|
||||
assert payload["source_fps"] > 0
|
||||
assert payload["result_fps"] == 8.0
|
||||
assert len(payload["frames"]) == 3
|
||||
first_frame = payload["frames"][0]
|
||||
assert first_frame["source_time"] == 0.0
|
||||
assert first_frame["result_time"] == 0.0
|
||||
assert first_frame["result_index"] == 0
|
||||
|
||||
with video_path.open("rb") as handle:
|
||||
compare = client.post(
|
||||
"/api/compare-frame",
|
||||
files={"file": ("sample.mp4", handle, "video/mp4")},
|
||||
data={"frame_index": str(payload["frames"][1]["frame_index"]), "sensitivity": "0.58"},
|
||||
)
|
||||
assert compare.status_code == 200
|
||||
compare_payload = compare.json()
|
||||
assert compare_payload["kind"] == "compare"
|
||||
assert {frame["method"] for frame in compare_payload["frames"]} == {
|
||||
"hessian_ridge",
|
||||
"edge_morphology",
|
||||
"temporal_difference",
|
||||
"fusion",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user