8000 fix broken examples · LumiGuide/haskell-opencv@88e1d30 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88e1d30

Browse files
committed
fix broken examples
1 parent ce04eb2 commit 88e1d30

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

opencv-examples/src/face-detect.hs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# language DataKinds #-}
22
{-# language FlexibleInstances #-}
3+
{-# language ScopedTypeVariables #-}
34
{-# language TemplateHaskell #-}
45
{-# language TupleSections #-}
56
{-# language ViewPatterns #-}
@@ -49,14 +50,19 @@ main = do
4950
case mbImg of
5051
Just img -> do
5152
-- Assert that the retrieved frame is 2-dimensional.
52-
let img' :: CV.Mat ('S ['D, 'D]) ('S 3) ('S Word8)
53-
img' = CV.exceptError $ CV.coerceMat img
54-
imgGray = CV.exceptError $ CV.cvtColor CV.bgr CV.gray img'
55-
56-
faces = ccDetectMultiscale ccFrontal imgGray
57-
eyedFaces = V.concat . V.toList . CV.exceptError
58-
$ mapM (\f -> V.map (addCorner f) . ccDetectMultiscale ccEyes
59-
<$> CV.matSubRect imgGray f) faces
53+
img' :: CV.Mat ('S ['D, 'D]) ('S 3) ('S Word8)
54+
<- CV.exceptErrorIO $ CV.coerceMat img
55+
imgGray <- CV.exceptErrorIO $ CV.cvtColor CV.bgr CV.gray img'
56+
faces <- CV.exceptErrorIO $ ccDetectMultiscale ccFrontal imgGray
57+
eyedFaces <-
58+
fmap (V.concat . V.toList) $ CV.exceptErrorIO $
59+
mapM
60+
(\faceRect -> do
61+
faceImg <- CV.matSubRect imgGray faceRect
62+
eyeRects <- ccDetectMultiscale ccEyes faceImg
63+
pure $ V.map (addCorner faceRect) eyeRects
64+
)
65+
faces
6066

6167
let box = CV.exceptError $
6268
CV.withMatM (h ::: w ::: Z) (Proxy :: Proxy 3) (Proxy :: Proxy Word8) white $ \imgM -> do

opencv-extra-examples/src/tracker.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ import Control.Monad.Trans.Class
2727
import System.IO.Unsafe
2828

2929
class LoopEnum a where
30-
next :: a -> a
30+
next :: a -> a
3131

3232
instance (Eq a, Bounded a, Enum a) => LoopEnum a where
33-
next x | x == maxBound = minBound
34-
| otherwise = succ x
33+
next x | x == maxBound = minBound
34+
| otherwise = succ x
3535

36-
blue ,white:: CV.Scalar
36+
blue, white :: CV.Scalar
3737
blue = CV.toScalar (V4 255 0 0 255 :: V4 Double)
3838
white = CV.toScalar (V4 255 255 255 255 :: V4 Double)
3939

@@ -68,7 +68,7 @@ main = do
6868
img' = CV.exceptError $ CV.coerceMat img
6969
imgGray = CV.exceptError $ CV.cvtColor CV.bgr CV.gray img'
7070

71-
faces = ccDetectMultiscale ccFrontal imgGray
71+
faces <- CV.exceptErrorIO $ ccDetectMultiscale ccFrontal imgGray
7272
mbTrac <- updateTracker tr $ CV.unsafeCoerceMat img
7373
let box = CV.exceptError $
7474
CV.withMatM (h ::: w ::: Z) (Proxy :: Proxy 3) (Proxy :: Proxy Word8) white $ \imgM -> do

0 commit comments

Comments
 (0)
0