opencv-0.0.2.1: Haskell binding to OpenCV-3.x

Safe HaskellNone
LanguageHaskell2010

OpenCV.Core.Types.Mat

Contents

Synopsis

Matrix

data Mat (shape :: DS [DS Nat]) (channels :: DS Nat) (depth :: DS *) Source #

Instances

FreezeThaw (Mat shape channels depth) Source # 

Methods

freeze :: PrimMonad m => Mutable (Mat shape channels depth) (PrimState m) -> m (Mat shape channels depth) Source #

thaw :: PrimMonad m => Mat shape channels depth -> m (Mutable (Mat shape channels depth) (PrimState m)) Source #

unsafeFreeze :: PrimMonad m => Mutable (Mat shape channels depth) (PrimState m) -> m (Mat shape channels depth) Source #

unsafeThaw :: PrimMonad m => Mat shape channels depth -> m (Mutable (Mat shape channels depth) (PrimState m)) Source #

FromPtr (Mat shape channels depth) Source # 

Methods

fromPtr :: IO (Ptr (C (Mat shape channels depth))) -> IO (Mat shape channels depth)

WithPtr (Mat shape channels depth) Source # 

Methods

withPtr :: Mat shape channels depth -> (Ptr (C (Mat shape channels depth)) -> IO b) -> IO b

FromMat (Mat shape channels depth) Source # 

Methods

fromMat :: Mat (MatShape (Mat shape channels depth)) (MatChannels (Mat shape channels depth)) (MatDepth (Mat shape channels depth)) -> Mat shape channels depth Source #

ToMat (Mat shape channels depth) Source # 

Methods

toMat :: Mat shape channels depth -> Mat (MatShape (Mat shape channels depth)) (MatChannels (Mat shape channels depth)) (MatDepth (Mat shape channels depth)) Source #

type Mutable (Mat shape channels depth) Source # 
type Mutable (Mat shape channels depth) = Mut * (Mat shape channels depth)
type MatDepth (Mat shape channels depth) Source # 
type MatDepth (Mat shape channels depth) = depth
type MatChannels (Mat shape channels depth) Source # 
type MatChannels (Mat shape channels depth) = channels
type MatShape (Mat shape channels depth) Source # 
type MatShape (Mat shape channels depth) = shape

type family MatShape (a :: *) :: DS [DS Nat] Source #

Instances

type MatShape (M23 depth) Source # 
type MatShape (M23 depth) = ShapeT [Nat] ((:) Nat 2 ((:) Nat 3 ([] Nat)))
type MatShape (M33 depth) Source # 
type MatShape (M33 depth) = ShapeT [Nat] ((:) Nat 3 ((:) Nat 3 ([] Nat)))
type MatShape (Vec dim depth) Source # 
type MatShape (Vec dim depth) = ShapeT [Nat] ((:) Nat dim ([] Nat))
type MatShape (Matx m n depth) Source # 
type MatShape (Matx m n depth) = ShapeT [Nat] ((:) Nat m ((:) Nat n ([] Nat)))
type MatShape (Mat shape channels depth) Source # 
type MatShape (Mat shape channels depth) = shape

type family MatChannels (a :: *) :: DS Nat Source #

Instances

type MatChannels (M23 depth) Source # 
type MatChannels (M23 depth) = S Nat 1
type MatChannels (M33 depth) Source # 
type MatChannels (M33 depth) = S Nat 1
type MatChannels (Vec dim depth) Source # 
type MatChannels (Vec dim depth) = S Nat 1
type MatChannels (Matx m n depth) Source # 
type MatChannels (Matx m n depth) = S Nat 1
type MatChannels (Mat shape channels depth) Source # 
type MatChannels (Mat shape channels depth) = channels

type family MatDepth (a :: *) :: DS * Source #

Instances

type MatDepth (M23 depth) Source # 
type MatDepth (M23 depth) = S * depth
type MatDepth (M33 depth) Source # 
type MatDepth (M33 depth) = S * depth
type MatDepth (Vec dim depth) Source # 
type MatDepth (Vec dim depth) = S * depth
type MatDepth (Matx m n depth) Source # 
type MatDepth (Matx m n depth) = S * depth
type MatDepth (Mat shape channels depth) Source # 
type MatDepth (Mat shape channels depth) = depth

class ToMat a where Source #

