(libload "opencv/opencv")
(libload "libc/libc")

(setq img0 (cvimage-read-rgb "lion.jpg"))
(setq img1 (cvimage-read-rgb "lion.jpg"))

(setq grayimg (new cvimage 640 480 8 1))    
(cvSetImageCOI  :img0:p  1)
(cvCopy  :img0:p  :grayimg:p  (gptr ())  )

(setq corners (new cvsmobarray (memsize_cvpoint2d32f) 300))
(setq count   (new cvsmobarray 4 1))
(setq eigimg  (new cvimage 640 480 32 1))
(setq tempimg (new cvimage 640 480 32 1))

(cvGoodFeaturesToTrack  :grayimg:p   :eigimg:p   :tempimg:p   :corners:p  :count:p  0.2  10  (gptr ())  )

(setq numpoints (peek-int (==> count ptr_nth 0)))
(for (i 0 numpoints)
     (let* ((ipoint  (new cvpoint 0 0))
	    (fpoint  (new cvpoint2d32f 0 0)))
       (==> fpoint copy (==> corners ptr_nth i))
       (==> ipoint set_x (cvround (==> fpoint get_x)))
       (==> ipoint set_y (cvround (==> fpoint get_y)))

       (cvCircle  :img1:p  :ipoint:p  2 (cv_rgb 0 0 255)  3) ) )	    
(cvimage-show img1)
