HOpenCV 0.1.2 → 0.1.2.1
raw patch · 3 files changed
+51/−36 lines, 3 filesdep +allocated-processordep +vector-spacedep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: allocated-processor, vector-space
Dependency ranges changed: base
API changes (from Hackage documentation)
- Foreign.ForeignPtrWrap: checkPtr :: IO (Ptr a) -> IO (Ptr a)
- Foreign.ForeignPtrWrap: createForeignPtr :: (FunPtr (Ptr a -> IO ())) -> IO (Ptr a) -> IO (ForeignPtr a)
- Foreign.ForeignPtrWrap: errorName :: String -> IO a -> IO a
+ AI.CV.OpenCV.CxCore: instance AdditiveGroup CvRect
+ AI.CV.OpenCV.CxCore: instance AdditiveGroup CvSize
+ AI.CV.OpenCV.CxCore: instance VectorSpace CvRect
+ AI.CV.OpenCV.CxCore: instance VectorSpace CvSize
+ AI.CV.OpenCV.CxCore: liftCvRect :: (RealFrac c, Num b) => (b -> c) -> CvRect -> CvRect
+ AI.CV.OpenCV.CxCore: liftCvRect2 :: (Num b, Num b1, RealFrac a) => (b -> b1 -> a) -> CvRect -> CvRect -> CvRect
+ AI.CV.OpenCV.CxCore: liftCvSize :: (RealFrac c, Num b) => (b -> c) -> CvSize -> CvSize
+ AI.CV.OpenCV.CxCore: liftCvSize2 :: (Num b, Num b1, RealFrac a) => (b -> b1 -> a) -> CvSize -> CvSize -> CvSize
+ AI.CV.OpenCV.CxCore: toFromIntegral :: (RealFrac c, Integral b, Integral a, Num b1) => (b1 -> c) -> a -> b
+ AI.CV.OpenCV.CxCore: toFromIntegral2 :: (Integral a, Num b, Integral a1, Num b1, RealFrac a2, Integral b2) => (b -> b1 -> a2) -> a -> a1 -> b2
Files
- HOpenCV.cabal +5/−6
- src/AI/CV/OpenCV/CxCore.hsc +46/−1
- src/Foreign/ForeignPtrWrap.hs +0/−29
HOpenCV.cabal view
@@ -1,5 +1,5 @@ name: HOpenCV-version: 0.1.2+version: 0.1.2.1 license: BSD3 maintainer: Noam Lewis <jones.noamle@gmail.com> bug-reports: mailto:jones.noamle@gmail.com@@ -37,23 +37,22 @@ AI.CV.OpenCV.CxCore AI.CV.OpenCV.HighGui AI.CV.OpenCV.Types- Foreign.ForeignPtrWrap c-sources: src/AI/CV/OpenCV/HOpenCV_wrap.c hs-Source-Dirs: src include-dirs: /usr/include/opencv extra-libraries: cv,highgui- build-depends: base >= 3 && < 5- ghc-options: -Wall+ build-depends: base >=4 && <5, allocated-processor, vector-space+ ghc-options: -Wall -fno-warn-type-defaults executable test-hopencv c-sources: src/AI/CV/OpenCV/HOpenCV_wrap.c include-dirs: /usr/include/opencv hs-source-dirs: src- Build-Depends: base >= 4+ Build-Depends: base >=4 && <5 main-is: Test.hs- Ghc-Options: -Wall + Ghc-Options: -Wall -fno-warn-type-defaults Ghc-Prof-Options: -prof -auto-all extra-libraries: cv,highgui other-modules: AI.CV.OpenCV.CxCore, AI.CV.OpenCV.CV, AI.CV.OpenCV.HighGui, AI.CV.OpenCV.Types
src/AI/CV/OpenCV/CxCore.hsc view
@@ -1,4 +1,4 @@-{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls #-}+{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls, TypeFamilies #-} module AI.CV.OpenCV.CxCore where @@ -7,11 +7,18 @@ import Foreign.C.String import Foreign +import Data.VectorSpace as VectorSpace #include <cxcore.h> ------------------------------------------------------+toFromIntegral :: (RealFrac c, Integral b, Integral a, Num b1) => (b1 -> c) -> a -> b+toFromIntegral f = round . f . fromIntegral +toFromIntegral2 :: (Integral a, Num b, Integral a1, Num b1, RealFrac a2, Integral b2) => (b -> b1 -> a2) -> a -> a1 -> b2+toFromIntegral2 f x y = round (f (fromIntegral x) (fromIntegral y))+------------------------------------------------------+ data CvSize = CvSize { sizeWidth :: CInt, sizeHeight :: CInt } deriving (Show, Eq) instance Storable CvSize where@@ -25,6 +32,24 @@ (#poke CvSize, width) ptr w (#poke CvSize, height) ptr h +liftCvSize ::(RealFrac c, Num b) => (b -> c) -> CvSize -> CvSize+liftCvSize f (CvSize w h) = CvSize (f' w) (f' h)+ where f' = toFromIntegral f++liftCvSize2 :: (Num b, Num b1, RealFrac a) => (b -> b1 -> a) -> CvSize -> CvSize -> CvSize+liftCvSize2 f (CvSize w1 h1) (CvSize w2 h2) = CvSize (f' w1 w2) (f' h1 h2)+ where f' = toFromIntegral2 f++instance AdditiveGroup CvSize where+ zeroV = CvSize 0 0+ (^+^) = liftCvSize2 (+)+ negateV = liftCvSize (0-)++instance VectorSpace CvSize where+ type Scalar CvSize = Double -- todo: use CInt instead of Double here?+ a *^ s = liftCvSize (a*) s++ data CvRect = CvRect { rectX :: CInt, rectY :: CInt, rectWidth :: CInt, rectHeight :: CInt } deriving (Show, Eq) @@ -42,6 +67,26 @@ (#poke CvRect, y) ptr y (#poke CvRect, width) ptr w (#poke CvRect, height) ptr h+ ++liftCvRect :: (RealFrac c, Num b) => (b -> c) -> CvRect -> CvRect+liftCvRect f (CvRect x y w h) = CvRect (f' x) (f' y) (f' w) (f' h)+ where f' = toFromIntegral f++liftCvRect2 :: (Num b, Num b1, RealFrac a) => (b -> b1 -> a) -> CvRect -> CvRect -> CvRect+liftCvRect2 f (CvRect x1 y1 w1 h1) (CvRect x2 y2 w2 h2) = CvRect (f' x1 x2) (f' y1 y2) (f' w1 w2) (f' h1 h2)+ where f' = toFromIntegral2 f++instance AdditiveGroup CvRect where+ zeroV = CvRect 0 0 0 0+ (^+^) = liftCvRect2 (+)+ negateV = liftCvRect (0-)++instance VectorSpace CvRect where+ type Scalar CvRect = Double -- todo: use CInt instead of Double here?+ a *^ r = liftCvRect (a*) r+ + ------------------------------------------------------ class IplArrayType a
− src/Foreign/ForeignPtrWrap.hs
@@ -1,29 +0,0 @@-module Foreign.ForeignPtrWrap where--import Foreign.Ptr-import Foreign.ForeignPtr--import System.IO.Error---- A wrapper for newForeignPtr that handles nullPtrs, and can be chained to an IO Ptr creator.--- usage:--- myPtrCreator = (createForeignPtr deallocFunc) . allocFunc--- where, allocFunc :: a->b->c->...-> IO (Ptr z)-createForeignPtr :: (FunPtr (Ptr a -> IO () )) -> IO (Ptr a) -> IO (ForeignPtr a)-createForeignPtr dealloc allocedPtr = do- ptr <- checkPtr allocedPtr- newForeignPtr dealloc ptr---checkPtr :: IO (Ptr a) -> IO (Ptr a)-checkPtr x = do - res <- x- if res /= nullPtr - then return res - else fail "Null Pointer"---------------------------------------------------errorName :: String -> IO a -> IO a-errorName = modifyIOError . const . userError--