never executed always true always false
    1 {-# language GeneralizedNewtypeDeriving #-}
    2 {-# language CPP #-}
    3 
    4 #ifndef ENABLE_INTERNAL_DOCUMENTATION
    5 {-# OPTIONS_HADDOCK hide #-}
    6 #endif
    7 
    8 module OpenCV.Internal.VideoIO.Types
    9     ( -- * VideoCodecs
   10       FourCC(..)
   11     , VideoCaptureProperties(..)
   12     , marshalCaptureProperties
   13     , VideoCaptureAPI(..)
   14     , marshalVideoCaptureAPI
   15     ) where
   16 
   17 import "base" Data.Char ( ord )
   18 import "base" Data.Int ( Int32 )
   19 import "base" Data.Word ( Word32 )
   20 import "base" Data.String ( IsString (..) )
   21 import "base" Data.List( unfoldr )
   22 import "this" OpenCV.Internal.VideoIO.Constants
   23 
   24 --------------------------------------------------------------------------------
   25 -- FourCC
   26 --------------------------------------------------------------------------------
   27 
   28 newtype FourCC = FourCC { unFourCC :: Int32 }
   29 
   30 instance IsString FourCC where
   31   fromString "ask" = FourCC (-1)
   32   fromString fcc =
   33       FourCC $ foldr (\x acc -> acc * 256 + fromIntegral (ord x))
   34                      0
   35                      (take 4 fcc)
   36 
   37 instance Show FourCC where
   38   show (FourCC (-1)) = "ask"
   39   show (FourCC fcc) = take 4 $ unfoldr worker (fromIntegral fcc :: Word32)
   40     where
   41       worker 0 = Nothing
   42       worker b = Just (toEnum . fromEnum $ b `mod` 256, b `div` 256)
   43 
   44 --------------------------------------------------------------------------------
   45 -- VideoCaptureProperties
   46 -- more at https://github.com/opencv/opencv/blob/master/modules/videoio/include/opencv2/videoio.hpp
   47 --------------------------------------------------------------------------------
   48 
   49 data VideoCaptureProperties
   50    = VideoCapPropPosMsec
   51           -- ^ Current position of the video file in milliseconds.
   52    | VideoCapPropPosFrames
   53           -- ^ 0-based index of the frame to be decoded/captured next.
   54    | VideoCapPropPosAviRatio
   55           -- ^ Relative position of the video file: 0=start of the film,
   56           --   1=end of the film.
   57    | VideoCapPropFrameWidth     -- ^ Width of the frames in the video stream.
   58    | VideoCapPropFrameHeight    -- ^ Height of the frames in the video stream.
   59    | VideoCapPropFps            -- ^ Frame rate.
   60    | VideoCapPropFourCc         -- ^ 4-character code of codec.
   61    | VideoCapPropFrameCount     -- ^ Number of frames in the video file.
   62    | VideoCapPropFormat
   63           -- ^ Format of the Mat objects returned by VideoCapture::retrieve().
   64    | VideoCapPropMode
   65           -- ^ Backend-specific value indicating the current capture mode.
   66    | VideoCapPropBrightness     -- ^ Brightness of the image (only for cameras).
   67    | VideoCapPropContrast       -- ^ Contrast of the image (only for cameras).
   68    | VideoCapPropSaturation     -- ^ Saturation of the image (only for cameras).
   69    | VideoCapPropHue            -- ^ Hue of the image (only for cameras).
   70    | VideoCapPropGain           -- ^ Gain of the image (only for cameras).
   71    | VideoCapPropExposure       -- ^ Exposure (only for cameras).
   72    | VideoCapPropConvertRgb
   73         -- ^ Boolean flags indicating whether images should be converted to RGB.
   74    | VideoCapPropWhiteBalanceBlueU -- ^ Currently unsupported.
   75    | VideoCapPropRectification
   76         -- ^ Rectification flag for stereo cameras
   77         --  (note: only supported by DC1394 v 2.x backend currently).
   78    | VideoCapPropMonochrome        -- ^
   79    | VideoCapPropSharpness         -- ^
   80    | VideoCapPropAutoExposure
   81         -- ^ DC1394: exposure control done by camera, user can adjust reference
   82         -- level using this feature.
   83    | VideoCapPropGamma             -- ^
   84    | VideoCapPropTemperature       -- ^
   85    | VideoCapPropTrigger           -- ^
   86    | VideoCapPropTriggerDelay      -- ^
   87    | VideoCapPropWhiteBalanceRedV  -- ^
   88    | VideoCapPropZoom              -- ^
   89    | VideoCapPropFocus             -- ^
   90    | VideoCapPropGuid              -- ^
   91    | VideoCapPropIsoSpeed          -- ^
   92    | VideoCapPropBacklight         -- ^
   93    | VideoCapPropPan               -- ^
   94    | VideoCapPropTilt              -- ^
   95    | VideoCapPropRoll              -- ^
   96    | VideoCapPropIris              -- ^
   97    | VideoCapPropSettings
   98         -- ^ Pop up video/camera filter dialog (note: only supported by DSHOW
   99         --  backend currently. Property value is ignored)
  100    | VideoCapPropBuffersize        -- ^
  101    | VideoCapPropAutofocus         -- ^
  102    | VideoCapPropInt !Int32
  103        -- ^ Any property we need. Meaning of this property depends on
  104        -- the backend.
  105 
  106 marshalCaptureProperties :: VideoCaptureProperties -> Int32
  107 marshalCaptureProperties = \case
  108    VideoCapPropPosMsec           -> c'CAP_PROP_POS_MSEC
  109    VideoCapPropPosFrames         -> c'CAP_PROP_POS_FRAMES
  110    VideoCapPropPosAviRatio       -> c'CAP_PROP_POS_AVI_RATIO
  111    VideoCapPropFrameWidth        -> c'CAP_PROP_FRAME_WIDTH
  112    VideoCapPropFrameHeight       -> c'CAP_PROP_FRAME_HEIGHT
  113    VideoCapPropFps               -> c'CAP_PROP_FPS
  114    VideoCapPropFourCc            -> c'CAP_PROP_FOURCC
  115    VideoCapPropFrameCount        -> c'CAP_PROP_FRAME_COUNT
  116    VideoCapPropFormat            -> c'CAP_PROP_FORMAT
  117    VideoCapPropMode              -> c'CAP_PROP_MODE
  118    VideoCapPropBrightness        -> c'CAP_PROP_BRIGHTNESS
  119    VideoCapPropContrast          -> c'CAP_PROP_CONTRAST
  120    VideoCapPropSaturation        -> c'CAP_PROP_SATURATION
  121    VideoCapPropHue               -> c'CAP_PROP_HUE
  122    VideoCapPropGain              -> c'CAP_PROP_GAIN
  123    VideoCapPropExposure          -> c'CAP_PROP_EXPOSURE
  124    VideoCapPropConvertRgb        -> c'CAP_PROP_CONVERT_RGB
  125    VideoCapPropWhiteBalanceBlueU -> c'CAP_PROP_WHITE_BALANCE_BLUE_U
  126    VideoCapPropRectification     -> c'CAP_PROP_RECTIFICATION
  127    VideoCapPropMonochrome        -> c'CAP_PROP_MONOCHROME
  128    VideoCapPropSharpness         -> c'CAP_PROP_SHARPNESS
  129    VideoCapPropAutoExposure      -> c'CAP_PROP_AUTO_EXPOSURE
  130    VideoCapPropGamma             -> c'CAP_PROP_GAMMA
  131    VideoCapPropTemperature       -> c'CAP_PROP_TEMPERATURE
  132    VideoCapPropTrigger           -> c'CAP_PROP_TRIGGER
  133    VideoCapPropTriggerDelay      -> c'CAP_PROP_TRIGGER_DELAY
  134    VideoCapPropWhiteBalanceRedV  -> c'CAP_PROP_WHITE_BALANCE_RED_V
  135    VideoCapPropZoom              -> c'CAP_PROP_ZOOM
  136    VideoCapPropFocus             -> c'CAP_PROP_FOCUS
  137    VideoCapPropGuid              -> c'CAP_PROP_GUID
  138    VideoCapPropIsoSpeed          -> c'CAP_PROP_ISO_SPEED
  139    VideoCapPropBacklight         -> c'CAP_PROP_BACKLIGHT
  140    VideoCapPropPan               -> c'CAP_PROP_PAN
  141    VideoCapPropTilt              -> c'CAP_PROP_TILT
  142    VideoCapPropRoll              -> c'CAP_PROP_ROLL
  143    VideoCapPropIris              -> c'CAP_PROP_IRIS
  144    VideoCapPropSettings          -> c'CAP_PROP_SETTINGS
  145    VideoCapPropBuffersize        -> c'CAP_PROP_BUFFERSIZE
  146    VideoCapPropAutofocus         -> c'CAP_PROP_AUTOFOCUS
  147    VideoCapPropInt a             -> a
  148 
  149 --------------------------------------------------------------------------------
  150 -- VideoCaptureProperties
  151 -- more at https://github.com/opencv/opencv/blob/master/modules/videoio/include/opencv2/videoio.hpp
  152 --------------------------------------------------------------------------------
  153 data VideoCaptureAPI
  154    = VideoCapAny          -- ^ Auto detect == 0
  155    | VideoCapVfw          -- ^ Video For Windows (platform native)
  156    | VideoCapV4l          -- ^ V4L/V4L2 capturing support via libv4l
  157    | VideoCapV4l2         -- ^ Same as CAP_V4L
  158    | VideoCapFirewire     -- ^ IEEE 1394 drivers
  159    | VideoCapFireware     -- ^ Same as CAP_FIREWIRE
  160    | VideoCapIeee1394     -- ^ Same as CAP_FIREWIRE
  161    | VideoCapDc1394       -- ^ Same as CAP_FIREWIRE
  162    | VideoCapCmu1394      -- ^ Same as CAP_FIREWIRE
  163    | VideoCapQt           -- ^ QuickTime
  164    | VideoCapUnicap       -- ^ Unicap drivers
  165    | VideoCapDshow        -- ^ DirectShow (via videoInput)
  166    | VideoCapPvapi        -- ^ PvAPI, Prosilica GigE SDK
  167    | VideoCapOpenni       -- ^ OpenNI (for Kinect)
  168    | VideoCapOpenniAsus   -- ^ OpenNI (for Asus Xtion)
  169    | VideoCapAndroid      -- ^ Android - not used
  170    | VideoCapXiapi        -- ^ XIMEA Camera API
  171    | VideoCapAvfoundation
  172         -- ^ AVFoundation framework for iOS (OS X Lion will have the same API)
  173    | VideoCapGiganetix    -- ^ Smartek Giganetix GigEVisionSDK
  174    | VideoCapMsmf         -- ^ Microsoft Media Foundation (via videoInput)
  175    | VideoCapWinrt        -- ^ Microsoft Windows Runtime using Media Foundation
  176    | VideoCapIntelperc    -- ^ Intel Perceptual Computing SDK
  177    | VideoCapOpenni2      -- ^ OpenNI2 (for Kinect)
  178    | VideoCapOpenni2Asus
  179         -- ^ OpenNI2 (for Asus Xtion and Occipital Structure sensors)
  180    | VideoCapGphoto2      -- ^ gPhoto2 connection
  181    | VideoCapGstreamer    -- ^ GStreamer
  182    | VideoCapFfmpeg
  183         -- ^ Open and record video file or stream using the FFMPEG library
  184    | VideoCapImages       -- ^ Image Sequence (e.g. img_%02d.jpg)
  185 
  186 marshalVideoCaptureAPI :: VideoCaptureAPI -> Int32
  187 marshalVideoCaptureAPI = \case
  188    VideoCapAny           -> c'CAP_ANY
  189    VideoCapVfw           -> c'CAP_VFW
  190    VideoCapV4l           -> c'CAP_V4L
  191    VideoCapV4l2          -> c'CAP_V4L2
  192    VideoCapFirewire      -> c'CAP_FIREWIRE
  193    VideoCapFireware      -> c'CAP_FIREWARE
  194    VideoCapIeee1394      -> c'CAP_IEEE1394
  195    VideoCapDc1394        -> c'CAP_DC1394
  196    VideoCapCmu1394       -> c'CAP_CMU1394
  197    VideoCapQt            -> c'CAP_QT
  198    VideoCapUnicap        -> c'CAP_UNICAP
  199    VideoCapDshow         -> c'CAP_DSHOW
  200    VideoCapPvapi         -> c'CAP_PVAPI
  201    VideoCapOpenni        -> c'CAP_OPENNI
  202    VideoCapOpenniAsus    -> c'CAP_OPENNI_ASUS
  203    VideoCapAndroid       -> c'CAP_ANDROID
  204    VideoCapXiapi         -> c'CAP_XIAPI
  205    VideoCapAvfoundation  -> c'CAP_AVFOUNDATION
  206    VideoCapGiganetix     -> c'CAP_GIGANETIX
  207    VideoCapMsmf          -> c'CAP_MSMF
  208    VideoCapWinrt         -> c'CAP_WINRT
  209    VideoCapIntelperc     -> c'CAP_INTELPERC
  210    VideoCapOpenni2       -> c'CAP_OPENNI2
  211    VideoCapOpenni2Asus   -> c'CAP_OPENNI2_ASUS
  212    VideoCapGphoto2       -> c'CAP_GPHOTO2
  213    VideoCapGstreamer     -> c'CAP_GSTREAMER
  214    VideoCapFfmpeg        -> c'CAP_FFMPEG
  215    VideoCapImages        -> c'CAP_IMAGES