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.

15 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?

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?