nx_face_count_test.nx source
↩ module page · 49 lines · 1552 B
1// nx_face_count_test.nx -- smoke for face-count detector (simplified to isolate).
2//
3// Earlier version segfaulted in qemu; bisecting to find the trigger.
4// This version: T1 only (torso, no eyes -> NO_FACE).
5
6import "nx_syscalls.nx"
7import "nx_image.nx"
8import "nx_face_count.nx"
9
10func fill_rect_skin(img: *Image, x0: i64, y0: i64, x1: i64, y1: i64) -> i64 {
11 var y: i64 = y0
12 while y < y1 {
13 var x: i64 = x0
14 while x < x1 {
15 nx_image_set(img, x, y, 0, 200); nx_image_set(img, x, y, 1, 150); nx_image_set(img, x, y, 2, 130)
16 x = x + 1
17 }
18 y = y + 1
19 }
20 return 0
21}
22
23func fill_rect_black(img: *Image, x0: i64, y0: i64, x1: i64, y1: i64) -> i64 {
24 var y: i64 = y0
25 while y < y1 {
26 var x: i64 = x0
27 while x < x1 {
28 nx_image_set(img, x, y, 0, 0); nx_image_set(img, x, y, 1, 0); nx_image_set(img, x, y, 2, 0)
29 x = x + 1
30 }
31 y = y + 1
32 }
33 return 0
34}
35
36func main() -> i64 {
37 let v: *FaceCountVerdict = (sys_mmap(64)) as *FaceCountVerdict
38
39 // T1 ONLY: torso, no eyes drawn -> NO_FACE (or NO_FACE because pairing fails)
40 // Use smaller 64x64 image to reduce memory pressure.
41 let img1: *Image = nx_image_alloc(64, 64, 3)
42 fill_rect_black(img1, 0, 0, 64, 64)
43 fill_rect_skin(img1, 20, 20, 45, 45)
44 nx_face_count_compute(img1, v)
45 if v.face_region_count != 1 { return 1 }
46 if v.kind != NX_FC_NO_FACE { return 2 }
47
48 return 0
49}