diff --git a/README.md b/README.md index 700a4d43..9b2a2d93 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,18 @@ related work installation instructions ------------------------- -(Tested on Ubuntu) +(Tested on Ubuntu 12.04) 1. Get the source code: $ git clone git://github.com/albertoruiz/easyVision.git -2. Install IPP. You can download a noncomercial version for Linux: + Checkout the reorg branch: + + $ git checkout reorg + +2. Install IPP. You can download the noncomercial version 7.1 for Linux + (go to the link "Intel Integrated Performance Primitives (Intel IPP) 7.1 for Linux") http://software.intel.com/en-us/articles/non-commercial-software-download/ @@ -57,30 +62,32 @@ installation instructions export EASYVISION=/your/path/to/easyVision/ export LD_LIBRARY_PATH=$IPP_SHARED:$EASYVISION/lib/lib32 - Make sure that the IPP .h headers are in IPP_INC and the corresponding .so - libs are in IPP_SHARED (modify as required in 64bit machines). Directory - structure and required auxiliary libs frequently change in different IPP versions. + Modify as required to make sure that the IPP .h headers are in IPP_INC and + the corresponding .so libs are in IPP_SHARED. Continue installation in a new terminal. -4. Install the Haskell Platform: +4. Install the Haskell Platform: $ sudo apt-get install haskell-platform $ cabal update - You will probably get the message that a new version of cabal-install is available. - Don't worry about that now. + Note that this branch works better with GHC 7.6.3. The official binary package is available from: -5. Install the required libraries: + https://www.haskell.org/ghc/download_ghc_7_6_3#x86linux + + $ ./configure --prefix=/path/to/desired/location/of/ghc7.6.3 + $ ./make install - $ sudo apt-get install libgsl0-dev liblapack-dev libglpk-dev - $ sudo apt-get install libghc6-glut-dev mplayer mencoder imagemagick + Change the path in .bashrc so this ghc is used instead of the ghc supplied by the Haskell Platform and + continue the installation in a new terminal. -6. Install optional libraries: +5. Install the required libraries: - ATLAS (optimized LAPACK): + $ sudo apt-get install libgsl0-dev libatlas-base-dev libglpk-dev + $ sudo apt-get install mplayer mencoder imagemagick - $ sudo apt-get install libatlas-base-dev +6. Install optional libraries: OPENCV: @@ -98,26 +105,16 @@ installation instructions $ sudo apt-get install libzbar-dev - 3ds: - - $ sudo apt-get install libglew1.5-dev lib3ds-dev - 7. Install the Haskell packages: $ cd easyVision/packages $ make - The basic system will be correctly installed if "ev-apps-0.1.0" is shown by + The basic system will be correctly installed if "hVision-0.3.0" is shown by $ ghc-pkg list - You can also install the optional packages: - - $ make optional - - (Dont' worry if you get any error here) - 8. Run the demos: $ cd ../projects/demos diff --git a/projects/help/HEADER b/projects/help/HEADER index ef4a275d..a8267c3f 100644 --- a/projects/help/HEADER +++ b/projects/help/HEADER @@ -1,14 +1,6 @@ - - + diff --git a/projects/help/HIGHLIGHT b/projects/help/HIGHLIGHT index 05016d94..139597f9 100644 --- a/projects/help/HIGHLIGHT +++ b/projects/help/HIGHLIGHT @@ -1,4 +1,2 @@ - - - + diff --git a/projects/help/help.md b/projects/help/help.md index f8c0d545..b0e1df1b 100644 --- a/projects/help/help.md +++ b/projects/help/help.md @@ -9,7 +9,7 @@ hVision Help [interactive point capture][points] -[programs][examples] +[example programs][examples] [tutorial][tutorial] diff --git a/projects/help/replace.hs b/projects/help/replace.hs index f7fb26d0..21496849 100755 --- a/projects/help/replace.hs +++ b/projects/help/replace.hs @@ -3,6 +3,8 @@ import Util.Text import Util.Misc(splitEvery) import Util.Options import Control.Applicative +import Language.Haskell.HsColour +import Language.Haskell.HsColour.Colourise main :: IO () main = do @@ -14,7 +16,18 @@ main = do rep <- getFlag "-r" if rep then do - putStr =<< ioReplace (rules++[include,codefile]) =<< getContents + putStr =<< ioReplace (rules++[include,codefile']) =<< getContents else interact (replace rules) +codefile' :: Rule +codefile' = "CODEFILE" :~> \f -> (return . hscolour HTML col False True "" False) =<< readFile f + where + col = defaultColourPrefs + { comment = [Italic, Dim, Foreground (Rgb 128 128 128)] + , keyword = [Bold] + , varop = [Foreground Green] + , layout = [Normal] + } + + diff --git a/projects/help/styles.css b/projects/help/styles.css new file mode 100644 index 00000000..c3dd23bf --- /dev/null +++ b/projects/help/styles.css @@ -0,0 +1,17 @@ + +html{ background-color: #d0d0e0 + } + +body{ max-width:800px; + font-family: "FreeSans", sans-serif ; font-size:18px; + margin:0; background-color: white; border: 40px solid #d0d0e0; padding:20px + } + +ul {list-style-type:square} + +h2 {color: #006000} + +p {margin:10px; margin-left: 20px; margin-top: 20px} + +pre {margin:40px; font-size: 16px; border: 1px solid gray;} + diff --git a/projects/help/tutorial.md b/projects/help/tutorial.md index 318a03fe..5142a910 100644 --- a/projects/help/tutorial.md +++ b/projects/help/tutorial.md @@ -26,17 +26,227 @@ Show a single image: CODEFILE(../examples/hello.hs) -Show a live video sequence captured from the default input source (webcam): +**play**, **nplay**: show a live video sequence captured from the default input source (webcam): CODEFILE(../examples/play.hs) +CODEFILE(../tour/nplay.hs) + +**chanShow**: + +CODEFILE(../tour/chanShow.hs) + +**matrix**: use matrix functions on images + +CODEFILE(../tour/matrix.hs) + +**playgray**: + +CODEFILE(../tour/playgray.hs) + +**play1**: show different stages of the processing pipeline + +CODEFILE(../tour/play1.hs) + +**arrIO**: Apply an IO operation to each element in the input pipeline: + +CODEFILE(../tour/arrIO.hs) + +**arrows**: Arrow notation (include diagram): + +**loop**: circuit loop in arrow notation: + +CODEFILE(../tour/loop.hs) + +**choice**: circuit with choice. + +CODEFILE(../tour/choice.hs) + +**circuit**, **nocircuit**: arrow notation and recursive do. + +**fast-slow**: pipeline at two frame rates. Check that there is no leaks. + +**play0**: create a pipeline step explicitly using transUI + +**play3**: insert frames in the video sequence. + +CODEFILE(../tour/play3.hs) + +**play4**: add frame rate measurement window: + +CODEFILE(../tour/play4.hs) + +**testwebcam**: explicitly open the webcam image source. + +CODEFILE(../tour/testwebcam.hs) + + +**play5**: the pipeline can be used with sequences of any kind of information. This is a clock: + +CODEFILE(../tour/play5.hs) + +**play6**: In this example we generate random numbers at about 1000Hz, and take the average of each group of 100 elements, producing a final 10Hz output. + +CODEFILE(../tour/play6.hs) + + +**runmode0**: work without GUI + +CODEFILE(../tour/runmode0.hs) + +**runmode1**: normal threaded mode + +CODEFILE(../tour/runmode1.hs) + +**runmode00**: explicitly open the input source and extract elements: + +CODEFILE(../tour/runmode00.hs) + + +**runmode01**: run a pipeline wihout a GUI: + +CODEFILE(../tour/runmode01.hs) + + +**nogui**: run a pipeline without GUI: + +CODEFILE(../tour/nogui.hs) + + + + +**runmode2**: threaded GUI, returning result: + +CODEFILE(../tour/runmode01.hs) + +**runmode02**: nonthreaded GUI, returning result: + +CODEFILE(../tour/runmode02.hs) + +**runmode3**: nonthreaded GUI, returning result: + +CODEFILE(../tour/runmode3.hs) + +**runmode03**: threaded GUI, returning result: + +CODEFILE(../tour/runmode03.hs) + +**runmode4**: nonthreaded GUI, returning result: + +CODEFILE(../tour/runmode4.hs) + +**runmode04**: load single image from the command line: + +CODEFILE(../tour/runmode04.hs) + +**runmode05**: load lazily all images in a directory: + +CODEFILE(../tour/runmode05.hs) + +**runmode06**: process pipeline and the work with it: + +CODEFILE(../tour/runmode05.hs) + + +**runS**: same thing. + +CODEFILE(../tour/runS.hs) + +**scanl1**: scanl to perform a recursive computation. The video is shown inside the video. Run as + + ./scanl1 ../../data/videos/rcube.avi + +CODEFILE(../tour/scanl1.hs) + + +**single**: read a list of image files and lazily work with them. Run as + + (fixme) + +CODEFILE(../tour/single.hs) + + +**skip**: drop the first n frames of the input sequence + + (fixme) + +CODEFILE(../tour/smon.hs) + +**smon**: show different things in a window, chosen with the mouse wheel. + + +CODEFILE(../tour/smon.hs) + + +**passROI**: example of an interactive window to capture the region of interest. + +CODEFILE(../tour/passROI.hs) + +**interface**: example of an intercative window which captures clicked points: + +CODEFILE(../tour/interface.hs) + + +**stand1**: "standalone" interactive graphic window. Click to change state: + +CODEFILE(../tour/stand1.hs) + +**stand2**: "browser" window. Use the wheel to see the elements of a list of things: + +CODEFILE(../tour/stand2.hs) + +**stand3**: "editor" window. change the elements of a list of things: + +CODEFILE(../tour/stand3.hs) + +**draw**, **drawParam**, **drawParam3D**: example of drawing functions. + + +**interactive3D**: add elements to a 3D graphic from ghci. + +**param**, **param2**, **param3**: interactive parameter window: + +CODEFILE(../tour/param.hs) + +CODEFILE(../tour/param2.hs) + +CODEFILE(../tour/param3.hs) + +**connect**: connect windows + +CODEFILE(../tour/connect.hs) + +**clickPoints**: another example of the "connect" function, using the general purpuse "clickPoints" window + +CODEFILE(../tour/clickPoints.hs) + +**noleak**, **noleak2**: check that there are no space leaks caused by observed results no longer used. + +**noguiraw**: tests of low level lazyIO functions. + +**batch**, **batch2** (run modes?) + +**cinematic**: very interesting. + +- - - + WIP +**lm** + +**grid**, **grid2**: fast slow? + +**focus** + +**concat**, **concat2** + +**contrib** + - - - [back to help][help] INCLUDE(LINKS) - + INCLUDE(HIGHLIGHT) diff --git a/projects/tour/arrIO.hs b/projects/tour/arrIO.hs index 53d51856..3fb09b9e 100644 --- a/projects/tour/arrIO.hs +++ b/projects/tour/arrIO.hs @@ -1,5 +1,5 @@ import Vision.GUI -import ImagProc +import Image.Processing main = run $ observe "img" rgb >>> arrIO (print . size . grayscale) diff --git a/projects/tour/arrows.hs b/projects/tour/arrows.hs index 0109d018..48fa1150 100644 --- a/projects/tour/arrows.hs +++ b/projects/tour/arrows.hs @@ -1,7 +1,7 @@ {-# LANGUAGE Arrows #-} import Vision.GUI -import ImagProc +import Image.Processing main = run $ observe "source" rgb >>> arr grayscale @@ -9,7 +9,7 @@ main = run $ observe "source" rgb >>> observe "result" (5.*) p = proc g -> do - let f = float g + let f = toFloat g x <- observe "x" id -< f s <- (observe "s" id <<< arr (gaussS 5)) -< f observe "inverted" notI -< g diff --git a/projects/tour/batch.hs b/projects/tour/batch.hs index 18c5ad65..031f960d 100644 --- a/projects/tour/batch.hs +++ b/projects/tour/batch.hs @@ -1,8 +1,8 @@ import Vision.GUI -import ImagProc +import Image.Processing main = do x <- runT camera $ observe "image" rgb - >>> arr (sum8u.grayscale) + >>> arr (sumPixels.grayscale) print (sum $ take 1000 x) diff --git a/projects/tour/chanShow.hs b/projects/tour/chanShow.hs index 50b7d486..2a54c796 100644 --- a/projects/tour/chanShow.hs +++ b/projects/tour/chanShow.hs @@ -2,7 +2,7 @@ import Vision.GUI -import ImagProc +import Image.Processing import Vision.GUI.Draw import Numeric.LinearAlgebra diff --git a/projects/tour/choice.hs b/projects/tour/choice.hs index 8a5542ea..23a8b045 100644 --- a/projects/tour/choice.hs +++ b/projects/tour/choice.hs @@ -1,7 +1,7 @@ {-# LANGUAGE Arrows #-} import Vision.GUI -import ImagProc +import Image.Processing main = run $ arrL (zip [0..]) >>> separ diff --git a/projects/tour/cinematic.hs b/projects/tour/cinematic.hs new file mode 100644 index 00000000..4ddc95be --- /dev/null +++ b/projects/tour/cinematic.hs @@ -0,0 +1,96 @@ +{-# LANGUAGE TemplateHaskell, RecordWildCards #-} + +import Vision.GUI +import Image.Processing +import Numeric.LinearAlgebra(subVector, (@>), inv, rcond, pinv, pinvTol, linearSolveSVD) +import Devel.Numeric.LinearAlgebra.Simple +import Util.Rotation +import Util.Homogeneous(desp) +import Util.Geometry(inhomog,unsafeFromVector) +import Util.Misc (degree,debug) + +autoParam "Angles" "" $ let r = 90*degree in + [ ("a", "Double", realParam (0) (-r) r) + , ("b", "Double", realParam (0) (-r) r) + , ("c", "Double", realParam (0) (-r) r) + ] + +autoParam "Position" "" $ let r = 4; s = 90*degree in + [ ("ia", "Double", realParam (0) (-s) s) + , ("ib", "Double", realParam (0) (-s) s) + , ("ic", "Double", realParam (0) (-s) s) + , ("x", "Double", realParam (0) (-r) r) + , ("y", "Double", realParam (0) (-r) r) + ] + + +main = runIt $ drawParam "forward" drwsA + >> drawParam "inverse" drwsP + + +drwsA Angles{..} = [ clearColor white + [ color gray $ axes3D 0.5 + , drawArm [a,b,c] + ] + ] + where + ps = map unsafeFromVector [p0,p1,p2,p3] + ss = zipWith Segment ps (tail ps) + p0 = fromList [0,0] + [p1,p2,p3] = map (($ [a,b,c]). ((/ 4).)) [f31,f32,f33] + + +drwsP Position{..} = [ clearColor white + [ color gray $ axes3D 0.5 + , drawArm [ia,ib,ic] + , drawArm (findAngles [x,y] [ia,ib,ic]) + , color orange . pointSz 10 $ Point (x/4) (y/4) + ] + ] + where + + + +f3 [a,b,c] = subVector 0 2 $ rot3 a + <> desp (0,1) <> rot3 b <> desp (0,-1) + <> desp (0,2) <> rot3 c <> desp (0,-2) + <> fromList [0,3,1] + +j3 [a,b,c] = fromColumns + [ subVector 0 2 $ rot3g <> rot3 a <> desp (0,1) <> rot3 b <> desp (0,-1) <> desp (0,2) <> rot3 c <> desp (0,-2) <> fromList [0,3,1] + , subVector 0 2 $ rot3 a <> desp (0,1) <> rot3g <> rot3 b <> desp (0,-1) <> desp (0,2) <> rot3 c <> desp (0,-2) <> fromList [0,3,1] + , subVector 0 2 $ rot3 a <> desp (0,1) <> rot3 b <> desp (0,-1) <> desp (0,2) <> rot3g <> rot3 c <> desp (0,-2) <> fromList [0,3,1] + ] + + +f31 [a,b,c] = subVector 0 2 $ rot3 a + <> fromList [0,1,1] + +f32 [a,b,c] = subVector 0 2 $ rot3 a + <> desp (0,1) <> rot3 b <> desp (0,-1) + <> fromList [0,2,1] + +f33 [a,b,c] = subVector 0 2 $ rot3 a + <> desp (0,1) <> rot3 b <> desp (0,-1) + <> desp (0,2) <> rot3 c <> desp (0,-2) + <> fromList [0,3,1] + +drawArm as = Draw [ color blue . lineWd 2 $ ss + , color red . pointSz 5 $ ps + ] + where + ps = map unsafeFromVector [p0,p1,p2,p3] + ss = zipWith Segment ps (tail ps) + p0 = fromList [0,0] + [p1,p2,p3] = map (($ as). ((/ 4).)) [f31,f32,f33] + + +findAngles target st = sol + where + resi x = f3 x - fromList target + grad x = resi x <> j3 x + hessi x = (\m -> trans m <> m) (j3 x) + new x = -- toList $ fromList x - (debug "PINV" id $ pinvTol (1E8) (hessi x + diagl (replicate 3 0))) <> grad x + toList $ fromList x - flatten (linearSolveSVD (hessi x + diagl (replicate 3 0.5)) (asColumn $ grad x)) + sol = iterate new st !! 20 + diff --git a/projects/tour/circuit.hs b/projects/tour/circuit.hs index f30754f0..96f88b61 100644 --- a/projects/tour/circuit.hs +++ b/projects/tour/circuit.hs @@ -1,8 +1,10 @@ -{-# LANGUAGE Arrows, DoRec #-} +{-# LANGUAGE Arrows, RecursiveDo #-} import Vision.GUI -import ImagProc(grayscale, warpOn, Polyline(..), Point(..), segmentLength,constImage,Size(..)) -import Vision.Apps.Contours(otsuContours, smoothPolyline, polygons, asSegments) +import Image.Processing +import Util.Geometry +import Contours +import Contours.Polygons import Numeric.LinearAlgebra((<>)) import Vision(cameraFromHomogZ0,estimateHomographyRaw,ht,scaling) import Util.Misc(rotateLeft,posMax) @@ -16,11 +18,13 @@ main = run $ proc im -> do (y,_,_) <- sMonitor "recursive" dr -< (s,g,ps) returnA -< y +otsuContours = contours 1000 100 . notI . otsuBinarize + -- dr would not be in scope if defined inside the proc dr _ (s,g,ps) = [ Draw s , Draw [ Draw g, (Draw . map (drawContourLabeled blue red white 2 3)) ps ] ] -f a im (c:_) = warpOn im h a +f a im (c:_) = warpon a [(h,im)] where h = estimateHomographyRaw (g c) [[1,r],[-1,r],[-1,-r],[1,-r]] <> scaling 0.95 where @@ -30,5 +34,5 @@ f a im (c:_) = warpOn im h a k = posMax $ map segmentLength (asSegments c) f _ x _ = x -zero = constImage 0 (Size 100 100) +zero = constantImage 0 (Size 200 200) diff --git a/projects/tour/concat.hs b/projects/tour/concat.hs deleted file mode 100644 index 9ffa8fa9..00000000 --- a/projects/tour/concat.hs +++ /dev/null @@ -1,21 +0,0 @@ --- concatenate sources --- $ ./concat '../../data/videos/rot4.avi -frames 25 -loop 1' '../../data/videos/rcube.avi -frames 25 -loop 1' - -import Vision.GUI -import ImagProc -import ImagProc.Camera -import Util.LazyIO - - -concatCams :: [IO (Maybe Channels)] -> Generator Channels -concatCams = (mkGenerator =<<) . fmap concat . sequence . map lazyList - - -main = do - cams <- getCams - print (length cams) - prepare - r <- runNT (concatCams cams) (observe "image" rgb >>> arr (sum8u.grayscale)) - print r - putStrLn "bye!" - diff --git a/projects/tour/concat2.hs b/projects/tour/concat2.hs deleted file mode 100644 index ae7d43fa..00000000 --- a/projects/tour/concat2.hs +++ /dev/null @@ -1,15 +0,0 @@ --- work on several streams --- $ ./concat '../../data/videos/rot4.avi -frames 25 -loop 1' '../../data/videos/rcube.avi -frames 25 -loop 1' - -import Vision.GUI -import ImagProc -import ImagProc.Camera - - -main = do - cams <- getCams - prepare - rs <- mapM (flip runNT (observe "image" rgb >>> arr (sum8u.grayscale))) (map return cams) - mapM_ print rs - putStrLn "bye!" - diff --git a/projects/tour/connect.hs b/projects/tour/connect.hs index 76211227..45fdd3fa 100644 --- a/projects/tour/connect.hs +++ b/projects/tour/connect.hs @@ -1,5 +1,6 @@ -import Vision.GUI -import ImagProc +import Vision.GUI.Simple +import Image +import Util.Geometry main = runIt $ do p <- click "click points" diff --git a/projects/tour/contrib.hs b/projects/tour/contrib.hs deleted file mode 100644 index 6d40f796..00000000 --- a/projects/tour/contrib.hs +++ /dev/null @@ -1,9 +0,0 @@ -import Vision.GUI -import ImagProc -import ImagProc.Contrib.Examples - -main = run $ observe "C wrapper test" (f.grayscale) - -f x = Draw [ Draw (invertInC x) - , text (Point 0 0) (show (sum8u x, sumInC x)) ] - diff --git a/projects/tour/draw.hs b/projects/tour/draw.hs index 1254921b..9226a192 100644 --- a/projects/tour/draw.hs +++ b/projects/tour/draw.hs @@ -1,5 +1,6 @@ -import Vision.GUI -import ImagProc +import Vision.GUI.Simple +import Image +import Util.Geometry main = runIt $ browser "points & lines" xs (const id) where diff --git a/projects/tour/draw3DParam.hs b/projects/tour/draw3DParam.hs index e9d80e13..697eb3c2 100644 --- a/projects/tour/draw3DParam.hs +++ b/projects/tour/draw3DParam.hs @@ -1,7 +1,7 @@ {-# LANGUAGE TemplateHaskell, RecordWildCards #-} -import Vision.GUI -import ImagProc +import Vision.GUI.Simple +import Image import Util.Geometry import qualified Graphics.UI.GLUT as GL diff --git a/projects/tour/drawParam.hs b/projects/tour/drawParam.hs index 14a84f02..96ad8d9a 100644 --- a/projects/tour/drawParam.hs +++ b/projects/tour/drawParam.hs @@ -1,7 +1,7 @@ {-# LANGUAGE TemplateHaskell, RecordWildCards #-} import Vision.GUI -import ImagProc +import Image autoParam "Position" "" [ ("x", "Double", realParam (0) (-1) 1) diff --git a/projects/tour/fast-slow.hs b/projects/tour/fast-slow.hs index 5827281b..f73fdf1a 100644 --- a/projects/tour/fast-slow.hs +++ b/projects/tour/fast-slow.hs @@ -6,15 +6,14 @@ {-# LANGUAGE Arrows #-} import Vision.GUI -import ImagProc +import Image.Processing import Util.Misc(splitEvery) -import Data.List(tails,foldl1') fast n = map head . splitEvery n main = run $ arr rgb >>> proc2 -proc1, proc2, proc3 :: ITrans ImageRGB ImageRGB +proc1, proc2, proc3 :: ITrans (Image RGB) (Image RGB) -- "normal" order: show orig, filter, show fast, output fast proc1 = proc x -> do diff --git a/projects/tour/grid.hs b/projects/tour/grid.hs index f42f85f5..5f239a26 100644 --- a/projects/tour/grid.hs +++ b/projects/tour/grid.hs @@ -1,5 +1,5 @@ import Vision.GUI -import ImagProc +import Image.Processing import Util.Misc(splitEvery) import Data.List(tails) diff --git a/projects/tour/interactive3D.hs b/projects/tour/interactive3D.hs index d201239a..67b3dbe1 100644 --- a/projects/tour/interactive3D.hs +++ b/projects/tour/interactive3D.hs @@ -1,5 +1,4 @@ -import Vision.GUI -import ImagProc +import Vision.GUI.Simple import Util.Geometry pause = putStrLn "Press any key (here) to continue..." >> getChar diff --git a/projects/tour/interface.hs b/projects/tour/interface.hs index aacec7df..9036b332 100644 --- a/projects/tour/interface.hs +++ b/projects/tour/interface.hs @@ -1,17 +1,17 @@ import Vision.GUI hiding (clickPoints) -import ImagProc +import Image.Processing main = run clickPoints -clickPoints :: ITrans Channels ([Point], ImageGray) +clickPoints :: ITrans Channels ([Point], Image Gray) clickPoints = transUI $ interface (Size 240 320) "click points" state0 firsttime updts acts result display where state0 = [] firsttime _ _ = return () - updts = [(key (MouseButton LeftButton), \_roi pt pts -> pt:pts)] + updts = [(key (MouseButton LeftButton), \_droi pt pts -> pt:pts)] acts = [] - result _roi pts input = (pts, (pts, notI . grayscale $ input)) - display _roi _pts _input (pts,x) = Draw [ Draw x, drwpts ] + result _droi pts input = (pts, (pts, notI . grayscale $ input)) + display _droi _pts _input (pts,x) = Draw [ Draw x, drwpts ] where drwpts = (color green . pointSz 3) pts diff --git a/projects/tour/loop.hs b/projects/tour/loop.hs index 2ba5a226..0e57d9ab 100644 --- a/projects/tour/loop.hs +++ b/projects/tour/loop.hs @@ -1,14 +1,14 @@ {-# LANGUAGE Arrows #-} import Vision.GUI -import ImagProc +import Image.Processing main = run $ observe "source" rgb >>> f >>> observe "result" (5.*) f = proc img -> do - let x = (float . grayscale) img + let x = (toFloat . grayscale) img p <- delay' -< x returnA -< x |-| p diff --git a/projects/tour/matrix.hs b/projects/tour/matrix.hs new file mode 100644 index 00000000..c938338b --- /dev/null +++ b/projects/tour/matrix.hs @@ -0,0 +1,13 @@ +import Vision.GUI +import Image.Processing +import Image.Capture +import Numeric.LinearAlgebra + +main = do + img <- loadRGB "../../data/images/pano/pano002.jpg" + runIt $ browser "image" [Draw img, Draw (f img)] (const id) + +f = mat2img . g . img2mat . toFloat . grayscale . channelsFromRGB + +g = {-subMatrix (100,100) (200,200) . -} trans + diff --git a/projects/tour/nocircuit.hs b/projects/tour/nocircuit.hs index 04a33825..11ae26a0 100644 --- a/projects/tour/nocircuit.hs +++ b/projects/tour/nocircuit.hs @@ -1,8 +1,10 @@ {-# LANGUAGE Arrows #-} import Vision.GUI -import ImagProc(grayscale, warpOn, Polyline(..), Point(..), segmentLength,constImage,Size(..)) -import Vision.Apps.Contours(otsuContours, smoothPolyline, polygons, asSegments) +import Image.Processing +import Util.Geometry +import Contours +import Contours.Polygons import Numeric.LinearAlgebra((<>)) import Vision(cameraFromHomogZ0,estimateHomographyRaw,ht,scaling) import Util.Misc(rotateLeft,posMax) @@ -20,7 +22,9 @@ main = run $ proc im -> do dr _ (s,g,ps) = [ Draw s , Draw [ Draw g, (Draw . map (drawContourLabeled blue red white 2 3)) ps ] ] -f a im (c:_) = warpOn im h a +otsuContours = contours 1000 100 . notI . otsuBinarize + +f a im (c:_) = warpon a [(h,im)] where h = estimateHomographyRaw (g c) [[1,r],[-1,r],[-1,-r],[1,-r]] <> scaling 0.95 where @@ -30,5 +34,5 @@ f a im (c:_) = warpOn im h a k = posMax $ map segmentLength (asSegments c) f _ x _ = x -zero = constImage 0 (Size 100 100) +zero = constantImage 0 (Size 100 100) diff --git a/projects/tour/nogui.hs b/projects/tour/nogui.hs index 9f2e4012..396cfe7c 100644 --- a/projects/tour/nogui.hs +++ b/projects/tour/nogui.hs @@ -1,9 +1,9 @@ import Vision.GUI -import ImagProc +import Image.Processing main = do putStrLn "Working without GUI..." - x <- runS camera $ arr (sum8u.grayscale) + x <- runS camera $ arr (sumPixels.grayscale) >>> arrL (zip [1..] . take 1000) print x diff --git a/projects/tour/param.hs b/projects/tour/param.hs index ed34630e..763d342d 100644 --- a/projects/tour/param.hs +++ b/projects/tour/param.hs @@ -1,7 +1,7 @@ {-# LANGUAGE TemplateHaskell, RecordWildCards #-} import Vision.GUI -import ImagProc +import Image.Processing autoParam "SParam" "g-" [ ("sigma","Float",realParam 3 0 20) , ("scale","Float",realParam 1 0 5) ] @@ -10,6 +10,6 @@ main = run $ arr grayscale >>> g @@@ winParam >>> observe "gauss" id -g SParam{..} = (scale .*) . gaussS sigma . float +g SParam{..} = (scale .*) . gaussS sigma . toFloat diff --git a/projects/tour/param2.hs b/projects/tour/param2.hs index 48184053..4293bec6 100644 --- a/projects/tour/param2.hs +++ b/projects/tour/param2.hs @@ -1,7 +1,7 @@ {-# LANGUAGE TemplateHaskell, RecordWildCards #-} import Vision.GUI -import ImagProc +import Image.Processing autoParam "SParam" "g-" [ ("sigma","Float",realParam 3 0 20) , ("scale","Float",realParam 1 0 5) ] @@ -10,5 +10,5 @@ main = run $ arr grayscale >>> withParam g >>> observe "gauss" id -g SParam{..} = (scale .*) . gaussS sigma . float +g SParam{..} = (scale .*) . gaussS sigma . toFloat diff --git a/projects/tour/param3.hs b/projects/tour/param3.hs index 2563aa3b..cc2f40ff 100644 --- a/projects/tour/param3.hs +++ b/projects/tour/param3.hs @@ -1,7 +1,7 @@ {-# LANGUAGE TemplateHaskell, RecordWildCards #-} import Vision.GUI -import ImagProc +import Image.Processing autoParam "SParam" "g-" [ ("radius","Int",intParam 2 0 10) ] diff --git a/projects/tour/passROI.hs b/projects/tour/passROI.hs index 3004f0dc..2e868cf0 100644 --- a/projects/tour/passROI.hs +++ b/projects/tour/passROI.hs @@ -1,10 +1,11 @@ import Vision.GUI -import ImagProc -import Contours.Base(setRegion) +import Image.Processing +import Image.ROI + main = run $ arr grayscale >>> getROI "change roi" >>> arr cleanROI >>> observe "only roi" Draw -cleanROI im = resize (roiSize (theROI im)) im +cleanROI im = resize (roiSize (roi im)) im getROI name = transUI $ interface (Size 240 360) name state0 firsttime updts acts result display @@ -13,6 +14,6 @@ getROI name = transUI firsttime _ _ = return () updts = [] acts = [] - result roi _s input = ((), setRegion roi input) - display _roi _s _input output = Draw output + result droi _s input = ((), setRegion droi input) + display _droi _s _input output = Draw output diff --git a/projects/tour/play0.hs b/projects/tour/play0.hs index f26c410c..f84b6e6c 100644 --- a/projects/tour/play0.hs +++ b/projects/tour/play0.hs @@ -1,9 +1,9 @@ import Vision.GUI -import ImagProc +import Image.Processing main = run $ transUI f >>> freqMonitor -f :: VCN Channels ImageRGB +f :: VCN Channels (Image RGB) f = return . adaptMb $ \cam -> do x <- cam let r = rgb x diff --git a/projects/tour/play1.hs b/projects/tour/play1.hs index 00a9479c..554a93cf 100644 --- a/projects/tour/play1.hs +++ b/projects/tour/play1.hs @@ -1,5 +1,5 @@ import Vision.GUI -import ImagProc +import Image.Processing main = run p diff --git a/projects/tour/play3.hs b/projects/tour/play3.hs index b7ddcf62..dab09b46 100644 --- a/projects/tour/play3.hs +++ b/projects/tour/play3.hs @@ -1,5 +1,5 @@ import Vision.GUI -import ImagProc +import Image.Processing import Util.Misc(splitEvery) main = run $ arrL f >>> observe "RGB" rgb >>> wait (100`div`30) diff --git a/projects/tour/play4.hs b/projects/tour/play4.hs index 9810ddb8..3c4d4815 100644 --- a/projects/tour/play4.hs +++ b/projects/tour/play4.hs @@ -1,5 +1,5 @@ import Vision.GUI -import ImagProc +import Image.Processing main = run $ observe "RGB" rgb >>> freqMonitor diff --git a/projects/tour/play6.hs b/projects/tour/play6.hs index 6b9f6fb6..e9402ff7 100644 --- a/projects/tour/play6.hs +++ b/projects/tour/play6.hs @@ -4,8 +4,8 @@ import System.Random(randomIO) import Util.Misc(mean,splitEvery) import Control.Concurrent(threadDelay) -main = runT_ rnd $ see "x" >>> arrL f >>> see "mean" - >>> freqMonitor +main = runT_ rnd $ see "x" >>> freqMonitor + >>> arrL f >>> see "mean" >>> freqMonitor see name = observe name (text (Point 0.9 0) . show) @@ -14,4 +14,5 @@ rnd = return (threadDelay 1000 >> fmap (Just . flip mod 10) randomIO) avg = map (mean . map fromIntegral) . splitEvery 100 f :: [Int] -> [(Int,Double)] -f = zip [1..20] . avg +f = zip [1..100] . avg + diff --git a/projects/tour/playgray.hs b/projects/tour/playgray.hs new file mode 100644 index 00000000..8f2f41a7 --- /dev/null +++ b/projects/tour/playgray.hs @@ -0,0 +1,4 @@ +import Vision.GUI.Simple +import Image.Processing + +main = run $ observe "image" grayscale diff --git a/projects/tour/runS.hs b/projects/tour/runS.hs index 8efe2604..5d69c9d4 100644 --- a/projects/tour/runS.hs +++ b/projects/tour/runS.hs @@ -1,5 +1,5 @@ import Vision.GUI -import ImagProc +import Image.Processing main = do r <- runS camera $ arr (size . grayscale) diff --git a/projects/tour/runmode0.hs b/projects/tour/runmode0.hs index 09c5c1b8..3d021ac7 100644 --- a/projects/tour/runmode0.hs +++ b/projects/tour/runmode0.hs @@ -1,11 +1,11 @@ -- no gui import Vision.GUI -import ImagProc +import Image.Processing main = do putStrLn "Working without GUI..." - x <- runS camera $ arr (sum8u . grayscale) + x <- runS camera $ arr (sumPixels . grayscale) >>> arrL (zip [1..] . take 10) print x print (length x) diff --git a/projects/tour/runmode00.hs b/projects/tour/runmode00.hs index d9a88ea4..1a00a011 100644 --- a/projects/tour/runmode00.hs +++ b/projects/tour/runmode00.hs @@ -1,9 +1,10 @@ import Vision.GUI -import ImagProc +import Image.Processing -f = sum8u . grayscale +f = sumPixels . grayscale main = do cam <- camera mbimg <- cam print (f `fmap` mbimg) + diff --git a/projects/tour/runmode01.hs b/projects/tour/runmode01.hs index 38576353..d0993c57 100644 --- a/projects/tour/runmode01.hs +++ b/projects/tour/runmode01.hs @@ -1,8 +1,9 @@ import Vision.GUI -import ImagProc +import Image.Processing -f = sum8u . grayscale +f = sumPixels . grayscale main = do rs <- runS camera $ arr f print rs + diff --git a/projects/tour/runmode02.hs b/projects/tour/runmode02.hs index 4307d105..784d994c 100644 --- a/projects/tour/runmode02.hs +++ b/projects/tour/runmode02.hs @@ -1,7 +1,7 @@ import Vision.GUI -import ImagProc +import Image.Processing -f = sum8u . grayscale +f = sumPixels . grayscale main = do prepare diff --git a/projects/tour/runmode03.hs b/projects/tour/runmode03.hs index d58d38a5..a47e1cdc 100644 --- a/projects/tour/runmode03.hs +++ b/projects/tour/runmode03.hs @@ -1,6 +1,6 @@ import Vision.GUI -import ImagProc +import Image.Processing -f = sum8u . grayscale +f = sumPixels . grayscale main = runT camera (observe "Image" rgb >>> arr f) >>= print diff --git a/projects/tour/runmode04.hs b/projects/tour/runmode04.hs index bf38fdc7..512b8c4f 100644 --- a/projects/tour/runmode04.hs +++ b/projects/tour/runmode04.hs @@ -1,9 +1,10 @@ -import ImagProc +import Image.Processing import System.Environment -f = sum8u . grayscale +f = sumPixels . grayscale main = do filename:_ <- getArgs img <- channelsFromRGB `fmap` loadRGB filename print (f img) + diff --git a/projects/tour/runmode05.hs b/projects/tour/runmode05.hs index f5762533..daeed707 100644 --- a/projects/tour/runmode05.hs +++ b/projects/tour/runmode05.hs @@ -1,10 +1,11 @@ -import ImagProc -import ImagProc.Camera +import Image.Processing +import Image.Capture import System.Environment -f = sum8u . grayscale +f = sumPixels . grayscale . channelsFromRGB main = do folder:_ <- getArgs imgs <- readFolderIM folder print (map (f.fst) imgs) + diff --git a/projects/tour/runmode06.hs b/projects/tour/runmode06.hs index dab12597..b0cfdfe7 100644 --- a/projects/tour/runmode06.hs +++ b/projects/tour/runmode06.hs @@ -1,6 +1,7 @@ import Vision.GUI -import ImagProc +import Image.Processing -f = sum8u . grayscale +f = sumPixels . grayscale main = runS camera (arr f) >>= print . sum + diff --git a/projects/tour/runmode1.hs b/projects/tour/runmode1.hs index df1d119c..823eeed0 100644 --- a/projects/tour/runmode1.hs +++ b/projects/tour/runmode1.hs @@ -1,7 +1,7 @@ -- threaded GUI, output discarded -- clean exit by user ESC or end of stream -import Vision.GUI -import ImagProc +import Vision.GUI.Simple +import Image main = run (observe "image" rgb) diff --git a/projects/tour/runmode2.hs b/projects/tour/runmode2.hs index 88b59b19..07d34efb 100644 --- a/projects/tour/runmode2.hs +++ b/projects/tour/runmode2.hs @@ -2,10 +2,10 @@ -- (this mode drops display frames) import Vision.GUI -import ImagProc +import Image.Processing main = do - r <- runT camera (observe "image" rgb >>> arr (sum8u.grayscale)) + r <- runT camera (observe "image" rgb >>> arr (sumPixels.grayscale)) print r putStrLn "bye!" diff --git a/projects/tour/runmode3.hs b/projects/tour/runmode3.hs index d3e3c1c5..2c06bc73 100644 --- a/projects/tour/runmode3.hs +++ b/projects/tour/runmode3.hs @@ -1,10 +1,10 @@ -- non threaded GUI, discarding result import Vision.GUI -import ImagProc +import Image.Processing main = do prepare - runNT_ camera (observe "image" rgb >>> arr (sum8u.grayscale)) + runNT_ camera (observe "image" rgb >>> arr (sumPixels.grayscale)) putStrLn "bye!" diff --git a/projects/tour/runmode4.hs b/projects/tour/runmode4.hs index a40f98a1..533f96ef 100644 --- a/projects/tour/runmode4.hs +++ b/projects/tour/runmode4.hs @@ -1,11 +1,11 @@ -- non threaded GUI, returning result import Vision.GUI -import ImagProc +import Image.Processing main = do prepare - r <- runNT camera (observe "image" rgb >>> arr (sum8u.grayscale)) + r <- runNT camera (observe "image" rgb >>> arr (sumPixels.grayscale)) print r putStrLn "bye!" diff --git a/projects/tour/scanl1.hs b/projects/tour/scanl1.hs index d19d93e1..da3ac383 100644 --- a/projects/tour/scanl1.hs +++ b/projects/tour/scanl1.hs @@ -1,12 +1,16 @@ import Vision.GUI -import ImagProc(grayscale, warpOn, Polyline(..), Point(..), segmentLength) -import Vision.Apps.Contours(otsuContours, smoothPolyline, polygons, asSegments) +import Image.Processing +import Contours.Polygons +import Contours +import Util.Geometry import Numeric.LinearAlgebra((<>)) import Vision(cameraFromHomogZ0,estimateHomographyRaw,ht,scaling) import Util.Misc(rotateLeft,posMax) darkContours = (id &&& (otsuContours >>> map (smoothPolyline 4))) +otsuContours = contours 1000 100 . notI . otsuBinarize + main = run $ arr grayscale >>> arr darkContours >>> arr (id *** take 1 . polygons 10 5 (4, 4)) @@ -17,7 +21,7 @@ main = run $ arr grayscale shinfo (im,ps) = Draw [ Draw im , (Draw . map (drawContourLabeled blue red white 2 3)) ps ] -f (a,_) (im,c:_) = (warpOn im h a, [c]) +f (a,_) (im,c:_) = (warpon im [(h,a)], [c]) where h = estimateHomographyRaw (g c) [[1,r],[-1,r],[-1,-r],[1,-r]] <> scaling 0.95 where diff --git a/projects/tour/single.hs b/projects/tour/single.hs index a61454b0..bcc6b174 100644 --- a/projects/tour/single.hs +++ b/projects/tour/single.hs @@ -1,9 +1,9 @@ import Vision.GUI -import ImagProc -import ImagProc.Camera +import Image.Processing +import Image.Capture import System.Environment -f = sum8u . grayscale +f = sumPixels . grayscale . channelsFromRGB main = getArgs >>= readImages >>= runITrans (arr f) >>= print diff --git a/projects/tour/skip.hs b/projects/tour/skip.hs new file mode 100644 index 00000000..3595542d --- /dev/null +++ b/projects/tour/skip.hs @@ -0,0 +1,12 @@ +import Vision.GUI +import Image.Processing +import Util.Options + +f = sumPixels . grayscale + +main = do + n <- getOption "--skip" 0 + prepare + r <- runNT camera $ arrL (drop n) >>> observe "image" rgb >>> arr f + print (length r) + diff --git a/projects/tour/smon.hs b/projects/tour/smon.hs index 375f8ae4..42788fe6 100644 --- a/projects/tour/smon.hs +++ b/projects/tour/smon.hs @@ -1,6 +1,6 @@ import Vision.GUI import Contours.Base -import ImagProc +import Image.Processing main = run $ sMonitor "result" f @@ -10,7 +10,7 @@ f roi x = [ msg "grayscale" [ Draw g ] where img = rgb x g = setRegion roi (grayscale x) - smooth = gauss Mask5x5 . float $ g + smooth = gauss Mask5x5 . toFloat $ g edges = canny (0.1,0.3) . gradients $ smooth msg s t = Draw [ Draw img, Draw t , color yellow $ text (Point 0.9 0.65) s ] diff --git a/projects/tour/stand1.hs b/projects/tour/stand1.hs index 012a4a8e..86f9d26f 100644 --- a/projects/tour/stand1.hs +++ b/projects/tour/stand1.hs @@ -1,5 +1,5 @@ import Vision.GUI -import ImagProc +import Image main = runIt win @@ -7,5 +7,5 @@ win = standalone (Size 100 400) "click to change" x0 updts [] sh where x0 = 7 sh = text (Point 0 0) . show - updts = [(key (MouseButton LeftButton), \roi pt -> (+1)) ] + updts = [(key (MouseButton LeftButton), \_droi _pt -> (+1)) ] diff --git a/projects/tour/stand2.hs b/projects/tour/stand2.hs index 97e16759..ac7fd37f 100644 --- a/projects/tour/stand2.hs +++ b/projects/tour/stand2.hs @@ -1,5 +1,5 @@ import Vision.GUI -import ImagProc +import Image main = runIt win diff --git a/projects/tour/stand3.hs b/projects/tour/stand3.hs index 15fa087e..2172d9ca 100644 --- a/projects/tour/stand3.hs +++ b/projects/tour/stand3.hs @@ -1,5 +1,5 @@ import Vision.GUI -import ImagProc +import Image import Util.Misc(replaceAt) main = runIt win diff --git a/projects/tour/testwebcam.hs b/projects/tour/testwebcam.hs new file mode 100644 index 00000000..7857dbf4 --- /dev/null +++ b/projects/tour/testwebcam.hs @@ -0,0 +1,8 @@ +import Vision.GUI.Simple +import Image.Capture +import Image.Devel + +cam = webcam "/dev/video1" (Size 600 800) 30 + +main = do + runT_ cam (observe "source" yuyv2rgb >>> freqMonitor)