OpenCV: Difference between revisions

Mmkaram (talk | contribs)
Added OpenCV page
 
Mmkaram (talk | contribs)
m minor grammatical errors
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[https://opencv.org/ OpenCV] is the world's largest and most popular computer vision library<ref>https://opencv.org/</ref>. Originally developed by [https://www.intel.com/content/www/us/en/homepage.html Intel] in 2000, it is open source under the [[wikipedia:Apache_License|Apache License]] 2. The purpose of this page is to help with the initial hassle of getting OpenCV to run in development environments.
[https://opencv.org/ OpenCV] is the world's largest and most popular computer vision library<ref name=":0">https://opencv.org/</ref>. It is open source under the [[wikipedia:Apache_License|Apache License]] 2<ref>https://github.com/opencv/opencv?tab=Apache-2.0-1-ov-file#</ref>. OpenCV interfaces with many languages such as C++, Python and Java<ref name=":0" />.
 
Due to needing dynamically linked libraries and not having all necessary dependencies packaged with the base version of the OpenCV package for all uses, this page was created to help with the initial hassle of getting OpenCV to run in development environments.


== Python ==
== Python ==
To use OpenCV with Python it is generally recommended to use the Python3XXPackage package found in [[nixpkgs]]. Although, as OpenCV is written mainly in C++<ref>https://github.com/opencv/opencv</ref>, it relies heavily on stdlibc which is generally a dynamically linked library. Attempting to run any OpenCV algorithms in Python may thereby lead to errors such as this:<syntaxhighlight lang="bash">
To use OpenCV with Python it is generally recommended to use the Python3XXPackage package found in [[nixpkgs]]. Although, as OpenCV is written mainly in C++<ref>https://github.com/opencv/opencv</ref>, it relies heavily on stdlibc which is a dynamically linked library. Attempting to run any OpenCV algorithms in Python may thereby lead to errors such as this:<syntaxhighlight lang="bash">
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory
</syntaxhighlight>There are two main ways of solving this issue, using a shell.nix or flakes.
</syntaxhighlight>There are two main ways of solving this issue, using a shell.nix or flakes.
Line 64: Line 66:
}
}


</syntaxhighlight>Both the dev shell and flake examples only allow for the base compilation of OpenCV, there are options you may want to enable like gtk support to use functions like cv2.imshow(). To enable said flags/features, you must use [https://nixos.org/guides/nix-pills/17-nixpkgs-overriding-packages.html overrides]. Beware, this may cause a full recompilation of OpenCV because you're changing build flags and that specific combination may not be cached for your system.
</syntaxhighlight>Both the dev shell and flake examples only allow for the base compilation of OpenCV. You can enable other flags such as gtk support to use functions like cv2.imshow() by using [https://nixos.org/guides/nix-pills/17-nixpkgs-overriding-packages.html overrides]. Beware, this may cause a full recompilation of OpenCV as you're changing build flags and that specific combination may not be cached for your system.


=== Shell.nix Override Example ===
=== Shell.nix Override Example ===
Line 124: Line 126:
== Rust ==
== Rust ==
It is important to note that the most popular OpenCV package for rust, [https://github.com/twistedfall/opencv-rust opencv-rust], is just a series of bindings for the C++ version of OpenCV, and is thereby unsafe. Errors that occur while trying to use these bindings may just fail quietly or return an error from the underlying C++ code. There is an effort to implement most of the main computer vision algorithms entirely in rust called [https://github.com/rust-cv/cv rust-cv]. The package has not been actively maintained since July of 2023.
It is important to note that the most popular OpenCV package for rust, [https://github.com/twistedfall/opencv-rust opencv-rust], is just a series of bindings for the C++ version of OpenCV, and is thereby unsafe. Errors that occur while trying to use these bindings may just fail quietly or return an error from the underlying C++ code. There is an effort to implement most of the main computer vision algorithms entirely in rust called [https://github.com/rust-cv/cv rust-cv]. The package has not been actively maintained since July of 2023.
The opencv-rust package does not include the C++ bindings, thereby requiring it to be installed alongside the package itself. Luckily, it is packaged in nixpkgs and using it is just a question of getting it on our system, the crate does the rest of the work.


=== Flake.nix Example ===
=== Flake.nix Example ===
Line 188: Line 192:
}
}
</syntaxhighlight>
</syntaxhighlight>
[[Category:Python]]
[[Category:Rust]]