Calling a C opencv function from haskell
我正在尝试将 OpenCV 与 Haskell 一起使用。我的想法是从 Haskell 调用 c 函数。
现在我正在这样做:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
{–# LANGUAGE ForeignFunctionInterface #-}
module Lib import Foreign.C data LplROI = LplROI { data LpImage = LpImage { foreign import ccall"_ZN2cv6imreadERKNS_6StringEi" imRead_ImRead :: CString –> CInt –> IO (Ptr LpImage) someFunc = do |
我从 Haskell 阅读了这篇 CPlusPlus 帖子,因此我得到了名称 _ZN2cv6imreadERKNS_6StringEi。在 2.1.1 中查找损坏的命名。
但是 GHCi 说:
ByteCodeLink: can’t find label
During interactive linking, GHCi couldn’t find the following symbol:
_ZN2cv6imreadERKNS_6StringEi
在 Python 中我应该”导入 cv2″,但我不知道它在 Haskell 上是如何工作的。
我还阅读了:FFI 烹饪书但我无法在那里得到我的问题的答案。
有什么想法吗?
我尝试的方法不起作用。
OpenCV api 是用 C 编写的。这就是为什么调用它的方式在这里:来自haskell的C。但是当你在 “/usr/lib/” 中安装 OpenCV 时,你不会得到像 cv2.so 这样的 .so 文件。这意味着使用
所以,我使用了@ReidBarton 所说的”haskell-opencv”,效果很好。或者至少比其他方式更容易。
这是一个使用示例:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 |
module Lib ( someFunc ) where import Control.Monad ( void ) someFunc :: IO () |
在
1
2 3 4 5 |
packages:
– location: git: https://github.com/LumiGuide/haskell-opencv.git commit: 07afde39fa16f7a4282d4a812e70b9ed33d0f3ef – ‘.’ |
因此看起来是 cabal 文件的一部分:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
library hs–source–dirs: src exposed–modules: Lib build–depends: base >= 4.7 && < 5 , opencv , bytestring default–language: Haskell2010 executable simple–exe test–suite simple–test |
我希望它可以帮助某人。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/268884.html