Minimal complete definition

toMat

Methods

toMat :: a -> Mat (MatShape a) (MatChannels a) (MatDepth a) Source #

Instances

ToMat Vec2i Source # 
ToMat Vec2f Source # 
ToMat Vec2d Source # 
ToMat Vec3i Source # 
ToMat Vec3f Source # 
ToMat Vec3d Source # 
ToMat Vec4i Source # 
ToMat Vec4f Source # 
ToMat Vec4d Source # 
ToMat Matx12f Source # 
ToMat Matx12d Source # 
ToMat Matx13f Source # 
ToMat Matx13d Source # 
ToMat Matx14f Source # 
ToMat Matx14d Source # 
ToMat Matx16f Source # 
ToMat Matx16d Source # 
ToMat Matx21f Source # 
ToMat Matx21d Source # 
ToMat Matx22f Source # 
ToMat Matx22d Source # 
ToMat Matx23f Source # 
ToMat Matx23d Source # 
ToMat Matx31f Source # 
ToMat Matx31d Source # 
ToMat Matx32f Source # 
ToMat Matx32d Source # 
ToMat Matx33f Source # 
ToMat Matx33d Source # 
ToMat Matx34f Source # 
ToMat Matx34d Source # 
ToMat Matx41f Source # 
ToMat Matx41d Source # 
ToMat Matx43f Source # 
ToMat Matx43d Source # 
ToMat Matx44f Source # 
ToMat Matx44d Source # 
ToMat Matx51f Source # 
ToMat Matx51d Source # 
ToMat Matx61f Source # 
ToMat Matx61d Source # 
ToMat Matx66f Source # 
ToMat Matx66d Source # 
(ToDepth (Proxy * depth), Storable depth) => ToMat (M23 depth) Source # 

Methods

toMat :: M23 depth -> Mat (MatShape (M23 depth)) (MatChannels (M23 depth)) (MatDepth (M23 depth)) Source #

(ToDepth (Proxy * depth), Storable depth) => ToMat (M33 depth) Source # 

Methods

toMat :: M33 depth -> Mat (MatShape (M33 depth)) (MatChannels (M33 depth)) (MatDepth (M33 depth)) Source #

ToMat (Mat shape channels depth) Source # 

Methods

toMat :: Mat shape channels depth -> Mat (MatShape (Mat shape channels depth)) (MatChannels (Mat shape channels depth)) (MatDepth (Mat shape channels depth)) Source #

class FromMat a where Source #

Minimal complete definition

fromMat

Methods

fromMat :: Mat (MatShape a) (MatChannels a) (MatDepth a) -> a Source #

Instances

Storable depth => FromMat (M23 depth) Source # 

Methods

fromMat :: Mat (MatShape (M23 depth)) (MatChannels (M23 depth)) (MatDepth (M23 depth)) -> M23 depth Source #

Storable depth => FromMat (M33 depth) Source # 

Methods

fromMat :: Mat (MatShape (M33 depth)) (MatChannels (M33 depth)) (MatDepth (M33 depth)) -> M33 depth Source #

FromMat (Mat shape channels depth) Source # 

Methods

fromMat :: Mat (MatShape (Mat shape channels depth)) (MatChannels (Mat shape channels depth)) (MatDepth (Mat shape channels depth)) -> Mat shape channels depth Source #

typeCheckMat Source #

Arguments

:: (ToShapeDS (Proxy shape), ToChannelsDS (Proxy channels), ToDepthDS (Proxy depth)) 
=> Mat shape channels depth

The matrix to be checked.

-> [CoerceMatError]

Error messages.

Tests whether a Mat is deserving of its type level attributes

Checks if the properties encoded in the type of a Mat correspond to the value level representation. For each property that does not hold this function will produce an error message. If everything checks out it will produce an empty list.

The following properties are checked:

  • Dimensionality
  • Size of each dimension
  • Number of channels
  • Depth (data type of elements)

If a property is explicitly encoded as statically unknown (Dynamic) it will not be checked.

relaxMat Source #

Arguments

:: (MayRelax shapeIn shapeOut, MayRelax channelsIn channelsOut, MayRelax depthIn depthOut) 
=> Mat shapeIn channelsIn depthIn

Original Mat.

-> Mat shapeOut channelsOut depthOut

Mat with relaxed constraints.

