OpenCV.jl: OpenCV's Julia Bindings

OpenCV.jl


OpenCV.jl is a Julia package that provides an interface to the popular computer vision library OpenCV. It allows Julia users to leverage the extensive functionalities and algorithms offered by OpenCV for various computer vision tasks, such as image and video processing, object detection, feature extraction, and more.

Example:

using ImageCore, OpenCV, TestImages, MosaicViews

img_orig = testimage("Mandrill")

img_raw =  collect(rawview(channelview(img_orig)))

img_gray = OpenCV.cvtColor(img_raw, OpenCV.COLOR_RGB2GRAY)

img_blur = OpenCV.blur(img_gray, OpenCV.Size(Int32(9), Int32(9)))

img_back =  colorview(Gray, float.(img_blur)./255)[1,:,:]

mosaic(img_orig, img_back; nrow=1)

Output:

Relevant Details:

We welcome new contributors to help improve the package and performance of existing solutions.

20 Likes

OpenCV.jl 4.5.3 is out

  • It should work on Julia 1.9 and is now being maintained in JuliaImages after Archit Rungta joined JuliaImages some days back.
  • Currently in maintenance mode given limited contributors. In list of wrapped methods mentioned above if any user finds a specific usecase/methods in OpenCV.jl which other packages in JuliaImages don’t solve and you really need it, do let us know(here, on slack(# image-processing) or zulip(# image-processing). Then we can collabratively work on providing those in a more streamlined way.
5 Likes

I tried to install OpenCV.jl version 1.10, but it didn’t work. Is there any reason for that or is it just because it’s still in release? It’s only working on version 1.6, which is the LTS. I wanted to take advantage of the performance of version 1.10, which is extremely good. Is there any way to make it work?

1 Like

Someone could run it on 1.9, see that GitHub issue.

It seems this is needed:
CxxWrap = “0.11, 0.12, 0.13, 0.14”

I tried that, though not enough:

(@v1.10) pkg> dev OpenCV

shell> vi /home/pharaldsson/.julia/dev/OpenCV/Project.toml
ERROR: LoadError: InitError: could not load library "/home/pharaldsson/.julia/artifacts/d454559ec7ae7732c2a6191fad8f40f16fdd75c8/lib/libopencv_julia.so"
/home/pharaldsson/.julia/artifacts/d454559ec7ae7732c2a6191fad8f40f16fdd75c8/lib/libopencv_julia.so: undefined symbol: small_typeof, version JL_LIBJULIA_1.10

i.e. similar change to:

This one might be relevant:

(@v1.11) pkg> add libcxxwrap_julia_jll@v0.12
   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package CxxWrap [1f15a43c]:
 CxxWrap [1f15a43c] log:
 ├─possible versions are: 0.7.0 - 0.14.2 or uninstalled
 ├─restricted by compatibility requirements with libcxxwrap_julia_jll [3eaa8342] to versions: 0.7.0 - 0.9.1 or uninstalled
 │ └─libcxxwrap_julia_jll [3eaa8342] log:
 │   ├─possible versions are: 0.6.5 - 0.12.0 or uninstalled
 │   └─restricted to versions 0.12 by an explicit requirement, leaving only versions: 0.12.0
 └─restricted by compatibility requirements with OpenCV [f878e3a2] to versions: 0.11.0 - 0.13.4 — no versions left
   └─OpenCV [f878e3a2] log:
     ├─possible versions are: 4.5.2 - 4.5.3 or uninstalled
     └─restricted to versions * by an explicit requirement, leaving only versions: 4.5.2 - 4.5.3

I thought 1.11 might maybe work even if 1.10 didn’t:

$ juliaup add nightly
Installing Julia latest-linux-x86_64

julia> [ Info: Precompiling REPLExt [e5eb5ef1-03cf-53a7-ae1d-5a66b08e832b] (cache misses: mismatched flags (2), dep uuid changed (2))

(@v1.11) pkg> add OpenCV_jll

and note I get different errors before and after this:

(@v1.11) pkg> up
    Updating registry at `~/.julia/registries/General.toml`
    Updating `~/.julia/environments/v1.11/Project.toml`
  [33b9d88c] ↑ OpenCV_jll v4.6.0+1 ⇒ v4.6.0+2


old error, probably not to worry about:

Precompiling OpenCV
        Info Given OpenCV was explicitly requested, output will be shown live 
ERROR: LoadError: UndefVarError: `artifact_dir` not defined in `OpenCV_jll`

OpenCV.jl isn’t my package, just trying to explain. If there had not been a problem elsewhere; in Julia, then the package would have worked.

It doesn’t directly depend on anything in Julia not guaranteed stable (while it does indirectly), but it relies on CxxWrap to call [OpenCV] C++ code, and Julia changed breaking CxxWrap.jl.

@Ashwani_Rathee It’s unfortunate that CxxWrap breaks. When it is “fixed”, seemingly all its dependants, e.g. OpenCV.jl, need to update its compatibility.

@barche, I see there’s also pybind11_jll that could have been used… but we don’t want to need to avoid your package (calling Python is stable, and will be, and apparently pybind11 is stable, and well documented, so also stable to call C++ that way indirectly even though a bit ugly to have to rely on Python for that…). I know the problem is Julia doesn’t keep stable for you (calling from Python to Julia also broke with 1.10.1, though not in the other direction), or you used something not promised to be stable, so do you know if that’s about to change? Was it the last thing Julia broke, unlikely to be more, or guaranteed, or no end in sight?

I think the problem is that OpenCV_jll is compiled against libcxxwrap_julia 0.10 or older. These older versions don’t support Julia 1.10 yet, so the correct solution would be to rebuild OpenCV_jll against libcxxwrap_julia 0.11 and set a compat bound. Version 0.12 of libcxxwrap_julia is not yet ready for use, but it also should not be pulled in automatically if compat is set correctly.

3 Likes

Did OpenCV.jl does not wrap Feature Matching methods, like SURF, SIFT, ORB?

Hi

we are hitting that (or similar) problem with CxxWrap. In May 2024.

Do you have any pointers about solving it?

Thanks

Marco

Hi Marco,

The problem is that OpenCV_jll.jl hasn’t been built against a libcxxwrap_julia that supports Julia 1.10. To do this, the build file needs to be updated with a PR to Yggdrasil. Easiest would be to build against libcxxwrap_julia version 0.11, and then also update the OpenCV.jl Project.toml to add the CxxWrap 0.14 compat. If you are looking to do this, feel free to tag me in the Yggdrasil PR, I can help.

Hi,

sorry but I am a bit at a loss here…

What exactly is a PR (a “pull request”?) to Yggdrasil?

It means one of two things.

  1. You pray to the Norse gods to pull you up to the world tree.
  2. You go to Github, navigate to the following Github repository, and you suggest a change:
    GitHub - JuliaPackaging/Yggdrasil: Collection of builder repositories for BinaryBuilder.jl

Sometimes these are one and the same, except that that the Norse god you encounter is a helpful Italian fellow who lives in London.

8 Likes

I understand… and we do have a PR ready (hopefully).

Just curious why no PR was produced yet, as this issue seems to have appeared some time ago.

Related: Add comment to OpenCV to force rebuild by cdsousa ¡ Pull Request #7941 ¡ JuliaPackaging/Yggdrasil ¡ GitHub
(after that I just gave up)

1 Like

Thank you @cdsousa
Things do not seem easy. At all.

Thanks to @barche OpenCV.jl is now updated to the latest opencv release (4.10) in BB, and works with Julia 1.10 and 1.11.

The package probably should be set up so that the wrappers are in the OpenCV.jl repo as discussed in Organization of the source code for the wrappers ¡ Issue #49 ¡ JuliaImages/OpenCV.jl ¡ GitHub

8 Likes