Notice: MediaWiki has been updated. Report any rough edges to marcan@marcan.st

Haskell Wrapper

From OpenKinect
Jump to: navigation, search

Currently supports depth. No video yet, but only because I care about depth more at the moment. More support to come. Will update this wiki and release on Hackage when done.

Git repo available at:

   https://github.com/chrisdone/freenect

Example program

   -- | Freenect examples.
   
   module Main
     (main)
     where
   
   import Freenect
   import Text.Printf
   import Control.Monad
   import Control.Monad.Fix
   import Data.IORef
   
   -- | Demos some Freenect use.
   main :: IO ()
   main =
     withContext $ \context -> do
       setLogLevel LogFlood context
       deviceCount <- countDevices context
       printf "Devices: %d\n" deviceCount
       selectSubdevices context devices
       printf "Selected devices: %s\n" (show devices)
       withDevice context index $ \device -> do
         printf "Opened device %d.\n" index
         done <- newIORef False
         setDepthCallback device $ \payload timestamp -> do
           printf "Payload: %s\n" (take 100 $ show payload)
           writeIORef done True
         printf "Setted depth callback.\n"
         setDepthMode device Medium ElevenBit
         startDepth device
         printf "Started depth stream.\n"
         printf "Processing…\n"
         fix $ \repeat -> do
           processEvents context
           isDone <- readIORef done
           if isDone
              then return ()
              else repeat
         printf "Finished processing events.\n"
   
     where devices = [Camera]
           index = 0 :: Integer