LumiGuide / haskell-opencv

Haskell binding to OpenCV-3.x
Other
154 stars 44 forks source link

Can only convert square JuicyPixels images to OpenCV #111

Closed ocharles closed 6 years ago

ocharles commented 6 years ago

Find this little beaut of a bug in the JuicyPixels -> OpenCV code:

forM_ ((,) <$> [0 .. h - 1] <*> [0 .. w - 1]) $ \(x,y) ->

Can you spot it?

How about if I rewrite the list building:

do x <- [0 .. h - 1]
   y <- [0 .. w - 1])
   return (x, y)

Whoops! We've accidentally transposed x and y! The correct loop should be:

forM_ ((,) <$> [0 .. h - 1] <*> [0 .. w - 1]) $ \(y,x) ->
roelvandijk commented 6 years ago

Well spotted! I completely agree with the much more readable version you propose.

Btw, the entire JuicyPixels encoding <-> decoding is extremely slow. It needs a complete rewrite.

ocharles commented 6 years ago

It's actually good enough for what I'm doing, so no need to worry about that. Just needs to avoid blowing up with an out of bounds exception :smile: