module AI.CV.OpenCV.CV where
import Foreign.C.Types
import Foreign.Ptr
import Foreign.ForeignPtr
import Data.Bits
import AI.CV.OpenCV.CxCore
import AI.CV.OpenCV.Util
foreign import ccall unsafe "cv.h cvCanny"
c_cvCanny :: Ptr Priv_IplImage -> Ptr Priv_IplImage -> CDouble -> CDouble -> CInt -> IO ()
canny :: IplImage -> IplImage -> Double -> Double -> Int -> IO ()
canny src dst threshold1 threshold2 apertureSize
= withForeignPtr2 src dst $ \s d ->
c_cvCanny s d
(realToFrac threshold1)
(realToFrac threshold2)
(fromIntegral apertureSize)
data InterpolationMethod = CV_INTER_NN
| CV_INTER_LINEAR
| CV_INTER_CUBIC
| CV_INTER_AREA
deriving (Enum,Eq)
foreign import ccall unsafe "cv.h cvResize"
c_cvResize :: Ptr Priv_IplImage -> Ptr Priv_IplImage -> CInt -> IO ()
resize :: IplImage -> IplImage -> InterpolationMethod -> IO ()
resize src dst interp
= withForeignPtr2 src dst $ \s d ->
c_cvResize s d (fromIntegral . fromEnum $ interp)
foreign import ccall unsafe "HOpenCV_wrap.h dilate"
c_dilate :: Ptr Priv_IplImage -> Ptr Priv_IplImage -> CInt -> IO ()
dilate :: IplImage -> IplImage -> Int -> IO ()
dilate src dst iter
= withForeignPtr2 src dst
$ \s d -> c_dilate s d $ fromIntegral iter
foreign import ccall unsafe "cv.h cvPyrDown"
c_cvPyrDown :: Ptr Priv_IplImage -> Ptr Priv_IplImage -> CInt -> IO ()
constCvGaussian5x5 :: CInt
constCvGaussian5x5 = 7
pyrDown :: IplImage -> IplImage -> IO ()
pyrDown src dst
= withForeignPtr2 src dst
$ \s d -> c_cvPyrDown s d constCvGaussian5x5
data Priv_CvHaarClassifierCascade
type HaarClassifierCascade = ForeignPtr Priv_CvHaarClassifierCascade
newtype HaarDetectFlag = HaarDetectFlag { unHaarDetectFlag :: CInt }
deriving (Eq, Show)
haarFlagNone :: HaarDetectFlag
haarFlagNone = HaarDetectFlag 0
haarDoCannyPruning :: HaarDetectFlag
haarDoCannyPruning = HaarDetectFlag 1
haarScaleImage :: HaarDetectFlag
haarScaleImage = HaarDetectFlag 2
haarFindBiggestObject :: HaarDetectFlag
haarFindBiggestObject = HaarDetectFlag 4
haarDoRoughSearch :: HaarDetectFlag
haarDoRoughSearch = HaarDetectFlag 8
combineHaarFlags :: [HaarDetectFlag] -> HaarDetectFlag
combineHaarFlags = HaarDetectFlag . foldr ((.|.) . unHaarDetectFlag) 0
foreign import ccall unsafe "HOpenCV_wrap.h c_cvHaarDetectObjects"
c_cvHaarDetectObjects :: Ptr Priv_IplImage
-> Ptr Priv_CvHaarClassifierCascade
-> Ptr Priv_CvMemStorage
-> CDouble
-> CInt
-> CInt
-> CInt -> CInt
-> IO (Ptr (Priv_CvSeq CvRect))
haarDetectObjects :: IplImage
-> HaarClassifierCascade
-> MemStorage
-> Double
-> Int
-> HaarDetectFlag
-> CvSize
-> IO (CvSeq CvRect)
haarDetectObjects image cascade storage scaleFactor minNeighbors flags minSize
= do p <- withForeignPtr3 image storage cascade $ \im' s' c' ->
c_cvHaarDetectObjects im' c' s'
(realToFrac scaleFactor)
(fromIntegral minNeighbors)
(unHaarDetectFlag flags)
(sizeWidth minSize) (sizeHeight minSize)
newForeignPtr cvFree p