File size: 1,687 Bytes
dac3297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
"""Draw YOLO v2 annotations on the cellar image to verify."""
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont

ROOT = Path(__file__).resolve().parent
V2_DIR = ROOT / "yolo_v2_data"
RAW_DIR = V2_DIR / "raw"
EXTRACT_DIR = V2_DIR / "extracted"

image_files = list(RAW_DIR.glob("*.jpg")) + list(RAW_DIR.glob("*.png"))
label_files = [f for f in EXTRACT_DIR.rglob("*.txt") if f.name != "classes.txt"]

img_path = image_files[0]
lbl_path = label_files[0]

img = Image.open(img_path).convert("RGB")
W, H = img.size
print(f"Image size: {W} x {H}")

draw = ImageDraw.Draw(img)
font = ImageFont.load_default()

colors = {
    "0": (0, 255, 0),   # ceiling_ducted = green
    "1": (255, 100, 0), # wall_mounted = orange
}
names = {
    "0": "ceiling_ducted",
    "1": "wall_mounted",
}

count_per_class = {"0": 0, "1": 0}

with open(lbl_path) as f:
    for idx, line in enumerate(f, 1):
        parts = line.strip().split()
        if len(parts) != 5:
            continue
        cls, xc, yc, w, h = parts
        count_per_class[cls] += 1
        xc, yc, w, h = float(xc), float(yc), float(w), float(h)
        x1 = int((xc - w / 2) * W)
        y1 = int((yc - h / 2) * H)
        x2 = int((xc + w / 2) * W)
        y2 = int((yc + h / 2) * H)
        color = colors[cls]
        draw.rectangle([x1, y1, x2, y2], outline=color, width=4)
        label = f"{idx}.{names[cls][0:3]}"
        draw.text((x1, y1 - 15), label, fill=color, font=font)

out_path = V2_DIR / "annotations_verified.jpg"
img.save(out_path, quality=80)
print(f"Saved verification: {out_path}")
print(f"Ceiling ducted (green): {count_per_class['0']}")
print(f"Wall mounted (orange):  {count_per_class['1']}")