278.1. opencv-4.14.0
Computer vision and machine-learning library, with the tracking, optical-flow and extended image-processing contrib modules and Python bindings
| Version | 4.14.0, release 2 |
| Shelf | ai — Machine learning inference, speech recognition, computer vision and neural translation |
| Phase | 43_toolkits (Toolkits), 2 of 344 in build order |
| Licence | Apache-2.0 |
| Homepage | https://opencv.org/ |
| Build time | 30.0 SBU |
| Installed size | 66.8 MiB in 434 files |
| Recipe | ports/core/ai/opencv/kpkgbuild |
About
OpenCV is the computer-vision library: image processing, feature detection, camera calibration, object tracking, video input and output, and a neural-network inference module, with Python bindings (cv2). The port is the 4.x line, the API digikam, mlt (the motion tracker of Kdenlive and Shotcut), sdrangel and the other consumers are written against. Eight modules come from the separate opencv_contrib tarball.
Sources
opencv-4.14.0.tar.gz(91.8 MiB)
sha256ee8fb9b30eb60850431b4656447080e3737b56e45719c92b67f245950609f86e
upstream: https://github.com/opencv/opencv/archive/refs/tags/4.14.0.tar.gz
archive copy: sources-1/ai--opencv-4.14.0.tar.gzopencv_contrib-4.14.0.tar.gz(52.9 MiB)
sha2564f17abd1bc7f88e19c3380c8de7cbf2d863aced5b5ee8d8934cc7902b67d42c9
upstream: https://github.com/opencv/opencv_contrib/archive/refs/tags/4.14.0.tar.gz
archive copy: sources-1/ai--opencv_contrib-4.14.0.tar.gz
Dependencies
Depends on: cmake, ninja, pkgconf, python3, numpy, zlib, libjpeg-turbo, libpng, libtiff, libwebp, openjpeg, openexr, libavif, libjxl, ffmpeg, gstreamer, gst-plugins-base, libva, onetbb, eigen, openblas, qt6-qtbase.
Required by (4): bcnc, digikam, mlt, sdrangel.
Optional, off in KDOS
These switches in build.sh turn off a feature whose library is a port here. The recipe may turn each off on purpose, or because the library was not yet a port when the recipe was written; this list cannot tell which.
-DWITH_SPNG=OFF, line 71: libspng (explained with the switches below)-DWITH_JASPER=OFF, line 75: jasper-DWITH_GDAL=OFF, line 79: gdal (explained with the switches below)-DWITH_GPHOTO2=OFF, line 88: gphoto2-DWITH_GTK=OFF, line 96: gtk3-DWITH_WAYLAND=OFF, line 97: wayland-DWITH_OPENGL=OFF, line 99: mesa (explained with the switches below)-DWITH_VTK=OFF, line 100: vtk-DWITH_VULKAN=OFF, line 101: vulkan-loader-DWITH_OPENMP=OFF, line 108: gcc
Patches
build.sh applies these; kpkg applies nothing by itself.
ffmpeg9.patch— Upstream’s change on the 4.x branch, after this release, to the videoio FFmpeg backend: where libavcodec is 61.13.100 or newer it asks for an encoder’s pixel formats and frame rates withavcodec_get_supported_config(), instead of readingAVCodec’spix_fmtsandsupported_frameratesfields, which FFmpeg 9 does not have. The old code stays behind#elsefor an older FFmpeg.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/43_toolkits/phase.env && kpkg install opencv'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/ai/opencv.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/ai/opencv
echo 'ee8fb9b30eb60850431b4656447080e3737b56e45719c92b67f245950609f86e opencv-4.14.0.tar.gz' | sha256sum -c -
echo '4f17abd1bc7f88e19c3380c8de7cbf2d863aced5b5ee8d8934cc7902b67d42c9 opencv_contrib-4.14.0.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/opencv
SRC=$SRC_ROOT/opencv-4.14.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf opencv-4.14.0.tar.gz -C "$SRC" --strip-components=1
tar --no-same-permissions --warning=no-unknown-keyword -xf opencv_contrib-4.14.0.tar.gz -C "$SRC_ROOT"
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/ffmpeg9.patch"
mkdir contrib
for m in aruco tracking optflow plot shape superres videostab ximgproc; do
mv "$SRC_ROOT/opencv_contrib-$version/modules/$m" contrib/
done
case "$(uname -m)" in
x86_64) _cpu="-DCPU_BASELINE=SSE2 -DCPU_BASELINE_DISABLE=SSE3" ;;
*) _cpu= ;;
esac
_pydir=$(python3 -c 'import sysconfig; print(sysconfig.get_path("platlib", "posix_prefix"))')
cmake -B build -G Ninja \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_SKIP_INSTALL_RPATH=ON \
-DOPENCV_EXTRA_MODULES_PATH="$SRC/contrib" \
-DOPENCV_GENERATE_PKGCONFIG=ON \
-DOPENCV_GENERATE_SETUPVARS=OFF \
-DOPENCV_ENABLE_NONFREE=OFF \
$_cpu \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_DOCS=OFF \
-DBUILD_PACKAGE=OFF \
-DBUILD_opencv_apps=ON \
-DBUILD_opencv_gapi=OFF \
-DBUILD_opencv_python3=ON \
-DBUILD_opencv_python2=OFF \
-DBUILD_JAVA=OFF \
-DBUILD_opencv_js=OFF \
-DINSTALL_C_EXAMPLES=OFF \
-DINSTALL_PYTHON_EXAMPLES=OFF \
-DINSTALL_TESTS=OFF \
-DPYTHON3_EXECUTABLE=/usr/bin/python3 \
-DOPENCV_SKIP_PYTHON_LOADER=ON \
-DOPENCV_PYTHON3_INSTALL_PATH="$_pydir" \
-DBUILD_ZLIB=OFF \
-DBUILD_JPEG=OFF \
-DBUILD_PNG=OFF \
-DBUILD_TIFF=OFF \
-DBUILD_WEBP=OFF \
-DBUILD_OPENJPEG=OFF \
-DBUILD_OPENEXR=OFF \
-DBUILD_JASPER=OFF \
-DBUILD_TBB=OFF \
-DBUILD_IPP_IW=OFF \
-DBUILD_ITT=OFF \
-DBUILD_PROTOBUF=ON \
-DPROTOBUF_UPDATE_FILES=OFF \
-DWITH_PROTOBUF=ON \
-DWITH_FLATBUFFERS=ON \
-DWITH_JPEG=ON \
-DWITH_PNG=ON \
-DWITH_SPNG=OFF \
-DWITH_TIFF=ON \
-DWITH_WEBP=ON \
-DWITH_OPENJPEG=ON \
-DWITH_JASPER=OFF \
-DWITH_OPENEXR=ON \
-DWITH_AVIF=ON \
-DWITH_JPEGXL=ON \
-DWITH_GDAL=OFF \
-DWITH_GDCM=OFF \
-DWITH_QUIRC=ON \
-DWITH_FFMPEG=ON \
-DWITH_GSTREAMER=ON \
-DWITH_V4L=ON \
-DWITH_VA=ON \
-DWITH_VA_INTEL=OFF \
-DWITH_1394=OFF \
-DWITH_GPHOTO2=OFF \
-DWITH_OPENNI2=OFF \
-DWITH_OBSENSOR=OFF \
-DWITH_PVAPI=OFF \
-DWITH_ARAVIS=OFF \
-DWITH_XIMEA=OFF \
-DWITH_UEYE=OFF \
-DWITH_QT=ON \
-DWITH_GTK=OFF \
-DWITH_WAYLAND=OFF \
-DWITH_FRAMEBUFFER=OFF \
-DWITH_OPENGL=OFF \
-DWITH_VTK=OFF \
-DWITH_VULKAN=OFF \
-DWITH_OPENCL=ON \
-DWITH_OPENCL_SVM=OFF \
-DWITH_OPENCLAMDFFT=OFF \
-DWITH_OPENCLAMDBLAS=OFF \
-DWITH_CUDA=OFF \
-DWITH_TBB=ON \
-DWITH_OPENMP=OFF \
-DWITH_PTHREADS_PF=ON \
-DWITH_EIGEN=ON \
-DWITH_LAPACK=ON \
-DWITH_IPP=OFF \
-DWITH_ITT=OFF \
-DWITH_ADE=OFF \
-DWITH_KLEIDICV=OFF \
-DWITH_FASTCV=OFF \
-DWITH_HALIDE=OFF \
-DWITH_OPENVINO=OFF \
-DWITH_ONNX=OFF \
-DWITH_TIMVX=OFF \
-DWITH_CANN=OFF
ninja -C build
DESTDIR=$PKG ninja -C build install
test -f "$PKG/usr/lib/libopencv_core.so"
test -f "$PKG/usr/lib/libopencv_tracking.so"
test -f "$PKG/usr/lib/pkgconfig/opencv4.pc"
test -f "$PKG/usr/include/opencv4/opencv2/core.hpp"
test -n "$(find "$PKG$_pydir" -name 'cv2*.so' | head -1)"
The switches, and why each is set:
-DOPENCV_EXTRA_MODULES_PATH="$SRC/contrib"— Configure the contrib modules fromcontrib/, into whichbuild.shmoves onlyaruco,tracking,optflow,plot,shape,superres,videostabandximgproc, so the rest ofopencv_contribis never configured. Pointing the path at the wholemodules/directory would configure every contrib module,faceamong them, whose configure downloads a landmark model.-DCPU_BASELINE=SSE2 -DCPU_BASELINE_DISABLE=SSE3— Compile the whole library for the x86-64 baseline instructions only. Upstream’s default baseline on x86-64 is SSE3, which a program would then require of the processor; the faster SSE4, AVX, AVX2 and AVX-512 kernels stay in the dispatch list and are chosen at run time on a processor that has them.-DCMAKE_SKIP_INSTALL_RPATH=ON— Install the libraries and programs without a run path; they are in/usr/lib.-DOPENCV_GENERATE_PKGCONFIG=ON— Installopencv4.pc, through which meson and autotools consumers find OpenCV. Upstream leaves it off.-DOPENCV_GENERATE_SETUPVARS=OFF— Do not installsetup_vars_opencv4.sh, a shell script that sets the environment variables for using the install; with everything under/usr, none is needed.-DOPENCV_ENABLE_NONFREE=OFF— Leave out the algorithms upstream marks non-free (patented).-DBUILD_opencv_apps=ON— Install theopencv_*command-line tools (opencv_version,opencv_annotation,opencv_interactive-calibrationand others).-DBUILD_opencv_gapi=OFF,-DWITH_ADE=OFF— The G-API graph module, which needs the ADE library that OpenCV downloads at configure time.-DBUILD_opencv_python3=ON,-DPYTHON3_EXECUTABLE=/usr/bin/python3— Build thecv2module for thepython3port, against numpy.-DOPENCV_SKIP_PYTHON_LOADER=ON,-DOPENCV_PYTHON3_INSTALL_PATH="$_pydir"— Install the compiledcv2extension straight intosite-packages($_pydir, read from Python’s ownsysconfig), instead of OpenCV’s loader package, acv2/directory of Python files that finds the binary through a generated configuration.-DBUILD_opencv_python2=OFF,-DBUILD_JAVA=OFF,-DBUILD_opencv_js=OFF— No Python 2, Java or JavaScript bindings.-DBUILD_ZLIB=OFF,-DBUILD_JPEG=OFF,-DBUILD_PNG=OFF,-DBUILD_TIFF=OFF,-DBUILD_WEBP=OFF,-DBUILD_OPENJPEG=OFF,-DBUILD_OPENEXR=OFF,-DBUILD_JASPER=OFF,-DBUILD_TBB=OFF— Never compile the copies under3rdparty/; every codec that is enabled, and TBB, comes from its port independs.-DBUILD_IPP_IW=OFF,-DWITH_IPP=OFF,-DBUILD_ITT=OFF,-DWITH_ITT=OFF— Intel’s IPP primitives, a prebuilt binary OpenCV downloads at configure, and the ITT tracing hooks.-DBUILD_PROTOBUF=ON,-DPROTOBUF_UPDATE_FILES=OFF,-DWITH_PROTOBUF=ON— The DNN module’s model importers use the protobuf runtime OpenCV carries in3rdparty/protobuf, linked intolibopencv_dnn, together with the.pb.ccfiles upstream generated against that copy. Building against the protobuf port instead would need the generated files regenerated with itsprotoc(PROTOBUF_UPDATE_FILES=ON), which upstream’s build refuses to combine with the bundled runtime.-DWITH_FLATBUFFERS=ON— The TFLite importer of the DNN module, through the header-only FlatBuffers copy in3rdparty/; FlatBuffers is not a port.-DWITH_QUIRC=ON— QR-code decoding through the quirc copy in3rdparty/; quirc is not a port. Upstream leaves it off.-DWITH_JPEG=ON,-DWITH_PNG=ON,-DWITH_TIFF=ON,-DWITH_WEBP=ON,-DWITH_OPENJPEG=ON,-DWITH_OPENEXR=ON,-DWITH_AVIF=ON,-DWITH_JPEGXL=ON— Image codecs, each through its port.-DWITH_SPNG=OFF,-DWITH_JASPER=OFF— The second PNG and JPEG 2000 readers; PNG goes through libpng and JPEG 2000 through openjpeg.-DWITH_GDAL=OFF,-DWITH_GDCM=OFF— Geospatial rasters through GDAL and DICOM through GDCM. gdal is a port but not independs; GDCM is not a port.-DWITH_FFMPEG=ON,-DWITH_GSTREAMER=ON,-DWITH_V4L=ON— Video input and output through ffmpeg and gstreamer, and cameras through V4L2.-DWITH_VA=ON,-DWITH_VA_INTEL=OFF— VA-API hardware decoding through libva, without the Intel-specific VA-API/OpenCL interoperability.-DWITH_1394=OFF,-DWITH_GPHOTO2=OFF,-DWITH_OPENNI2=OFF,-DWITH_OBSENSOR=OFF,-DWITH_PVAPI=OFF,-DWITH_ARAVIS=OFF,-DWITH_XIMEA=OFF,-DWITH_UEYE=OFF— The FireWire, gPhoto2, OpenNI 2, Orbbec, Prosilica, GenICam (Aravis), XIMEA and IDS uEye camera backends. On Linux the Orbbec backend needs only the V4L2 headers and is on by default; the libraries the others need are not ports, apart from libgphoto2, which is not independs.-DWITH_QT=ON,-DWITH_GTK=OFF,-DWITH_WAYLAND=OFF,-DWITH_FRAMEBUFFER=OFF— HighGUI, theimshowwindow, draws through qt6-qtbase; the GTK backend, OpenCV’s own Wayland backend and the framebuffer backend are left out.-DWITH_OPENGL=OFF,-DWITH_VTK=OFF,-DWITH_VULKAN=OFF— OpenGL windows in HighGUI, thevizmodule (VTK) and the Vulkan DNN backend.-DWITH_OPENCL=ON— The OpenCL acceleration (cv::UMat), which OpenCV loads at run time, so a machine with no OpenCL driver runs the CPU paths.-DWITH_OPENCL_SVM=OFF,-DWITH_OPENCLAMDFFT=OFF,-DWITH_OPENCLAMDBLAS=OFF— OpenCL shared virtual memory, and AMD’s clFFT and clBLAS libraries, which are not ports.-DWITH_CUDA=OFF— NVIDIA CUDA, whose toolkit is not a port.-DWITH_TBB=ON,-DWITH_OPENMP=OFF,-DWITH_PTHREADS_PF=ON— Parallel loops run on onetbb; OpenCV uses one parallel framework, and the pthreads one is its fallback.-DWITH_EIGEN=ON,-DWITH_LAPACK=ON— eigen for some solvers, and LAPACK through openblas.-DWITH_KLEIDICV=OFF,-DWITH_FASTCV=OFF— Arm’s KleidiCV, whose source OpenCV downloads at configure time, and Qualcomm’s FastCV, a prebuilt library it downloads; both are Arm-only HAL backends.-DWITH_HALIDE=OFF,-DWITH_OPENVINO=OFF,-DWITH_ONNX=OFF,-DWITH_TIMVX=OFF,-DWITH_CANN=OFF— Further DNN backends: Halide, OpenVINO, ONNX Runtime, TIM-VX and Huawei CANN. onnxruntime is a port but not independs; the rest are not ports.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/opencv, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf opencv-4.14.0-2.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/opencv, and runs the triggers its paths call for.
Contents
Installed programs: opencv_annotation, opencv_interactive-calibration, opencv_model_diagnostics, opencv_version, opencv_visualisation.
Installed libraries: libopencv_aruco.so, libopencv_calib3d.so, libopencv_core.so, libopencv_dnn.so, libopencv_features2d.so, libopencv_flann.so, libopencv_highgui.so, libopencv_imgcodecs.so, libopencv_imgproc.so, libopencv_ml.so, libopencv_objdetect.so, libopencv_optflow.so, libopencv_photo.so, libopencv_plot.so, libopencv_shape.so, libopencv_stitching.so, libopencv_superres.so, libopencv_tracking.so, libopencv_video.so, libopencv_videoio.so, libopencv_videostab.so, libopencv_ximgproc.so.
Installed directories: /usr/include/opencv4, /usr/lib/cmake/opencv4, /usr/share/licenses/opencv, /usr/share/licenses/opencv4, /usr/share/opencv4.
Short descriptions
opencv4.pc |
Open Source Computer Vision Library |
Notes
The two tarballs unpack side by side under $SRC_ROOT; build.sh runs in the OpenCV tree and moves the eight contrib modules out of opencv_contrib-<version>/modules/ into contrib/. Both tarballs carry the same version, and a bump must move both sha256 lines together, or the contrib modules are built against a core they were not released with.
The test lines after the install stop the build unless the core and tracking libraries, opencv4.pc, the headers and the cv2 extension are all in the package, so a contrib module or the Python binding that CMake quietly dropped cannot ship.