Safe Haskell | None |
---|---|
Language | Haskell98 |
Freenect
Description
Interface to the Kinect device.
See the package archive for example programs.
Synopsis
- initialize :: Context -> IO ()
- newContext :: IO Context
- shutdown :: Context -> IO ()
- countDevices :: Context -> IO Integer
- withContext :: (Context -> IO a) -> IO a
- processEvents :: Context -> IO ()
- processEventsTimeout :: Context -> Int -> IO ()
- selectSubdevices :: Context -> [Subdevice] -> IO ()
- newDevice :: IO Device
- openDevice :: Context -> Device -> Integer -> IO ()
- closeDevice :: Device -> IO ()
- withDevice :: Context -> Integer -> (Device -> IO a) -> IO a
- setLogLevel :: LogLevel -> Context -> IO ()
- setVideoCallback :: Device -> (Vector Word8 -> Word32 -> IO ()) -> IO ()
- startVideo :: Device -> IO ()
- stopVideo :: Device -> IO ()
- setDepthCallback :: Device -> (Vector Word16 -> Word32 -> IO ()) -> IO ()
- startDepth :: Device -> IO ()
- stopDepth :: Device -> IO ()
- setTiltDegrees :: Double -> Device -> IO ()
- getTiltDegrees :: Device -> IO Double
- getAcceleration :: Device -> IO (Double, Double, Double)
- setLed :: Device -> Led -> IO ()
- setVideoMode :: Device -> Resolution -> VideoFormat -> IO ()
- setDepthMode :: Device -> Resolution -> DepthFormat -> IO ()
- setFlag :: Device -> Flag -> Bool -> IO ()
- data Context
- data Device
- data FreenectException
- = InitFail
- | ShutdownFail
- | CloseDeviceFail
- | AlreadyInitializedContext
- | AlreadyOpenedDevice
- | UseOfUninitializedContext
- | UseOfUninitializedDevice
- | ProcessEvents CInt
- | OpenDeviceFailed Integer
- | StartVideoProblem
- | StopVideoProblem
- | StartDepthProblem
- | StopDepthProblem
- | UnableToSetTilt
- | UnableToSetLed
- | UnableToSetFlag
- | SetVideoMode
- | VideoModeNotSet
- | SetDepthMode
- | DepthModeNotSet
- | StartAudioProblem
- | StopAudioProblem
- data Subdevice
- data LogLevel
- data Led
- = Off
- | Green
- | Red
- | Yellow
- | BlinkGreen
- | BlinkRedYellow
- data Flag
- data Resolution
- data VideoFormat
- = RGB
- | Bayer
- | EightBitIR
- | TenBitIR
- | TenBitPackedIR
- | YUVRGB
- | YUVRaw
- data DepthFormat
- setAudioInCallback :: Device -> (Int -> Vector Word32 -> Vector Word32 -> Vector Word32 -> Vector Word32 -> Vector Word16 -> IO ()) -> IO ()
- startAudio :: Device -> IO ()
- stopAudio :: Device -> IO ()
Initializing the context
First you need to initalize a context. Example:
do context <- newContext initalize context ... shutdown context
Rather than messing around with this, it's better if you just use withContext, which does this for you:
withContext $ context -> do ...
All stuff with this library works within a context.
Working with devices
You need to select which sub devices you want to use from the Kinect (e.g. camera, motor, audio):
selectSubdevices context [Camera,Motor]
Then you open a device context through which you can control the sub devices.
withDevice context 0 $ device -> do ...
The second argument is which Kinect to use. You can get a count of these using
deviceCount <- countDevices context
Then you should set the depth mode you want:
setDepthMode device Medium ElevenBit
This should come before the next part, which is setting the callback:
setDepthCallback device $ payload timestamp -> do printf "Payload: %sn" (take 100 $ show payload)
Important: Based on the depth mode set earlier, setDepthCallback
knows how to copy the payload into a vector for the callback. This
is why it should come first. Arguably in future APIs a device
should not be initializable without a depth mode.
Once that's done, you start the depth stream:
startDepth device
Likewise, you can grab video frames. Once you have a context, set the video mode you want using
setVideoMode device Medium RGB
In this example, we set medium resolution (640x480) with raw RGB24 Bytes.
Next, set the video callback:
setVideoCallback device $ payload timestamp -> do printf "Payload: %sn" (take 100 $ show payload)
Note that unlike depth, which comes in as vector of Word16's, video is a vector of Word8's.
Lastly, start the video stream:
startVideo device
Events; recieving data
Finally you need a way to receieve data. You call processEvents
like this, for example:
forever $ do processEvents context
Calls processEvents
to trigger the depth and/or video callback. Continue calling
it sequentially as much as you want, but not from within the depth or video
callbacks.
initialize :: Context -> IO () Source #
Initialize a Freenect context. Throws exception if already initialized.
newContext :: IO Context Source #
Create a new Freenect context. Must be initialized before use.
withContext :: (Context -> IO a) -> IO a Source #
Do something with an initialized context, and free the context at the end of the comutation, or on exception.
processEvents :: Context -> IO () Source #
Process events.
selectSubdevices :: Context -> [Subdevice] -> IO () Source #
Set which subdevices any subsequent calls to openDevice should open. This will not affect devices which have already been opened. The default behavior, should you choose not to call this function at all, is to open all supported subdevices - motor, cameras, and audio, if supported on the platform.
closeDevice :: Device -> IO () Source #
Close a device.
withDevice :: Context -> Integer -> (Device -> IO a) -> IO a Source #
Do something with an initialized context, and free the context at the end of the comutation, or on exception.
setLogLevel :: LogLevel -> Context -> IO () Source #
Set the logging level for the specified context.
setVideoCallback :: Device -> (Vector Word8 -> Word32 -> IO ()) -> IO () Source #
Set callback for video information received event.
startVideo :: Device -> IO () Source #
Start the video information stream for a device.
setDepthCallback :: Device -> (Vector Word16 -> Word32 -> IO ()) -> IO () Source #
Set callback for depth information received event.
startDepth :: Device -> IO () Source #
Start the depth information stream for a device.
getAcceleration :: Device -> IO (Double, Double, Double) Source #
Get the accelaretion for (x, y, z) axes from the internal tilt state
setVideoMode :: Device -> Resolution -> VideoFormat -> IO () Source #
setDepthMode :: Device -> Resolution -> DepthFormat -> IO () Source #
Sets the current depth mode for the specified device. The mode cannot be changed while streaming is active.
setFlag :: Device -> Flag -> Bool -> IO () Source #
Sets a specific device flag for depth and video cameras. The bool value defines to enable or disable the given flag. The specific camera has to be started with startVideo/startDepth before Freenect accepts these flags (seems to be a small bug for me, an issue is written at libfreenect)
data FreenectException Source #
Freenect exception type.
Constructors
InitFail | There was a problem initializing. |
ShutdownFail | There was a problem shutting down. |
CloseDeviceFail | There was a problem closing the device. |
AlreadyInitializedContext | Trying to initialize a context that was already initialized. |
AlreadyOpenedDevice | Trying to open a device that was already opened. |
UseOfUninitializedContext | Attempt to use an uninitialized context. |
UseOfUninitializedDevice | Attempt to use an uninitialized device. |
ProcessEvents CInt | Call to process events failed. |
OpenDeviceFailed Integer | Opening a device failed. |
StartVideoProblem | Problem starting the video stream. |
StopVideoProblem | Problem stopping the video stream |
StartDepthProblem | Problem starting the depth stream. |
StopDepthProblem | Problem stopping the depth stream |
UnableToSetTilt | Unable to set the tilt. |
UnableToSetLed | Unable to set active led |
UnableToSetFlag | Failed to enable a specific device flag |
SetVideoMode | Unable to set the video mode. |
VideoModeNotSet | TODO, not used: You didn't set the video mode. |
SetDepthMode | Unable to set the depth mode. |
DepthModeNotSet | TODO, not used: You didn't set the depth mode. |
StartAudioProblem | Problem starting the audio stream |
StopAudioProblem | Problem stopping the audio stream |
Instances
Exception FreenectException Source # | |
Defined in Freenect Methods toException :: FreenectException -> SomeException # | |
Show FreenectException Source # | |
Defined in Freenect Methods showsPrec :: Int -> FreenectException -> ShowS # show :: FreenectException -> String # showList :: [FreenectException] -> ShowS # |
A sub-device (motor, camera and audio), if supported on the platform.
Message logging levels.
Constructors
LogFatal | Crashing/non-recoverable errors |
LogError | Major errors |
LogWarning | Warning messages |
LogNotice | Important messages |
LogInfo | Normal messages |
LogDebug | Useful development messages |
LogSpew | Slightly less useful messages |
LogFlood | EVERYTHING. May slow performance. |
Instances
Enum LogLevel Source # | |
Show LogLevel Source # | |
Eq LogLevel Source # | |
Constructors
Off | |
Green | |
Red | |
Yellow | |
BlinkGreen | |
BlinkRedYellow |
Constructors
AutoExposure | |
AutoWhiteBalance | |
RawColor | |
MirrorDepth | |
MirrorVideo |
data Resolution Source #
Instances
Enum Resolution Source # | |
Defined in Freenect Methods succ :: Resolution -> Resolution # pred :: Resolution -> Resolution # toEnum :: Int -> Resolution # fromEnum :: Resolution -> Int # enumFrom :: Resolution -> [Resolution] # enumFromThen :: Resolution -> Resolution -> [Resolution] # enumFromTo :: Resolution -> Resolution -> [Resolution] # enumFromThenTo :: Resolution -> Resolution -> Resolution -> [Resolution] # | |
Show Resolution Source # | |
Defined in Freenect Methods showsPrec :: Int -> Resolution -> ShowS # show :: Resolution -> String # showList :: [Resolution] -> ShowS # | |
Eq Resolution Source # | |
Defined in Freenect | |
Ord Resolution Source # | |
Defined in Freenect Methods compare :: Resolution -> Resolution -> Ordering # (<) :: Resolution -> Resolution -> Bool # (<=) :: Resolution -> Resolution -> Bool # (>) :: Resolution -> Resolution -> Bool # (>=) :: Resolution -> Resolution -> Bool # max :: Resolution -> Resolution -> Resolution # min :: Resolution -> Resolution -> Resolution # |
data VideoFormat Source #
Constructors
RGB | |
Bayer | |
EightBitIR | |
TenBitIR | |
TenBitPackedIR | |
YUVRGB | |
YUVRaw |
Instances
Enum VideoFormat Source # | |
Defined in Freenect Methods succ :: VideoFormat -> VideoFormat # pred :: VideoFormat -> VideoFormat # toEnum :: Int -> VideoFormat # fromEnum :: VideoFormat -> Int # enumFrom :: VideoFormat -> [VideoFormat] # enumFromThen :: VideoFormat -> VideoFormat -> [VideoFormat] # enumFromTo :: VideoFormat -> VideoFormat -> [VideoFormat] # enumFromThenTo :: VideoFormat -> VideoFormat -> VideoFormat -> [VideoFormat] # | |
Show VideoFormat Source # | |
Defined in Freenect Methods showsPrec :: Int -> VideoFormat -> ShowS # show :: VideoFormat -> String # showList :: [VideoFormat] -> ShowS # | |
Eq VideoFormat Source # | |
Defined in Freenect |
data DepthFormat Source #
Constructors
ElevenBit | |
TenBit | |
ElevenBitPacked | |
TenBitPacked |
Instances
Enum DepthFormat Source # | |
Defined in Freenect Methods succ :: DepthFormat -> DepthFormat # pred :: DepthFormat -> DepthFormat # toEnum :: Int -> DepthFormat # fromEnum :: DepthFormat -> Int # enumFrom :: DepthFormat -> [DepthFormat] # enumFromThen :: DepthFormat -> DepthFormat -> [DepthFormat] # enumFromTo :: DepthFormat -> DepthFormat -> [DepthFormat] # enumFromThenTo :: DepthFormat -> DepthFormat -> DepthFormat -> [DepthFormat] # | |
Show DepthFormat Source # | |
Defined in Freenect Methods showsPrec :: Int -> DepthFormat -> ShowS # show :: DepthFormat -> String # showList :: [DepthFormat] -> ShowS # | |
Eq DepthFormat Source # | |
Defined in Freenect |
setAudioInCallback :: Device -> (Int -> Vector Word32 -> Vector Word32 -> Vector Word32 -> Vector Word32 -> Vector Word16 -> IO ()) -> IO () Source #
Set callback for incoming audio events.
startAudio :: Device -> IO () Source #
Start the audio information stream for a device.