
;; by Fu Jie Huang, Jan 2003

;; this script shows how to combine the OpenCV and Video4Linux
;; the images are catpured into "captimg" (IDX3-UBYTE)
;; it's converted into a gray image, and shown on the window

;; the parameters need to be adjusted when create the v4l device
;; in different systems.

(libload "video4linux/v4l")
(libload "opencv/opencv")


(setq width 320)
(setq height 240)

(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))

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

   (cvSetImageCOI  :bufimg:p 1)
   (cvSetImageROI  :bufimg:p :roirect:p)

   (cvCopy     :bufimg:p  :grayimg:p  (gptr ()) )
   (cvimage-show grayimg)
)

