LumiGuide / haskell-opencv

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

Out of bounds error #96

Open drull95 opened 7 years ago

drull95 commented 7 years ago

this program:

import Codec.Picture
import OpenCV.HighGui
import OpenCV.Juicy
import System.FilePath

workingDir = "/home/cmo/src/fps-bot/data"
thumbnail = workingDir </> "level-thumbnail.png"
startScreen = workingDir </> "screen-0169.png"

main = do
  w <- makeWindow "hello"
  a <- readImage thumbnail
  b <- readImage startScreen
  let (thum, start) =
          case (a, b) of
            (Right (ImageRGB8 thum'), Right (ImageRGB8 start')) -> 
                (fromImage thum', fromImage start') 
            _ -> error "something went wrong loading images"
  -- imshow w thum
  imshow w start
  waitKey 5000

results in this error:

locateStartLevelThumbnail: ./Data/Vector/Generic.hs:245 ((!)): index out of bounds (3932160,3932160)
CallStack (from HasCallStack):
  error, called at ./Data/Vector/Internal/Check.hs:87:5 in vector-0.12.0.1-
692PQMDMB6pIQ1uGwefDcQ:Data.Vector.Internal.Check

I've put the png files online at github.com/drull95/fps-bot. Any help is greatly appreciated.

roelvandijk commented 7 years ago

It look likes you found a bug in the JuicyPixels conversion function OpenCV.Juicy.fromImage!

Until we can fix that bug I suggest you use OpenCV.ImgCodecs.imdecode.

Your program with imdecode (untested):

{-# language DataKinds #-}

import Codec.Picture
import qualified Data.ByteString as B
import OpenCV.HighGui
import qualified OpenCV as CV
import System.FilePath

workingDir = "/home/cmo/src/fps-bot/data"
thumbnail = workingDir </> "level-thumbnail.png"
startScreen = workingDir </> "screen-0169.png"

loadImage :: FilePath -> IO (CV.Mat ('S ['D, 'D]) 'D 'D)
loadImage path = CV.imdecode CV.ImreadColor <$> B.readFile path

main = do
  w <- makeWindow "hello"
  thum<- loadImage thumbnail
  start<- loadImage startScreen
  -- imshow w thum
  imshow w start
  waitKey 5000

Thank you for reporting the bug!