haskell-opencv icon indicating copy to clipboard operation
haskell-opencv copied to clipboard

OpenCV 4 only, GHC 9.2 support

Open nh2 opened this issue 11 months ago • 6 comments

In this PR I modernise opencv:

  • Proper OpenCV 4 support.
    • Until now, opencv-extra code didn't seem to compile.
  • GHC 9.2 support.
    • Single-line TemplateHaskell change in the DoE constructor.
  • Newer library support.
    • Fixed breakage of the fancy example image generator, which used a copy-paste of a module from haskell-src-meta; it broke because its dependency haskell-src-exts evolved its API, see:
      • https://github.com/haskell-suite/haskell-src-exts/issues/446
      • https://github.com/mihaimaruseac/hindent/issues/562). The solution here is to use the upstreamed changes into haskell-src-meta which supports everything except * syntax for kinds (that syntax is now deprecated), so switching * to Type fixed that, see https://github.com/bmillwood/haskell-src-meta/pull/54#issuecomment-1708908138.
  • Add Cabal flag enable-nonfree to enable those modules that require the system OpenCV 4 to be compiled with the OPENCV_ENABLE_NONFREE option (most OpenCV installations lack this by default). This was previously enabled unconditionally, which worked fine for OpenCV 3 but not OpenCV 4.

FYI @ocharles

TODO

  • [x] Handle the fact that the aruco API broke between OpenCV 4.6 and 4.7, and the current Ubuntu 22.04 LTS has 4.5 while NixOS has 4.7.
    • Done with help of https://hackage.haskell.org/package/cabal-pkg-config-version-hook, thanks @roberth!
  • [x] Test with multiple versions of OpenCV 4.
    • Done, see stack.yaml's nix section.
  • [x] Check that enable-nonfree compiles fine.
    • Since I can't test that on Ubuntu easily (see above), probably best to be tested enabled in an OpenCV environment from Nix.
      • Done, I added an entry about this in the CHANGELOG.
  • [ ] File an issue for Stackage that Stackage 21+ needs repa added back, so that opencv can be added back.
    • This needs this easy issue: https://github.com/haskell-repa/repa/pull/25
    • And this harder issue regarding GHC 9.4 touch compatibility: https://github.com/haskell-repa/repa/issues/26
  • [ ] File separate issue about QuickCheck flake I observed: Repro with stack test opencv --ta --quickcheck-replay=369455:
    getAffineTransform:
      *** Failed! (after 2 tests):
      The points are too far apart; newPoints =
      V3 (V2 0.0 0.0) (V2 0.0 0.0) (V2 0.0 0.0)
      V3 (V2 1.0 1.0) (V2 1.0 1.0) (V2 0.0 (-1.0))
      V3 (V2 0.0 1.0) (V2 0.0 (-1.0)) (V2 (-1.0) 1.0)
      Use --quickcheck-replay=369455 to reproduce.
      Use -p '/getAffineTransform/' to rerun this test only.
    

nh2 avatar Sep 06 '23 18:09 nh2

Thanks @nh2 ! We have a bunch of commits in our circuithub fork. I'm on holiday for the next two weeks, but I'll try and get on top of things when I'm back and we get this all ship shape again

ocharles avatar Sep 06 '23 19:09 ocharles

Another thing that could be done:

The SIFT patent expired in 2020 (https://opencv.org/blog/2020/07/18/opencv-4-4-0/) so we should be able to change our code here to move that out of the enable-nonfree Cabal flag I'm adding in this PR.

nh2 avatar Sep 29 '23 14:09 nh2

@ocharles Do you want to do a short call regarding this?

I'm also in London starting from tonight in case you want to hang out :)

nh2 avatar Oct 03 '23 17:10 nh2

Hey @nh2, sorry for not getting back earlier! A call sounds good - can you do next week some time? And how long are you in London for?

ocharles avatar Oct 07 '23 07:10 ocharles

@ocharles Afternoons from 16:00 work for me (except Monday), I'm in London at least the whole week, probably more.

nh2 avatar Oct 07 '23 19:10 nh2

Hey @nh2, sorry I never got back to you! Unfortunately time has been very short recently, and as things go that isn't looking to change any time soon :sweat_smile: I don't think I have time for a call, but I have viewed all your changes here and they look excellent. I'm very happy for you to just crack on with this and merge/release as necessary. If there's anything in particular you want to talk about, let me know. This looks like a sensible and incremental path forward though, and I can't see anything remotely controversial. Good work!

ocharles avatar Nov 28 '23 11:11 ocharles