Created
May 1, 2014 19:29
-
-
Save aavogt/88bb0f5be06a951e545f to your computer and use it in GitHub Desktop.
HOpenCV contours crash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds #-} | |
module Main where | |
import OpenCV.ArrayOps | |
import OpenCV.ColorConversion | |
import OpenCV.Contours ( withContourList, cvMoments, cvGetHuMoments, cvDrawContours, cvContourArea ) | |
import OpenCV.Core.CVOp ( cv ) | |
import OpenCV.Core.CxCore | |
import OpenCV.Core.ImageUtil | |
import OpenCV.HighCV | |
import Control.Applicative | |
import Control.Monad | |
method = 1 -- 1 crashes, 0 does not | |
mkFiles = False | |
main = do | |
-- http://i.imgur.com/ZrFTk42.jpg is circ.jpg | |
f <- fromFileColor "circ.jpg" | |
let ed n = dilate n . erode n | |
f' = ed 5 $ thresholdBinaryOtsuInv 100 (convertRGBToGray f) | |
when mkFiles (toFile "tresh.jpg" f') | |
withContourList f' $ \c -> do | |
let dc im = cvDrawContours im c (CvScalar 255 0 0 0) (CvScalar 0 0 0 0) 0 (-1) 8 (CvPoint 0 0) | |
im <- case method of | |
0 -> fst <$> withDuplicateImage f dc | |
1 -> return . cv dc =<< duplicateImage f | |
a <- cvContourArea c | |
let selected = cvAnd im f | |
selected' = cvAnd im (convertGrayToRGB f') | |
when mkFiles $ do | |
toFile ("gen/c"++show a++".jpg") im | |
toFile ("gen/d"++show a++".jpg") selected | |
let getHu img = unsafeWithHIplImage img (cvGetHuMoments <=< cvMoments) | |
print =<< getHu (convertRGBToGray selected) | |
print =<< getHu (convertRGBToGray selected') | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
valgrind of crash