aleator / CV

Haskell wrappers and utilities for OpenCV machine vision library
http://hackage.haskell.org/package/CV
BSD 3-Clause "New" or "Revised" License
51 stars 13 forks source link

GHC 7.8.3 can't compile CV master #47

Closed vlatkoB closed 10 years ago

vlatkoB commented 10 years ago

Hello,

My system: GHC 7.8.3, Cabal 1.20.0.2, Ubuntu 12.04, tried both OpenCV 2.3.1 and 2.4.5

When compiling the master branch, I'm getting these errors:

CV/Matrix.hs:145:83: Could not deduce (Enum s0) arising from a use of ‘fromEnum’ from the context (Exists (Matrix a), Args (Matrix a) ~ Size (Matrix a)) bound by the type signature for invert :: (Exists (Matrix a), Args (Matrix a) ~ Size (Matrix a)) => Matrix a -> Matrix a at CV/Matrix.hs:141:11-88 The type variable ‘s0’ is ambiguous Note: there are several potential instances: instance Enum RGB_Channel -- Defined at CV/Image.chs:159:56 instance Enum LAB_Channel -- Defined at CV/Image.chs:165:59 instance Enum ImageDepth -- Defined at CV/Image.chs:965:10 ...plus 72 others In the second argument of ‘(.)’, namely ‘fromEnum’ In the expression: fromIntegral . fromEnum In the third argument of ‘c'cvInvert’, namely ‘(fromIntegral . fromEnum $ c'CV_LU)’

CV/Matrix.hs:145:94: Could not deduce (Num s0) arising from a use of ‘c'CV_LU’ from the context (Exists (Matrix a), Args (Matrix a) ~ Size (Matrix a)) bound by the type signature for invert :: (Exists (Matrix a), Args (Matrix a) ~ Size (Matrix a)) => Matrix a -> Matrix a at CV/Matrix.hs:141:11-88 The type variable ‘s0’ is ambiguous Note: there are several potential instances: instance Num a => Num (Utils.Point.Pt a) -- Defined at Utils/Point.hs:8:10 instance Num Double -- Defined in ‘GHC.Float’ instance Num Float -- Defined in ‘GHC.Float’ ...plus 64 others In the second argument of ‘($)’, namely ‘c'CV_LU’ In the third argument of ‘c'cvInvert’, namely ‘(fromIntegral . fromEnum $ c'CV_LU)’ In the expression: c'cvInvert c_m c_c (fromIntegral . fromEnum $ c'CV_LU)

TomMD commented 10 years ago

@vlatkoB Does my branch / pull request fix your problem? https://github.com/aleator/CV/pull/45

vlatkoB commented 10 years ago

I took pxqr:master #46, I suppose. I assumed it is the newest with all fixes merged. However, I just tried yours (https://github.com/TomMD/CV) and got the following errors:

