Permalink
Browse files

Merge remote-tracking branch 'origin/ME/development'

Conflicts:
	CV.cabal
	CV/Bindings/Core.hsc
	CV/Bindings/ImgProc.hsc
	CV/Bindings/Types.hsc
	CV/Conversions.hs
	CV/DFT.hs
	CV/Histogram.chs
	CV/Image.chs
	CV/Operations.hs
	cbits/cvWrapLEO.c
  • Loading branch information...
2 parents 220c716 + cfa71ba commit bea423a55a8cc4dd11743f9722731936bc15e135 @aleator committed Aug 16, 2012
Showing with 87 additions and 247 deletions.
  1. +11 −91 CV/Bindings/Core.hsc
  2. +0 −1 CV/Bindings/ImgProc.hsc
  3. +5 −5 CV/Conversions.hs
  4. +42 −124 CV/DFT.hs
  5. +7 −6 CV/Drawing.chs
  6. +0 −1 CV/Histogram.chs
  7. +16 −14 CV/Image.chs
  8. +3 −3 CV/Operations.hs
  9. +2 −1 Utils/Pointer.hs
  10. +1 −1 cbits/cvWrapLEO.c
View
@@ -11,98 +11,21 @@ import CV.Image(BareImage)
#include "cvWrapCore.h"
#include <opencv2/core/core_c.h>
--- CVAPI(IplImage*) cvCreateImage(
--- CvSize size,
--- int depth,
--- int channels
--- );
-
--- Creates IPL image (header and data)
-
--- need to use wrapper functions since passing struct by value.
-
--- #ccall wrapCreateImage , CInt -> CInt -> CInt -> CInt -> IO (Ptr IplImage)
-
--- Releases IPL image header and data
--- CVAPI(void) cvReleaseImage(
--- IplImage** image
--- );
-
--- Allocates and initializes CvMat header and allocates data
--- CVAPI(CvMat*) cvCreateMat(
--- int rows,
--- int cols,
--- int type
--- );
-
--- Releases CvMat header and deallocates matrix data
--- (reference counting is used for data)
--- CVAPI(void) cvReleaseMat(
--- CvMat** mat
--- );
-
--- CVAPI(void) cvSet(
--- CvArr* arr,
--- CvScalar value,
--- const CvArr* mask CV_DEFAULT(NULL)
--- );
-
--- Sets all or "masked" elements of input array
--- to the same value
-
--- need to use wrapper functions since passing struct by value.
-
#ccall wrapSet , Ptr <CvArr> -> Ptr <CvScalar> -> Ptr <CvArr> -> IO ()
#ccall wrapSetAll , Ptr <CvArr> -> CDouble -> Ptr <CvArr> -> IO ()
#ccall wrapSet1 , Ptr <CvArr> -> CDouble -> Ptr <CvArr> -> IO ()
#ccall wrapSet2 , Ptr <CvArr> -> CDouble -> CDouble -> Ptr <CvArr> -> IO ()
#ccall wrapSet3 , Ptr <CvArr> -> CDouble -> CDouble -> CDouble -> Ptr <CvArr> -> IO ()
#ccall wrapSet4 , Ptr <CvArr> -> CDouble -> CDouble -> CDouble -> CDouble -> Ptr <CvArr> -> IO ()
--- CVAPI(void) cvSetZero(
--- CvArr* arr
--- );
-
-- Clears all the array elements (sets them to 0)
+#ccall cvSetZero , Ptr BareImage -> IO ()
-#ccall cvSetZero , Ptr <CvArr> -> IO ()
+#ccall cvSplit , Ptr BareImage -> Ptr BareImage -> Ptr BareImage -> Ptr BareImage -> Ptr BareImage -> IO ()
--- CVAPI(void) cvSplit(
--- const CvArr* src,
--- CvArr* dst0,
--- CvArr* dst1,
--- CvArr* dst2,
--- CvArr* dst3
--- );
+#ccall cvMerge , Ptr BareImage -> Ptr BareImage -> Ptr BareImage -> Ptr BareImage -> Ptr BareImage -> IO ()
--- Splits a multi-channel array into the set of single-channel arrays or
--- extracts particular [color] plane
-
-#ccall cvSplit , Ptr <CvArr> -> Ptr <CvArr> -> Ptr <CvArr> -> Ptr <CvArr> -> Ptr <CvArr> -> IO ()
-
--- |CVAPI(void) cvMerge(
--- | const CvArr* src0,
--- | const CvArr* src1,
--- | const CvArr* src2,
--- | const CvArr* src3,
--- | CvArr* dst
--- |);
--- |Merges a set of single-channel arrays into the single multi-channel array
--- |or inserts one particular [color] plane to the array
-#ccall cvMerge , Ptr <CvArr> -> Ptr <CvArr> -> Ptr <CvArr> -> Ptr <CvArr> -> Ptr <CvArr> -> IO ()
-
--- CVAPI(void) cvCartToPolar(
--- const CvArr* x,
--- const CvArr* y,
--- CvArr* magnitude,
--- CvArr* angle CV_DEFAULT(NULL),
--- int angle_in_degrees CV_DEFAULT(0)
--- );
-
--- Does cartesian->polar coordinates conversion.
--- Either of output components (magnitude or angle) is optional
-
-#ccall cvCartToPolar , Ptr <CvArr> -> Ptr <CvArr> -> Ptr <CvArr> -> Ptr <CvArr> -> CInt -> IO ()
+#ccall cvCartToPolar , Ptr BareImage -> Ptr BareImage -> Ptr BareImage -> Ptr BareImage -> CInt -> IO ()
-- | CVAPI(void) cvPolarToCart(
-- | const CvArr* magnitude,
@@ -165,7 +88,7 @@ import CV.Image(BareImage)
-- const CvArr* mask CV_DEFAULT(NULL)
-- );
-#ccall cvNormalize , Ptr <CvArr> -> Ptr <CvArr> -> CDouble -> CDouble -> CInt -> Ptr <CvArr> -> IO ()
+#ccall cvNormalize , Ptr BareImage -> Ptr BareImage -> CDouble -> CDouble -> CInt -> Ptr BareImage -> IO ()
-- stuff related to DFT
@@ -178,6 +101,7 @@ import CV.Image(BareImage)
#num CV_DXT_COMPLEX_OUTPUT
#num CV_DXT_REAL_OUTPUT
#num CV_DXT_INV_REAL
+#num CV_DXT_INVERSE_SCALE
-- CVAPI(void) cvDFT(
-- const CvArr* src,
@@ -191,11 +115,7 @@ import CV.Image(BareImage)
-- real->ccs (forward),
-- ccs->real (inverse)
-#ccall cvDFT , Ptr <CvArr> -> Ptr <CvArr> -> CInt -> CInt -> IO ()
-
--- #ccall cvWrapDFT , Ptr <CvArr> -> Ptr <CvArr> -> IO ()
-
--- #ccall cvWrapIDFT , Ptr <CvArr> -> Ptr <CvArr> -> IO ()
+#ccall cvDFT , Ptr BareImage -> Ptr BareImage -> CInt -> CInt -> IO ()
-- CVAPI(void) cvMulSpectrums(
-- const CvArr* src1,
@@ -204,11 +124,9 @@ import CV.Image(BareImage)
-- int flags
-- );
-#ccall swapQuadrants, Ptr <CvArr> -> IO ()
-
-- Multiply results of DFTs: DFT(X)*DFT(Y) or DFT(X)*conj(DFT(Y))
-#ccall cvMulSpectrums , Ptr <CvArr> -> Ptr <CvArr> -> Ptr <CvArr> -> CInt -> IO ()
+#ccall cvMulSpectrums , Ptr BareImage -> Ptr BareImage -> Ptr BareImage -> CInt -> IO ()
-- CVAPI(int) cvGetOptimalDFTSize(
-- int size0
@@ -227,5 +145,7 @@ import CV.Image(BareImage)
-- Discrete Cosine Transform
-#ccall cvDCT , Ptr <CvArr> -> Ptr <CvArr> -> CInt -> IO ()
+#ccall cvDCT , Ptr BareImage -> Ptr BareImage -> CInt -> IO ()
+-- TODO: This might be expanded:
+#opaque_t CvSeq
View
@@ -52,7 +52,6 @@ copyMakeBorder i t b l r border value =
(fromIntegral r)
(cBorderType border)
(realToFrac value)
-
-- moments
-- | Calculates all spatial and central moments up to the 3rd order
View
@@ -22,7 +22,7 @@ module CV.Conversions (
,acquireImageSlow8URGB'
) where
-import Data.Complex
+import Data.Complex as C
import CV.Image
import Data.Word
@@ -76,7 +76,7 @@ copyImageToFCArray (S img) = unsafePerformIO $
-- |Copy the real part of an array to image
-copyComplexCArrayToImage :: CArray (Int,Int) (Complex Double) -> Image GrayScale D32
+copyComplexCArrayToImage :: CArray (Int,Int) (C.Complex Double) -> Image GrayScale D32
copyComplexCArrayToImage carr = S $ unsafePerformIO $
creatingBareImage (withCArray carr (acquireImageSlowComplex' w h))
where
@@ -99,7 +99,7 @@ copyImageToExistingCArray (S img) arr =
(w,h) = getSize img
-- |Copy image as a real part of a complex CArray
-copyImageToComplexCArray :: Image GrayScale D32 -> CArray (Int,Int) (Complex Double)
+copyImageToComplexCArray :: Image GrayScale D32 -> CArray (Int,Int) (C.Complex Double)
copyImageToComplexCArray (S img) = unsafePerformIO $
withBareImage img $ \cimg ->
createCArray ((0,0),(w-1,h-1)) (exportImageSlowComplex' cimg) --({#call exportImageSlow#} cimg)
@@ -113,7 +113,7 @@ foreign import ccall safe "CV/cvWrapLeo.h exportImageSlowF"
exportImageSlowF' :: ((Ptr (BareImage)) -> ((Ptr Float) -> (IO ())))
foreign import ccall safe "CV/cvWrapLeo.h exportImageSlowComplex"
- exportImageSlowComplex' :: ((Ptr (BareImage)) -> ((Ptr (Complex Double)) -> (IO ())))
+ exportImageSlowComplex' :: ((Ptr (BareImage)) -> ((Ptr (C.Complex Double)) -> (IO ())))
foreign import ccall safe "CV/cvWrapLeo.h acquireImageSlow"
acquireImageSlow' :: (Int -> (Int -> ((Ptr Double) -> (IO (Ptr (BareImage))))))
@@ -131,5 +131,5 @@ foreign import ccall safe "CV/cvWrapLeo.h acquireImageSlow8U"
acquireImageSlow8U' :: (Int -> (Int -> ((Ptr Word8) -> (IO (Ptr (BareImage))))))
foreign import ccall safe "CV/cvWrapLeo.h acquireImageSlowComplex"
- acquireImageSlowComplex' :: (Int -> (Int -> ((Ptr (Complex Double)) -> (IO (Ptr (BareImage))))))
+ acquireImageSlowComplex' :: (Int -> (Int -> ((Ptr (C.Complex Double)) -> (IO (Ptr (BareImage))))))
View
166 CV/DFT.hs
@@ -1,143 +1,61 @@
{-# LANGUAGE ScopedTypeVariables #-}
module CV.DFT where
+import CV.Bindings.Types
import CV.Bindings.Core
import CV.Bindings.ImgProc
-import CV.Bindings.Types
import CV.Image
-import CV.Operations
-
-import Foreign.Ptr (castPtr,nullPtr)
+import CV.ImageMath as IM
+import CV.ImageMathOp
import System.IO.Unsafe
-import Data.Complex
-
-type I32 = Image GrayScale D32
-type Idft32 = Image DFT D32
-data Ipolar32 = Ipolar32 (Complex D32)
-
-data Swap = SwapQuadrants | DontSwapQuadrants deriving (Eq,Show)
-
-dft = dft' SwapQuadrants
-dft' :: Swap -> Image GrayScale d -> Image DFT D32
-dft' swap i = unsafePerformIO $ do
- --n::(Image GrayScale D32) <- create (w', h')
- --n <- copyMakeBorder i 0 (h'-h) 0 (w'-w) BorderReplicate 0
- z::(Image GrayScale D32) <- create (w, h)
- d::(Image DFT D32) <- create (w, h)
- withImage i $ \i_ptr ->
- withImage z $ \z_ptr ->
- withImage d $ \d_ptr -> do
- c'cvMerge (castPtr i_ptr) (castPtr z_ptr) nullPtr nullPtr (castPtr d_ptr)
- c'cvDFT (castPtr d_ptr) (castPtr d_ptr) c'CV_DXT_FORWARD (fromIntegral 0)
- case swap of
- SwapQuadrants -> c'swapQuadrants (castPtr d_ptr)
- DontSwapQuadrants -> return ()
- return d
+import Foreign.Ptr
+
+dft :: Image GrayScale d -> Image Complex D32
+dft i = unsafePerformIO $ do
+ n::(Image GrayScale D32) <- create (w', h')
+ n <- copyMakeBorder i 0 (h'-h) 0 (w'-w) BorderConstant 0
+ c::(Image Complex D32) <- create (w', h')
+ withGenImage n $ \nimg ->
+ withGenImage c $ \cimg -> do
+ c'cvMerge nimg nullPtr nullPtr nullPtr cimg
+ c'cvDFT cimg cimg c'CV_DXT_FORWARD 0
+ return c
where
(w,h) = getSize i
- --w' = fromIntegral $ c'cvGetOptimalDFTSize (fromIntegral w)
- --h' = fromIntegral $ c'cvGetOptimalDFTSize (fromIntegral h)
+ w' = fromIntegral $ c'cvGetOptimalDFTSize (fromIntegral w)
+ h' = fromIntegral $ c'cvGetOptimalDFTSize (fromIntegral h)
-idft = idft' SwapQuadrants
-idft' :: Swap -> Image DFT D32 -> Image GrayScale D32
-idft' swap d = unsafePerformIO $ do
+idft :: Image Complex D32 -> Image GrayScale D32
+idft c = unsafePerformIO $ do
n::(Image GrayScale D32) <- create s
- --z::(Image GrayScale D32) <- create s
- withImage d $ \d_ptr ->
- withImage n $ \n_ptr -> do
- --withImage z $ \z_ptr -> do
- case swap of
- SwapQuadrants -> c'swapQuadrants (castPtr d_ptr)
- DontSwapQuadrants -> return ()
- --c'swapQuadrants (castPtr d_ptr)
- c'cvDFT (castPtr d_ptr) (castPtr n_ptr) c'CV_DXT_INV_SCALE (fromIntegral 0)
- --c'cvSplit (castPtr d_ptr) (castPtr n_ptr) (castPtr z_ptr) nullPtr nullPtr
- return n
+ withGenImage c $ \c_ptr ->
+ withGenImage n $ \n_ptr -> do
+ c'cvDFT c_ptr c_ptr c'CV_DXT_INVERSE 0
+ c'cvSplit c_ptr n_ptr nullPtr nullPtr nullPtr
+ return n
where
- s = getSize d
+ s = getSize c
-swapQuadrants img = unsafePerformIO $ do
- e <- cloneImage img
- withImage e (c'swapQuadrants . castPtr)
- return e
-
-dftSplit :: Image DFT D32 -> (Image GrayScale D32, Image GrayScale D32)
-dftSplit d = unsafePerformIO $ do
+complexSplit :: Image Complex D32 -> (Image GrayScale D32, Image GrayScale D32)
+complexSplit c = unsafePerformIO $ do
re::(Image GrayScale D32) <- create (w, h)
im::(Image GrayScale D32) <- create (w, h)
- withImage d $ \d_ptr ->
- withImage re $ \re_ptr ->
- withImage im $ \im_ptr -> do
- c'cvSplit (castPtr d_ptr) (castPtr re_ptr) (castPtr im_ptr) nullPtr nullPtr
+ withGenImage c $ \c_ptr ->
+ withGenImage re $ \re_ptr ->
+ withGenImage im $ \im_ptr -> do
+ c'cvSplit c_ptr re_ptr im_ptr nullPtr nullPtr
return (re,im)
where
- (w,h) = getSize d
-
-dftMerge :: (Image GrayScale D32, Image GrayScale D32) -> Image DFT D32
-dftMerge (re,im) = unsafePerformIO $ do
- d::(Image DFT D32) <- create (w, h)
- withImage re $ \re_ptr ->
- withImage im $ \im_ptr ->
- withImage d $ \d_ptr -> do
- c'cvMerge (castPtr re_ptr) (castPtr im_ptr) nullPtr nullPtr (castPtr d_ptr)
- return d
- where
- (w,h) = getSize re
+ (w,h) = getSize c
-dftToPolar :: Image DFT D32 -> (Image GrayScale D32, Image GrayScale D32)
-dftToPolar d = unsafePerformIO $ do
+complexToMagnitude :: Image Complex D32 -> Image GrayScale D32
+complexToMagnitude c = unsafePerformIO $ do
mag::(Image GrayScale D32) <- create (w, h)
- ang::(Image GrayScale D32) <- create (w, h)
- withImage re $ \re_ptr ->
- withImage im $ \im_ptr ->
- withImage mag $ \mag_ptr ->
- withImage ang $ \ang_ptr ->
- c'cvCartToPolar (castPtr re_ptr) (castPtr im_ptr) (castPtr mag_ptr) (castPtr ang_ptr) (fromIntegral 0)
- return (mag,ang)
- where
- (re,im) = dftSplit d
- (w,h) = getSize d
-
-dftFromPolar :: (Image GrayScale D32, Image GrayScale D32) -> Image DFT D32
-dftFromPolar (mag,ang) = unsafePerformIO $ do
- re::(Image GrayScale D32) <- create (w, h)
- im::(Image GrayScale D32) <- create (w, h)
- withImage mag $ \mag_ptr ->
- withImage ang $ \ang_ptr ->
- withImage re $ \re_ptr -> do
- withImage im $ \im_ptr -> do
- c'cvPolarToCart (castPtr mag_ptr) (castPtr ang_ptr) (castPtr re_ptr) (castPtr im_ptr) (fromIntegral 0)
- return $ dftMerge (re,im)
- where
- (w,h) = getSize mag
-
---withPolar :: Image DFT D32 ->
--- ((Image GrayScale D32, Image GrayScale D32) -> (Image GrayScale D32, Image GrayScale D32)) ->
--- Image DFT D32
-
-
-rgbSplit :: Image RGB D32 -> (Image GrayScale D32, Image GrayScale D32, Image GrayScale D32)
-rgbSplit i = unsafePerformIO $ do
- r::(Image GrayScale D32) <- create (w, h)
- g::(Image GrayScale D32) <- create (w, h)
- b::(Image GrayScale D32) <- create (w, h)
- withImage i $ \i_ptr ->
- withImage r $ \r_ptr ->
- withImage g $ \g_ptr ->
- withImage b $ \b_ptr -> do
- c'cvSplit (castPtr i_ptr) (castPtr r_ptr) (castPtr g_ptr) (castPtr b_ptr) nullPtr
- return (r,g,b)
- where
- (w,h) = getSize i
-
-rgbMerge :: (Image GrayScale D32, Image GrayScale D32, Image GrayScale D32) -> Image RGB D32
-rgbMerge (r,g,b) = unsafePerformIO $ do
- i::(Image RGB D32) <- create (w, h)
- withImage r $ \r_ptr ->
- withImage g $ \g_ptr ->
- withImage b $ \b_ptr ->
- withImage i $ \i_ptr -> do
- c'cvMerge (castPtr r_ptr) (castPtr g_ptr) (castPtr b_ptr) nullPtr (castPtr i_ptr)
- return i
- where
- (w,h) = getSize r
+ withGenImage re $ \re_ptr ->
+ withGenImage im $ \im_ptr ->
+ withGenImage mag $ \mag_ptr -> do
+ c'cvCartToPolar re_ptr im_ptr mag_ptr nullPtr (fromIntegral 0)
+ return $ IM.log $ 1 |+ mag
+ where
+ (re,im) = complexSplit c
+ (w,h) = getSize c
Oops, something went wrong.

0 comments on commit bea423a

Please sign in to comment.