8000 Cleaned up examples/src/videoio-decolor.hs · LumiGuide/haskell-opencv@4829fec · GitHub
[go: up one dir, main page]

Skip to content

Commit 4829fec

Browse files
committed
Cleaned up examples/src/videoio-decolor.hs
1 parent 36c772e commit 4829fec

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

examples/src/videoio-decolor.hs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{-# language DataKinds #-}
22
{-# language FlexibleInstances #-}
33

4-
import Control.Monad ( unless )
4+
import Control.Monad ( unless, forM_ )
5+
import Data.Function ( fix )
56
import qualified OpenCV as CV
67
import OpenCV.TypeLevel
78
import OpenCV.Photo
@@ -11,24 +12,21 @@ import OpenCV.Example
1112
main :: IO ()
1213
main = do
1314
cap <- createCaptureArg
14-
CV.withWindow "gray" $ \w1 -> CV.withWindow "boost" $ loop cap w1
15-
where
16-
loop cap grayWindow boostWindow = do
17-
_ok <- CV.videoCaptureGrab cap
18-
mbImg <- CV.videoCaptureRetrieve cap
19-
case mbImg of
20-
Just img -> do
21-
-- Assert that the retrieved frame is 2-dimensional.
22-
let img' :: CV.Mat ('S ['D, 'D]) ('S 3) ('S Word8)
23-
img' = CV.exceptError $ CV.coerceMat img
15+
CV.withWindow "gray" $ \grayWindow ->
16+
CV.withWindow "boost" $ \boostWindow ->
17+
fix $ \continue -> do
18+
_ok <- CV.videoCaptureGrab cap
19+
mbImg <- CV.videoCaptureRetrieve cap
20+
forM_ mbImg $ \img -> do
21+
-- Assert that the retrieved frame is 2-dimensional.
22+
let img' :: CV.Mat ('S ['D, 'D]) ('S 3) ('S Word8)
23+
img' = CV.exceptError $ CV.coerceMat img
2424

25-
let (grayImg, boostImg) = CV.exceptError $ decolor img'
25+
(grayImg, boostImg) = CV.exceptError $ decolor img'
2626

27-
CV.imshow grayWindow grayImg
28-
CV.imshow boostWindow boostImg
27+
CV.imshow grayWindow grayImg
28+
CV.imshow boostWindow boostImg
2929

30-
key <- CV.waitKey 20
31-
-- Loop unless the escape key is pressed.
32-
unless (key == 27) $ loop cap grayWindow boostWindow
33-
-- Out of frames, stop looping.
34-
Nothing -> pure ()
30+
key <- CV.waitKey 20
31+
-- Loop unless the escape key is pressed.
32+
unless (key == 27) continue

0 commit comments

Comments
 (0)
0