CV/Transforms.chs:108:32: Could not deduce (RealFrac s0) arising from a use of ‘floor’ from the context (CreateImage (Image c D32)) bound by the type signature for scaleToSize :: CreateImage (Image c D32) => Interpolation -> Bool -> (Int, Int) -> Image c D32 -> Image c D32 at CV/Transforms.chs:(96,16)-(97,68) The type variable ‘s0’ is ambiguous Relevant bindings include ratio :: s0 (bound at CV/Transforms.chs:110:14) Note: there are several potential instances: instance RealFrac Double -- Defined in ‘GHC.Float’ instance RealFrac Float -- Defined in ‘GHC.Float’ instance Integral a => RealFrac (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ ...plus two others In the expression: floor In the expression: floor $ fromIntegral ow * ratio In the expression: (floor $ fromIntegral ow * ratio, floor $ fromIntegral oh * ratio)

CV/Transforms.chs:110:23: Could not deduce (Ord s0) arising from a use of ‘max’ from the context (CreateImage (Image c D32)) bound by the type signature for scaleToSize :: CreateImage (Image c D32) => Interpolation -> Bool -> (Int, Int) -> Image c D32 -> Image c D32 at CV/Transforms.chs:(96,16)-(97,68) The type variable ‘s0’ is ambiguous Relevant bindings include ratio :: s0 (bound at CV/Transforms.chs:110:14) Note: there are several potential instances: instance Ord LAB_Channel -- Defined in ‘CV.Image’ instance Ord RGB_Channel -- Defined in ‘CV.Image’ instance Ord CV.Image.YUV_Channel -- Defined in ‘CV.Image’ ...plus 139 others In the expression: max (fromIntegral w / fromIntegral ow) (fromIntegral h / fromIntegral oh) In an equation for ‘ratio’: ratio = max (fromIntegral w / fromIntegral ow) (fromIntegral h / fromIntegral oh) In an equation for ‘scaleToSize’: scaleToSize tpe retainRatio (w, h) img = unsafePerformIO $ do { target <- create (w', h'); withGenImage img $ \ i -> withGenImage target $ ...; return target } where (ow, oh) = getSize img (w', h') = if retainRatio then (floor $ fromIntegral ow * ratio, floor $ fromIntegral oh * ratio) else (w, h) ratio = max (fromIntegral w / fromIntegral ow) (fromIntegral h / fromIntegral oh)

CV/Transforms.chs:110:28: Could not deduce (Num s0) arising from a use of ‘fromIntegral’ from the context (CreateImage (Image c D32)) bound by the type signature for scaleToSize :: CreateImage (Image c D32) => Interpolation -> Bool -> (Int, Int) -> Image c D32 -> Image c D32 at CV/Transforms.chs:(96,16)-(97,68) The type variable ‘s0’ is ambiguous Relevant bindings include ratio :: s0 (bound at CV/Transforms.chs:110:14) Note: there are several potential instances: instance Num a => Num (Utils.Point.Pt a) -- Defined in ‘Utils.Point’ instance Num Double -- Defined in ‘GHC.Float’ instance Num Float -- Defined in ‘GHC.Float’ ...plus 46 others In the first argument of ‘(/)’, namely ‘fromIntegral w’ In the first argument of ‘max’, namely ‘(fromIntegral w / fromIntegral ow)’ In the expression: max (fromIntegral w / fromIntegral ow) (fromIntegral h / fromIntegral oh)

CV/Transforms.chs:110:42: Could not deduce (Fractional s0) arising from a use of ‘/’ from the context (CreateImage (Image c D32)) bound by the type signature for scaleToSize :: CreateImage (Image c D32) => Interpolation -> Bool -> (Int, Int) -> Image c D32 -> Image c D32 at CV/Transforms.chs:(96,16)-(97,68) The type variable ‘s0’ is ambiguous Relevant bindings include ratio :: s0 (bound at CV/Transforms.chs:110:14) Note: there are several potential instances: instance Fractional Double -- Defined in ‘GHC.Float’ instance Fractional Float -- Defined in ‘GHC.Float’ instance Integral a => Fractional (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ ...plus four others In the first argument of ‘max’, namely ‘(fromIntegral w / fromIntegral ow)’ In the expression: max (fromIntegral w / fromIntegral ow) (fromIntegral h / fromIntegral oh) In an equation for ‘ratio’: ratio = max (fromIntegral w / fromIntegral ow) (fromIntegral h / fromIntegral oh)

CV/Transforms.chs:342:9: Couldn't match expected type ‘IO a0’ with actual type ‘CInt -> IO ()’ Probable cause: ‘cvDistTransform’ is applied to too few arguments In the expression: cvDistTransform c_source c_result (fromIntegral . fromEnum $ dtype) (fromIntegral . fromEnum $ maskSize) nullPtr nullPtr In the second argument of ‘($)’, namely ‘\ c_result -> cvDistTransform c_source c_result (fromIntegral . fromEnum $ dtype) (fromIntegral . fromEnum $ maskSize) nullPtr nullPtr’

vlatkoB commented 10 years ago

Bump...

TomMD commented 10 years ago

@vlatkoB Are you building for OpenCV 2.3? I know my fork doesn't build with 2.3 - only 2.4 by using cabal install -fopencv24. I would bet aleator's master branch is in a similar state.

vlatkoB commented 10 years ago

@TomMD Made it. It seems that last conditional clause in Transformers.chs, on line 347-349 `#ifdef OpenCV24 (fromIntegral . fromEnum $ CCOMP)

endif`

should be written with space after the # (_ is space)

`#_ifdef OpenCV24 (fromIntegral . fromEnum $ CCOMP)

_endif`

otherwise compiler doesn't see it (?)

TomMD commented 10 years ago

No, it should behave identically either way - if it does't then your C pre-processor is badly broken. I've pushed a patch to my repo that removes the CPP and just assumed CV 2.4, if you are inclined to give that a try then let me know how things go.

vlatkoB commented 10 years ago

@TomMD Just tried it. Compiles without problems. :-) Any idea how to check/fix "badly broken C pre-processor"?

TomMD commented 10 years ago

I have no good idea what could have gone wrong with the CPP - that is an issue I've never ran across, very odd one too.

vlatkoB commented 10 years ago

@TomMD Thnaks a lot for help. Any idea when your patch(es) would get applied, to cv 4.0.0?

TomMD commented 10 years ago

@vlatkoB I don't expect my patches to ever be applied. I am getting the feeling @aleator is busy and perhaps abandoning this repository.

vlatkoB commented 10 years ago

Seems quite a few changes in this release, some functions (mapContours) and types missing/changed.