File size: 1,967 Bytes
a8dceee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Quick evaluation harness: run the pipeline on the example pairs and print
detection counts. Compares the DINODenseMatcher path on vs off.

NOTE: PatternDetectionPipeline.detect_auto signature is (pattern_input, drawing_input).
"""
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from src.pipeline import PatternDetectionPipeline  # noqa: E402


def run(pipe, name, ppath, dpath):
    result = pipe.detect_auto(ppath, dpath, return_visualization=False)
    dets = result.get("detections", [])
    print(f"\n=== {name}: {result.get('total_detections')} detections ===")
    for d in dets:
        bbox = d.get("bbox", (d.get("x"), d.get("y"), d.get("w"), d.get("h")))
        print(f"    bbox={bbox} conf={d.get('confidence')} dino={d.get('dino_score')} "
              f"angle={d.get('angle')}")
    return result.get("total_detections")


def main():
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    ex = os.path.join(root, "examples")
    pairs = [
        ("example1", os.path.join(ex, "example1_pattern.png"), os.path.join(ex, "example1_drawing.png")),
        ("example2", os.path.join(ex, "example2_pattern.png"), os.path.join(ex, "example2_drawing.png")),
    ]

    summary = {}
    for mode_name, flag in [("dense_ON", True), ("dense_OFF", False)]:
        print(f"\n########## MODE: {mode_name} (use_dino_dense={flag}) ##########")
        pipe = PatternDetectionPipeline(config={"use_dino_dense": flag})
        for name, ppath, dpath in pairs:
            if not (os.path.exists(dpath) and os.path.exists(ppath)):
                print(f"SKIP {name}: missing files")
                continue
            n = run(pipe, name, ppath, dpath)
            summary[(mode_name, name)] = n

    print("\n\n========== SUMMARY ==========")
    for (mode_name, name), n in summary.items():
        print(f"  {mode_name:10s} {name:10s} -> {n}")


if __name__ == "__main__":
    main()