{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}
module ArrayFire.Vision where
import Control.Exception hiding (TypeError)
import Data.Typeable
import Foreign.ForeignPtr
import Foreign.Marshal
import Foreign.Storable
import System.IO.Unsafe
import Data.Word (Word32)
import ArrayFire.Exception
import ArrayFire.FFI
import ArrayFire.Internal.Features
import ArrayFire.Internal.Vision
import ArrayFire.Internal.Types
fast
:: Array a
-> Float
-> Int
-> Bool
-> Float
-> Int
-> Features
{-# NOINLINE fast #-}
fast :: forall a.
Array a -> Float -> Int -> Bool -> Float -> Int -> Features
fast (Array ForeignPtr ()
fptr) Float
thr (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
arc) (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
non) Float
ratio (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
edge)
= IO Features -> Features
forall a. IO a -> a
unsafePerformIO (IO Features -> Features)
-> ((AFFeatures -> IO Features) -> IO Features)
-> (AFFeatures -> IO Features)
-> Features
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO Features -> IO Features
forall a. IO a -> IO a
mask_ (IO Features -> IO Features)
-> ((AFFeatures -> IO Features) -> IO Features)
-> (AFFeatures -> IO Features)
-> IO Features
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr () -> (AFFeatures -> IO Features) -> IO Features
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
fptr ((AFFeatures -> IO Features) -> Features)
-> (AFFeatures -> IO Features) -> Features
forall a b. (a -> b) -> a -> b
$ \AFFeatures
aptr ->
do feat <- (Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures)
-> (Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
ptr -> do
AFErr -> IO ()
throwAFError (AFErr -> IO ()) -> IO AFErr -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr AFFeatures
-> AFFeatures
-> Float
-> CUInt
-> CBool
-> Float
-> CUInt
-> IO AFErr
af_fast Ptr AFFeatures
ptr AFFeatures
aptr Float
thr CUInt
arc CBool
non Float
ratio CUInt
edge
Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
ptr
Features <$>
newForeignPtr af_release_features feat
harris
:: Array a
-> Int
-> Float
-> Float
-> Int
-> Float
-> Features
{-# NOINLINE harris #-}
harris :: forall a.
Array a -> Int -> Float -> Float -> Int -> Float -> Features
harris (Array ForeignPtr ()
fptr) (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
maxc) Float
minresp Float
sigma (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
bs) Float
thr
= IO Features -> Features
forall a. IO a -> a
unsafePerformIO (IO Features -> Features)
-> ((AFFeatures -> IO Features) -> IO Features)
-> (AFFeatures -> IO Features)
-> Features
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO Features -> IO Features
forall a. IO a -> IO a
mask_ (IO Features -> IO Features)
-> ((AFFeatures -> IO Features) -> IO Features)
-> (AFFeatures -> IO Features)
-> IO Features
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr () -> (AFFeatures -> IO Features) -> IO Features
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
fptr ((AFFeatures -> IO Features) -> Features)
-> (AFFeatures -> IO Features) -> Features
forall a b. (a -> b) -> a -> b
$ \AFFeatures
aptr ->
do feat <- (Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures)
-> (Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
ptr -> do
AFErr -> IO ()
throwAFError (AFErr -> IO ()) -> IO AFErr -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr AFFeatures
-> AFFeatures
-> CUInt
-> Float
-> Float
-> CUInt
-> Float
-> IO AFErr
af_harris Ptr AFFeatures
ptr AFFeatures
aptr CUInt
maxc Float
minresp Float
sigma CUInt
bs Float
thr
Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
ptr
Features <$>
newForeignPtr af_release_features feat
orb
:: Array a
-> Float
-> Int
-> Float
-> Int
-> Bool
-> (Features, Array a)
{-# NOINLINE orb #-}
orb :: forall a.
Array a
-> Float -> Int -> Float -> Int -> Bool -> (Features, Array a)
orb (Array ForeignPtr ()
fptr) Float
thr (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
feat) Float
scl (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
levels) (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
blur)
= IO (Features, Array a) -> (Features, Array a)
forall a. IO a -> a
unsafePerformIO (IO (Features, Array a) -> (Features, Array a))
-> ((AFFeatures -> IO (Features, Array a))
-> IO (Features, Array a))
-> (AFFeatures -> IO (Features, Array a))
-> (Features, Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Features, Array a) -> IO (Features, Array a)
forall a. IO a -> IO a
mask_ (IO (Features, Array a) -> IO (Features, Array a))
-> ((AFFeatures -> IO (Features, Array a))
-> IO (Features, Array a))
-> (AFFeatures -> IO (Features, Array a))
-> IO (Features, Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr ()
-> (AFFeatures -> IO (Features, Array a)) -> IO (Features, Array a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
fptr ((AFFeatures -> IO (Features, Array a)) -> (Features, Array a))
-> (AFFeatures -> IO (Features, Array a)) -> (Features, Array a)
forall a b. (a -> b) -> a -> b
$ \AFFeatures
inptr ->
do (feature, arr) <-
(Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures))
-> (Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
aptr -> do
(Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures))
-> (Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
bptr -> do
AFErr -> IO ()
throwAFError (AFErr -> IO ()) -> IO AFErr -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr AFFeatures
-> Ptr AFFeatures
-> AFFeatures
-> Float
-> CUInt
-> Float
-> CUInt
-> CBool
-> IO AFErr
af_orb Ptr AFFeatures
aptr Ptr AFFeatures
bptr AFFeatures
inptr Float
thr CUInt
feat Float
scl CUInt
levels CBool
blur
(,) (AFFeatures -> AFFeatures -> (AFFeatures, AFFeatures))
-> IO AFFeatures -> IO (AFFeatures -> (AFFeatures, AFFeatures))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
aptr IO (AFFeatures -> (AFFeatures, AFFeatures))
-> IO AFFeatures -> IO (AFFeatures, AFFeatures)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
bptr
feats <- Features <$> newForeignPtr af_release_features feature
array <- Array <$> newForeignPtr af_release_array_finalizer arr
pure (feats, array)
sift
:: Array a
-> Int
-> Float
-> Float
-> Float
-> Bool
-> Float
-> Float
-> (Features, Array a)
{-# NOINLINE sift #-}
sift :: forall a.
Array a
-> Int
-> Float
-> Float
-> Float
-> Bool
-> Float
-> Float
-> (Features, Array a)
sift (Array ForeignPtr ()
fptr) (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
a) Float
b Float
c Float
d (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
e) Float
f Float
g
= IO (Features, Array a) -> (Features, Array a)
forall a. IO a -> a
unsafePerformIO (IO (Features, Array a) -> (Features, Array a))
-> ((AFFeatures -> IO (Features, Array a))
-> IO (Features, Array a))
-> (AFFeatures -> IO (Features, Array a))
-> (Features, Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Features, Array a) -> IO (Features, Array a)
forall a. IO a -> IO a
mask_ (IO (Features, Array a) -> IO (Features, Array a))
-> ((AFFeatures -> IO (Features, Array a))
-> IO (Features, Array a))
-> (AFFeatures -> IO (Features, Array a))
-> IO (Features, Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr ()
-> (AFFeatures -> IO (Features, Array a)) -> IO (Features, Array a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
fptr ((AFFeatures -> IO (Features, Array a)) -> (Features, Array a))
-> (AFFeatures -> IO (Features, Array a)) -> (Features, Array a)
forall a b. (a -> b) -> a -> b
$ \AFFeatures
inptr ->
do (feat, arr) <-
(Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures))
-> (Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
aptr -> do
(Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures))
-> (Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
bptr -> do
AFErr -> IO ()
throwAFError (AFErr -> IO ()) -> IO AFErr -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr AFFeatures
-> Ptr AFFeatures
-> AFFeatures
-> CUInt
-> Float
-> Float
-> Float
-> CBool
-> Float
-> Float
-> IO AFErr
af_sift Ptr AFFeatures
aptr Ptr AFFeatures
bptr AFFeatures
inptr CUInt
a Float
b Float
c Float
d CBool
e Float
f Float
g
(,) (AFFeatures -> AFFeatures -> (AFFeatures, AFFeatures))
-> IO AFFeatures -> IO (AFFeatures -> (AFFeatures, AFFeatures))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
aptr IO (AFFeatures -> (AFFeatures, AFFeatures))
-> IO AFFeatures -> IO (AFFeatures, AFFeatures)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
bptr
feats <- Features <$> newForeignPtr af_release_features feat
array <- Array <$> newForeignPtr af_release_array_finalizer arr
pure (feats, array)
gloh
:: Array a
-> Int
-> Float
-> Float
-> Float
-> Bool
-> Float
-> Float
-> (Features, Array a)
{-# NOINLINE gloh #-}
gloh :: forall a.
Array a
-> Int
-> Float
-> Float
-> Float
-> Bool
-> Float
-> Float
-> (Features, Array a)
gloh (Array ForeignPtr ()
fptr) (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
a) Float
b Float
c Float
d (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
e) Float
f Float
g
= IO (Features, Array a) -> (Features, Array a)
forall a. IO a -> a
unsafePerformIO (IO (Features, Array a) -> (Features, Array a))
-> ((AFFeatures -> IO (Features, Array a))
-> IO (Features, Array a))
-> (AFFeatures -> IO (Features, Array a))
-> (Features, Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Features, Array a) -> IO (Features, Array a)
forall a. IO a -> IO a
mask_ (IO (Features, Array a) -> IO (Features, Array a))
-> ((AFFeatures -> IO (Features, Array a))
-> IO (Features, Array a))
-> (AFFeatures -> IO (Features, Array a))
-> IO (Features, Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr ()
-> (AFFeatures -> IO (Features, Array a)) -> IO (Features, Array a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
fptr ((AFFeatures -> IO (Features, Array a)) -> (Features, Array a))
-> (AFFeatures -> IO (Features, Array a)) -> (Features, Array a)
forall a b. (a -> b) -> a -> b
$ \AFFeatures
inptr ->
do (feat, arr) <-
(Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures))
-> (Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
aptr -> do
(Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures))
-> (Ptr AFFeatures -> IO (AFFeatures, AFFeatures))
-> IO (AFFeatures, AFFeatures)
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
bptr -> do
AFErr -> IO ()
throwAFError (AFErr -> IO ()) -> IO AFErr -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr AFFeatures
-> Ptr AFFeatures
-> AFFeatures
-> CUInt
-> Float
-> Float
-> Float
-> CBool
-> Float
-> Float
-> IO AFErr
af_gloh Ptr AFFeatures
aptr Ptr AFFeatures
bptr AFFeatures
inptr CUInt
a Float
b Float
c Float
d CBool
e Float
f Float
g
(,) (AFFeatures -> AFFeatures -> (AFFeatures, AFFeatures))
-> IO AFFeatures -> IO (AFFeatures -> (AFFeatures, AFFeatures))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
aptr IO (AFFeatures -> (AFFeatures, AFFeatures))
-> IO AFFeatures -> IO (AFFeatures, AFFeatures)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
bptr
feats <- Features <$> newForeignPtr af_release_features feat
array <- Array <$> newForeignPtr af_release_array_finalizer arr
pure (feats, array)
hammingMatcher
:: Array a
-> Array a
-> Int
-> Int
-> (Array Word32, Array a)
hammingMatcher :: forall a.
Array a -> Array a -> Int -> Int -> (Array Word32, Array a)
hammingMatcher Array a
a Array a
b (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
x) (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
y)
= Array a
-> Array a
-> (Ptr AFFeatures
-> Ptr AFFeatures -> AFFeatures -> AFFeatures -> IO AFErr)
-> (Array Word32, Array a)
forall a b c d.
Array a
-> Array b
-> (Ptr AFFeatures
-> Ptr AFFeatures -> AFFeatures -> AFFeatures -> IO AFErr)
-> (Array c, Array d)
op2p2 Array a
a Array a
b (\Ptr AFFeatures
p Ptr AFFeatures
c AFFeatures
d AFFeatures
e -> Ptr AFFeatures
-> Ptr AFFeatures
-> AFFeatures
-> AFFeatures
-> DimT
-> CUInt
-> IO AFErr
af_hamming_matcher Ptr AFFeatures
p Ptr AFFeatures
c AFFeatures
d AFFeatures
e DimT
x CUInt
y)
nearestNeighbor
:: Array a
-> Array a
-> Int
-> Int
-> MatchType
-> (Array Word32, Array a)
nearestNeighbor :: forall a.
Array a
-> Array a -> Int -> Int -> MatchType -> (Array Word32, Array a)
nearestNeighbor Array a
a Array a
b (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
x) (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
y) (MatchType -> AFMatchType
fromMatchType -> AFMatchType
match)
= Array a
-> Array a
-> (Ptr AFFeatures
-> Ptr AFFeatures -> AFFeatures -> AFFeatures -> IO AFErr)
-> (Array Word32, Array a)
forall a b c d.
Array a
-> Array b
-> (Ptr AFFeatures
-> Ptr AFFeatures -> AFFeatures -> AFFeatures -> IO AFErr)
-> (Array c, Array d)
op2p2 Array a
a Array a
b (\Ptr AFFeatures
p Ptr AFFeatures
c AFFeatures
d AFFeatures
e -> Ptr AFFeatures
-> Ptr AFFeatures
-> AFFeatures
-> AFFeatures
-> DimT
-> CUInt
-> AFMatchType
-> IO AFErr
af_nearest_neighbour Ptr AFFeatures
p Ptr AFFeatures
c AFFeatures
d AFFeatures
e DimT
x CUInt
y AFMatchType
match)
matchTemplate
:: Array a
-> Array a
-> MatchType
-> Array a
matchTemplate :: forall a. Array a -> Array a -> MatchType -> Array a
matchTemplate Array a
a Array a
b (MatchType -> AFMatchType
fromMatchType -> AFMatchType
match)
= Array a
-> Array a
-> (Ptr AFFeatures -> AFFeatures -> AFFeatures -> IO AFErr)
-> Array a
forall b a c.
Array b
-> Array a
-> (Ptr AFFeatures -> AFFeatures -> AFFeatures -> IO AFErr)
-> Array c
op2 Array a
a Array a
b (\Ptr AFFeatures
p AFFeatures
c AFFeatures
d -> Ptr AFFeatures
-> AFFeatures -> AFFeatures -> AFMatchType -> IO AFErr
af_match_template Ptr AFFeatures
p AFFeatures
c AFFeatures
d AFMatchType
match)
susan
:: Array a
-> Int
-> Float
-> Float
-> Float
-> Int
-> Features
{-# NOINLINE susan #-}
susan :: forall a.
Array a -> Int -> Float -> Float -> Float -> Int -> Features
susan (Array ForeignPtr ()
fptr) (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
a) Float
b Float
c Float
d (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
e)
= IO Features -> Features
forall a. IO a -> a
unsafePerformIO (IO Features -> Features)
-> ((AFFeatures -> IO Features) -> IO Features)
-> (AFFeatures -> IO Features)
-> Features
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO Features -> IO Features
forall a. IO a -> IO a
mask_ (IO Features -> IO Features)
-> ((AFFeatures -> IO Features) -> IO Features)
-> (AFFeatures -> IO Features)
-> IO Features
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr () -> (AFFeatures -> IO Features) -> IO Features
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
fptr ((AFFeatures -> IO Features) -> Features)
-> (AFFeatures -> IO Features) -> Features
forall a b. (a -> b) -> a -> b
$ \AFFeatures
inptr ->
do feat <-
(Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures)
-> (Ptr AFFeatures -> IO AFFeatures) -> IO AFFeatures
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
aptr -> do
AFErr -> IO ()
throwAFError (AFErr -> IO ()) -> IO AFErr -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr AFFeatures
-> AFFeatures
-> CUInt
-> Float
-> Float
-> Float
-> CUInt
-> IO AFErr
af_susan Ptr AFFeatures
aptr AFFeatures
inptr CUInt
a Float
b Float
c Float
d CUInt
e
Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
aptr
Features <$> newForeignPtr af_release_features feat
dog
:: Array a
-> Int
-> Int
-> Array a
dog :: forall a. Array a -> Int -> Int -> Array a
dog Array a
a (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CInt
x) (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CInt
y) =
Array a -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array b
op1 Array a
a (\Ptr AFFeatures
p AFFeatures
c -> Ptr AFFeatures -> AFFeatures -> CInt -> CInt -> IO AFErr
af_dog Ptr AFFeatures
p AFFeatures
c CInt
x CInt
y)
homography
:: forall a . AFType a
=> Array a
-> Array a
-> Array a
-> Array a
-> HomographyType
-> Float
-> Int
-> (Int, Array a)
{-# NOINLINE homography #-}
homography :: forall a.
AFType a =>
Array a
-> Array a
-> Array a
-> Array a
-> HomographyType
-> Float
-> Int
-> (Int, Array a)
homography
(Array ForeignPtr ()
a)
(Array ForeignPtr ()
b)
(Array ForeignPtr ()
c)
(Array ForeignPtr ()
d)
(HomographyType -> AFHomographyType
fromHomographyType -> AFHomographyType
homo)
Float
inlier
(Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
iterations) = do
IO (Int, Array a) -> (Int, Array a)
forall a. IO a -> a
unsafePerformIO (IO (Int, Array a) -> (Int, Array a))
-> (IO (Int, Array a) -> IO (Int, Array a))
-> IO (Int, Array a)
-> (Int, Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO (Int, Array a) -> IO (Int, Array a)
forall a. IO a -> IO a
mask_ (IO (Int, Array a) -> (Int, Array a))
-> IO (Int, Array a) -> (Int, Array a)
forall a b. (a -> b) -> a -> b
$ do
ForeignPtr ()
-> (AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
a ((AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a))
-> (AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. (a -> b) -> a -> b
$ \AFFeatures
aptr ->
ForeignPtr ()
-> (AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
b ((AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a))
-> (AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. (a -> b) -> a -> b
$ \AFFeatures
bptr ->
ForeignPtr ()
-> (AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
c ((AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a))
-> (AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. (a -> b) -> a -> b
$ \AFFeatures
cptr ->
ForeignPtr ()
-> (AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
d ((AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a))
-> (AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. (a -> b) -> a -> b
$ \AFFeatures
dptr -> do
(Ptr AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a))
-> (Ptr AFFeatures -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. (a -> b) -> a -> b
$ \Ptr AFFeatures
outPtrA ->
(Ptr CInt -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (Int, Array a)) -> IO (Int, Array a))
-> (Ptr CInt -> IO (Int, Array a)) -> IO (Int, Array a)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
outPtrI -> do
AFErr -> IO ()
throwAFError (AFErr -> IO ()) -> IO AFErr -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
Ptr AFFeatures
-> Ptr CInt
-> AFFeatures
-> AFFeatures
-> AFFeatures
-> AFFeatures
-> AFHomographyType
-> Float
-> CUInt
-> AFDtype
-> IO AFErr
af_homography
Ptr AFFeatures
outPtrA
Ptr CInt
outPtrI
AFFeatures
aptr
AFFeatures
bptr
AFFeatures
cptr
AFFeatures
dptr
AFHomographyType
homo
Float
inlier
CUInt
iterations
AFDtype
dtype
arrayPtr <- Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
outPtrA
(,) <$> do fromIntegral <$> peek outPtrI
<*> do Array <$> newForeignPtr af_release_array_finalizer arrayPtr
where
dtype :: AFDtype
dtype = Proxy a -> AFDtype
forall a. AFType a => Proxy a -> AFDtype
afType (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @a)