
;; by Fu Jie Huang, Jan 2003

;; combine stuff from d04_video.lsh and d02_cannyedge.lsh 
;; do pyramid smoothing, canny edge detection, and morphology processing
(libload "video4linux/v4l")
(libload "opencv/opencv")

(setq width 640)
(setq height 480)

(new-window width height  "webcam")
(setq webcam (new v4ldevice "/dev/video0" "NTSC" 0 width height))

(setq captimg (ubyte-matrix height width 3))
(setq bufimg (new cvimage width height @IPL_DEPTH_8U 3))
(setq roirect (new cvrect 0 0 width height))
(setq grayimg (new cvimage width height @IPL_DEPTH_8U 1))
(setq edgeimg (new cvimage width height @IPL_DEPTH_8U 1))
(setq halfimg (new cvimage (/ width 2) (/ height 2) @IPL_DEPTH_8U 3))

 (while t
   (==> webcam grab-into-rgb captimg)
   (idx8u_ipl  captimg  :bufimg:p)

   (cvPyrDown :bufimg:p  :halfimg:p  7)
   (cvPyrUp   :halfimg:p :bufimg:p   7)

   (cvSetImageCOI  :bufimg:p 1)
   (cvSetImageROI  :bufimg:p :roirect:p)
   (cvCopy     :bufimg:p  :grayimg:p  (gptr ()) )

   (cvCanny  :grayimg:p    :edgeimg:p  0 50 3)
   (cvDilate :edgeimg:p    :edgeimg:p  (gptr ()) 1)
   (cvimage-show edgeimg)
)

