(bind-func draw_color_body_frame_with_hands
(let ((num:i64 1))
(lambda (frame:astra_colorizedbodyframe_t hands:astra_handpoint_X* numhands:i32 mlres:i8* vid:ocv_VideoWriter* record:i1)
(letz ((bytes:i32 0) (i:i32 0) (hand:astra_handpoint_X* null)
(dat:i8* (salloc))
(sizesqr:i32 128))
;; (astra_colorframe_get_data_ptr frame (ref dat) (ref bytes))
(astra_colorizedbodyframe_get_data_ptr frame (convert (ref dat)) (ref bytes))
;; (println "size:" bytes)
(if (= bytes (* 640 480 4))
(let ((img (ocv_cvtColor (ocv_Mat 480 640 (CV_MAKE_TYPE CV_8U 4) dat) ocv_COLOR_RGBA2BGR))
(grey (ocv_cvtColor (ocv_Mat 480 640 (CV_MAKE_TYPE CV_8U 4) dat) ocv_COLOR_RGBA2GRAY))
(rect (ocv_Rect_val 0 0 0 0))
(point (ocv_Point_val 0 0))
(foundHand #f)
(scalar (ocv_Scalar_val 0.0 255.0 0.0 0.0)))
(tfill! (ref rect)
(clamp (- 320 (/ sizesqr 2)) 0 (- 640 sizesqr))
(clamp (- 240 (/ sizesqr 2)) 0 (- 480 sizesqr))
sizesqr sizesqr)
(tfill! (ref point) 20 60)
(dotimes (i numhands)
(set! hand (pref-ptr hands i))
(if (and (> (tref hand 0) 0) (= (tref hand 1) 2))
(begin
(set! num (+ num 1))
(tfill! (ref rect)
(clamp (- (tref (tref hand 2) 0) (/ sizesqr 2)) 0 (- 640 sizesqr))
(clamp (- (tref (tref hand 2) 1) (- (/ sizesqr 2) 5)) 0 (- 480 sizesqr))
sizesqr sizesqr)
(set! foundHand #t)
(if record
(ocv_imwrite (cat 'data/image_' (toString num) '.png') (ocv_region grey (convert (ref rect)))))
(ocv_rectangle img (convert (ref rect)) (convert (ref scalar)) 2))))
; (set! num (+ num 1))
; (tfill! (ref rect) 250 200 sizesqr sizesqr)
;; (ocv_imwrite (cat 'data/null/image_' (toString num) '.png') (ocv_region grey (convert (ref rect))))
;; (ocv_rectangle img (convert (ref rect)) (convert (ref scalar)) 2)
;; (println "write out image")
(ocv_imwrite 'data/image.png' (ocv_region grey (convert (ref rect))))
(if foundHand
(ocv_puttext img mlres (convert (ref point)) 0 2.0 (convert (ref scalar)) 2)
(ocv_puttext img "None" (convert (ref point)) 0 2.0 (convert (ref scalar)) 2))
;; (println "draw image to screen")
(ocv_write vid img)
(ocv_imshow 'Body' img)))
void))))