haskell-opencv
haskell-opencv copied to clipboard
Out of bounds error
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.
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!