{-# 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 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
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 AFFeatures
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
ForeignPtr () -> Features
Features (ForeignPtr () -> Features) -> IO (ForeignPtr ()) -> IO Features
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_features AFFeatures
feat
harris
:: Array a
-> Int
-> Float
-> Float
-> Int
-> Float
-> Features
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 AFFeatures
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
ForeignPtr () -> Features
Features (ForeignPtr () -> Features) -> IO (ForeignPtr ()) -> IO Features
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_features AFFeatures
feat
orb
:: Array a
-> Float
-> Int
-> Float
-> Int
-> Bool
-> (Features, Array a)
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 (AFFeatures
feature, AFFeatures
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 (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
Features
feats <- ForeignPtr () -> Features
Features (ForeignPtr () -> Features) -> IO (ForeignPtr ()) -> IO Features
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_features AFFeatures
feature
Array a
array <- ForeignPtr () -> Array a
forall a. ForeignPtr () -> Array a
Array (ForeignPtr () -> Array a) -> IO (ForeignPtr ()) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_array_finalizer AFFeatures
arr
(Features, Array a) -> IO (Features, Array a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Features
feats, Array a
array)
sift
:: Array a
-> Int
-> Float
-> Float
-> Float
-> Bool
-> Float
-> Float
-> (Features, Array a)
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 (AFFeatures
feat, AFFeatures
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 (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
Features
feats <- ForeignPtr () -> Features
Features (ForeignPtr () -> Features) -> IO (ForeignPtr ()) -> IO Features
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_features AFFeatures
feat
Array a
array <- ForeignPtr () -> Array a
forall a. ForeignPtr () -> Array a
Array (ForeignPtr () -> Array a) -> IO (ForeignPtr ()) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_array_finalizer AFFeatures
arr
(Features, Array a) -> IO (Features, Array a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Features
feats, Array a
array)
gloh
:: Array a
-> Int
-> Float
-> Float
-> Float
-> Bool
-> Float
-> Float
-> (Features, Array a)
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 (AFFeatures
feat, AFFeatures
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 (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
Features
feats <- ForeignPtr () -> Features
Features (ForeignPtr () -> Features) -> IO (ForeignPtr ()) -> IO Features
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_features AFFeatures
feat
Array a
array <- ForeignPtr () -> Array a
forall a. ForeignPtr () -> Array a
Array (ForeignPtr () -> Array a) -> IO (ForeignPtr ()) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_array_finalizer AFFeatures
arr
(Features, Array a) -> IO (Features, Array a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Features
feats, Array a
array)
hammingMatcher
:: Array a
-> Array a
-> Int
-> Int
-> (Array a, Array a)
hammingMatcher :: forall a. Array a -> Array a -> Int -> Int -> (Array a, 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 a, Array a)
forall a.
Array a
-> Array a
-> (Ptr AFFeatures
-> Ptr AFFeatures -> AFFeatures -> AFFeatures -> IO AFErr)
-> (Array a, Array a)
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 a, Array a)
nearestNeighbor :: forall a.
Array a -> Array a -> Int -> Int -> MatchType -> (Array a, 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 a, Array a)
forall a.
Array a
-> Array a
-> (Ptr AFFeatures
-> Ptr AFFeatures -> AFFeatures -> AFFeatures -> IO AFErr)
-> (Array a, Array a)
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.
Array b
-> Array a
-> (Ptr AFFeatures -> AFFeatures -> AFFeatures -> IO AFErr)
-> Array a
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
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 AFFeatures
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
ForeignPtr () -> Features
Features (ForeignPtr () -> Features) -> IO (ForeignPtr ()) -> IO Features
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_features AFFeatures
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.
Array a -> (Ptr AFFeatures -> AFFeatures -> IO AFErr) -> Array a
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)
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
AFFeatures
arrayPtr <- Ptr AFFeatures -> IO AFFeatures
forall a. Storable a => Ptr a -> IO a
peek Ptr AFFeatures
outPtrA
(,) (Int -> Array a -> (Int, Array a))
-> IO Int -> IO (Array a -> (Int, Array a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
outPtrI
IO (Array a -> (Int, Array a)) -> IO (Array a) -> IO (Int, Array a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> do ForeignPtr () -> Array a
forall a. ForeignPtr () -> Array a
Array (ForeignPtr () -> Array a) -> IO (ForeignPtr ()) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FinalizerPtr () -> AFFeatures -> IO (ForeignPtr ())
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr ()
af_release_array_finalizer AFFeatures
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)