nx_arm_count_test.nx source
↩ module page · 72 lines · 2467 B
1// nx_arm_count_test.nx -- smoke for limb-count detector.
2// T1 empty / T2 torso only / T3 torso + attached / T4 torso + floating.
3
4import "nx_syscalls.nx"
5import "nx_image.nx"
6import "nx_arm_count.nx"
7
8func fill_rect_skin(img: *Image, x0: i64, y0: i64, x1: i64, y1: i64) -> i64 {
9 var y: i64 = y0
10 while y < y1 {
11 var x: i64 = x0
12 while x < x1 {
13 nx_image_set(img, x, y, 0, 200); nx_image_set(img, x, y, 1, 150); nx_image_set(img, x, y, 2, 130)
14 x = x + 1
15 }
16 y = y + 1
17 }
18 return 0
19}
20
21func fill_black(img: *Image) -> i64 {
22 var y: i64 = 0
23 while y < img.height {
24 var x: i64 = 0
25 while x < img.width {
26 nx_image_set(img, x, y, 0, 0); nx_image_set(img, x, y, 1, 0); nx_image_set(img, x, y, 2, 0)
27 x = x + 1
28 }
29 y = y + 1
30 }
31 return 0
32}
33
34func main() -> i64 {
35 let v: *ArmCountVerdict = (sys_mmap(128)) as *ArmCountVerdict
36
37 // T1: empty -> no torso
38 let img1: *Image = nx_image_alloc(64, 64, 3)
39 fill_black(img1)
40 nx_arm_count_compute(img1, v)
41 if v.torso_present != 0 { return 1 }
42 if v.limb_candidate_count != 0 { return 2 }
43
44 // T2: torso only -> no limbs
45 let img2: *Image = nx_image_alloc(64, 64, 3)
46 fill_black(img2)
47 fill_rect_skin(img2, 20, 20, 45, 45)
48 nx_arm_count_compute(img2, v)
49 if v.torso_present != 1 { return 10 }
50 if v.limb_candidate_count != 0 { return 11 }
51
52 // T3: torso + attached limb -> 1 plausible
53 let img3: *Image = nx_image_alloc(64, 64, 3)
54 fill_black(img3)
55 fill_rect_skin(img3, 20, 20, 45, 45)
56 fill_rect_skin(img3, 46, 20, 58, 29)
57 nx_arm_count_compute(img3, v)
58 if v.limb_candidate_count != 1 { return 20 }
59 if v.plausible_count != 1 { return 21 }
60
61 // T4: torso + floating limb -> 1 implausible by bbox
62 let img4: *Image = nx_image_alloc(64, 64, 3)
63 fill_black(img4)
64 fill_rect_skin(img4, 20, 20, 45, 45)
65 fill_rect_skin(img4, 50, 5, 62, 14)
66 nx_arm_count_compute(img4, v)
67 if v.limb_candidate_count != 1 { return 30 }
68 if v.implausible_count != 1 { return 31 }
69 if v.severity_q10 != 256 { return 32 }
70
71 return 0
72}