# opencv-bazel **Repository Path**: wasku/opencv-bazel ## Basic Information - **Project Name**: opencv-bazel - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-01 - **Last Updated**: 2024-09-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Build OpenCV projects using Bazel on Linux ## OpenCV Packages Many Linux distributions have OpenCV packages. Debian-based ones: OS | OpenCV -------------------- | ------ Debian 9 (stretch) | 2.4 Debian 10 (buster) | 3.2 Debian 11 (bullseye) | 4.5 Ubuntu 16.04 LTS | 2.4 Ubuntu 18.04 LTS | 3.2 Ubuntu 20.04 LTS | 4.2 Ubuntu 21.04 | 4.5 Install OpenCV: ```bash sudo apt-get install -y \ libopencv-core-dev \ libopencv-highgui-dev \ libopencv-calib3d-dev \ libopencv-features2d-dev \ libopencv-imgproc-dev \ libopencv-video-dev ``` Check where OpenCV header files are located: ```bash dpkg -L libopencv-core-dev | grep 'include/' ``` Checek where OpenCV shared libraries are located: ```bash dpkg -L libopencv-core-dev | grep 'lib/' ``` Get the version of currently installed OpenCV: ```bash apt-cache show libopencv-core-dev ``` Inspect a list of default GCC include directories: ```bash echo | gcc -xc++ -E -v - ``` Bazel uses the same list of default include directories: ```bash cat $(bazel info output_base)/external/local_config_cc/builtin_include_directory_paths ``` Inspect a list of default GCC library directories: ```bash gcc -print-search-dirs | grep 'libraries:' ``` ### OpenCV 2/3 Packages Header files are installed to `/usr/include/opencv2/`. `/usr/include` is a default include directory (`-I` flag is not needed). Library files are installed to `/usr/lib/aarch64-linux-gnu/`. This is a default library directory (`-L` flag is not needed). Link specific OpenCV libraries by adding `-l` flags: ```bash -lopencv_core -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_video -lopencv_videoio ``` There are both static `.a` and shared `.so` versions of each library. Shared library is chosen by default. Usage of *only* shared libraries can be more explicit: ```bash -l:libopencv_core.so -l:libopencv_calib3d.so -l:libopencv_features2d.so -l:libopencv_highgui.so -l:libopencv_imgcodecs.so -l:libopencv_imgproc.so -l:libopencv_video.so -l:libopencv_videoio.so ``` Pay attention that sometimes (e.g. manual compilation) OpenCV libraries can go to `/usr/local/lib`. This is not a default library directory for the compiler! You have to pass `-L/usr/local/lib` explicitly in this case. ### OpneCV 4 Packages Header files are installed to `/usr/include/opencv4/opencv2` and `/usr/include//opencv4/opencv2`. Pass additional include directories to the compiler: ```bash -I/usr/include/opencv4/ -I/usr/include/$(shell gcc -print-multiarch)/opencv4/ ``` Library files are installed at the same location as for OpenCV 2/3. ## Bazel Compilation Pass any compiler flag to Bazel using `--copt=