nx_localizers_test.nx source
↩ module page · 83 lines · 3000 B
1import "nx_syscalls.nx"
2import "nx_image.nx"
3import "nx_cheek_localize.nx"
4import "nx_breast_localize.nx"
5
6func main() -> i64 {
7 // T1: nx_cheek_localize — face bbox 100..300 x 50..250 (200x200).
8 // Expected: cheek band at y 150..180 (50..65% down), 30-70px in from each side.
9 let cheek_res: *i64 = (sys_mmap(NX_CHEEK_RES_FIELDS * 8 + 16)) as *i64
10 nx_cheek_localize(100, 50, 300, 250, cheek_res)
11
12 let l_x0: i64 = cheek_res[NX_CHEEK_RES_LEFT_X0]
13 let l_y0: i64 = cheek_res[NX_CHEEK_RES_LEFT_Y0]
14 let l_x1: i64 = cheek_res[NX_CHEEK_RES_LEFT_X1]
15 let l_y1: i64 = cheek_res[NX_CHEEK_RES_LEFT_Y1]
16
17 // Left cheek X: face_x0 + 15% width to face_x0 + 35% width = 130 to 170.
18 if l_x0 != 130 { return 1 }
19 if l_x1 != 170 { return 2 }
20 // Left cheek Y: face_y0 + 50%h to face_y0 + 65%h = 150 to 180.
21 if l_y0 != 150 { return 3 }
22 if l_y1 != 180 { return 4 }
23
24 let r_x0: i64 = cheek_res[NX_CHEEK_RES_RIGHT_X0]
25 let r_x1: i64 = cheek_res[NX_CHEEK_RES_RIGHT_X1]
26 // Right cheek: face_x1 - 35% width to face_x1 - 15% width = 230 to 270.
27 if r_x0 != 230 { return 10 }
28 if r_x1 != 270 { return 11 }
29
30 // T2: nx_breast_localize — torso 50..250 x 100..400 (200x300).
31 // Upper third = y 100..200.
32 // Paint two oval breasts: L at (80..130, 110..170), R at (170..220, 110..170).
33 let w: i64 = 300
34 let h: i64 = 500
35 let mask: *Image = nx_image_alloc(w, h, 1)
36 var yy: i64 = 0
37 while yy < h {
38 var xx: i64 = 0
39 while xx < w { nx_image_set(mask, xx, yy, 0, 0); xx = xx + 1 }
40 yy = yy + 1
41 }
42 var by: i64 = 110
43 while by < 170 {
44 var bx: i64 = 80
45 while bx < 130 { nx_image_set(mask, bx, by, 0, 255); bx = bx + 1 }
46 bx = 170
47 while bx < 220 { nx_image_set(mask, bx, by, 0, 255); bx = bx + 1 }
48 by = by + 1
49 }
50
51 let torso_bbox: *i64 = (sys_mmap(4 * 8 + 16)) as *i64
52 torso_bbox[0] = 50; torso_bbox[1] = 100
53 torso_bbox[2] = 250; torso_bbox[3] = 400
54
55 let breast_res: *i64 = (sys_mmap(NX_BLOC_RES_FIELDS * 8 + 16)) as *i64
56 nx_breast_localize(mask, torso_bbox, breast_res)
57
58 // Left breast: x0 should be 80, x1 should be 129 (last filled column).
59 let bl_x0: i64 = breast_res[NX_BLOC_RES_L_X0]
60 let bl_x1: i64 = breast_res[NX_BLOC_RES_L_X1]
61 if bl_x0 != 80 { return 20 }
62 if bl_x1 != 129 { return 21 }
63
64 let bl_area: i64 = breast_res[NX_BLOC_RES_L_AREA]
65 // Area should be 50 wide * 60 tall = 3000.
66 if bl_area != 3000 { return 22 }
67
68 let bl_cx: i64 = breast_res[NX_BLOC_RES_L_CX]
69 // Centroid X should be at ~104 (avg of 80..129 = 104.5).
70 if bl_cx < 103 { return 23 }
71 if bl_cx > 105 { return 24 }
72
73 // Right breast: x0=170, x1=219.
74 let br_x0: i64 = breast_res[NX_BLOC_RES_R_X0]
75 let br_x1: i64 = breast_res[NX_BLOC_RES_R_X1]
76 if br_x0 != 170 { return 30 }
77 if br_x1 != 219 { return 31 }
78
79 let br_area: i64 = breast_res[NX_BLOC_RES_R_AREA]
80 if br_area != 3000 { return 32 }
81
82 return 0
83}