Skip to content
Browse files

Merge pull request #3 from izuk/master

Various things.
  • Loading branch information...
2 parents f91b906 + 7b70e22 commit 454dd9ef3d7c25c7842dea29d8ae4e30a30045d5 @sinelaw committed Feb 20, 2012
Showing with 27 additions and 8 deletions.
  1. +4 −4 HOpenCV.cabal
  2. +3 −1 src/AI/CV/OpenCV/CxCore.hsc
  3. +1 −1 src/AI/CV/OpenCV/HOpenCV_wrap.c
  4. +19 −2 src/AI/CV/OpenCV/HighGui.hsc
View
8 HOpenCV.cabal
@@ -41,20 +41,20 @@ library
src/AI/CV/OpenCV/HOpenCV_wrap.c
hs-Source-Dirs: src
include-dirs: /usr/include/opencv
- extra-libraries: cxcore,cv,highgui
- build-depends: base >=4 && <5, allocated-processor >= 0.0.1, vector-space
+ pkgconfig-depends: opencv
+ build-depends: base >= 4 && < 5, allocated-processor >= 0.0.1, 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 && <5
+ Build-Depends: base >= 4 && < 5
main-is: Test.hs
Ghc-Options: -Wall -fno-warn-type-defaults
Ghc-Prof-Options: -prof -auto-all
- extra-libraries: cxcore,cv,highgui
+ pkgconfig-depends: opencv
other-modules: AI.CV.OpenCV.CxCore, AI.CV.OpenCV.CV, AI.CV.OpenCV.HighGui, AI.CV.OpenCV.Types
View
4 src/AI/CV/OpenCV/CxCore.hsc
@@ -5,10 +5,12 @@ module AI.CV.OpenCV.CxCore where
import Foreign.ForeignPtrWrap
import Foreign.C.Types
import Foreign.C.String
-import Foreign
+import Foreign hiding (unsafePerformIO)
import Data.VectorSpace as VectorSpace
+import System.IO.Unsafe (unsafePerformIO)
+
#include <cxcore.h>
------------------------------------------------------
View
2 src/AI/CV/OpenCV/HOpenCV_wrap.c
@@ -141,6 +141,6 @@ CvSeq *c_cvHaarDetectObjects( const CvArr* image,
int min_neighbors , int flags,
int width, int height)
{
- return cvHaarDetectObjects(image, cascade, storage, scale_factor, min_neighbors, flags, cvSize(width, height));
+ return cvHaarDetectObjects(image, cascade, storage, scale_factor, min_neighbors, flags, cvSize(width, height), cvSize(0, 0));
}
View
21 src/AI/CV/OpenCV/HighGui.hsc
@@ -2,6 +2,7 @@
module AI.CV.OpenCV.HighGui where
+import Control.Monad
import Foreign.ForeignPtrWrap
import Foreign.C.Types
import Foreign.Ptr
@@ -96,5 +97,21 @@ newtype LoadImageColor = LoadImageColor { unLoadImageColor :: CInt }
, loadImageUnchanged = CV_LOAD_IMAGE_UNCHANGED }
foreign import ccall unsafe "highgui.h cvLoadImage"
- cvLoadImage :: CString -> CInt -> IO (Ptr IplImage)
-
+ c_cvLoadImage :: CString -> CInt -> IO (Ptr IplImage)
+
+cvLoadImage :: String -> LoadImageColor -> IO (Ptr IplImage)
+cvLoadImage filename (LoadImageColor color) = err' . checkPtr $ withCString filename f
+ where
+ err' = errorName $ "Failed to load from file: '" ++ filename ++ "'"
+ f filenameC = c_cvLoadImage filenameC color
+
+foreign import ccall unsafe "highgui.h cvSaveImage"
+ c_cvSaveImage :: CString -> Ptr CvArr -> IO CInt
+
+cvSaveImage :: String -> Ptr IplImage -> IO CInt
+cvSaveImage filename image = withCString filename f
+ where
+ f filenameC = do
+ ret <- c_cvSaveImage filenameC (fromArr image)
+ when (ret == 0) $ fail $ "Failed to save to file: '" ++ filename ++ "'"
+ return ret

0 comments on commit 454dd9e

Please sign in to comment.
Something went wrong with that request. Please try again.