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

Haskell Wrapper

From OpenKinect
Revision as of 21:33, 23 October 2011 by Chrisdone (talk | contribs) (Added Haskell wrapper.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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