Relaxes the type level constraints

Only identical or looser constraints are allowed. For tighter constraints use coerceMat.

This allows you to 'forget' type level guarantees for zero cost. Similar to unsafeCoerceMat, but totally safe.

Identical
a to b with a ~ b
Looser
('S a) to 'D or ('S a) to ('S b) with MayRelax a b
Tighter
'D to ('S a)

coerceMat Source #

Arguments

:: (ToShapeDS (Proxy shapeOut), ToChannelsDS (Proxy channelsOut), ToDepthDS (Proxy depthOut)) 
=> Mat shapeIn channelsIn depthIn 
-> CvExcept (Mat shapeOut channelsOut depthOut) 

emptyMat :: Mat (S '[]) (S 1) (S Word8) Source #

mkMat Source #

Arguments

:: (ToShape shape, ToChannels channels, ToDepth depth, ToScalar scalar) 
=> shape 
-> channels 
-> depth 
-> scalar 
-> CvExcept (Mat (ShapeT shape) (ChannelsT channels) (DepthT depth)) 

eyeMat Source #

Arguments

:: (ToInt32 height, ToInt32 width, ToChannels channels, ToDepth depth) 
=> height 
-> width 
-> channels 
-> depth 
-> Mat (ShapeT (height ::: (width ::: Z))) (ChannelsT channels) (DepthT depth) 

Identity matrix

OpenCV Sphinx doc

cloneMat :: Mat shape channels depth -> Mat shape channels depth Source #

matSubRect :: Mat (S [height, width]) channels depth -> Rect2i -> CvExcept (Mat (S [D, D]) channels depth) Source #

Extract a sub region from a 2D-matrix (image)

Example:

matSubRectImg :: Mat ('S ['D, 'D]) ('S 3) ('S Word8)
matSubRectImg = exceptError $
    withMatM (h ::: 2 * w ::: Z)
             (Proxy :: Proxy 3)
             (Proxy :: Proxy Word8)
             white $ \imgM -> do
      matCopyToM imgM (V2 0 0) birds_512x341 Nothing
      matCopyToM imgM (V2 w 0) subImg        Nothing
      lift $ rectangle imgM subRect blue 1 LineType_4 0
      lift $ rectangle imgM (toRect $ HRect (V2 w 0) (V2 w h) :: Rect2i) blue 1 LineType_4 0
  where
    subRect = toRect $ HRect (V2 96 131) (V2 90 60)
    subImg = exceptError $
               resize (ResizeAbs $ toSize $ V2 w h) InterCubic =<<
               matSubRect birds_512x341 subRect
    [h, w] = miShape $ matInfo birds_512x341

matCopyTo Source #

Arguments

:: Mat (S [dstHeight, dstWidth]) channels depth 
-> V2 Int32 
-> Mat (S [srcHeight, srcWidth]) channels depth 
-> Maybe (Mat (S [srcHeight, srcWidth]) (S 1) (S Word8)) 
-> CvExcept (Mat (S [dstHeight, dstWidth]) channels depth) 

matConvertTo Source #

Arguments

:: ToDepthDS (Proxy dstDepth) 
=> Maybe Double

Optional scale factor.

-> Maybe Double

Optional delta added to the scaled values.

-> Mat shape channels srcDepth 
-> CvExcept (Mat shape channels dstDepth) 

Converts an array to another data type with optional scaling

OpenCV Sphinx doc

matFromFunc Source #

Arguments

:: (ToShape shape, ToChannels channels, ToDepth depth, Storable (StaticDepthT depth)) 
=> shape 
-> channels 
-> depth 
-> ([Int] -> Int -> StaticDepthT depth) 
-> CvExcept (Mat (ShapeT shape) (ChannelsT channels) (DepthT depth)) 

Create a matrix whose elements are defined by a function.

Example:

matFromFuncImg
  :: forall size. (size ~ 300)
  => Mat (ShapeT [size, size]) ('S 4) ('S Word8)
matFromFuncImg = exceptError $
    matFromFunc
      (Proxy :: Proxy [size, size])
      (Proxy :: Proxy 4)
      (Proxy :: Proxy Word8)
      example
  where
    example [y, x] 0 = 255 - normDist (V2 x y ^-^ bluePt )
    example [y, x] 1 = 255 - normDist (V2 x y ^-^ greenPt)
    example [y, x] 2 = 255 - normDist (V2 x y ^-^ redPt  )
    example [y, x] 3 =       normDist (V2 x y ^-^ alphaPt)
    example _pos _channel = error "impossible"

    normDist :: V2 Int -> Word8
    normDist v = floor $ min 255 $ 255 * Linear.norm (fromIntegral <$> v) / s'

    bluePt  = V2 0 0
    greenPt = V2 s s
    redPt   = V2 s 0
    alphaPt = V2 0 s

    s = fromInteger $ natVal (Proxy :: Proxy size) :: Int
    s' = fromIntegral s :: Double

Mutable Matrix

typeCheckMatM Source #

Arguments

:: (ToShapeDS (Proxy shape), ToChannelsDS (Proxy channels), ToDepthDS (Proxy depth)) 
=> Mut (Mat shape channels depth) s

The matrix to be checked.

-> [CoerceMatError]

Error messages.

relaxMatM Source #

Arguments

:: (MayRelax shapeIn shapeOut, MayRelax channelsIn channelsOut, MayRelax depthIn depthOut) 
=> Mut (Mat shapeIn channelsIn depthIn) s

Original Mat.

-> Mut (Mat shapeOut channelsOut depthOut) s

Mat with relaxed constraints.

coerceMatM Source #

Arguments

:: (ToShapeDS (Proxy shapeOut), ToChannelsDS (Proxy channelsOut), ToDepthDS (Proxy depthOut)) 
=> Mut (Mat shapeIn channelsIn depthIn) s 
-> CvExcept (Mut (Mat shapeOut channelsOut depthOut) s) 

freeze :: (FreezeThaw a, PrimMonad m) => Mutable a (PrimState m) -> m a Source #

thaw :: (FreezeThaw a, PrimMonad m) => a -> m (Mutable a (PrimState m)) Source #

mkMatM Source #

Arguments

:: (PrimMonad m, ToShape shape, ToChannels channels, ToDepth depth, ToScalar scalar) 
=> shape 
-> channels 
-> depth 
-> scalar 
-> CvExceptT m (Mut (Mat (ShapeT shape) (ChannelsT channels) (DepthT depth)) (PrimState m)) 

createMat Source #

Arguments

:: (forall s. CvExceptT (ST s) (Mut (Mat shape channels depth) s)) 
-> CvExcept (Mat shape channels depth) 

withMatM Source #

Arguments

:: (ToShape shape, ToChannels channels, ToDepth depth, ToScalar scalar) 
=> shape 
-> channels 
-> depth 
-> scalar 
-> (forall s. Mut (Mat (ShapeT shape) (ChannelsT channels) (DepthT depth)) (PrimState (ST s)) -> CvExceptT (ST s) ()) 
-> CvExcept (Mat (ShapeT shape) (ChannelsT channels) (DepthT depth)) 

cloneMatM :: PrimMonad m => Mat shape channels depth -> m (Mat shape channels depth) Source #

matCopyToM Source #

Arguments

:: PrimMonad m 
=> Mut (Mat (S [dstHeight, dstWidth]) channels depth) (PrimState m) 
-> V2 Int32 
-> Mat (S [srcHeight, srcWidth]) channels depth 
-> Maybe (Mat (S [srcHeight, srcWidth]) (S 1) (S Word8)) 
-> CvExceptT m () 

class All (p :: k -> Constraint) (xs :: [k]) Source #

Instances

All k p ([] k) Source # 
(p x, All a p xs) => All a p ((:) a x xs) Source # 

class PrivateIsStatic ds => IsStatic (ds :: DS a) Source #

Instances

IsStatic a1 (S a1 a2) Source # 

foldMat Source #

Arguments

:: forall (shape :: [DS Nat]) (channels :: Nat) (depth :: *). (Storable depth, Storable a, All IsStatic shape) 
=> (a -> Vector depth -> a) 
-> a 
-> [Mat (S shape) (S channels) (S depth)] 
-> Maybe (Vector a) 

Transforms a given list of matrices of equal shape, channels, and depth, by folding the given function over all matrix elements at each position.

Meta information

data MatInfo Source #

Constructors

MatInfo 

Fields

matInfo :: Mat shape channels depth -> MatInfo Source #

type family ShapeT (a :: ka) :: DS [DS Nat] where ... Source #

Equations

ShapeT [Int32] = D 
ShapeT (Vector Int32) = D 
ShapeT (x ::: xs) = S (DSNats (x ::: xs)) 
ShapeT (xs :: [Nat]) = S (DSNats xs) 
ShapeT (Proxy a) = ShapeT a 

type ChannelsT a = DSNat a Source #

type family DepthT a :: DS * where ... Source #

Equations

DepthT Depth = D 
DepthT (proxy d) = S d 

class ToShape a where Source #

Minimal complete definition

toShape

Methods

toShape :: a -> Vector Int32 Source #

Instances

ToShape Z Source #

empty Vector

Methods

toShape :: Z -> Vector Int32 Source #

ToShape [Int32] Source #

direct conversion to Vector

Methods

toShape :: [Int32] -> Vector Int32 Source #

ToShape (Vector Int32) Source #

identity

(ToInt32 (Proxy a1 a2), ToShape (Proxy [a1] as)) => ToShape (Proxy [a1] ((:) a1 a2 as)) Source #

fold over the type level list

Methods

toShape :: Proxy [a1] ((a1 ': a2) as) -> Vector Int32 Source #

ToShape (Proxy [k] ([] k)) Source #

empty Vector

Methods

toShape :: Proxy [k] [k] -> Vector Int32 Source #

(ToInt32 a, ToShape as) => ToShape ((:::) a as) Source #

fold over :::

Methods

toShape :: (a ::: as) -> Vector Int32 Source #

class ToShapeDS a where Source #

Minimal complete definition

toShapeDS

Methods

toShapeDS :: a -> DS [DS Int32] Source #

Instances

ToShapeDS (proxy (D a)) Source # 

Methods

toShapeDS :: proxy (D a) -> DS [DS Int32] Source #

ToNatListDS (Proxy a as) => ToShapeDS (Proxy (DS a) (S a as)) Source # 

Methods

toShapeDS :: Proxy (DS a) (S a as) -> DS [DS Int32] Source #

class ToDepth a where Source #

Minimal complete definition

toDepth

Methods

toDepth :: a -> Depth Source #

Instances

ToDepth Depth Source # 

Methods

toDepth :: Depth -> Depth Source #

ToDepth (proxy Double) Source # 

Methods

toDepth :: proxy Double -> Depth Source #

ToDepth (proxy Float) Source # 

Methods

toDepth :: proxy Float -> Depth Source #

ToDepth (proxy Int32) Source # 

Methods

toDepth :: proxy Int32 -> Depth Source #

ToDepth (proxy Int16) Source # 

Methods

toDepth :: proxy Int16 -> Depth Source #

ToDepth (proxy Word16) Source # 

Methods

toDepth :: proxy Word16 -> Depth Source #

ToDepth (proxy Int8) Source # 

Methods

toDepth :: proxy Int8 -> Depth Source #

ToDepth (proxy Word8) Source # 

Methods

toDepth :: proxy Word8 -> Depth Source #

class ToDepthDS a where Source #

Minimal complete definition

toDepthDS

Methods

toDepthDS :: a -> DS Depth Source #

Instances

ToDepthDS Depth Source # 
ToDepthDS (proxy (S * Double)) Source # 

Methods

toDepthDS :: proxy (S * Double) -> DS Depth Source #

ToDepthDS (proxy (S * Float)) Source # 

Methods

toDepthDS :: proxy (S * Float) -> DS Depth Source #

ToDepthDS (proxy (S * Int32)) Source # 

Methods

toDepthDS :: proxy (S * Int32) -> DS Depth Source #

ToDepthDS (proxy (S * Int16)) Source # 

Methods

toDepthDS :: proxy (S * Int16) -> DS Depth Source #

ToDepthDS (proxy (S * Word16)) Source # 

Methods

toDepthDS :: proxy (S * Word16) -> DS Depth Source #

ToDepthDS (proxy (S * Int8)) Source # 

Methods

toDepthDS :: proxy (S * Int8) -> DS Depth Source #

ToDepthDS (proxy (S * Word8)) Source # 

Methods

toDepthDS :: proxy (S * Word8) -> DS Depth Source #

ToDepthDS (proxy (D a)) Source # 

Methods

toDepthDS :: proxy (D a) -> DS Depth Source #