[OpenCV] disable LTO for MacOS Cocoa backend for HighGUI (#10423)
- objc targets don't play nicely with LTO from non-xcode toolchains
(e.g. hermetic LLVM)
diff --git a/modules/opencv/5.0.0.bcr.6/MODULE.bazel b/modules/opencv/5.0.0.bcr.6/MODULE.bazel
new file mode 100644
index 0000000..72bdd7d
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/MODULE.bazel
@@ -0,0 +1,41 @@
+module(
+ name = "opencv",
+ version = "5.0.0.bcr.6",
+ bazel_compatibility = [">=8.0.0"],
+ compatibility_level = 0,
+)
+
+bazel_dep(name = "apple_support", version = "2.8.1")
+bazel_dep(name = "bazel_skylib", version = "1.9.2")
+bazel_dep(name = "cpu_features", version = "0.11.0.bcr.1")
+bazel_dep(name = "eigen", version = "5.0.1.bcr.2")
+bazel_dep(name = "libjpeg_turbo", version = "3.1.3.bcr.6")
+bazel_dep(name = "libpng", version = "1.6.58")
+bazel_dep(name = "libtiff", version = "4.7.2.bcr.1")
+bazel_dep(name = "libwebp", version = "1.6.0.bcr.1")
+bazel_dep(name = "platforms", version = "1.1.0")
+bazel_dep(name = "protobuf", version = "36.0.bcr.1")
+bazel_dep(name = "rules_cc", version = "0.2.22")
+bazel_dep(name = "rules_license", version = "1.0.0")
+bazel_dep(name = "rules_python", version = "2.3.2")
+bazel_dep(name = "rules_qt", version = "0.0.7")
+bazel_dep(name = "zlib", version = "1.3.2")
+
+python = use_extension("@rules_python//python/extensions:python.bzl", "python")
+python.toolchain(python_version = "3.14")
+
+rules_qt_fetch = use_extension("@rules_qt//extension:qt.bzl", "fetch")
+rules_qt_fetch.install(
+ name = "qt_mac_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/mac_aarch64.BUILD",
+ os = "macos",
+ version = "6.8.3",
+)
+rules_qt_fetch.install(
+ name = "qt_windows_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/windows_x86_64.BUILD",
+ os = "windows",
+ version = "6.8.3",
+ windows_architecture = "win64_msvc2022",
+)
+use_repo(rules_qt_fetch, "qt_linux_x86_64", "qt_linux_aarch64", "qt_mac_aarch64", "qt_mac_x86_64", "qt_windows_x86_64")
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/BUILD.bazel b/modules/opencv/5.0.0.bcr.6/overlay/BUILD.bazel
new file mode 100644
index 0000000..653b00f
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/BUILD.bazel
@@ -0,0 +1,1270 @@
+load("@bazel_skylib//lib:selects.bzl", "selects")
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
+load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
+load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
+load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
+load("@protobuf//bazel:proto_library.bzl", "proto_library")
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+load("@rules_cc//cc:objc_library.bzl", "objc_library")
+load("@rules_license//rules:license.bzl", "license")
+load("@rules_python//python:py_binary.bzl", "py_binary")
+load("@rules_qt//:qt.bzl", "qt_cc_library")
+load(":utils.bzl", "blob2hdr")
+
+load(
+ "//:opencv.bzl",
+ "CONFIG_DESKTOP",
+ "CONFIG_NON_DESKTOP",
+ "ENABLED_OPTS",
+ "OPENCV_COPTS",
+ "OPENCV_OPTIMIZATION_COPTS",
+ "opencv_module",
+)
+
+package(
+ default_applicable_licenses = [":license"],
+)
+
+license(
+ name = "license",
+ license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"],
+ license_text = "LICENSE",
+)
+
+exports_files([
+ "LICENSE",
+])
+
+py_binary(
+ name = "blob2hdr",
+ srcs = ["blob2hdr.py"],
+ visibility = ["//visibility:public"],
+)
+
+write_file(
+ name = "_private/version_string.inc",
+ out = "private/version_string.inc",
+ content = ["\"5.0.0\""],
+)
+
+write_file(
+ name = "_opencv2/opencv_modules_desktop.hpp",
+ out = "opencv2/opencv_modules_desktop.hpp",
+ content = ["".join([
+ "#define HAVE_OPENCV_{}\n".format(x.upper())
+ for x in CONFIG_DESKTOP["modules"]
+ ])],
+)
+
+write_file(
+ name = "_opencv2/opencv_modules_non_desktop.hpp",
+ out = "opencv2/opencv_modules_non_desktop.hpp",
+ content = ["".join([
+ "#define HAVE_OPENCV_{}\n".format(x.upper())
+ for x in CONFIG_NON_DESKTOP["modules"]
+ ])],
+)
+
+copy_file(
+ name = "generate_opencv_modules_hpp",
+ src = select({
+ "@platforms//os:linux": "opencv2/opencv_modules_desktop.hpp",
+ "@platforms//os:macos": "opencv2/opencv_modules_desktop.hpp",
+ "@platforms//os:windows": "opencv2/opencv_modules_desktop.hpp",
+ "//conditions:default": "opencv2/opencv_modules_non_desktop.hpp",
+ }),
+ out = "opencv2/opencv_modules.hpp",
+)
+
+write_file(
+ name = "_custom_hal.hpp",
+ out = "custom_hal.hpp",
+ content = [
+ "#ifndef _CUSTOM_HAL_INCLUDED_",
+ "#define _CUSTOM_HAL_INCLUDED_",
+ "#endif",
+ ],
+)
+
+write_file(
+ name = "_opencv_data_config.hpp",
+ out = "opencv_data_config.hpp",
+ content = [
+ "#define OPENCV_INSTALL_PREFIX \"\"",
+ "#define OPENCV_DATA_INSTALL_PATH \"\"",
+ "#define OPENCV_BUILD_DIR \"\"",
+ "#define OPENCV_DATA_BUILD_DIR_SEARCH_PATHS \"\"",
+ "#define OPENCV_INSTALL_DATA_DIR_RELATIVE \"\"",
+ ],
+)
+
+[
+ write_file(
+ name = "_bazel-config/cv_cpu_config-{}.h".format(arch),
+ out = "bazel-config/cv_cpu_config-{}.h".format(arch),
+ content = [
+ "// OpenCV CPU baseline features\n",
+ ] + [
+ "#define CV_CPU_COMPILE_{} 1\n#define CV_CPU_BASELINE_COMPILE_{} 1\n".format(arch.upper(), arch.upper())
+ for arch in config.get("baseline", [])
+ ] + [
+ "#define CV_CPU_BASELINE_FEATURES 0 \\",
+ ] + [
+ " , CV_CPU_{} \\".format(arch.upper())
+ for arch in config.get("baseline", [])
+ ] + [
+ "\n",
+ "// OpenCV supported CPU dispathed features\n",
+ ] + [
+ "#define CV_CPU_DISPATCH_COMPILE_{} 1".format(arch.upper())
+ for arch in config.get("dispatch", [])
+ ] + [
+ "\n#define CV_CPU_DISPATCH_FEATURES 0 \\",
+ ] + [
+ " , CV_CPU_{} \\".format(arch.upper())
+ for arch in config.get("dispatch", [])
+ ] + [
+ "\n",
+ ],
+ ) for arch, config in ENABLED_OPTS.items()
+]
+
+write_file(
+ name = "_bazel-config/cv_cpu_config_no_baseline.h",
+ out = "bazel-config/cv_cpu_config_no_baseline.h",
+ content = [
+ "// OpenCV CPU baseline features\n",
+ "#define CV_CPU_BASELINE_FEATURES 0\n",
+ "// OpenCV supported CPU dispathed features\n",
+ "#define CV_CPU_DISPATCH_FEATURES 0\n",
+ ],
+)
+
+copy_file(
+ name = "_cv_cpu_config.h",
+ out = "cv_cpu_config.h",
+ src = select({
+ "@platforms//cpu:arm64": "bazel-config/cv_cpu_config-arm64.h",
+ "@platforms//cpu:armv7": "bazel-config/cv_cpu_config-armv7.h",
+ "@platforms//cpu:x86_64": "bazel-config/cv_cpu_config-x86_64.h",
+ "@platforms//cpu:mips64": "bazel-config/cv_cpu_config-mips64.h",
+ "@platforms//cpu:ppc64le": "bazel-config/cv_cpu_config-ppc64le.h",
+ "@platforms//cpu:riscv64": "bazel-config/cv_cpu_config-riscv64.h",
+ # LoongArch is not yet supported in the official platforms repo
+ # "@platforms//cpu:loongarch64": "bazel-config/cv_cpu_config-loongarch64.h",
+ "//conditions:default": "bazel-config/cv_cpu_config_no_baseline.h",
+ }),
+)
+
+# Opencv has a lot of options to enable certain features
+# Leverage this, cv_cpu_config.h, and cpu opts to enable these features
+expand_template(
+ name = "expand_cvconfig.h.in",
+ out = "cvconfig.h",
+ substitutions = {
+ # Don't include line endings in these substitutions. This preserves either
+ # LF or CRLF from the template and makes expansion host-independent.
+ # Keep markers with a shared prefix ordered from longest to shortest.
+ "#cmakedefine BUILD_SHARED_LIBS": "/* #undef BUILD_SHARED_LIBS */",
+ "#cmakedefine CV_ENABLE_INTRINSICS": "#define CV_ENABLE_INTRINSICS",
+ "#cmakedefine CV_DISABLE_OPTIMIZATION": "/* #undef CV_DISABLE_OPTIMIZATION */",
+ "${OPENCV_CUDA_ARCH_BIN}": "",
+ "${OPENCV_CUDA_ARCH_FEATURES}": "",
+ "${OPENCV_CUDA_ARCH_PTX}": "",
+ "#cmakedefine HAVE_CLAMDBLAS": "/* #undef HAVE_CLAMDBLAS */",
+ "#cmakedefine HAVE_CLAMDFFT": "/* #undef HAVE_CLAMDFFT */",
+ "#cmakedefine HAVE_CLP": "/* #undef HAVE_CLP */",
+ "#cmakedefine HAVE_CUDA": "/* #undef HAVE_CUDA */",
+ "#cmakedefine HAVE_CUBLAS": "/* #undef HAVE_CUBLAS */",
+ "#cmakedefine HAVE_CUDNN": "/* #undef HAVE_CUDNN */",
+ "#cmakedefine HAVE_CUFFT": "/* #undef HAVE_CUFFT */",
+ "#cmakedefine HAVE_DIRECTX_NV12": "/* #undef HAVE_DIRECTX_NV12 */",
+ "#cmakedefine HAVE_DIRECTX": "/* #undef HAVE_DIRECTX */",
+ "#cmakedefine HAVE_D3D11": "/* #undef HAVE_D3D11 */",
+ "#cmakedefine HAVE_D3D10": "/* #undef HAVE_D3D10 */",
+ "#cmakedefine HAVE_D3D9": "/* #undef HAVE_D3D9 */",
+ "#cmakedefine HAVE_GDAL": "/* #undef HAVE_GDAL */",
+ "#cmakedefine HAVE_VULKAN": "/* #undef HAVE_VULKAN */",
+ "#cmakedefine HAVE_INTTYPES_H 1": "/* #undef HAVE_INTTYPES_H */",
+ "#cmakedefine HAVE_IPP_IW_LL": "/* #undef HAVE_IPP_IW_LL */",
+ "#cmakedefine HAVE_IPP_ICV": "/* #undef HAVE_IPP_ICV */",
+ "#cmakedefine HAVE_IPP_IW": "/* #undef HAVE_IPP_IW */",
+ "#cmakedefine HAVE_IPP_A": "/* #undef HAVE_IPP_A */",
+ "#cmakedefine HAVE_IPP": "/* #undef HAVE_IPP */",
+ "#cmakedefine HAVE_OPENJPEG": "/* #undef HAVE_OPENJPEG */",
+ "#cmakedefine HAVE_JASPER": "/* #undef HAVE_JASPER */",
+ "#cmakedefine HAVE_AVIF": "/* #undef HAVE_AVIF */",
+ "#cmakedefine HAVE_JPEGXL": "/* #undef HAVE_JPEGXL */",
+ "#cmakedefine HAVE_JPEG": "#define HAVE_JPEG 1",
+ "#cmakedefine HAVE_GDCM": "/* #undef HAVE_GDCM */",
+ "#cmakedefine HAVE_DYNLINK_NVCUVID_HEADER": "/* #undef HAVE_DYNLINK_NVCUVID_HEADER */",
+ "#cmakedefine HAVE_NVCUVID_HEADER": "/* #undef HAVE_NVCUVID_HEADER */",
+ "#cmakedefine HAVE_NVCUVID": "/* #undef HAVE_NVCUVID */",
+ "#cmakedefine HAVE_NVCUVENC": "/* #undef HAVE_NVCUVENC */",
+ "#cmakedefine HAVE_OPENCL_D3D11_NV": "/* #undef HAVE_OPENCL_D3D11_NV */",
+ "#cmakedefine HAVE_OPENCL_STATIC": "/* #undef HAVE_OPENCL_STATIC */",
+ "#cmakedefine HAVE_OPENCL_SVM": "/* #undef HAVE_OPENCL_SVM */",
+ "#cmakedefine HAVE_OPENCL": "/* #undef HAVE_OPENCL */",
+ "#cmakedefine HAVE_OPENEXR": "/* #undef HAVE_OPENEXR */",
+ "#cmakedefine HAVE_OPENGL": "/* #undef HAVE_OPENGL */",
+ "#cmakedefine HAVE_PNG": "#define HAVE_PNG 1",
+ "#cmakedefine HAVE_SPNG": "/* #undef HAVE_SPNG */",
+ "#cmakedefine HAVE_TBB": "/* #undef HAVE_TBB */",
+ "#cmakedefine HAVE_HPX": "/* #undef HAVE_HPX */",
+ "#cmakedefine HAVE_TIFF": "#define HAVE_TIFF 1",
+ "#cmakedefine WORDS_BIGENDIAN": "/* #undef WORDS_BIGENDIAN */",
+ "#cmakedefine HAVE_VA_INTEL": "/* #undef HAVE_VA_INTEL */",
+ "#cmakedefine HAVE_VA": "/* #undef HAVE_VA */",
+ "#cmakedefine HAVE_LAPACK": "/* #undef HAVE_LAPACK */",
+ "#cmakedefine ENABLE_INSTRUMENTATION": "/* #undef ENABLE_INSTRUMENTATION */",
+ "#cmakedefine OPENCV_TRACE": "/* #undef OPENCV_TRACE */",
+ "#cmakedefine HAVE_UNIFONT": "/* undef HAVE_UNIFONT */",
+ } | select({
+ "@platforms//os:windows": {
+ "#cmakedefine HAVE_PTHREADS_PF": "/* #undef HAVE_PTHREADS_PF */",
+ "#cmakedefine HAVE_PTHREAD": "/* #undef HAVE_PTHREAD */",
+ },
+ "//conditions:default": {
+ "#cmakedefine HAVE_PTHREADS_PF": "#define HAVE_PTHREADS_PF",
+ "#cmakedefine HAVE_PTHREAD": "#define HAVE_PTHREAD",
+ },
+ }) | select({
+ ":have_eigen": {
+ "#cmakedefine HAVE_EIGEN": "#define HAVE_EIGEN 1",
+ },
+ "//conditions:default": {
+ "#cmakedefine HAVE_EIGEN": "/* #undef HAVE_EIGEN */",
+ },
+ }),
+ template = "@opencv//:cmake/templates/cvconfig.h.in",
+)
+
+cc_library(
+ name = "_base_headers",
+ hdrs = [
+ "custom_hal.hpp",
+ "cv_cpu_config.h",
+ "cvconfig.h",
+ "opencv2/opencv_modules.hpp",
+ "opencv_data_config.hpp",
+ "include/opencv2/opencv.hpp",
+ ],
+ includes = [
+ "opencv2",
+ "private",
+ "include",
+ ],
+ textual_hdrs = [
+ "private/version_string.inc",
+ ],
+ defines = select({
+ ":emscripten_with_simd": ["CV_WASM_SIMD=1"],
+ "@platforms//os:emscripten": ["CV_FORCE_SIMD128_CPP=1"], # Use CPP SIMD emulation on Emscripten when WASM SIMD is not available
+ "//conditions:default": [],
+ })
+)
+
+cc_library(
+ name = "opencv",
+ deps = selects.with_or({
+ ("@platforms//os:linux", "@platforms//os:macos", "@platforms//os:windows"): [":" + module for module in CONFIG_DESKTOP["modules"]],
+ "//conditions:default": [":" + module for module in CONFIG_NON_DESKTOP["modules"]],
+ }),
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "cpufeatures_android",
+ hdrs = ["3rdparty/cpufeatures/cpu-features.h"],
+ strip_include_prefix = "3rdparty/cpufeatures",
+ deps = [
+ "@cpu_features//:ndk_compat",
+ ],
+ target_compatible_with = ["@platforms//os:android"],
+)
+
+opencv_module(
+ name = "calib",
+ cl_copts = [],
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ ],
+ deps = [
+ ":imgproc",
+ ":objdetect",
+ ":flann",
+ ":geometry",
+ ":stereo",
+ ],
+)
+
+opencv_module(
+ name = "core",
+ dispatched_files = {
+ "mathfuncs_core": [
+ "sse2",
+ "avx",
+ "avx2",
+ "lasx",
+ ],
+ "stat": [
+ "sse4_2",
+ "avx2",
+ "lasx",
+ ],
+ "arithm": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "vsx3",
+ "lasx",
+ ],
+ "convert": [
+ "sse2",
+ "avx2",
+ "vsx3",
+ "lasx",
+ ],
+ "convert_scale": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "count_non_zero": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "has_non_zero": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "matmul": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "avx512_skx",
+ "neon_dotprod",
+ "lasx",
+ ],
+ "mean": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "merge": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "minmax": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "vsx3",
+ "lasx",
+ ],
+ "nan_mask": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "split": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "sum": [
+ "sse2",
+ "avx2",
+ "lasx",
+ ],
+ "reduce": [
+ "sse2",
+ "ssse3",
+ "avx2",
+ "neon_dotprod",
+ ],
+ "norm": [
+ "sse2",
+ "sse4_1",
+ "avx",
+ "avx2",
+ "neon_dotprod",
+ "lasx",
+ ],
+ "transpose": [
+ "avx",
+ "avx2",
+ "neon",
+ "rvv",
+ "lasx",
+ ],
+ },
+ linkopts = select({
+ "@platforms//os:linux": ["-ldl", "-lpthread", "-lrt"],
+ "@platforms//os:windows": ["ole32.lib"],
+ "//conditions:default": [],
+ }),
+ local_defines = select({
+ ":have_allocator_stats": [],
+ "//conditions:default": [
+ "OPENCV_DISABLE_ALLOCATOR_STATS=1"
+ ],
+ }) + select({
+ "@platforms//os:android": [
+ "HAVE_CPUFEATURES=1",
+ ],
+ "//conditions:default": [],
+ }) + selects.with_or({
+ "@platforms//os:windows": [
+ "HAVE_WIN32_ALIGNED_MALLOC=1",
+ ],
+ ("@platforms//os:macos", "@platforms//os:ios"): [
+ "HAVE_POSIX_MEMALIGN=1",
+ ],
+ ("@platforms//os:android", "@platforms//os:linux", "@platforms//os:emscripten"): [
+ "HAVE_POSIX_MEMALIGN=1",
+ "HAVE_MALLOC_H=1",
+ "HAVE_MEMALIGN=1",
+ ],
+ "//conditions:default": [ ],
+ }),
+ deps = [
+ "@zlib",
+ ] + select({
+ "@platforms//os:android": [":cpufeatures_android"],
+ "//conditions:default": [],
+ }) + select({
+ ":have_eigen": ["@eigen"],
+ "//conditions:default": [],
+ }),
+ test_srcs_excludes_globs = [
+ # test dispatching not yet implemented with bazel
+ "modules/core/test/**/test_intrin*.cpp",
+ # including private source files from src, not yet implemented with bazel
+ "modules/core/test/test_logtag*.cpp",
+ ],
+)
+
+proto_library(
+ name = "dnn_tf_msgs_proto",
+ srcs = glob([
+ "modules/dnn/src/tensorflow/**/*.proto",
+ ]),
+ strip_import_prefix = "modules/dnn/src/tensorflow",
+)
+
+cc_proto_library(
+ name = "dnn_tf_msgs",
+ deps = [ ":dnn_tf_msgs_proto" ],
+)
+
+proto_library(
+ name = "dnn_caffe_msgs_proto",
+ srcs = glob([
+ "modules/dnn/src/caffe/**/*.proto",
+ ]),
+ strip_import_prefix = "modules/dnn/src/caffe",
+)
+
+cc_proto_library(
+ name = "dnn_caffe_msgs",
+ deps = [ ":dnn_caffe_msgs_proto" ],
+)
+
+proto_library(
+ name = "dnn_onnx_msgs_proto",
+ srcs = glob([
+ "modules/dnn/src/onnx/**/*.proto",
+ ]),
+ strip_import_prefix = "modules/dnn/src/onnx",
+)
+
+cc_proto_library(
+ name = "dnn_onnx_msgs",
+ deps = [ ":dnn_onnx_msgs_proto" ],
+)
+
+opencv_module(
+ name = "dnn",
+ cl_copts = [
+ "/fp:fast",
+ ],
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ "-Wno-deprecated-volatile",
+ "-ffast-math",
+ "-fno-finite-math-only",
+ ],
+ local_defines = [
+ "HAVE_PROTOBUF=1",
+ ],
+ srcs_excludes_globs = [
+ "modules/dnn/src/ocl4dnn/**",
+ "modules/dnn/src/cuda4dnn/**",
+ ],
+ force_dispatch = True,
+ dispatched_files = {
+ "layers/layers_common": [
+ "avx",
+ "avx2",
+ "avx512_skx",
+ "rvv",
+ "lasx",
+ "neon",
+ "sve"
+ ],
+ "int8layers/layers_common": [
+ "avx2",
+ "avx512_skx",
+ "rvv",
+ "lasx",
+ "neon",
+ ],
+ "layers/cpu_kernels/conv_block": [
+ "avx",
+ "avx2",
+ "neon",
+ "neon_fp16",
+ ],
+ "layers/cpu_kernels/conv_depthwise": [
+ "avx",
+ "avx2",
+ "rvv",
+ "lasx",
+ ],
+ "layers/cpu_kernels/conv_winograd_f63": [
+ "avx",
+ "avx2",
+ "neon",
+ "neon_fp16",
+ ],
+ "layers/cpu_kernels/fast_gemm_kernels": [
+ "avx",
+ "avx2",
+ "neon",
+ "lasx",
+ ],
+ "layers/cpu_kernels/conv2_depthwise": [
+ "avx",
+ "avx2",
+ "neon",
+ "neon_fp16",
+ ],
+ "layers/cpu_kernels/conv2_kernels": [
+ "avx",
+ "avx2",
+ "neon",
+ "neon_fp16",
+ ],
+ "int8layers/conv2_int8_kernels": [
+ "avx2",
+ ],
+ "layers/cpu_kernels/activation_kernels": [
+ "avx",
+ "avx2",
+ "neon",
+ "neon_fp16",
+ ],
+ "layers/cpu_kernels/reduce2_kernels": [
+ "avx",
+ "avx2",
+ "neon",
+ "rvv",
+ "lasx",
+ ],
+ "layers/cpu_kernels/transpose_kernels": [
+ "avx",
+ "avx2",
+ "neon",
+ "rvv",
+ "lasx",
+ ],
+ "layers/cpu_kernels/gridsample_kernels": [
+ "avx",
+ "avx2",
+ "neon",
+ "rvv",
+ "lasx",
+ ],
+ "layers/cpu_kernels/nary_eltwise_kernels": [
+ "avx",
+ "avx2",
+ "neon",
+ "rvv",
+ "lasx",
+ ],
+ },
+ deps = [
+ ":core",
+ ":imgproc",
+ ":geometry",
+ ":dnn_caffe_msgs",
+ ":dnn_onnx_msgs",
+ ":dnn_tf_msgs",
+ ],
+)
+
+opencv_module(
+ name = "features",
+ cl_copts = [],
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ "-Wno-deprecated-volatile",
+ ],
+ dispatched_files = {
+ "sift": [
+ "sse4_1",
+ "avx2",
+ "avx512_skx",
+ ],
+ },
+ deps = [
+ ":imgproc",
+ ":geometry",
+ ":flann",
+ ":dnn",
+ ],
+)
+
+opencv_module(
+ name = "flann",
+ deps = [":core"],
+)
+
+opencv_module(
+ name = "geometry",
+ deps = [":flann"]
+)
+
+opencv_module(
+ name = "imgcodecs",
+ local_defines = [
+ "HAVE_IMGCODEC_PXM",
+ "HAVE_IMGCODEC_PFM",
+ "HAVE_IMGCODEC_HDR",
+ "HAVE_IMGCODEC_SUNRASTER",
+ "HAVE_IMGCODEC_GIF",
+ "HAVE_WEBP",
+ ],
+ deps = [
+ ":imgproc",
+ "@libjpeg_turbo//:jpeg",
+ "@libpng",
+ "@libtiff//:tiff",
+ "@libwebp",
+ ],
+)
+
+blob2hdr(
+ name = "imgproc-builtin-font-sans",
+ src = "modules/imgproc/fonts/Rubik.ttf.gz",
+ out = "builtin_font_sans.h",
+ cpp_variable = "OcvBuiltinFontSans",
+)
+
+blob2hdr(
+ name = "imgproc-builtin-font-italic",
+ src = "modules/imgproc/fonts/Rubik-Italic.ttf.gz",
+ out = "builtin_font_italic.h",
+ cpp_variable = "OcvBuiltinFontItalic",
+)
+
+cc_library(
+ name = "imgproc_fonts",
+ hdrs = [
+ ":imgproc-builtin-font-sans",
+ ":imgproc-builtin-font-italic",
+ ],
+)
+
+opencv_module(
+ name = "imgproc",
+ cl_copts = [],
+ copts = [
+ "-Wno-deprecated-enum-float-conversion",
+ "-Wno-deprecated-volatile",
+ ],
+ dispatched_files = {
+ "accum": [
+ "sse4_1",
+ "avx",
+ "avx2",
+ ],
+ "bilateral_filter": [
+ "sse2",
+ "avx2",
+ "avx512_skx",
+ "avx512_icl", # fails with GCC, need to test clang
+ ],
+ "box_filter": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "avx512_skx",
+ ],
+ "filter": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "color_hsv": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "color_rgb": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "color_yuv": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "median_blur": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "avx512_skx",
+ "avx512_icl",
+ ],
+ "morph": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ ],
+ "smooth": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "avx512_icl",
+ ],
+ "sumpixels": [
+ "sse2",
+ "avx2",
+ "avx512_skx",
+ ],
+ "warp_kernels": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "neon",
+ "neon_fp16",
+ "rvv",
+ "lasx",
+ ],
+ "undistort": [
+ "sse2",
+ "avx2",
+ ],
+ },
+ deps = [
+ ":core",
+ ":geometry",
+ ":imgproc_fonts",
+ ],
+)
+
+opencv_module(
+ name = "objdetect",
+ deps = [
+ ":core",
+ ":imgproc",
+ ":features",
+ ":geometry",
+ ":dnn",
+ ],
+)
+
+opencv_module(
+ name = "photo",
+ deps = [
+ ":imgproc",
+ ":geometry",
+ ],
+)
+
+opencv_module(
+ name = "ptcloud",
+ deps = [
+ ":geometry",
+ ":imgproc",
+ ":flann",
+ ],
+)
+
+opencv_module(
+ name = "stereo",
+ deps = [
+ ":imgproc",
+ ":geometry",
+ ],
+)
+
+opencv_module(
+ name = "stitching",
+ deps = [
+ ":imgproc",
+ ":features",
+ ":geometry",
+ ":flann",
+ ],
+)
+
+opencv_module(
+ name = "video",
+ dispatched_files = {
+ "lkpyramid": [
+ "sse2",
+ "sse4_1",
+ "avx2",
+ "avx512_skx",
+ "avx512_icl",
+ ],
+ },
+ deps = [
+ ":imgproc",
+ ":geometry",
+ ":features",
+ ":dnn",
+ ],
+)
+
+### DESKTOP-ONLY MODULES BELOW ###
+
+# TODO: add build flags for enabling varoious video backends on different platforms
+objc_library(
+ name = "ocv.3rdparty.avfoundation",
+ features = ["-thin_lto"],
+ srcs = select({
+ "@platforms//os:macos": [
+ "modules/videoio/src/cap_avfoundation_mac.mm",
+ ],
+ "@platforms//os:ios": [
+ "modules/videoio/src/cap_avfoundation.mm",
+ ],
+ "//conditions:default": [],
+ }),
+ hdrs = glob([
+ "modules/videoio/src/**/*.h",
+ "modules/videoio/src/**/*.hpp",
+ "modules/videoio/include/**/*.hpp",
+ "modules/videoio/include/**/*.h",
+ ]),
+ includes = [
+ "modules/videoio/include",
+ "modules/videoio/src",
+ ],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS + [
+ "-fno-objc-arc", # Disable Automatic Reference Counting, as OpenCV uses manual reference counting
+ "-fno-lto",
+ ],
+ linkopts = select({
+ "@platforms//os:macos": [
+ "-framework Cocoa",
+ "-framework Accelerate",
+ "-framework AVFoundation",
+ "-framework CoreGraphics",
+ "-framework CoreMedia",
+ "-framework CoreVideo",
+ "-framework QuartzCore",
+ ],
+ "@platforms//os:ios": [
+ "-framework AVFoundation",
+ "-framework QuartzCore",
+ ],
+ }),
+ deps = [
+ ":imgproc",
+ ":imgcodecs",
+ ],
+ target_compatible_with = select({
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "@platforms//os:ios": ["@platforms//os:ios"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+opencv_module(
+ name = "videoio",
+ deps = [
+ ":imgproc",
+ ":imgcodecs",
+ ] + select({
+ "@platforms//os:macos": [":ocv.3rdparty.avfoundation"],
+ "@platforms//os:ios": [":ocv.3rdparty.avfoundation"],
+ "//conditions:default": [],
+ }),
+ local_defines = select({
+ "@platforms//os:macos": ["HAVE_AVFOUNDATION=1"],
+ "@platforms//os:ios": ["HAVE_AVFOUNDATION=1"],
+ "@platforms//os:linux": ["HAVE_CAMV4L=1", "HAVE_CAMV4L2=1"],
+ "@platforms//os:windows": ["HAVE_DSHOW=1"],
+ "//conditions:default": [],
+ }),
+ linkopts = select({
+ "@platforms//os:windows": [
+ "ole32.lib",
+ "oleaut32.lib",
+ ],
+ "//conditions:default": [],
+ }),
+ sources = [
+ "modules/videoio/src/videoio_registry.cpp",
+ "modules/videoio/src/cap.cpp",
+ "modules/videoio/src/cap_images.cpp",
+ "modules/videoio/src/cap_mjpeg_encoder.cpp",
+ "modules/videoio/src/cap_mjpeg_decoder.cpp",
+ "modules/videoio/src/backend_plugin.cpp",
+ "modules/videoio/src/backend_static.cpp",
+ "modules/videoio/src/container_avi.cpp",
+ ] + select({
+ "@platforms//os:linux": [
+ "modules/videoio/src/cap_v4l.cpp",
+ ],
+ "@platforms//os:windows": [
+ "modules/videoio/src/cap_dshow.cpp",
+ ],
+ "//conditions:default": [],
+ }),
+ compatible_with = select({
+ "@platforms//os:linux": ["@platforms//os:linux"],
+ "@platforms//os:windows": ["@platforms//os:windows"],
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ test_enabled = False, # missing main
+)
+
+objc_library(
+ name = "ocv.3rdparty.cocoa",
+ features = ["-thin_lto"],
+ srcs = [
+ "opencv_highgui_config.hpp",
+ ] + select({
+ "@platforms//os:macos": [
+ "modules/highgui/src/window_cocoa.mm",
+ ],
+ "//conditions:default": [],
+ }),
+ hdrs = glob([
+ "modules/highgui/src/**/*.h",
+ "modules/highgui/src/**/*.hpp",
+ "modules/highgui/include/**/*.hpp",
+ ]),
+ includes = [
+ "modules/highgui/include",
+ "modules/highgui/src",
+ ],
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS + [
+ "-fno-objc-arc", # Disable Automatic Reference Counting, as OpenCV uses manual reference counting
+ "-fno-lto",
+ ],
+ linkopts = select({
+ "@platforms//os:macos": [
+ "-framework Cocoa",
+ ],
+ }),
+ deps = [
+ ":videoio",
+ ":imgcodecs",
+ ],
+ target_compatible_with = select({
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+write_file(
+ name = "_highgui_config.hpp",
+ out = "opencv_highgui_config.hpp",
+ content = select({
+ ":have_qt": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"QT\"",
+ ],
+ ":have_gtk3": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"GTK3\"",
+ ],
+ "@platforms//os:macos": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"COCOA\"",
+ ],
+ "@platforms//os:windows": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"WIN32UI\"",
+ ],
+ "//conditions:default": [
+ "#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"\"",
+ ],
+ }),
+)
+
+# NOTE: HighGUI is not a hermetic module, it depends on system-provided GUI libraries
+# Referencing of system libs based on https://stackoverflow.com/questions/51408079/how-do-i-reference-a-system-library-used-by-an-external-dependency-if-copts-does
+
+genrule(
+ name = "highgui_qrc",
+ srcs = ["modules/highgui/src/window_QT.qrc"] + glob(["modules/highgui/src/files_Qt/Material/*.png"]),
+ outs = ["qrc_window_QT.cpp"],
+ cmd = select({
+ "@rules_qt//:linux_x86_64": "$(location @qt_linux_x86_64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ "@rules_qt//:linux_aarch64": "$(location @qt_linux_aarch64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ "@rules_qt//:osx_arm64": "$(location @qt_mac_aarch64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ "@rules_qt//:osx_x86_64": "$(location @qt_mac_x86_64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ "@platforms//os:windows": "$(location @qt_windows_x86_64//:rcc) -name window_QT $(location modules/highgui/src/window_QT.qrc) -o $@",
+ }),
+ tools = select({
+ "@rules_qt//:linux_x86_64": ["@qt_linux_x86_64//:rcc"],
+ "@rules_qt//:linux_aarch64": ["@qt_linux_aarch64//:rcc"],
+ "@rules_qt//:osx_arm64": ["@qt_mac_aarch64//:rcc"],
+ "@rules_qt//:osx_x86_64": ["@qt_mac_x86_64//:rcc"],
+ "@platforms//os:windows": ["@qt_windows_x86_64//:rcc"],
+ }),
+ tags = ["local"],
+)
+
+qt_cc_library(
+ name = "highgui_qt",
+ srcs = [
+ "modules/highgui/src/window_QT.cpp",
+ ":highgui_qrc",
+ ],
+ hdrs = ["modules/highgui/src/window_QT.h"],
+ normal_hdrs = ["opencv_highgui_config.hpp"] + glob([
+ "modules/highgui/include/**/*.hpp",
+ "modules/highgui/src/**/*.hpp",
+ "modules/highgui/src/**/*.h",
+ ], exclude = ["modules/highgui/src/window_QT.h"]),
+ copts = OPENCV_COPTS + OPENCV_OPTIMIZATION_COPTS + select({
+ "@rules_cc//cc/compiler:clang-cl": [
+ "/permissive-",
+ "/std:c++17",
+ "/Zc:__cplusplus",
+ ],
+ "@rules_cc//cc/compiler:msvc-cl": [
+ "/permissive-",
+ "/std:c++17",
+ "/Zc:__cplusplus",
+ ],
+ "//conditions:default": [],
+ }),
+ includes = ["modules/highgui/include"],
+ local_defines = ["HAVE_QT=1"] + select({
+ # The prebuilt Linux Qt binaries are built with libstdc++, while
+ # consumers may use libc++. Avoid QtConcurrent's inline
+ # QUnhandledException(std::exception_ptr) ABI boundary.
+ "@platforms//os:linux": ["QT_NO_EXCEPTIONS"],
+ "//conditions:default": [],
+ }),
+ deps = [
+ ":_base_headers",
+ ":videoio",
+ ":imgcodecs",
+ "@rules_qt//:qt_widgets",
+ "@rules_qt//:qt_gui",
+ "@rules_qt//:qt_core",
+ "@rules_qt//:qt_concurrent",
+ "@rules_qt//:qt_test",
+ ],
+ target_compatible_with = select({
+ ":have_qt": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+)
+
+opencv_module(
+ name = "highgui",
+ deps = [
+ ":videoio",
+ ":imgcodecs",
+ ] + select({
+ ":have_qt": [":highgui_qt"],
+ ":have_gtk3": [":gtk3"],
+ "@platforms//os:macos": [":ocv.3rdparty.cocoa"],
+ "//conditions:default": [],
+ }),
+ local_defines = select({
+ ":have_qt": ["HAVE_QT=1"],
+ ":have_gtk3": ["HAVE_GTK3=1", "HAVE_GTK=1"],
+ "@platforms//os:macos": ["HAVE_COCOA=1"],
+ "@platforms//os:windows": ["HAVE_WIN32UI=1"],
+ "//conditions:default": [],
+ }),
+ sources = [
+ "modules/highgui/src/backend.cpp",
+ "modules/highgui/src/window.cpp",
+ "modules/highgui/src/roiSelector.cpp",
+ "opencv_highgui_config.hpp",
+ ] + select({
+ ":have_gtk3": [
+ "modules/highgui/src/window_gtk.cpp",
+ ],
+ "@platforms//os:windows": [
+ "modules/highgui/src/window_w32.cpp",
+ ],
+ "//conditions:default": [],
+ }),
+ linkopts = select({
+ "@platforms//os:windows": [
+ "user32.lib",
+ "gdi32.lib",
+ "comdlg32.lib",
+ "advapi32.lib",
+ ],
+ "//conditions:default": [],
+ }),
+ compatible_with = select({
+ "@platforms//os:linux": ["@platforms//os:linux"],
+ "@platforms//os:windows": ["@platforms//os:windows"],
+ "@platforms//os:macos": ["@platforms//os:macos"],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ test_enabled = False,
+)
+
+
+################ FLAGS and configuration settings ################
+
+
+bool_flag(
+ name = "disable_allocator_stats",
+ build_setting_default = True,
+ visibility = ["//visibility:public"],
+)
+
+config_setting(
+ name = "have_allocator_stats",
+ flag_values = {":disable_allocator_stats": "False"},
+)
+
+bool_flag(
+ name = "with_eigen",
+ build_setting_default = False,
+ visibility = ["//visibility:public"],
+)
+
+config_setting(
+ name = "have_eigen",
+ flag_values = {":with_eigen": "True"},
+)
+
+config_setting(
+ name = "debug_build",
+ values = {"compilation_mode": "dbg"},
+)
+
+# These compiler-and-mode settings specialize both debug_build and the rules_cc
+# compiler settings, avoiding an ambiguous match in OPENCV_OPTIMIZATION_COPTS.
+config_setting(
+ name = "debug_clang_cl_build",
+ flag_values = {"@rules_cc//cc/compiler:compiler": "clang-cl"},
+ values = {"compilation_mode": "dbg"},
+)
+
+config_setting(
+ name = "debug_msvc_cl_build",
+ flag_values = {"@rules_cc//cc/compiler:compiler": "msvc-cl"},
+ values = {"compilation_mode": "dbg"},
+)
+
+# Baseline SIMD copts select on both CPU and compiler. These combined settings
+# take precedence over the CPU-only branches for MSVC-compatible toolchains.
+config_setting(
+ name = "x86_64_clang_cl",
+ constraint_values = ["@platforms//cpu:x86_64"],
+ flag_values = {"@rules_cc//cc/compiler:compiler": "clang-cl"},
+)
+
+config_setting(
+ name = "x86_64_msvc_cl",
+ constraint_values = ["@platforms//cpu:x86_64"],
+ flag_values = {"@rules_cc//cc/compiler:compiler": "msvc-cl"},
+)
+
+config_setting(
+ name = "armv7_clang_cl",
+ constraint_values = ["@platforms//cpu:armv7"],
+ flag_values = {"@rules_cc//cc/compiler:compiler": "clang-cl"},
+)
+
+config_setting(
+ name = "armv7_msvc_cl",
+ constraint_values = ["@platforms//cpu:armv7"],
+ flag_values = {"@rules_cc//cc/compiler:compiler": "msvc-cl"},
+)
+
+config_setting(
+ name = "emscripten_with_simd",
+ constraint_values = [
+ "@platforms//os:emscripten",
+ ],
+ values = {
+ "features": "wasm_simd",
+ },
+)
+
+bool_flag(
+ name = "with_gtk3",
+ build_setting_default = False,
+ visibility = ["//visibility:public"],
+)
+
+config_setting(
+ name = "have_gtk3",
+ flag_values = {":with_gtk3": "True"},
+)
+
+bool_flag(
+ name = "with_qt",
+ build_setting_default = False,
+)
+
+config_setting(
+ name = "have_qt",
+ flag_values = {":with_qt": "True"},
+)
+
+# TODO: replace with BCR version of GTK3 after https://github.com/bazelbuild/bazel-central-registry/issues/6187 is resolved
+label_flag(
+ name = "gtk3",
+ build_setting_default = ":gtk3_stub",
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "gtk3_stub",
+ target_compatible_with = ["@platforms//:incompatible"],
+)
+
+################ Test support ################
+
+write_file(
+ name = "_opencv_tests_config.hpp",
+ out = "opencv_tests_config.hpp",
+ content = [
+ "#define OPENCV_INSTALL_PREFIX \"bazel-bin\"\n",
+ "\n",
+ "#define OPENCV_TEST_DATA_INSTALL_PATH \"share/opencv5/testdata\"\n",
+ ],
+)
+
+cc_library(
+ name = "test_config",
+ hdrs = [":opencv_tests_config.hpp"],
+)
+
+opencv_module(
+ name = "ts",
+ test_enabled = False,
+ deps = [
+ ":test_config",
+ ":core",
+ ":imgproc",
+ ":imgcodecs",
+ ":videoio",
+ ":highgui",
+ ],
+)
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/MODULE.bazel b/modules/opencv/5.0.0.bcr.6/overlay/MODULE.bazel
new file mode 100644
index 0000000..72bdd7d
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/MODULE.bazel
@@ -0,0 +1,41 @@
+module(
+ name = "opencv",
+ version = "5.0.0.bcr.6",
+ bazel_compatibility = [">=8.0.0"],
+ compatibility_level = 0,
+)
+
+bazel_dep(name = "apple_support", version = "2.8.1")
+bazel_dep(name = "bazel_skylib", version = "1.9.2")
+bazel_dep(name = "cpu_features", version = "0.11.0.bcr.1")
+bazel_dep(name = "eigen", version = "5.0.1.bcr.2")
+bazel_dep(name = "libjpeg_turbo", version = "3.1.3.bcr.6")
+bazel_dep(name = "libpng", version = "1.6.58")
+bazel_dep(name = "libtiff", version = "4.7.2.bcr.1")
+bazel_dep(name = "libwebp", version = "1.6.0.bcr.1")
+bazel_dep(name = "platforms", version = "1.1.0")
+bazel_dep(name = "protobuf", version = "36.0.bcr.1")
+bazel_dep(name = "rules_cc", version = "0.2.22")
+bazel_dep(name = "rules_license", version = "1.0.0")
+bazel_dep(name = "rules_python", version = "2.3.2")
+bazel_dep(name = "rules_qt", version = "0.0.7")
+bazel_dep(name = "zlib", version = "1.3.2")
+
+python = use_extension("@rules_python//python/extensions:python.bzl", "python")
+python.toolchain(python_version = "3.14")
+
+rules_qt_fetch = use_extension("@rules_qt//extension:qt.bzl", "fetch")
+rules_qt_fetch.install(
+ name = "qt_mac_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/mac_aarch64.BUILD",
+ os = "macos",
+ version = "6.8.3",
+)
+rules_qt_fetch.install(
+ name = "qt_windows_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/windows_x86_64.BUILD",
+ os = "windows",
+ version = "6.8.3",
+ windows_architecture = "win64_msvc2022",
+)
+use_repo(rules_qt_fetch, "qt_linux_x86_64", "qt_linux_aarch64", "qt_mac_aarch64", "qt_mac_x86_64", "qt_windows_x86_64")
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/blob2hdr.py b/modules/opencv/5.0.0.bcr.6/overlay/blob2hdr.py
new file mode 100644
index 0000000..c27fc43
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/blob2hdr.py
@@ -0,0 +1,43 @@
+"""Converts a binary blob file into a C header declaring a static unsigned char array.
+
+Equivalent to the CMake ocv_blob2hdr() function.
+
+Usage: blob2hdr.py <input_blob> <output_header> <cpp_variable_name>
+
+The generated header has the form:
+
+ // Auto generated file.
+ static const unsigned char <cpp_variable_name>[] =
+ {
+ 0xNN, 0xNN, ..., 0xNN,
+ ...
+ 0xNN, 0xNN, ..., 0xNN
+ };
+
+Full 16-byte lines carry a trailing ", " before the newline to match the
+CMake ocv_blob2hdr() output format; the final (possibly partial) line does not.
+"""
+
+import sys
+
+blob_path, out_path, cpp_variable = sys.argv[1], sys.argv[2], sys.argv[3]
+
+with open(blob_path, "rb") as f:
+ data = f.read()
+
+hex_bytes = ["0x{:02x}".format(b) for b in data]
+chunks = [hex_bytes[i : i + 16] for i in range(0, len(hex_bytes), 16)]
+lines = []
+for i, chunk in enumerate(chunks):
+ if i < len(chunks) - 1:
+ # Full 16-byte lines keep a trailing ", " before the newline.
+ lines.append(", ".join(chunk) + ", ")
+ else:
+ lines.append(", ".join(chunk))
+content = "\n".join(lines)
+
+with open(out_path, "w") as f:
+ f.write("// Auto generated file.\n")
+ f.write("static const unsigned char " + cpp_variable + "[] =\n{\n")
+ f.write(content)
+ f.write("\n};\n")
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/modules/dnn/src/caffe/opencv-caffe.proto b/modules/opencv/5.0.0.bcr.6/overlay/modules/dnn/src/caffe/opencv-caffe.proto
new file mode 100644
index 0000000..d540591
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/modules/dnn/src/caffe/opencv-caffe.proto
@@ -0,0 +1,1649 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//COPYRIGHT
+//
+//All contributions by the University of California:
+//Copyright (c) 2014, The Regents of the University of California (Regents)
+//All rights reserved.
+//
+//All other contributions:
+//Copyright (c) 2014, the respective contributors
+//All rights reserved.
+//
+//Caffe uses a shared copyright model: each contributor holds copyright over
+//their contributions to Caffe. The project versioning records all such
+//contribution and copyright details. If a contributor wants to further mark
+//their specific copyright on a particular contribution, they should indicate
+//their copyright solely in the commit message of the change when it is
+//committed.
+//
+//LICENSE
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions are met:
+//
+//1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+//2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+//ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+//ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+//(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+//ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+//CONTRIBUTION AGREEMENT
+//
+//By contributing to the BVLC/caffe repository through pull-request, comment,
+//or otherwise, the contributor releases their content to the
+//license and copyright terms herein.
+//
+//M*/
+
+syntax = "proto2";
+
+package opencv_caffe;
+
+// NVIDIA's Caffe feature is used to store fp16 weights, https://github.com/NVIDIA/caffe:
+// Math and storage types
+enum Type {
+ DOUBLE = 0;
+ FLOAT = 1;
+ FLOAT16 = 2;
+ INT = 3; // math not supported
+ UINT = 4; // math not supported
+}
+
+// Specifies the shape (dimensions) of a Blob.
+message BlobShape {
+ repeated int64 dim = 1 [packed = true];
+}
+
+message BlobProto {
+ optional BlobShape shape = 7;
+ repeated float data = 5 [packed = true];
+ repeated float diff = 6 [packed = true];
+ repeated double double_data = 8 [packed = true];
+ repeated double double_diff = 9 [packed = true];
+
+ // NVIDIA's Caffe fields begin.
+ optional Type raw_data_type = 10;
+ optional bytes raw_data = 12 [packed = false];
+ // NVIDIA's Caffe fields end.
+
+ // 4D dimensions -- deprecated. Use "shape" instead.
+ optional int32 num = 1 [default = 0];
+ optional int32 channels = 2 [default = 0];
+ optional int32 height = 3 [default = 0];
+ optional int32 width = 4 [default = 0];
+}
+
+// The BlobProtoVector is simply a way to pass multiple blobproto instances
+// around.
+message BlobProtoVector {
+ repeated BlobProto blobs = 1;
+}
+
+message PermuteParameter {
+ // The new orders of the axes of data. Notice it should be with
+ // in the same range as the input data, and it starts from 0.
+ // Do not provide repeated order.
+ repeated uint32 order = 1;
+}
+
+// Message that stores parameters used by NormalizeBBoxLayer
+message NormalizeBBoxParameter {
+ optional bool across_spatial = 1 [default = true];
+ // Initial value of scale. Default is 1.0 for all
+ optional FillerParameter scale_filler = 2;
+ // Whether or not scale parameters are shared across channels.
+ optional bool channel_shared = 3 [default = true];
+ // Epsilon for not dividing by zero while normalizing variance
+ optional float eps = 4 [default = 1e-10];
+}
+
+// Message that store parameters used by PriorBoxLayer
+message PriorBoxParameter {
+ // Encode/decode type.
+ enum CodeType {
+ CORNER = 1;
+ CENTER_SIZE = 2;
+ }
+ // Minimum box size (in pixels). Required!
+ repeated float min_size = 1;
+ // Maximum box size (in pixels). Required!
+ repeated float max_size = 2;
+ // Various of aspect ratios. Duplicate ratios will be ignored.
+ // If none is provided, we use default ratio 1.
+ repeated float aspect_ratio = 3;
+ // If true, will flip each aspect ratio.
+ // For example, if there is aspect ratio "r",
+ // we will generate aspect ratio "1.0/r" as well.
+ optional bool flip = 4 [default = true];
+ // If true, will clip the prior so that it is within [0, 1]
+ optional bool clip = 5 [default = true];
+ // Variance for adjusting the prior bboxes.
+ repeated float variance = 6;
+ // By default, we calculate img_height, img_width, step_x, step_y based on
+ // bottom[0] (feat) and bottom[1] (img). Unless these values are explicitly
+ // provided.
+ // Explicitly provide the img_size.
+ optional uint32 img_size = 7;
+ // Either img_size or img_h/img_w should be specified; not both.
+ optional uint32 img_h = 8;
+ optional uint32 img_w = 9;
+ // Explicitly provide the step size.
+ optional float step = 10;
+ // Either step or step_h/step_w should be specified; not both.
+ optional float step_h = 11;
+ optional float step_w = 12;
+ // Offset to the top left corner of each cell.
+ optional float offset = 13 [default = 0.5];
+ // Offset to the top corner of each cell.
+ repeated float offset_h = 14;
+ // Offset to the left corner of each cell.
+ repeated float offset_w = 15;
+ // Priox boxes width (in pixels).
+ repeated float width = 16;
+ // Priox boxes height (in pixels).
+ repeated float height = 17;
+}
+
+// Message that store parameters used by DetectionOutputLayer
+message DetectionOutputParameter {
+ // Number of classes to be predicted. Required!
+ optional uint32 num_classes = 1;
+ // If true, bounding box are shared among different classes.
+ optional bool share_location = 2 [default = true];
+ // Background label id. If there is no background class,
+ // set it as -1.
+ optional int32 background_label_id = 3 [default = 0];
+ // Parameters used for non maximum suppression.
+ optional NonMaximumSuppressionParameter nms_param = 4;
+ // Parameters used for saving detection results.
+ optional SaveOutputParameter save_output_param = 5;
+ // Type of coding method for bbox.
+ optional PriorBoxParameter.CodeType code_type = 6 [default = CORNER];
+ // If true, variance is encoded in target; otherwise we need to adjust the
+ // predicted offset accordingly.
+ optional bool variance_encoded_in_target = 8 [default = false];
+ // Number of total bboxes to be kept per image after nms step.
+ // -1 means keeping all bboxes after nms step.
+ optional int32 keep_top_k = 7 [default = -1];
+ // Only consider detections whose confidences are larger than a threshold.
+ // If not provided, consider all boxes.
+ optional float confidence_threshold = 9;
+ // If prior boxes are normalized to [0, 1] or not.
+ optional bool normalized_bbox = 10 [default = true];
+ // OpenCV custom parameter
+ optional bool clip = 1000 [default = false];
+}
+
+message Datum {
+ optional int32 channels = 1;
+ optional int32 height = 2;
+ optional int32 width = 3;
+ // the actual image data, in bytes
+ optional bytes data = 4;
+ optional int32 label = 5;
+ // Optionally, the datum could also hold float data.
+ repeated float float_data = 6;
+ // If true data contains an encoded image that need to be decoded
+ optional bool encoded = 7 [default = false];
+}
+
+message FillerParameter {
+ // The filler type.
+ optional string type = 1 [default = 'constant'];
+ optional float value = 2 [default = 0]; // the value in constant filler
+ optional float min = 3 [default = 0]; // the min value in uniform filler
+ optional float max = 4 [default = 1]; // the max value in uniform filler
+ optional float mean = 5 [default = 0]; // the mean value in Gaussian filler
+ optional float std = 6 [default = 1]; // the std value in Gaussian filler
+ // The expected number of non-zero output weights for a given input in
+ // Gaussian filler -- the default -1 means don't perform sparsification.
+ optional int32 sparse = 7 [default = -1];
+ // Normalize the filler variance by fan_in, fan_out, or their average.
+ // Applies to 'xavier' and 'msra' fillers.
+ enum VarianceNorm {
+ FAN_IN = 0;
+ FAN_OUT = 1;
+ AVERAGE = 2;
+ }
+ optional VarianceNorm variance_norm = 8 [default = FAN_IN];
+}
+
+message NetParameter {
+ optional string name = 1; // consider giving the network a name
+ // DEPRECATED. See InputParameter. The input blobs to the network.
+ repeated string input = 3;
+ // DEPRECATED. See InputParameter. The shape of the input blobs.
+ repeated BlobShape input_shape = 8;
+
+ // 4D input dimensions -- deprecated. Use "input_shape" instead.
+ // If specified, for each input blob there should be four
+ // values specifying the num, channels, height and width of the input blob.
+ // Thus, there should be a total of (4 * #input) numbers.
+ repeated int32 input_dim = 4;
+
+ // Whether the network will force every layer to carry out backward operation.
+ // If set False, then whether to carry out backward is determined
+ // automatically according to the net structure and learning rates.
+ optional bool force_backward = 5 [default = false];
+ // The current "state" of the network, including the phase, level, and stage.
+ // Some layers may be included/excluded depending on this state and the states
+ // specified in the layers' include and exclude fields.
+ optional NetState state = 6;
+
+ // Print debugging information about results while running Net::Forward,
+ // Net::Backward, and Net::Update.
+ optional bool debug_info = 7 [default = false];
+
+ // The layers that make up the net. Each of their configurations, including
+ // connectivity and behavior, is specified as a LayerParameter.
+ repeated LayerParameter layer = 100; // ID 100 so layers are printed last.
+
+ // DEPRECATED: use 'layer' instead.
+ repeated V1LayerParameter layers = 2;
+}
+
+// NOTE
+// Update the next available ID when you add a new SolverParameter field.
+//
+// SolverParameter next available ID: 41 (last added: type)
+message SolverParameter {
+ //////////////////////////////////////////////////////////////////////////////
+ // Specifying the train and test networks
+ //
+ // Exactly one train net must be specified using one of the following fields:
+ // train_net_param, train_net, net_param, net
+ // One or more test nets may be specified using any of the following fields:
+ // test_net_param, test_net, net_param, net
+ // If more than one test net field is specified (e.g., both net and
+ // test_net are specified), they will be evaluated in the field order given
+ // above: (1) test_net_param, (2) test_net, (3) net_param/net.
+ // A test_iter must be specified for each test_net.
+ // A test_level and/or a test_stage may also be specified for each test_net.
+ //////////////////////////////////////////////////////////////////////////////
+
+ // Proto filename for the train net, possibly combined with one or more
+ // test nets.
+ optional string net = 24;
+ // Inline train net param, possibly combined with one or more test nets.
+ optional NetParameter net_param = 25;
+
+ optional string train_net = 1; // Proto filename for the train net.
+ repeated string test_net = 2; // Proto filenames for the test nets.
+ optional NetParameter train_net_param = 21; // Inline train net params.
+ repeated NetParameter test_net_param = 22; // Inline test net params.
+
+ // The states for the train/test nets. Must be unspecified or
+ // specified once per net.
+ //
+ // By default, all states will have solver = true;
+ // train_state will have phase = TRAIN,
+ // and all test_state's will have phase = TEST.
+ // Other defaults are set according to the NetState defaults.
+ optional NetState train_state = 26;
+ repeated NetState test_state = 27;
+
+ // The number of iterations for each test net.
+ repeated int32 test_iter = 3;
+
+ // The number of iterations between two testing phases.
+ optional int32 test_interval = 4 [default = 0];
+ optional bool test_compute_loss = 19 [default = false];
+ // If true, run an initial test pass before the first iteration,
+ // ensuring memory availability and printing the starting value of the loss.
+ optional bool test_initialization = 32 [default = true];
+ optional float base_lr = 5; // The base learning rate
+ // the number of iterations between displaying info. If display = 0, no info
+ // will be displayed.
+ optional int32 display = 6;
+ // Display the loss averaged over the last average_loss iterations
+ optional int32 average_loss = 33 [default = 1];
+ optional int32 max_iter = 7; // the maximum number of iterations
+ // accumulate gradients over `iter_size` x `batch_size` instances
+ optional int32 iter_size = 36 [default = 1];
+
+ // The learning rate decay policy. The currently implemented learning rate
+ // policies are as follows:
+ // - fixed: always return base_lr.
+ // - step: return base_lr * gamma ^ (floor(iter / step))
+ // - exp: return base_lr * gamma ^ iter
+ // - inv: return base_lr * (1 + gamma * iter) ^ (- power)
+ // - multistep: similar to step but it allows non uniform steps defined by
+ // stepvalue
+ // - poly: the effective learning rate follows a polynomial decay, to be
+ // zero by the max_iter. return base_lr (1 - iter/max_iter) ^ (power)
+ // - sigmoid: the effective learning rate follows a sigmod decay
+ // return base_lr ( 1/(1 + exp(-gamma * (iter - stepsize))))
+ //
+ // where base_lr, max_iter, gamma, step, stepvalue and power are defined
+ // in the solver parameter protocol buffer, and iter is the current iteration.
+ optional string lr_policy = 8;
+ optional float gamma = 9; // The parameter to compute the learning rate.
+ optional float power = 10; // The parameter to compute the learning rate.
+ optional float momentum = 11; // The momentum value.
+ optional float weight_decay = 12; // The weight decay.
+ // regularization types supported: L1 and L2
+ // controlled by weight_decay
+ optional string regularization_type = 29 [default = "L2"];
+ // the stepsize for learning rate policy "step"
+ optional int32 stepsize = 13;
+ // the stepsize for learning rate policy "multistep"
+ repeated int32 stepvalue = 34;
+
+ // Set clip_gradients to >= 0 to clip parameter gradients to that L2 norm,
+ // whenever their actual L2 norm is larger.
+ optional float clip_gradients = 35 [default = -1];
+
+ optional int32 snapshot = 14 [default = 0]; // The snapshot interval
+ optional string snapshot_prefix = 15; // The prefix for the snapshot.
+ // whether to snapshot diff in the results or not. Snapshotting diff will help
+ // debugging but the final protocol buffer size will be much larger.
+ optional bool snapshot_diff = 16 [default = false];
+ enum SnapshotFormat {
+ HDF5 = 0;
+ BINARYPROTO = 1;
+ }
+ optional SnapshotFormat snapshot_format = 37 [default = BINARYPROTO];
+ // the mode solver will use: 0 for CPU and 1 for GPU. Use GPU in default.
+ enum SolverMode {
+ CPU = 0;
+ GPU = 1;
+ }
+ optional SolverMode solver_mode = 17 [default = GPU];
+ // the device_id will that be used in GPU mode. Use device_id = 0 in default.
+ optional int32 device_id = 18 [default = 0];
+ // If non-negative, the seed with which the Solver will initialize the Caffe
+ // random number generator -- useful for reproducible results. Otherwise,
+ // (and by default) initialize using a seed derived from the system clock.
+ optional int64 random_seed = 20 [default = -1];
+
+ // type of the solver
+ optional string type = 40 [default = "SGD"];
+
+ // numerical stability for RMSProp, AdaGrad and AdaDelta and Adam
+ optional float delta = 31 [default = 1e-8];
+ // parameters for the Adam solver
+ optional float momentum2 = 39 [default = 0.999];
+
+ // RMSProp decay value
+ // MeanSquare(t) = rms_decay*MeanSquare(t-1) + (1-rms_decay)*SquareGradient(t)
+ optional float rms_decay = 38 [default = 0.99];
+
+ // If true, print information about the state of the net that may help with
+ // debugging learning problems.
+ optional bool debug_info = 23 [default = false];
+
+ // If false, don't save a snapshot after training finishes.
+ optional bool snapshot_after_train = 28 [default = true];
+
+ // DEPRECATED: old solver enum types, use string instead
+ enum SolverType {
+ SGD = 0;
+ NESTEROV = 1;
+ ADAGRAD = 2;
+ RMSPROP = 3;
+ ADADELTA = 4;
+ ADAM = 5;
+ }
+ // DEPRECATED: use type instead of solver_type
+ optional SolverType solver_type = 30 [default = SGD];
+}
+
+// A message that stores the solver snapshots
+message SolverState {
+ optional int32 iter = 1; // The current iteration
+ optional string learned_net = 2; // The file that stores the learned net.
+ repeated BlobProto history = 3; // The history for sgd solvers
+ optional int32 current_step = 4 [default = 0]; // The current step for learning rate
+}
+
+enum Phase {
+ TRAIN = 0;
+ TEST = 1;
+}
+
+message NetState {
+ optional Phase phase = 1 [default = TEST];
+ optional int32 level = 2 [default = 0];
+ repeated string stage = 3;
+}
+
+message NetStateRule {
+ // Set phase to require the NetState have a particular phase (TRAIN or TEST)
+ // to meet this rule.
+ optional Phase phase = 1;
+
+ // Set the minimum and/or maximum levels in which the layer should be used.
+ // Leave undefined to meet the rule regardless of level.
+ optional int32 min_level = 2;
+ optional int32 max_level = 3;
+
+ // Customizable sets of stages to include or exclude.
+ // The net must have ALL of the specified stages and NONE of the specified
+ // "not_stage"s to meet the rule.
+ // (Use multiple NetStateRules to specify conjunctions of stages.)
+ repeated string stage = 4;
+ repeated string not_stage = 5;
+}
+
+// Specifies training parameters (multipliers on global learning constants,
+// and the name and other settings used for weight sharing).
+message ParamSpec {
+ // The names of the parameter blobs -- useful for sharing parameters among
+ // layers, but never required otherwise. To share a parameter between two
+ // layers, give it a (non-empty) name.
+ optional string name = 1;
+
+ // Whether to require shared weights to have the same shape, or just the same
+ // count -- defaults to STRICT if unspecified.
+ optional DimCheckMode share_mode = 2;
+ enum DimCheckMode {
+ // STRICT (default) requires that num, channels, height, width each match.
+ STRICT = 0;
+ // PERMISSIVE requires only the count (num*channels*height*width) to match.
+ PERMISSIVE = 1;
+ }
+
+ // The multiplier on the global learning rate for this parameter.
+ optional float lr_mult = 3 [default = 1.0];
+
+ // The multiplier on the global weight decay for this parameter.
+ optional float decay_mult = 4 [default = 1.0];
+}
+
+// NOTE
+// Update the next available ID when you add a new LayerParameter field.
+//
+// LayerParameter next available layer-specific ID: 147 (last added: recurrent_param)
+message LayerParameter {
+ optional string name = 1; // the layer name
+ optional string type = 2; // the layer type
+ repeated string bottom = 3; // the name of each bottom blob
+ repeated string top = 4; // the name of each top blob
+
+ // The train / test phase for computation.
+ optional Phase phase = 10;
+
+ // The amount of weight to assign each top blob in the objective.
+ // Each layer assigns a default value, usually of either 0 or 1,
+ // to each top blob.
+ repeated float loss_weight = 5;
+
+ // Specifies training parameters (multipliers on global learning constants,
+ // and the name and other settings used for weight sharing).
+ repeated ParamSpec param = 6;
+
+ // The blobs containing the numeric parameters of the layer.
+ repeated BlobProto blobs = 7;
+
+ // Specifies whether to backpropagate to each bottom. If unspecified,
+ // Caffe will automatically infer whether each input needs backpropagation
+ // to compute parameter gradients. If set to true for some inputs,
+ // backpropagation to those inputs is forced; if set false for some inputs,
+ // backpropagation to those inputs is skipped.
+ //
+ // The size must be either 0 or equal to the number of bottoms.
+ repeated bool propagate_down = 11;
+
+ // Rules controlling whether and when a layer is included in the network,
+ // based on the current NetState. You may specify a non-zero number of rules
+ // to include OR exclude, but not both. If no include or exclude rules are
+ // specified, the layer is always included. If the current NetState meets
+ // ANY (i.e., one or more) of the specified rules, the layer is
+ // included/excluded.
+ repeated NetStateRule include = 8;
+ repeated NetStateRule exclude = 9;
+
+ // Parameters for data pre-processing.
+ optional TransformationParameter transform_param = 100;
+
+ // Parameters shared by loss layers.
+ optional LossParameter loss_param = 101;
+
+ // Layer type-specific parameters.
+ //
+ // Note: certain layers may have more than one computational engine
+ // for their implementation. These layers include an Engine type and
+ // engine parameter for selecting the implementation.
+ // The default for the engine is set by the ENGINE switch at compile-time.
+ optional AccuracyParameter accuracy_param = 102;
+ optional ArgMaxParameter argmax_param = 103;
+ optional BatchNormParameter batch_norm_param = 139;
+ optional BiasParameter bias_param = 141;
+ optional ConcatParameter concat_param = 104;
+ optional ContrastiveLossParameter contrastive_loss_param = 105;
+ optional ConvolutionParameter convolution_param = 106;
+ optional CropParameter crop_param = 144;
+ optional DataParameter data_param = 107;
+ optional DetectionOutputParameter detection_output_param = 147;
+ optional DropoutParameter dropout_param = 108;
+ optional DummyDataParameter dummy_data_param = 109;
+ optional EltwiseParameter eltwise_param = 110;
+ optional ELUParameter elu_param = 140;
+ optional EmbedParameter embed_param = 137;
+ optional ExpParameter exp_param = 111;
+ optional FlattenParameter flatten_param = 135;
+ optional HDF5DataParameter hdf5_data_param = 112;
+ optional HDF5OutputParameter hdf5_output_param = 113;
+ optional HingeLossParameter hinge_loss_param = 114;
+ optional ImageDataParameter image_data_param = 115;
+ optional InfogainLossParameter infogain_loss_param = 116;
+ optional InnerProductParameter inner_product_param = 117;
+ optional InputParameter input_param = 143;
+ optional LogParameter log_param = 134;
+ optional LRNParameter lrn_param = 118;
+ optional MemoryDataParameter memory_data_param = 119;
+ optional MVNParameter mvn_param = 120;
+ optional NormalizeBBoxParameter norm_param = 149;
+ optional PermuteParameter permute_param = 148;
+ optional ParameterParameter parameter_param = 145;
+ optional PoolingParameter pooling_param = 121;
+ optional PowerParameter power_param = 122;
+ optional PReLUParameter prelu_param = 131;
+ optional PriorBoxParameter prior_box_param = 150;
+ optional ProposalParameter proposal_param = 201;
+ optional PSROIPoolingParameter psroi_pooling_param = 10002; // https://github.com/daijifeng001/caffe-rfcn
+ optional PythonParameter python_param = 130;
+ optional RecurrentParameter recurrent_param = 146;
+ optional ReductionParameter reduction_param = 136;
+ optional ReLUParameter relu_param = 123;
+ optional ReshapeParameter reshape_param = 133;
+ optional ROIPoolingParameter roi_pooling_param = 8266711; // https://github.com/rbgirshick/caffe-fast-rcnn/tree/fast-rcnn
+ optional ScaleParameter scale_param = 142;
+ optional SigmoidParameter sigmoid_param = 124;
+ optional SoftmaxParameter softmax_param = 125;
+ optional SPPParameter spp_param = 132;
+ optional SliceParameter slice_param = 126;
+ optional TanHParameter tanh_param = 127;
+ optional ThresholdParameter threshold_param = 128;
+ optional TileParameter tile_param = 138;
+ optional WindowDataParameter window_data_param = 129;
+}
+
+// Message that stores parameters used to apply transformation
+// to the data layer's data
+message TransformationParameter {
+ // For data pre-processing, we can do simple scaling and subtracting the
+ // data mean, if provided. Note that the mean subtraction is always carried
+ // out before scaling.
+ optional float scale = 1 [default = 1];
+ // Specify if we want to randomly mirror data.
+ optional bool mirror = 2 [default = false];
+ // Specify if we would like to randomly crop an image.
+ optional uint32 crop_size = 3 [default = 0];
+ // mean_file and mean_value cannot be specified at the same time
+ optional string mean_file = 4;
+ // if specified can be repeated once (would subtract it from all the channels)
+ // or can be repeated the same number of times as channels
+ // (would subtract them from the corresponding channel)
+ repeated float mean_value = 5;
+ // Force the decoded image to have 3 color channels.
+ optional bool force_color = 6 [default = false];
+ // Force the decoded image to have 1 color channels.
+ optional bool force_gray = 7 [default = false];
+}
+
+// Message that stores parameters shared by loss layers
+message LossParameter {
+ // If specified, ignore instances with the given label.
+ optional int32 ignore_label = 1;
+ // How to normalize the loss for loss layers that aggregate across batches,
+ // spatial dimensions, or other dimensions. Currently only implemented in
+ // SoftmaxWithLoss and SigmoidCrossEntropyLoss layers.
+ enum NormalizationMode {
+ // Divide by the number of examples in the batch times spatial dimensions.
+ // Outputs that receive the ignore label will NOT be ignored in computing
+ // the normalization factor.
+ FULL = 0;
+ // Divide by the total number of output locations that do not take the
+ // ignore_label. If ignore_label is not set, this behaves like FULL.
+ VALID = 1;
+ // Divide by the batch size.
+ BATCH_SIZE = 2;
+ // Do not normalize the loss.
+ NONE = 3;
+ }
+ // For historical reasons, the default normalization for
+ // SigmoidCrossEntropyLoss is BATCH_SIZE and *not* VALID.
+ optional NormalizationMode normalization = 3 [default = VALID];
+ // Deprecated. Ignored if normalization is specified. If normalization
+ // is not specified, then setting this to false will be equivalent to
+ // normalization = BATCH_SIZE to be consistent with previous behavior.
+ optional bool normalize = 2;
+}
+
+// Messages that store parameters used by individual layer types follow, in
+// alphabetical order.
+
+message AccuracyParameter {
+ // When computing accuracy, count as correct by comparing the true label to
+ // the top k scoring classes. By default, only compare to the top scoring
+ // class (i.e. argmax).
+ optional uint32 top_k = 1 [default = 1];
+
+ // The "label" axis of the prediction blob, whose argmax corresponds to the
+ // predicted label -- may be negative to index from the end (e.g., -1 for the
+ // last axis). For example, if axis == 1 and the predictions are
+ // (N x C x H x W), the label blob is expected to contain N*H*W ground truth
+ // labels with integer values in {0, 1, ..., C-1}.
+ optional int32 axis = 2 [default = 1];
+
+ // If specified, ignore instances with the given label.
+ optional int32 ignore_label = 3;
+}
+
+message ArgMaxParameter {
+ // If true produce pairs (argmax, maxval)
+ optional bool out_max_val = 1 [default = false];
+ optional uint32 top_k = 2 [default = 1];
+ // The axis along which to maximise -- may be negative to index from the
+ // end (e.g., -1 for the last axis).
+ // By default ArgMaxLayer maximizes over the flattened trailing dimensions
+ // for each index of the first / num dimension.
+ optional int32 axis = 3;
+}
+
+message ConcatParameter {
+ // The axis along which to concatenate -- may be negative to index from the
+ // end (e.g., -1 for the last axis). Other axes must have the
+ // same dimension for all the bottom blobs.
+ // By default, ConcatLayer concatenates blobs along the "channels" axis (1).
+ optional int32 axis = 2 [default = 1];
+
+ // DEPRECATED: alias for "axis" -- does not support negative indexing.
+ optional uint32 concat_dim = 1 [default = 1];
+}
+
+message BatchNormParameter {
+ // If false, accumulate global mean/variance values via a moving average. If
+ // true, use those accumulated values instead of computing mean/variance
+ // across the batch.
+ optional bool use_global_stats = 1;
+ // How much does the moving average decay each iteration?
+ optional float moving_average_fraction = 2 [default = .999];
+ // Small value to add to the variance estimate so that we don't divide by
+ // zero.
+ optional float eps = 3 [default = 1e-5];
+ // It true, scale and add biases. Source: https://github.com/NVIDIA/caffe/
+ optional bool scale_bias = 7 [default = false];
+}
+
+message BiasParameter {
+ // The first axis of bottom[0] (the first input Blob) along which to apply
+ // bottom[1] (the second input Blob). May be negative to index from the end
+ // (e.g., -1 for the last axis).
+ //
+ // For example, if bottom[0] is 4D with shape 100x3x40x60, the output
+ // top[0] will have the same shape, and bottom[1] may have any of the
+ // following shapes (for the given value of axis):
+ // (axis == 0 == -4) 100; 100x3; 100x3x40; 100x3x40x60
+ // (axis == 1 == -3) 3; 3x40; 3x40x60
+ // (axis == 2 == -2) 40; 40x60
+ // (axis == 3 == -1) 60
+ // Furthermore, bottom[1] may have the empty shape (regardless of the value of
+ // "axis") -- a scalar bias.
+ optional int32 axis = 1 [default = 1];
+
+ // (num_axes is ignored unless just one bottom is given and the bias is
+ // a learned parameter of the layer. Otherwise, num_axes is determined by the
+ // number of axes by the second bottom.)
+ // The number of axes of the input (bottom[0]) covered by the bias
+ // parameter, or -1 to cover all axes of bottom[0] starting from `axis`.
+ // Set num_axes := 0, to add a zero-axis Blob: a scalar.
+ optional int32 num_axes = 2 [default = 1];
+
+ // (filler is ignored unless just one bottom is given and the bias is
+ // a learned parameter of the layer.)
+ // The initialization for the learned bias parameter.
+ // Default is the zero (0) initialization, resulting in the BiasLayer
+ // initially performing the identity operation.
+ optional FillerParameter filler = 3;
+}
+
+message ContrastiveLossParameter {
+ // margin for dissimilar pair
+ optional float margin = 1 [default = 1.0];
+ // The first implementation of this cost did not exactly match the cost of
+ // Hadsell et al 2006 -- using (margin - d^2) instead of (margin - d)^2.
+ // legacy_version = false (the default) uses (margin - d)^2 as proposed in the
+ // Hadsell paper. New models should probably use this version.
+ // legacy_version = true uses (margin - d^2). This is kept to support /
+ // reproduce existing models and results
+ optional bool legacy_version = 2 [default = false];
+}
+
+message ConvolutionParameter {
+ optional uint32 num_output = 1; // The number of outputs for the layer
+ optional bool bias_term = 2 [default = true]; // whether to have bias terms
+
+ // Pad, kernel size, and stride are all given as a single value for equal
+ // dimensions in all spatial dimensions, or once per spatial dimension.
+ repeated uint32 pad = 3; // The padding size; defaults to 0
+ repeated uint32 kernel_size = 4; // The kernel size
+ repeated uint32 stride = 6; // The stride; defaults to 1
+ // Factor used to dilate the kernel, (implicitly) zero-filling the resulting
+ // holes. (Kernel dilation is sometimes referred to by its use in the
+ // algorithme à trous from Holschneider et al. 1987.)
+ repeated uint32 dilation = 18; // The dilation; defaults to 1
+
+ // For 2D convolution only, the *_h and *_w versions may also be used to
+ // specify both spatial dimensions.
+ optional uint32 pad_h = 9 [default = 0]; // The padding height (2D only)
+ optional uint32 pad_w = 10 [default = 0]; // The padding width (2D only)
+ optional uint32 kernel_h = 11; // The kernel height (2D only)
+ optional uint32 kernel_w = 12; // The kernel width (2D only)
+ optional uint32 stride_h = 13; // The stride height (2D only)
+ optional uint32 stride_w = 14; // The stride width (2D only)
+
+ optional uint32 group = 5 [default = 1]; // The group size for group conv
+
+ optional FillerParameter weight_filler = 7; // The filler for the weight
+ optional FillerParameter bias_filler = 8; // The filler for the bias
+ enum Engine {
+ DEFAULT = 0;
+ CAFFE = 1;
+ CUDNN = 2;
+ }
+ optional Engine engine = 15 [default = DEFAULT];
+
+ // The axis to interpret as "channels" when performing convolution.
+ // Preceding dimensions are treated as independent inputs;
+ // succeeding dimensions are treated as "spatial".
+ // With (N, C, H, W) inputs, and axis == 1 (the default), we perform
+ // N independent 2D convolutions, sliding C-channel (or (C/g)-channels, for
+ // groups g>1) filters across the spatial axes (H, W) of the input.
+ // With (N, C, D, H, W) inputs, and axis == 1, we perform
+ // N independent 3D convolutions, sliding (C/g)-channels
+ // filters across the spatial axes (D, H, W) of the input.
+ optional int32 axis = 16 [default = 1];
+
+ // Whether to force use of the general ND convolution, even if a specific
+ // implementation for blobs of the appropriate number of spatial dimensions
+ // is available. (Currently, there is only a 2D-specific convolution
+ // implementation; for input blobs with num_axes != 2, this option is
+ // ignored and the ND implementation will be used.)
+ optional bool force_nd_im2col = 17 [default = false];
+}
+
+message CropParameter {
+ // To crop, elements of the first bottom are selected to fit the dimensions
+ // of the second, reference bottom. The crop is configured by
+ // - the crop `axis` to pick the dimensions for cropping
+ // - the crop `offset` to set the shift for all/each dimension
+ // to align the cropped bottom with the reference bottom.
+ // All dimensions up to but excluding `axis` are preserved, while
+ // the dimensions including and trailing `axis` are cropped.
+ // If only one `offset` is set, then all dimensions are offset by this amount.
+ // Otherwise, the number of offsets must equal the number of cropped axes to
+ // shift the crop in each dimension accordingly.
+ // Note: standard dimensions are N,C,H,W so the default is a spatial crop,
+ // and `axis` may be negative to index from the end (e.g., -1 for the last
+ // axis).
+ optional int32 axis = 1 [default = 2];
+ repeated uint32 offset = 2;
+}
+
+message DataParameter {
+ enum DB {
+ LEVELDB = 0;
+ LMDB = 1;
+ }
+ // Specify the data source.
+ optional string source = 1;
+ // Specify the batch size.
+ optional uint32 batch_size = 4;
+ // The rand_skip variable is for the data layer to skip a few data points
+ // to avoid all asynchronous sgd clients to start at the same point. The skip
+ // point would be set as rand_skip * rand(0,1). Note that rand_skip should not
+ // be larger than the number of keys in the database.
+ // DEPRECATED. Each solver accesses a different subset of the database.
+ optional uint32 rand_skip = 7 [default = 0];
+ optional DB backend = 8 [default = LEVELDB];
+ // DEPRECATED. See TransformationParameter. For data pre-processing, we can do
+ // simple scaling and subtracting the data mean, if provided. Note that the
+ // mean subtraction is always carried out before scaling.
+ optional float scale = 2 [default = 1];
+ optional string mean_file = 3;
+ // DEPRECATED. See TransformationParameter. Specify if we would like to randomly
+ // crop an image.
+ optional uint32 crop_size = 5 [default = 0];
+ // DEPRECATED. See TransformationParameter. Specify if we want to randomly mirror
+ // data.
+ optional bool mirror = 6 [default = false];
+ // Force the encoded image to have 3 color channels
+ optional bool force_encoded_color = 9 [default = false];
+ // Prefetch queue (Number of batches to prefetch to host memory, increase if
+ // data access bandwidth varies).
+ optional uint32 prefetch = 10 [default = 4];
+}
+
+message NonMaximumSuppressionParameter {
+ // Threshold to be used in nms.
+ optional float nms_threshold = 1 [default = 0.3];
+ // Maximum number of results to be kept.
+ optional int32 top_k = 2;
+ // Parameter for adaptive nms.
+ optional float eta = 3 [default = 1.0];
+}
+
+message SaveOutputParameter {
+ // Output directory. If not empty, we will save the results.
+ optional string output_directory = 1;
+ // Output name prefix.
+ optional string output_name_prefix = 2;
+ // Output format.
+ // VOC - PASCAL VOC output format.
+ // COCO - MS COCO output format.
+ optional string output_format = 3;
+ // If you want to output results, must also provide the following two files.
+ // Otherwise, we will ignore saving results.
+ // label map file.
+ optional string label_map_file = 4;
+ // A file which contains a list of names and sizes with same order
+ // of the input DB. The file is in the following format:
+ // name height width
+ // ...
+ optional string name_size_file = 5;
+ // Number of test images. It can be less than the lines specified in
+ // name_size_file. For example, when we only want to evaluate on part
+ // of the test images.
+ optional uint32 num_test_image = 6;
+}
+
+message DropoutParameter {
+ optional float dropout_ratio = 1 [default = 0.5]; // dropout ratio
+ // Faster-RCNN framework's parameter.
+ // source: https://github.com/rbgirshick/caffe-fast-rcnn/tree/faster-rcnn
+ optional bool scale_train = 2 [default = true]; // scale train or test phase
+}
+
+// DummyDataLayer fills any number of arbitrarily shaped blobs with random
+// (or constant) data generated by "Fillers" (see "message FillerParameter").
+message DummyDataParameter {
+ // This layer produces N >= 1 top blobs. DummyDataParameter must specify 1 or N
+ // shape fields, and 0, 1 or N data_fillers.
+ //
+ // If 0 data_fillers are specified, ConstantFiller with a value of 0 is used.
+ // If 1 data_filler is specified, it is applied to all top blobs. If N are
+ // specified, the ith is applied to the ith top blob.
+ repeated FillerParameter data_filler = 1;
+ repeated BlobShape shape = 6;
+
+ // 4D dimensions -- deprecated. Use "shape" instead.
+ repeated uint32 num = 2;
+ repeated uint32 channels = 3;
+ repeated uint32 height = 4;
+ repeated uint32 width = 5;
+}
+
+message EltwiseParameter {
+ enum EltwiseOp {
+ PROD = 0;
+ SUM = 1;
+ MAX = 2;
+ }
+ optional EltwiseOp operation = 1 [default = SUM]; // element-wise operation
+ repeated float coeff = 2; // blob-wise coefficient for SUM operation
+
+ // Whether to use an asymptotically slower (for >2 inputs) but stabler method
+ // of computing the gradient for the PROD operation. (No effect for SUM op.)
+ optional bool stable_prod_grad = 3 [default = true];
+}
+
+// Message that stores parameters used by ELULayer
+message ELUParameter {
+ // Described in:
+ // Clevert, D.-A., Unterthiner, T., & Hochreiter, S. (2015). Fast and Accurate
+ // Deep Network Learning by Exponential Linear Units (ELUs). arXiv
+ optional float alpha = 1 [default = 1];
+}
+
+// Message that stores parameters used by EmbedLayer
+message EmbedParameter {
+ optional uint32 num_output = 1; // The number of outputs for the layer
+ // The input is given as integers to be interpreted as one-hot
+ // vector indices with dimension num_input. Hence num_input should be
+ // 1 greater than the maximum possible input value.
+ optional uint32 input_dim = 2;
+
+ optional bool bias_term = 3 [default = true]; // Whether to use a bias term
+ optional FillerParameter weight_filler = 4; // The filler for the weight
+ optional FillerParameter bias_filler = 5; // The filler for the bias
+
+}
+
+// Message that stores parameters used by ExpLayer
+message ExpParameter {
+ // ExpLayer computes outputs y = base ^ (shift + scale * x), for base > 0.
+ // Or if base is set to the default (-1), base is set to e,
+ // so y = exp(shift + scale * x).
+ optional float base = 1 [default = -1.0];
+ optional float scale = 2 [default = 1.0];
+ optional float shift = 3 [default = 0.0];
+}
+
+/// Message that stores parameters used by FlattenLayer
+message FlattenParameter {
+ // The first axis to flatten: all preceding axes are retained in the output.
+ // May be negative to index from the end (e.g., -1 for the last axis).
+ optional int32 axis = 1 [default = 1];
+
+ // The last axis to flatten: all following axes are retained in the output.
+ // May be negative to index from the end (e.g., the default -1 for the last
+ // axis).
+ optional int32 end_axis = 2 [default = -1];
+}
+
+// Message that stores parameters used by HDF5DataLayer
+message HDF5DataParameter {
+ // Specify the data source.
+ optional string source = 1;
+ // Specify the batch size.
+ optional uint32 batch_size = 2;
+
+ // Specify whether to shuffle the data.
+ // If shuffle == true, the ordering of the HDF5 files is shuffled,
+ // and the ordering of data within any given HDF5 file is shuffled,
+ // but data between different files are not interleaved; all of a file's
+ // data are output (in a random order) before moving onto another file.
+ optional bool shuffle = 3 [default = false];
+}
+
+message HDF5OutputParameter {
+ optional string file_name = 1;
+}
+
+message HingeLossParameter {
+ enum Norm {
+ L1 = 1;
+ L2 = 2;
+ }
+ // Specify the Norm to use L1 or L2
+ optional Norm norm = 1 [default = L1];
+}
+
+message ImageDataParameter {
+ // Specify the data source.
+ optional string source = 1;
+ // Specify the batch size.
+ optional uint32 batch_size = 4 [default = 1];
+ // The rand_skip variable is for the data layer to skip a few data points
+ // to avoid all asynchronous sgd clients to start at the same point. The skip
+ // point would be set as rand_skip * rand(0,1). Note that rand_skip should not
+ // be larger than the number of keys in the database.
+ optional uint32 rand_skip = 7 [default = 0];
+ // Whether or not ImageLayer should shuffle the list of files at every epoch.
+ optional bool shuffle = 8 [default = false];
+ // It will also resize images if new_height or new_width are not zero.
+ optional uint32 new_height = 9 [default = 0];
+ optional uint32 new_width = 10 [default = 0];
+ // Specify if the images are color or gray
+ optional bool is_color = 11 [default = true];
+ // DEPRECATED. See TransformationParameter. For data pre-processing, we can do
+ // simple scaling and subtracting the data mean, if provided. Note that the
+ // mean subtraction is always carried out before scaling.
+ optional float scale = 2 [default = 1];
+ optional string mean_file = 3;
+ // DEPRECATED. See TransformationParameter. Specify if we would like to randomly
+ // crop an image.
+ optional uint32 crop_size = 5 [default = 0];
+ // DEPRECATED. See TransformationParameter. Specify if we want to randomly mirror
+ // data.
+ optional bool mirror = 6 [default = false];
+ optional string root_folder = 12 [default = ""];
+}
+
+message InfogainLossParameter {
+ // Specify the infogain matrix source.
+ optional string source = 1;
+}
+
+message InnerProductParameter {
+ optional uint32 num_output = 1; // The number of outputs for the layer
+ optional bool bias_term = 2 [default = true]; // whether to have bias terms
+ optional FillerParameter weight_filler = 3; // The filler for the weight
+ optional FillerParameter bias_filler = 4; // The filler for the bias
+
+ // The first axis to be lumped into a single inner product computation;
+ // all preceding axes are retained in the output.
+ // May be negative to index from the end (e.g., -1 for the last axis).
+ optional int32 axis = 5 [default = 1];
+ // Specify whether to transpose the weight matrix or not.
+ // If transpose == true, any operations will be performed on the transpose
+ // of the weight matrix. The weight matrix itself is not going to be transposed
+ // but rather the transfer flag of operations will be toggled accordingly.
+ optional bool transpose = 6 [default = false];
+}
+
+message InputParameter {
+ // This layer produces N >= 1 top blob(s) to be assigned manually.
+ // Define N shapes to set a shape for each top.
+ // Define 1 shape to set the same shape for every top.
+ // Define no shape to defer to reshaping manually.
+ repeated BlobShape shape = 1;
+}
+
+// Message that stores parameters used by LogLayer
+message LogParameter {
+ // LogLayer computes outputs y = log_base(shift + scale * x), for base > 0.
+ // Or if base is set to the default (-1), base is set to e,
+ // so y = ln(shift + scale * x) = log_e(shift + scale * x)
+ optional float base = 1 [default = -1.0];
+ optional float scale = 2 [default = 1.0];
+ optional float shift = 3 [default = 0.0];
+}
+
+// Message that stores parameters used by LRNLayer
+message LRNParameter {
+ optional uint32 local_size = 1 [default = 5];
+ optional float alpha = 2 [default = 1.];
+ optional float beta = 3 [default = 0.75];
+ enum NormRegion {
+ ACROSS_CHANNELS = 0;
+ WITHIN_CHANNEL = 1;
+ }
+ optional NormRegion norm_region = 4 [default = ACROSS_CHANNELS];
+ optional float k = 5 [default = 1.];
+ enum Engine {
+ DEFAULT = 0;
+ CAFFE = 1;
+ CUDNN = 2;
+ }
+ optional Engine engine = 6 [default = DEFAULT];
+}
+
+message MemoryDataParameter {
+ optional uint32 batch_size = 1;
+ optional uint32 channels = 2;
+ optional uint32 height = 3;
+ optional uint32 width = 4;
+}
+
+message MVNParameter {
+ // This parameter can be set to false to normalize mean only
+ optional bool normalize_variance = 1 [default = true];
+
+ // This parameter can be set to true to perform DNN-like MVN
+ optional bool across_channels = 2 [default = false];
+
+ // Epsilon for not dividing by zero while normalizing variance
+ optional float eps = 3 [default = 1e-9];
+}
+
+message ParameterParameter {
+ optional BlobShape shape = 1;
+}
+
+message PoolingParameter {
+ enum PoolMethod {
+ MAX = 0;
+ AVE = 1;
+ STOCHASTIC = 2;
+ }
+ optional PoolMethod pool = 1 [default = MAX]; // The pooling method
+ // Pad, kernel size, and stride are all given as a single value for equal
+ // dimensions in height and width or as Y, X pairs.
+ optional uint32 pad = 4 [default = 0]; // The padding size (equal in Y, X)
+ optional uint32 pad_h = 9 [default = 0]; // The padding height
+ optional uint32 pad_w = 10 [default = 0]; // The padding width
+ optional uint32 kernel_size = 2; // The kernel size (square)
+ optional uint32 kernel_h = 5; // The kernel height
+ optional uint32 kernel_w = 6; // The kernel width
+ optional uint32 stride = 3 [default = 1]; // The stride (equal in Y, X)
+ optional uint32 stride_h = 7; // The stride height
+ optional uint32 stride_w = 8; // The stride width
+ enum Engine {
+ DEFAULT = 0;
+ CAFFE = 1;
+ CUDNN = 2;
+ }
+ optional Engine engine = 11 [default = DEFAULT];
+ // If global_pooling then it will pool over the size of the bottom by doing
+ // kernel_h = bottom->height and kernel_w = bottom->width
+ optional bool global_pooling = 12 [default = false];
+ // Specify floor/ceil mode
+ // source: https://github.com/BVLC/caffe/pull/3057
+ optional bool ceil_mode = 13 [default = true];
+}
+
+message PowerParameter {
+ // PowerLayer computes outputs y = (shift + scale * x) ^ power.
+ optional float power = 1 [default = 1.0];
+ optional float scale = 2 [default = 1.0];
+ optional float shift = 3 [default = 0.0];
+}
+
+message PythonParameter {
+ optional string module = 1;
+ optional string layer = 2;
+ // This value is set to the attribute `param_str` of the `PythonLayer` object
+ // in Python before calling the `setup()` method. This could be a number,
+ // string, dictionary in Python dict format, JSON, etc. You may parse this
+ // string in `setup` method and use it in `forward` and `backward`.
+ optional string param_str = 3 [default = ''];
+ // Whether this PythonLayer is shared among worker solvers during data parallelism.
+ // If true, each worker solver sequentially run forward from this layer.
+ // This value should be set true if you are using it as a data layer.
+ optional bool share_in_parallel = 4 [default = false];
+}
+
+// Message that stores parameters used by RecurrentLayer
+message RecurrentParameter {
+ // The dimension of the output (and usually hidden state) representation --
+ // must be explicitly set to non-zero.
+ optional uint32 num_output = 1 [default = 0];
+
+ optional FillerParameter weight_filler = 2; // The filler for the weight
+ optional FillerParameter bias_filler = 3; // The filler for the bias
+
+ // Whether to enable displaying debug_info in the unrolled recurrent net.
+ optional bool debug_info = 4 [default = false];
+
+ // Whether to add as additional inputs (bottoms) the initial hidden state
+ // blobs, and add as additional outputs (tops) the final timestep hidden state
+ // blobs. The number of additional bottom/top blobs required depends on the
+ // recurrent architecture -- e.g., 1 for RNNs, 2 for LSTMs.
+ optional bool expose_hidden = 5 [default = false];
+}
+
+// Message that stores parameters used by ReductionLayer
+message ReductionParameter {
+ enum ReductionOp {
+ SUM = 1;
+ ASUM = 2;
+ SUMSQ = 3;
+ MEAN = 4;
+ }
+
+ optional ReductionOp operation = 1 [default = SUM]; // reduction operation
+
+ // The first axis to reduce to a scalar -- may be negative to index from the
+ // end (e.g., -1 for the last axis).
+ // (Currently, only reduction along ALL "tail" axes is supported; reduction
+ // of axis M through N, where N < num_axes - 1, is unsupported.)
+ // Suppose we have an n-axis bottom Blob with shape:
+ // (d0, d1, d2, ..., d(m-1), dm, d(m+1), ..., d(n-1)).
+ // If axis == m, the output Blob will have shape
+ // (d0, d1, d2, ..., d(m-1)),
+ // and the ReductionOp operation is performed (d0 * d1 * d2 * ... * d(m-1))
+ // times, each including (dm * d(m+1) * ... * d(n-1)) individual data.
+ // If axis == 0 (the default), the output Blob always has the empty shape
+ // (count 1), performing reduction across the entire input --
+ // often useful for creating new loss functions.
+ optional int32 axis = 2 [default = 0];
+
+ optional float coeff = 3 [default = 1.0]; // coefficient for output
+}
+
+// Message that stores parameters used by ReLULayer
+message ReLUParameter {
+ // Allow non-zero slope for negative inputs to speed up optimization
+ // Described in:
+ // Maas, A. L., Hannun, A. Y., & Ng, A. Y. (2013). Rectifier nonlinearities
+ // improve neural network acoustic models. In ICML Workshop on Deep Learning
+ // for Audio, Speech, and Language Processing.
+ optional float negative_slope = 1 [default = 0];
+ enum Engine {
+ DEFAULT = 0;
+ CAFFE = 1;
+ CUDNN = 2;
+ }
+ optional Engine engine = 2 [default = DEFAULT];
+}
+
+message ReshapeParameter {
+ // Specify the output dimensions. If some of the dimensions are set to 0,
+ // the corresponding dimension from the bottom layer is used (unchanged).
+ // Exactly one dimension may be set to -1, in which case its value is
+ // inferred from the count of the bottom blob and the remaining dimensions.
+ // For example, suppose we want to reshape a 2D blob "input" with shape 2 x 8:
+ //
+ // layer {
+ // type: "Reshape" bottom: "input" top: "output"
+ // reshape_param { ... }
+ // }
+ //
+ // If "input" is 2D with shape 2 x 8, then the following reshape_param
+ // specifications are all equivalent, producing a 3D blob "output" with shape
+ // 2 x 2 x 4:
+ //
+ // reshape_param { shape { dim: 2 dim: 2 dim: 4 } }
+ // reshape_param { shape { dim: 0 dim: 2 dim: 4 } }
+ // reshape_param { shape { dim: 0 dim: 2 dim: -1 } }
+ // reshape_param { shape { dim: 0 dim:-1 dim: 4 } }
+ //
+ optional BlobShape shape = 1;
+
+ // axis and num_axes control the portion of the bottom blob's shape that are
+ // replaced by (included in) the reshape. By default (axis == 0 and
+ // num_axes == -1), the entire bottom blob shape is included in the reshape,
+ // and hence the shape field must specify the entire output shape.
+ //
+ // axis may be non-zero to retain some portion of the beginning of the input
+ // shape (and may be negative to index from the end; e.g., -1 to begin the
+ // reshape after the last axis, including nothing in the reshape,
+ // -2 to include only the last axis, etc.).
+ //
+ // For example, suppose "input" is a 2D blob with shape 2 x 8.
+ // Then the following ReshapeLayer specifications are all equivalent,
+ // producing a blob "output" with shape 2 x 2 x 4:
+ //
+ // reshape_param { shape { dim: 2 dim: 2 dim: 4 } }
+ // reshape_param { shape { dim: 2 dim: 4 } axis: 1 }
+ // reshape_param { shape { dim: 2 dim: 4 } axis: -3 }
+ //
+ // num_axes specifies the extent of the reshape.
+ // If num_axes >= 0 (and axis >= 0), the reshape will be performed only on
+ // input axes in the range [axis, axis+num_axes].
+ // num_axes may also be -1, the default, to include all remaining axes
+ // (starting from axis).
+ //
+ // For example, suppose "input" is a 2D blob with shape 2 x 8.
+ // Then the following ReshapeLayer specifications are equivalent,
+ // producing a blob "output" with shape 1 x 2 x 8.
+ //
+ // reshape_param { shape { dim: 1 dim: 2 dim: 8 } }
+ // reshape_param { shape { dim: 1 dim: 2 } num_axes: 1 }
+ // reshape_param { shape { dim: 1 } num_axes: 0 }
+ //
+ // On the other hand, these would produce output blob shape 2 x 1 x 8:
+ //
+ // reshape_param { shape { dim: 2 dim: 1 dim: 8 } }
+ // reshape_param { shape { dim: 1 } axis: 1 num_axes: 0 }
+ //
+ optional int32 axis = 2 [default = 0];
+ optional int32 num_axes = 3 [default = -1];
+}
+
+message ScaleParameter {
+ // The first axis of bottom[0] (the first input Blob) along which to apply
+ // bottom[1] (the second input Blob). May be negative to index from the end
+ // (e.g., -1 for the last axis).
+ //
+ // For example, if bottom[0] is 4D with shape 100x3x40x60, the output
+ // top[0] will have the same shape, and bottom[1] may have any of the
+ // following shapes (for the given value of axis):
+ // (axis == 0 == -4) 100; 100x3; 100x3x40; 100x3x40x60
+ // (axis == 1 == -3) 3; 3x40; 3x40x60
+ // (axis == 2 == -2) 40; 40x60
+ // (axis == 3 == -1) 60
+ // Furthermore, bottom[1] may have the empty shape (regardless of the value of
+ // "axis") -- a scalar multiplier.
+ optional int32 axis = 1 [default = 1];
+
+ // (num_axes is ignored unless just one bottom is given and the scale is
+ // a learned parameter of the layer. Otherwise, num_axes is determined by the
+ // number of axes by the second bottom.)
+ // The number of axes of the input (bottom[0]) covered by the scale
+ // parameter, or -1 to cover all axes of bottom[0] starting from `axis`.
+ // Set num_axes := 0, to multiply with a zero-axis Blob: a scalar.
+ optional int32 num_axes = 2 [default = 1];
+
+ // (filler is ignored unless just one bottom is given and the scale is
+ // a learned parameter of the layer.)
+ // The initialization for the learned scale parameter.
+ // Default is the unit (1) initialization, resulting in the ScaleLayer
+ // initially performing the identity operation.
+ optional FillerParameter filler = 3;
+
+ // Whether to also learn a bias (equivalent to a ScaleLayer+BiasLayer, but
+ // may be more efficient). Initialized with bias_filler (defaults to 0).
+ optional bool bias_term = 4 [default = false];
+ optional FillerParameter bias_filler = 5;
+}
+
+message SigmoidParameter {
+ enum Engine {
+ DEFAULT = 0;
+ CAFFE = 1;
+ CUDNN = 2;
+ }
+ optional Engine engine = 1 [default = DEFAULT];
+}
+
+message SliceParameter {
+ // The axis along which to slice -- may be negative to index from the end
+ // (e.g., -1 for the last axis).
+ // By default, SliceLayer concatenates blobs along the "channels" axis (1).
+ optional int32 axis = 3 [default = 1];
+ repeated uint32 slice_point = 2;
+
+ // DEPRECATED: alias for "axis" -- does not support negative indexing.
+ optional uint32 slice_dim = 1 [default = 1];
+}
+
+// Message that stores parameters used by SoftmaxLayer, SoftmaxWithLossLayer
+message SoftmaxParameter {
+ enum Engine {
+ DEFAULT = 0;
+ CAFFE = 1;
+ CUDNN = 2;
+ }
+ optional Engine engine = 1 [default = DEFAULT];
+
+ // The axis along which to perform the softmax -- may be negative to index
+ // from the end (e.g., -1 for the last axis).
+ // Any other axes will be evaluated as independent softmaxes.
+ optional int32 axis = 2 [default = 1];
+}
+
+message TanHParameter {
+ enum Engine {
+ DEFAULT = 0;
+ CAFFE = 1;
+ CUDNN = 2;
+ }
+ optional Engine engine = 1 [default = DEFAULT];
+}
+
+// Message that stores parameters used by TileLayer
+message TileParameter {
+ // The index of the axis to tile.
+ optional int32 axis = 1 [default = 1];
+
+ // The number of copies (tiles) of the blob to output.
+ optional int32 tiles = 2;
+}
+
+// Message that stores parameters used by ThresholdLayer
+message ThresholdParameter {
+ optional float threshold = 1 [default = 0]; // Strictly positive values
+}
+
+message WindowDataParameter {
+ // Specify the data source.
+ optional string source = 1;
+ // For data pre-processing, we can do simple scaling and subtracting the
+ // data mean, if provided. Note that the mean subtraction is always carried
+ // out before scaling.
+ optional float scale = 2 [default = 1];
+ optional string mean_file = 3;
+ // Specify the batch size.
+ optional uint32 batch_size = 4;
+ // Specify if we would like to randomly crop an image.
+ optional uint32 crop_size = 5 [default = 0];
+ // Specify if we want to randomly mirror data.
+ optional bool mirror = 6 [default = false];
+ // Foreground (object) overlap threshold
+ optional float fg_threshold = 7 [default = 0.5];
+ // Background (non-object) overlap threshold
+ optional float bg_threshold = 8 [default = 0.5];
+ // Fraction of batch that should be foreground objects
+ optional float fg_fraction = 9 [default = 0.25];
+ // Amount of contextual padding to add around a window
+ // (used only by the window_data_layer)
+ optional uint32 context_pad = 10 [default = 0];
+ // Mode for cropping out a detection window
+ // warp: cropped window is warped to a fixed size and aspect ratio
+ // square: the tightest square around the window is cropped
+ optional string crop_mode = 11 [default = "warp"];
+ // cache_images: will load all images in memory for faster access
+ optional bool cache_images = 12 [default = false];
+ // append root_folder to locate images
+ optional string root_folder = 13 [default = ""];
+}
+
+message SPPParameter {
+ enum PoolMethod {
+ MAX = 0;
+ AVE = 1;
+ STOCHASTIC = 2;
+ }
+ optional uint32 pyramid_height = 1;
+ optional PoolMethod pool = 2 [default = MAX]; // The pooling method
+ enum Engine {
+ DEFAULT = 0;
+ CAFFE = 1;
+ CUDNN = 2;
+ }
+ optional Engine engine = 6 [default = DEFAULT];
+}
+
+// DEPRECATED: use LayerParameter.
+message V1LayerParameter {
+ repeated string bottom = 2;
+ repeated string top = 3;
+ optional string name = 4;
+ repeated NetStateRule include = 32;
+ repeated NetStateRule exclude = 33;
+ enum LayerType {
+ NONE = 0;
+ ABSVAL = 35;
+ ACCURACY = 1;
+ ARGMAX = 30;
+ BNLL = 2;
+ CONCAT = 3;
+ CONTRASTIVE_LOSS = 37;
+ CONVOLUTION = 4;
+ DATA = 5;
+ DECONVOLUTION = 39;
+ DROPOUT = 6;
+ DUMMY_DATA = 32;
+ EUCLIDEAN_LOSS = 7;
+ ELTWISE = 25;
+ EXP = 38;
+ FLATTEN = 8;
+ HDF5_DATA = 9;
+ HDF5_OUTPUT = 10;
+ HINGE_LOSS = 28;
+ IM2COL = 11;
+ IMAGE_DATA = 12;
+ INFOGAIN_LOSS = 13;
+ INNER_PRODUCT = 14;
+ LRN = 15;
+ MEMORY_DATA = 29;
+ MULTINOMIAL_LOGISTIC_LOSS = 16;
+ MVN = 34;
+ POOLING = 17;
+ POWER = 26;
+ RELU = 18;
+ SIGMOID = 19;
+ SIGMOID_CROSS_ENTROPY_LOSS = 27;
+ SILENCE = 36;
+ SOFTMAX = 20;
+ SOFTMAX_LOSS = 21;
+ SPLIT = 22;
+ SLICE = 33;
+ TANH = 23;
+ WINDOW_DATA = 24;
+ THRESHOLD = 31;
+ }
+ optional LayerType type = 5;
+ repeated BlobProto blobs = 6;
+ repeated string param = 1001;
+ repeated DimCheckMode blob_share_mode = 1002;
+ enum DimCheckMode {
+ STRICT = 0;
+ PERMISSIVE = 1;
+ }
+ repeated float blobs_lr = 7;
+ repeated float weight_decay = 8;
+ repeated float loss_weight = 35;
+ optional AccuracyParameter accuracy_param = 27;
+ optional ArgMaxParameter argmax_param = 23;
+ optional ConcatParameter concat_param = 9;
+ optional ContrastiveLossParameter contrastive_loss_param = 40;
+ optional ConvolutionParameter convolution_param = 10;
+ optional DataParameter data_param = 11;
+ optional DropoutParameter dropout_param = 12;
+ optional DummyDataParameter dummy_data_param = 26;
+ optional EltwiseParameter eltwise_param = 24;
+ optional ExpParameter exp_param = 41;
+ optional HDF5DataParameter hdf5_data_param = 13;
+ optional HDF5OutputParameter hdf5_output_param = 14;
+ optional HingeLossParameter hinge_loss_param = 29;
+ optional ImageDataParameter image_data_param = 15;
+ optional InfogainLossParameter infogain_loss_param = 16;
+ optional InnerProductParameter inner_product_param = 17;
+ optional LRNParameter lrn_param = 18;
+ optional MemoryDataParameter memory_data_param = 22;
+ optional MVNParameter mvn_param = 34;
+ optional PoolingParameter pooling_param = 19;
+ optional PowerParameter power_param = 21;
+ optional ReLUParameter relu_param = 30;
+ optional SigmoidParameter sigmoid_param = 38;
+ optional SoftmaxParameter softmax_param = 39;
+ optional SliceParameter slice_param = 31;
+ optional TanHParameter tanh_param = 37;
+ optional ThresholdParameter threshold_param = 25;
+ optional WindowDataParameter window_data_param = 20;
+ optional TransformationParameter transform_param = 36;
+ optional LossParameter loss_param = 42;
+ optional V0LayerParameter layer = 1;
+}
+
+// DEPRECATED: V0LayerParameter is the old way of specifying layer parameters
+// in Caffe. We keep this message type around for legacy support.
+message V0LayerParameter {
+ optional string name = 1; // the layer name
+ optional string type = 2; // the string to specify the layer type
+
+ // Parameters to specify layers with inner products.
+ optional uint32 num_output = 3; // The number of outputs for the layer
+ optional bool biasterm = 4 [default = true]; // whether to have bias terms
+ optional FillerParameter weight_filler = 5; // The filler for the weight
+ optional FillerParameter bias_filler = 6; // The filler for the bias
+
+ optional uint32 pad = 7 [default = 0]; // The padding size
+ optional uint32 kernelsize = 8; // The kernel size
+ optional uint32 group = 9 [default = 1]; // The group size for group conv
+ optional uint32 stride = 10 [default = 1]; // The stride
+ enum PoolMethod {
+ MAX = 0;
+ AVE = 1;
+ STOCHASTIC = 2;
+ }
+ optional PoolMethod pool = 11 [default = MAX]; // The pooling method
+ optional float dropout_ratio = 12 [default = 0.5]; // dropout ratio
+
+ optional uint32 local_size = 13 [default = 5]; // for local response norm
+ optional float alpha = 14 [default = 1.]; // for local response norm
+ optional float beta = 15 [default = 0.75]; // for local response norm
+ optional float k = 22 [default = 1.];
+
+ // For data layers, specify the data source
+ optional string source = 16;
+ // For data pre-processing, we can do simple scaling and subtracting the
+ // data mean, if provided. Note that the mean subtraction is always carried
+ // out before scaling.
+ optional float scale = 17 [default = 1];
+ optional string meanfile = 18;
+ // For data layers, specify the batch size.
+ optional uint32 batchsize = 19;
+ // For data layers, specify if we would like to randomly crop an image.
+ optional uint32 cropsize = 20 [default = 0];
+ // For data layers, specify if we want to randomly mirror data.
+ optional bool mirror = 21 [default = false];
+
+ // The blobs containing the numeric parameters of the layer
+ repeated BlobProto blobs = 50;
+ // The ratio that is multiplied on the global learning rate. If you want to
+ // set the learning ratio for one blob, you need to set it for all blobs.
+ repeated float blobs_lr = 51;
+ // The weight decay that is multiplied on the global weight decay.
+ repeated float weight_decay = 52;
+
+ // The rand_skip variable is for the data layer to skip a few data points
+ // to avoid all asynchronous sgd clients to start at the same point. The skip
+ // point would be set as rand_skip * rand(0,1). Note that rand_skip should not
+ // be larger than the number of keys in the database.
+ optional uint32 rand_skip = 53 [default = 0];
+
+ // Fields related to detection (det_*)
+ // foreground (object) overlap threshold
+ optional float det_fg_threshold = 54 [default = 0.5];
+ // background (non-object) overlap threshold
+ optional float det_bg_threshold = 55 [default = 0.5];
+ // Fraction of batch that should be foreground objects
+ optional float det_fg_fraction = 56 [default = 0.25];
+
+ // optional bool OBSOLETE_can_clobber = 57 [default = true];
+
+ // Amount of contextual padding to add around a window
+ // (used only by the window_data_layer)
+ optional uint32 det_context_pad = 58 [default = 0];
+
+ // Mode for cropping out a detection window
+ // warp: cropped window is warped to a fixed size and aspect ratio
+ // square: the tightest square around the window is cropped
+ optional string det_crop_mode = 59 [default = "warp"];
+
+ // For ReshapeLayer, one needs to specify the new dimensions.
+ optional int32 new_num = 60 [default = 0];
+ optional int32 new_channels = 61 [default = 0];
+ optional int32 new_height = 62 [default = 0];
+ optional int32 new_width = 63 [default = 0];
+
+ // Whether or not ImageLayer should shuffle the list of files at every epoch.
+ // It will also resize images if new_height or new_width are not zero.
+ optional bool shuffle_images = 64 [default = false];
+
+ // For ConcatLayer, one needs to specify the dimension for concatenation, and
+ // the other dimensions must be the same for all the bottom blobs.
+ // By default it will concatenate blobs along the channels dimension.
+ optional uint32 concat_dim = 65 [default = 1];
+
+ optional HDF5OutputParameter hdf5_output_param = 1001;
+}
+
+message PReLUParameter {
+ // Parametric ReLU described in K. He et al, Delving Deep into Rectifiers:
+ // Surpassing Human-Level Performance on ImageNet Classification, 2015.
+
+ // Initial value of a_i. Default is a_i=0.25 for all i.
+ optional FillerParameter filler = 1;
+ // Whether or not slope parameters are shared across channels.
+ optional bool channel_shared = 2 [default = false];
+}
+
+// The normalized bounding box [0, 1] w.r.t. the input image size.
+message NormalizedBBox {
+ optional float xmin = 1;
+ optional float ymin = 2;
+ optional float xmax = 3;
+ optional float ymax = 4;
+ optional int32 label = 5;
+ optional bool difficult = 6;
+ optional float score = 7;
+ optional float size = 8;
+}
+
+// origin: https://github.com/rbgirshick/caffe-fast-rcnn/tree/fast-rcnn
+// Message that stores parameters used by ROIPoolingLayer
+message ROIPoolingParameter {
+ // Pad, kernel size, and stride are all given as a single value for equal
+ // dimensions in height and width or as Y, X pairs.
+ optional uint32 pooled_h = 1 [default = 0]; // The pooled output height
+ optional uint32 pooled_w = 2 [default = 0]; // The pooled output width
+ // Multiplicative spatial scale factor to translate ROI coords from their
+ // input scale to the scale used when pooling
+ optional float spatial_scale = 3 [default = 1];
+}
+
+message ProposalParameter {
+ optional uint32 feat_stride = 1 [default = 16];
+ optional uint32 base_size = 2 [default = 16];
+ optional uint32 min_size = 3 [default = 16];
+ repeated float ratio = 4;
+ repeated float scale = 5;
+ optional uint32 pre_nms_topn = 6 [default = 6000];
+ optional uint32 post_nms_topn = 7 [default = 300];
+ optional float nms_thresh = 8 [default = 0.7];
+}
+
+// origin: https://github.com/daijifeng001/caffe-rfcn
+message PSROIPoolingParameter {
+ required float spatial_scale = 1;
+ required int32 output_dim = 2; // output channel number
+ required int32 group_size = 3; // equal to pooled_size
+}
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/opencv.bzl b/modules/opencv/5.0.0.bcr.6/overlay/opencv.bzl
new file mode 100644
index 0000000..4b1e6a0
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/opencv.bzl
@@ -0,0 +1,676 @@
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+load("@rules_cc//cc:cc_test.bzl", "cc_test")
+
+# Select MSVC-style flags for both cl.exe and clang-cl.exe. The compiler identifiers
+# are provided by rules_cc and come from the selected C++ toolchain.
+def _compiler_copts(copts, cl_copts):
+ return select({
+ "@rules_cc//cc/compiler:clang-cl": cl_copts,
+ "@rules_cc//cc/compiler:msvc-cl": cl_copts,
+ "//conditions:default": copts,
+ })
+
+OPENCV_COPTS = _compiler_copts(
+ copts = [
+ "-D_USE_MATH_DEFINES",
+ "-D__OPENCV_BUILD=1",
+ "-D__STDC_CONSTANT_MACROS",
+ "-D__STDC_FORMAT_MACROS",
+ "-D__STDC_LIMIT_MACROS",
+ ],
+ cl_copts = [
+ "/D_USE_MATH_DEFINES",
+ "/D__OPENCV_BUILD=1",
+ "/D__STDC_CONSTANT_MACROS",
+ "/D__STDC_FORMAT_MACROS",
+ "/D__STDC_LIMIT_MACROS",
+ ],
+)
+
+OPENCV_OPTIMIZATION_COPTS = select({
+ "//:debug_clang_cl_build": [],
+ "//:debug_msvc_cl_build": [],
+ "@rules_cc//cc/compiler:clang-cl": [
+ "/O1",
+ ],
+ "@rules_cc//cc/compiler:msvc-cl": [
+ "/O1",
+ ],
+ "//:debug_build": [],
+ "//conditions:default": [
+ "-Os",
+ ],
+})
+
+# NOTE: The copts here are compatible with GCC and Clang, except for PPCLE64 which are clang-specific.
+# cl_copts contains the corresponding options for compilers with an MSVC-compatible command line.
+# This is based on OpenCVCompilerOptimizations.cmake
+# TODO: Add support for ICC.
+
+# NOTE: Starlark does not support while loops nor recursion, sw we have to manually compute full "implies" and "copts"
+_KNOWN_OPTS = {
+ "x86_64": {
+ "sse": {
+ "copts": ["-msse"],
+ "cl_copts": [],
+ "implies": [],
+ },
+ "sse2": {
+ "copts": ["-msse", "-msse2"],
+ "cl_copts": [],
+ "implies": ["sse"],
+ },
+ "sse3": {
+ "copts": ["-msse", "-msse2", "-msse3"],
+ "cl_copts": [],
+ "implies": ["sse", "sse2"],
+ },
+ "ssse3": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3"],
+ "cl_copts": [],
+ "implies": ["sse", "sse2", "sse3"],
+ },
+ "sse4_1": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1"],
+ "cl_copts": [],
+ "implies": ["sse", "sse2", "sse3", "ssse3"],
+ },
+ "popcnt": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt"],
+ "cl_copts": [],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1"],
+ },
+ "sse4_2": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2"],
+ "cl_copts": [],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt"],
+ },
+ "avx": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mavx"],
+ "cl_copts": ["/arch:AVX"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2"],
+ },
+ "fp16": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mavx"],
+ "cl_copts": ["/arch:AVX"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx"],
+ },
+ "fma3": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mfma", "-mavx"],
+ "cl_copts": ["/arch:AVX"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx"],
+ },
+ "avx2": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2"],
+ "cl_copts": ["/arch:AVX2"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16"],
+ },
+ "avx_512f": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f"],
+ "cl_copts": ["/arch:AVX512"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2"],
+ },
+ "avx512_common": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd"],
+ "cl_copts": ["/arch:AVX512"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f"],
+ },
+ "avx512_knl": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512er", "-mavx512pf"],
+ "cl_copts": ["/arch:AVX512"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common"],
+ },
+ "avx512_knm": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512er", "-mavx512pf", "-mavx5124fmaps", "-mavx5124vnniw", "-mavx512vpopcntdq"],
+ "cl_copts": ["/arch:AVX512"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_knl"],
+ },
+ "avx512_skx": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl"],
+ "cl_copts": ["/arch:AVX512"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common"],
+ },
+ "avx512_cnl": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl", "-mavx512ifma", "-mavx512vbmi"],
+ "cl_copts": ["/arch:AVX512"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_skx"],
+ },
+ "avx512_clx": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl", "-mavx512vnni"],
+ "cl_copts": ["/arch:AVX512"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_skx"],
+ },
+ "avx512_icl": {
+ "copts": ["-msse", "-msse2", "-msse3", "-mssse3", "-msse4.1", "-mpopcnt", "-msse4.2", "-mf16c", "-mfma", "-mavx", "-mavx2", "-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl", "-mavx512ifma", "-mavx512vbmi", "-mavx512vbmi2", "-mavx512bitalg", "-mavx512vpopcntdq"],
+ "cl_copts": ["/arch:AVX512"],
+ "implies": ["sse", "sse2", "sse3", "ssse3", "sse4_1", "popcnt", "sse4_2", "avx", "fma3", "fp16", "avx2", "avx_512f", "avx512_common", "avx512_skx"],
+ },
+ },
+ "armv7": {
+ "vfpv3": {
+ "copts": ["-mfpu=vfpv3"],
+ "cl_copts": [],
+ "implies": [],
+ },
+ "neon": {
+ "copts": ["-mfpu=neon"],
+ "cl_copts": [],
+ "implies": [],
+ },
+ "fp16": {
+ "copts": ["-mfpu=neon-fp16", "-mfp16-format=ieee"],
+ "cl_copts": [],
+ "implies": ["neon"],
+ },
+ },
+ "arm64": {
+ "neon": {
+ "copts": [],
+ "cl_copts": [],
+ "implies": [],
+ },
+ "fp16": {
+ "copts": [],
+ "cl_copts": [],
+ "implies": ["neon"],
+ },
+ "neon_dotprod": {
+ "copts": ["-march=armv8.2-a+dotprod"],
+ "cl_copts": [],
+ "implies": ["neon"],
+ },
+ "neon_fp16": {
+ "copts": ["-march=armv8.2-a+fp16"],
+ "cl_copts": [],
+ "implies": ["neon"],
+ },
+ "neon_bf16": {
+ "copts": ["-march=armv8.2-a+bf16"],
+ "cl_copts": [],
+ "implies": ["neon"],
+ },
+ "sve": {
+ "copts": ["-march=armv8.2-a+sve"],
+ "cl_copts": [],
+ "implies": [],
+ }
+ },
+ "mips64": {
+ "msa": {
+ "copts": ["-mmsa"],
+ "cl_copts": [],
+ "implies": [],
+ },
+ },
+ "ppc64le": {
+ "vsx": {
+ "copts": ["-mvsx", "-maltivec"],
+ "cl_copts": [],
+ "implies": [],
+ },
+ "vsx3": {
+ "copts": ["-mvsx", "-maltivec", "-mpower9-vector"],
+ "cl_copts": [],
+ "implies": ["vsx"],
+ },
+ },
+ "riscv64": {
+ "rvv": {
+ "copts": [],
+ "cl_copts": [],
+ "implies": [],
+ },
+ },
+ "loongarch64": {
+ "lsx": {
+ "copts": ["-mlsx"],
+ "cl_copts": [],
+ "implies": [],
+ },
+ "lasx": {
+ "copts": ["-mlasx"],
+ "cl_copts": [],
+ "implies": [],
+ },
+ },
+}
+
+def _arches_for_opt(opt):
+ arches = []
+ for arch, opts in _KNOWN_OPTS.items():
+ if opt in opts:
+ arches.append(arch)
+ if len(arches) == 0:
+ fail("Unknown optimization: {}".format(opt))
+ else:
+ return arches
+
+
+# Optimizations that will always be enabled for a given architecture
+# All other optimizations will be dispatched at runtime
+# TODO: make these configurable via build flag
+BASELINE_OPTS = {
+ "x86_64": ["sse", "sse2", "sse3"],
+ "armv7": ["neon"],
+ "arm64": ["neon", "fp16"],
+ "mips64": [],
+ "ppc64le": [],
+ "riscv64": [],
+ "loongarch64": [],
+}
+
+def _calc_enabled_opts():
+ enabled_opts = {}
+ for arch, baseline_opts in BASELINE_OPTS.items():
+ possible_opts = _KNOWN_OPTS[arch].keys()
+ dispatched_opts = [opt for opt in possible_opts if opt not in baseline_opts]
+ enabled_opts[arch] = {
+ "baseline": baseline_opts,
+ "dispatched": dispatched_opts,
+ }
+ return enabled_opts
+
+ENABLED_OPTS = _calc_enabled_opts()
+
+# OpenCV modules that will be built
+# TODO: make this configurable via build flag
+MODULES_COMMON = [
+ "calib",
+ "core",
+ "dnn",
+ "features",
+ "flann",
+ "geometry",
+ "imgcodecs",
+ "imgproc",
+ "objdetect",
+ "photo",
+ "ptcloud",
+ "stereo",
+ "stitching",
+ "video",
+]
+
+MODULES_DESKTOP = MODULES_COMMON + [
+ "videoio",
+ "highgui",
+]
+
+CONFIG_BASE = {
+ "stub_opencl": [
+ "calib",
+ "core",
+ "geometry",
+ "features",
+ "imgproc",
+ "objdetect",
+ "photo",
+ "ptcloud",
+ "stereo",
+ "stitching",
+ "video",
+ ],
+ "contains_src_headers": [
+ "dnn",
+ "geometry",
+ "imgcodecs",
+ "videoio",
+ ],
+ "contains_3rdparty": [
+ "features",
+ ],
+}
+
+def _merge_dicts(dict1, dict2):
+ merged = dict(dict1) # Create a copy of the first dictionary
+ merged.update(dict2) # Update with the second dictionary
+ return merged
+
+CONFIG_DESKTOP =_merge_dicts(CONFIG_BASE, {
+ "modules": MODULES_DESKTOP,
+})
+
+CONFIG_NON_DESKTOP = _merge_dicts(CONFIG_BASE, {
+ "modules": MODULES_COMMON,
+})
+
+def opencv_module(
+ name,
+ dispatched_files = {},
+ force_dispatch = False,
+ deps = [],
+ copts = [],
+ cl_copts = [],
+ linkopts = [],
+ local_defines = [],
+ compatible_with = [],
+ srcs_excludes_globs = [],
+ sources = None, # reserved for modules that list sources explicitly, such as videoio or highgui
+ test_enabled = True,
+ test_srcs_excludes_globs = [],
+ test_sources = None, # reserved for modules that list sources explicitly, such as videoio or highgui
+ ):
+ """
+ Creates a Bazel rule for an OpenCV module.
+
+ Args:
+ name: The name of the module.
+ dispatched_files: A mapping of keys to a list of operators.
+ force_dispatch: If enabled, all optimizations for the files in dispatched_files will be forced to be dispatched, even if they are included in baseline.
+ deps: A list of dependencies for the module.
+ copts: Additional compiler options for GCC-compatible command lines.
+ cl_copts: Additional compiler options for MSVC-compatible command lines.
+ linkopts: Additional linker options.
+ local_defines: A list of preprocessor definitions to be added to the module.
+ compatible_with: A list of labels that specify the platforms compatible with this module.
+ srcs_excludes_globs: A list of glob patterns to exclude from the module's sources.
+ sources: A list of sources for the module. If None, sources will be determined by globbing the src directory. This is useful for modules that need to explicitly list their sources, such as videoio or highgui.
+ """
+ prefix = "modules/{}".format(name)
+ extra_headers = []
+
+ glob_hdrs = [
+ prefix + "/include/**/*.hpp",
+ prefix + "/include/**/*.h",
+ ]
+
+ # Stub out opencl as all empty since we don't need to use any opencl functionality
+ if name in CONFIG_BASE["stub_opencl"]:
+ header_file = prefix + "/src/opencl_kernels_{}.hpp".format(name)
+ write_file(
+ name = "_{}".format(header_file),
+ content = [
+ "#include \"opencv2/core/ocl.hpp\"",
+ "#include \"opencv2/core/ocl_genbase.hpp\"",
+ "#include \"opencv2/core/opencl/ocl_defs.hpp\"",
+ ],
+ out = header_file,
+ )
+ extra_headers.append(header_file)
+
+ # A Helper target to hold the headers generated in module's src dir
+ # This is to avoid hacks with `copts` to include src dir as this can lead to issues
+ # with include paths when target is used as a dependency from other modules
+ cc_library(
+ name = name + "_generated_headers",
+ hdrs = extra_headers,
+ strip_include_prefix = prefix + "/src",
+ )
+
+ simd_extra_headers = []
+
+ dispatched_targets = {
+ "@platforms//cpu:x86_64": [],
+ "@platforms//cpu:armv7": [],
+ "@platforms//cpu:arm64": [],
+ "@platforms//cpu:mips64": [],
+ "@platforms//cpu:ppc64le": [],
+ "@platforms//cpu:riscv64": [],
+ "@platforms//cpu:loongarch64": [],
+ "//conditions:default": [],
+ }
+
+ for fname, opts in dispatched_files.items():
+ # Define file paths for SIMD declarations and SIMD header
+ simd_declarations = "{}/src/{}.simd_declarations.hpp".format(prefix, fname)
+ simd_filename = "{}/src/{}.simd.hpp".format(prefix, fname)
+
+ simd_definitions_start = [
+ "#define CV_CPU_SIMD_FILENAME \"{}\"".format(simd_filename),
+ ]
+ simd_opts = {
+ "x86_64": [],
+ "armv7": [],
+ "arm64": [],
+ "mips64": [],
+ "ppc64le": [],
+ "riscv64": [],
+ "loongarch64": [],
+ }
+ dispatch_simd = {
+ "x86_64": [],
+ "armv7": [],
+ "arm64": [],
+ "mips64": [],
+ "ppc64le": [],
+ "riscv64": [],
+ "loongarch64": [],
+ }
+ for opt in opts:
+ arches = _arches_for_opt(opt)
+ for arch in arches:
+ if force_dispatch or opt not in ENABLED_OPTS[arch]["baseline"]:
+ simd_opts[arch] += [
+ "#define CV_CPU_DISPATCH_MODE {}".format(opt.upper()),
+ "#include \"opencv2/core/private/cv_cpu_include_simd_declarations.hpp\"",
+ ]
+ dispatch_simd[arch] += [opt]
+
+ dispatch_modes_simd = {}
+ dispatch_modes_empty = [
+ "#define CV_CPU_DISPATCH_MODES_ALL BASELINE",
+ ]
+ for arch, dispatched_opts in dispatch_simd.items():
+ if len(dispatched_opts) > 0:
+ dispatch_modes_simd[arch] = [
+ "#define CV_CPU_DISPATCH_MODES_ALL " + ", ".join([x.upper() for x in reversed(dispatched_opts) + ["BASELINE"]]),
+ ]
+
+ # also, create a cc_library for each dispatched file and add it to list of deps
+ for opt in dispatched_opts:
+ simd_cpp_file = "{}/src/{}.{}.{}.cpp".format(prefix, fname, opt, arch)
+
+ write_file(
+ name = "_{}".format(simd_cpp_file),
+ out = simd_cpp_file,
+ content = [
+ "#include \"{}/src/precomp.hpp\"".format(prefix),
+ "#include \"{}/src/{}.simd.hpp\"".format(prefix, fname),
+ ],
+ )
+
+ simd_target_name = "_{}/src/{}_{}_{}_{}_simd".format(prefix, name, fname, arch, opt)
+
+ cc_library(
+ name = simd_target_name,
+ srcs = [
+ simd_cpp_file,
+ simd_declarations,
+ ] + native.glob([
+ prefix + "/src/**/*.hpp",
+ prefix + "/src/**/*.h"
+ ],
+ allow_empty = True
+ ),
+ hdrs = native.glob(glob_hdrs, allow_empty = True),
+ deps = deps + [":_base_headers"],
+ # note: some files don't include generated simd_declarations.hpp, so
+ # we need to define CV_CPU_DISPATCH_MODE here as well
+ # notable example: color_hsv operators in imgproc module
+ # This workaround also exist in OpenCVCompilerOptimizations.cmake
+ # in function ocv_compiler_optimization_process_sources
+ local_defines = [
+ "CV_CPU_DISPATCH_MODE={}".format(opt.upper()),
+ "CV_CPU_COMPILE_{}=1".format(opt.upper()),
+ ] + [
+ "CV_CPU_COMPILE_{}=1".format(x.upper())
+ for x in _KNOWN_OPTS[arch][opt]["implies"]
+ if x not in ENABLED_OPTS[arch]["baseline"]
+ ],
+ implementation_deps = [":" + name + "_generated_headers"],
+ copts = OPENCV_COPTS +
+ OPENCV_OPTIMIZATION_COPTS +
+ _compiler_copts(
+ copts + _KNOWN_OPTS[arch][opt]["copts"],
+ cl_copts + _KNOWN_OPTS[arch][opt]["cl_copts"],
+ ),
+ target_compatible_with = ["@platforms//cpu:{}".format(arch)],
+ strip_include_prefix = prefix + "/include",
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ "-ubsan", # disable UBSAN for opencv modules
+ ],
+ )
+ dispatched_targets["@platforms//cpu:{}".format(arch)].append(Label(":" + simd_target_name))
+ else:
+ dispatch_modes_simd[arch] = dispatch_modes_empty
+
+ simd_definitions_end = ["#undef CV_CPU_SIMD_FILENAME"]
+ simd_extra_headers.append(simd_declarations)
+
+ select_dict = {}
+ for arch in simd_opts.keys():
+ select_dict["@platforms//cpu:{}".format(arch)] = simd_definitions_start + simd_opts[arch] + dispatch_modes_simd[arch] + simd_definitions_end
+
+ select_dict["//conditions:default"] = simd_definitions_start + dispatch_modes_empty + simd_definitions_end
+
+ # Write the SIMD declarations to the file
+ write_file(
+ name = "_{}".format(simd_declarations),
+ # note, simd_opts declarations are mainly for x86_64
+ content = select(select_dict),
+ out = simd_declarations,
+ )
+
+ glob_srcs = [prefix + "/src/**/*.cpp", prefix + "/src/**/*.hpp"]
+ if name in CONFIG_BASE["contains_src_headers"]:
+ glob_srcs.append(prefix + "/src/**/*.h")
+ if name in CONFIG_BASE["contains_3rdparty"]:
+ glob_srcs.append(prefix + "/3rdparty/**/*.h")
+
+ baseline_copts = {
+ "//conditions:default": [],
+ }
+
+ # exclude handcrafted SIMD files from the main srcs and include them only in their respective cc_library
+ srcs_excludes = []
+ srcs_excludes += srcs_excludes_globs
+ # however, for baseline optimizations, any handcrafted SIMD files should be included back in the main srcs
+ srcs_baseline_includes = []
+
+ # A Helper target to hold the headers generated in module's src dir
+ # This is to avoid hacks with `copts` to include src dir as this can lead to issues
+ # with include paths when target is used as a dependency from other modules
+ cc_library(
+ name = name + "_generated_simd_headers",
+ hdrs = simd_extra_headers,
+ strip_include_prefix = prefix + "/src",
+ deps = [":" + name + "_generated_headers"],
+ )
+
+ for arch, opts in ENABLED_OPTS.items():
+ srcs_excludes += [
+ prefix + "/src/**/*.{}.cpp".format(x)
+ for x in opts["dispatched"]
+ ]
+ arch_flags = []
+ arch_cl_flags = []
+ for opt in opts["baseline"]:
+ arch_flags += _KNOWN_OPTS[arch][opt]["copts"]
+ arch_cl_flags += _KNOWN_OPTS[arch][opt]["cl_copts"]
+ srcs_baseline_includes.append(prefix + "/src/**/*.{}.cpp".format(opt))
+ baseline_copts["@platforms//cpu:{}".format(arch)] = arch_flags
+ if arch in ["x86_64", "armv7"]:
+ baseline_copts["//:{}_clang_cl".format(arch)] = arch_cl_flags
+ baseline_copts["//:{}_msvc_cl".format(arch)] = arch_cl_flags
+
+ # some modules have hand-optimized version for specific dispatched optimization
+ # This will not be covered by the dispatched cc_library above, so we need to add additional target for it
+
+ for opt in opts["dispatched"]:
+ simd_target_name = "_{}/src/{}_{}_{}_simd_handcrafted".format(prefix, name, arch, opt)
+
+ cc_library(
+ name = simd_target_name,
+ srcs = native.glob(
+ [
+ prefix + "/src/**/*.hpp",
+ prefix + "/src/**/*.h",
+ prefix + "/src/**/*.{}.cpp".format(opt)
+ ],
+ allow_empty = True
+ ),
+ hdrs = native.glob(glob_hdrs, allow_empty = True),
+ deps = deps + [":_base_headers"],
+ # note: some files don't include generated simd_declarations.hpp, so
+ # we need to define CV_CPU_DISPATCH_MODE here as well
+ # notable example: color_hsv operators in imgproc module
+ # This workaround also exist in OpenCVCompilerOptimizations.cmake
+ # in function ocv_compiler_optimization_process_sources
+ local_defines = [
+ "CV_CPU_DISPATCH_MODE={}".format(opt.upper()),
+ "CV_CPU_COMPILE_{}=1".format(opt.upper()),
+ ] + [
+ "CV_CPU_COMPILE_{}=1".format(x.upper())
+ for x in _KNOWN_OPTS[arch][opt]["implies"]
+ if x not in ENABLED_OPTS[arch]["baseline"]
+ ],
+ implementation_deps = [":" + name + "_generated_simd_headers"],
+ copts = OPENCV_COPTS +
+ OPENCV_OPTIMIZATION_COPTS +
+ _compiler_copts(
+ copts + _KNOWN_OPTS[arch][opt]["copts"],
+ cl_copts + _KNOWN_OPTS[arch][opt]["cl_copts"],
+ ),
+ target_compatible_with = ["@platforms//cpu:{}".format(arch)],
+ strip_include_prefix = prefix + "/include",
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ "-ubsan", # disable UBSAN for opencv modules
+ ],
+ )
+ dispatched_targets["@platforms//cpu:{}".format(arch)].append(Label(":" + simd_target_name))
+
+ if sources != None:
+ # used by videoio and highgui modules
+ full_sources = sources
+ else:
+ full_sources = native.glob(glob_srcs, exclude = srcs_excludes) + native.glob(srcs_baseline_includes, allow_empty = True)
+
+ cc_library(
+ name = name,
+ srcs = full_sources,
+ hdrs = native.glob(glob_hdrs, allow_empty = True),
+ deps = deps + [":_base_headers"] + select(dispatched_targets),
+ copts = OPENCV_COPTS +
+ OPENCV_OPTIMIZATION_COPTS +
+ _compiler_copts(copts, cl_copts) +
+ select(baseline_copts),
+ implementation_deps = [":" + name + "_generated_simd_headers"],
+ linkopts = linkopts,
+ local_defines = local_defines,
+ target_compatible_with = compatible_with,
+ strip_include_prefix = prefix + "/include",
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ "-ubsan", # disable UBSAN for opencv modules
+ ],
+ visibility = ["//visibility:public"],
+ )
+
+ if test_enabled:
+ glob_test_srcs = [prefix + "/test/**/*.cpp", prefix + "/test/**/*.hpp"]
+
+ if sources != None:
+ # used by videoio and highgui modules
+ full_test_sources = test_sources
+ else:
+ full_test_sources = native.glob(glob_test_srcs, exclude = test_srcs_excludes_globs)
+
+ cc_test(
+ name = name + "_test",
+ srcs = full_test_sources,
+ deps = [
+ ":" + name,
+ ":ts",
+ ],
+ copts = OPENCV_COPTS +
+ OPENCV_OPTIMIZATION_COPTS +
+ _compiler_copts(copts, cl_copts) +
+ select(baseline_copts),
+ features = [
+ "exceptions", # enable exceptions for opencv modules
+ "-ubsan", # disable UBSAN for opencv modules
+ ],
+ )
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/test/BUILD.bazel b/modules/opencv/5.0.0.bcr.6/overlay/test/BUILD.bazel
new file mode 100644
index 0000000..338bc18
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/test/BUILD.bazel
@@ -0,0 +1,12 @@
+load("@rules_qt//:qt.bzl", "qt_cc_test")
+
+qt_cc_test(
+ name = "qt6_smoke_test",
+ srcs = ["qt6_smoke_test.cpp"],
+ env = {"QT_QPA_PLATFORM": "offscreen"},
+ deps = [
+ "@opencv//:core",
+ "@opencv//:highgui",
+ ],
+)
+
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/test/MODULE.bazel b/modules/opencv/5.0.0.bcr.6/overlay/test/MODULE.bazel
new file mode 100644
index 0000000..5f34019
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/test/MODULE.bazel
@@ -0,0 +1,29 @@
+bazel_dep(name = "apple_support", version = "2.8.1")
+bazel_dep(name = "rules_cc", version = "0.2.22")
+bazel_dep(name = "platforms", version = "1.1.0")
+bazel_dep(name = "opencv")
+bazel_dep(name = "rules_qt", version = "0.0.7")
+
+local_path_override(
+ module_name = "opencv",
+ path = "..",
+)
+
+new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
+new_local_repository(name = "ubuntu-gtk-deps", build_file = "//:ubuntu-gtk-deps.BUILD.bazel", path = "/")
+
+rules_qt_fetch = use_extension("@rules_qt//extension:qt.bzl", "fetch")
+rules_qt_fetch.install(
+ name = "qt_mac_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/mac_aarch64.BUILD",
+ os = "macos",
+ version = "6.8.3",
+)
+rules_qt_fetch.install(
+ name = "qt_windows_x86_64",
+ build_file = "@rules_qt//extension:qt/6.8.3/windows_x86_64.BUILD",
+ os = "windows",
+ version = "6.8.3",
+ windows_architecture = "win64_msvc2022",
+)
+use_repo(rules_qt_fetch, "qt_linux_x86_64", "qt_linux_aarch64", "qt_mac_aarch64", "qt_mac_x86_64", "qt_windows_x86_64")
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/test/qt6_smoke_test.cpp b/modules/opencv/5.0.0.bcr.6/overlay/test/qt6_smoke_test.cpp
new file mode 100644
index 0000000..cedadd0
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/test/qt6_smoke_test.cpp
@@ -0,0 +1,14 @@
+#include <opencv2/core.hpp>
+#include <opencv2/highgui.hpp>
+#include <iostream>
+
+// Exercises the Qt6 highgui backend end-to-end (window creation, event pump,
+// teardown) under Qt's offscreen QPA platform so it can run headless in CI.
+int main() {
+ cv::Mat img(64, 64, CV_8UC3, cv::Scalar(240, 240, 240));
+ cv::imshow("qt6_smoke_test", img);
+ cv::waitKey(1000);
+ cv::destroyAllWindows();
+ std::cout << "qt6 highgui smoke test OK" << std::endl;
+ return 0;
+}
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/test/ubuntu-gtk-deps.BUILD.bazel b/modules/opencv/5.0.0.bcr.6/overlay/test/ubuntu-gtk-deps.BUILD.bazel
new file mode 100644
index 0000000..af46d76
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/test/ubuntu-gtk-deps.BUILD.bazel
@@ -0,0 +1,200 @@
+load("@rules_cc//cc:cc_import.bzl", "cc_import")
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+
+package(default_visibility = ["//visibility:public"])
+
+cc_import(
+ name = "gtk3",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgtk-3.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgtk-3.so",
+ }),
+ hdrs = glob(["usr/include/gtk-3.0/**/*.h"]),
+ strip_include_prefix = "usr/include/gtk-3.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":gdk3",
+ ":atk",
+ ],
+)
+
+cc_import(
+ name = "gdk3",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgdk-3.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgdk-3.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":pangocairo",
+ ":gdk_pixbuf",
+ ":gio",
+ ":glib",
+ ],
+)
+
+cc_import(
+ name = "pangocairo",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libpangocairo-1.0.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":pango",
+ ":cairo",
+ ],
+)
+
+cc_import(
+ name = "pango",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libpango-1.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libpango-1.0.so",
+ }),
+ hdrs = glob(["usr/include/pango-1.0/**/*.h"]),
+ strip_include_prefix = "usr/include/pango-1.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":harfbuzz",
+ ":glib",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "harfbuzz",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libharfbuzz.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libharfbuzz.so",
+ }),
+ hdrs = glob(["usr/include/harfbuzz/**/*.h"]),
+ strip_include_prefix = "usr/include/harfbuzz",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ],
+)
+
+cc_import(
+ name = "atk",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libatk-1.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libatk-1.0.so",
+ }),
+ hdrs = glob(["usr/include/atk-1.0/**/*.h"]),
+ strip_include_prefix = "usr/include/atk-1.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":cairo",
+ ],
+)
+
+cc_import(
+ name = "cairo-gobject",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libcairo-gobject.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libcairo-gobject.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":cairo",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "cairo",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libcairo.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libcairo.so",
+ }),
+ hdrs = glob(["usr/include/cairo/**/*.h"]),
+ strip_include_prefix = "usr/include/cairo",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":gdk_pixbuf",
+ ":gio",
+ ],
+)
+
+cc_import(
+ name = "gdk_pixbuf",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgdk_pixbuf-2.0.so",
+ }),
+ hdrs = glob(["usr/include/gdk-pixbuf-2.0/**/*.h"]),
+ strip_include_prefix = "usr/include/gdk-pixbuf-2.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "gio",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgio-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgio-2.0.so",
+ }),
+ hdrs = glob(["usr/include/gio-unix-2.0/**/*.h"]),
+ strip_include_prefix = "usr/include/gio-unix-2.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ":gobject",
+ ],
+)
+
+cc_import(
+ name = "gobject",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libgobject-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libgobject-2.0.so",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glib",
+ ],
+)
+
+cc_library(
+ name = "glibconfig-headers",
+ hdrs = select({
+ "@platforms//cpu:x86_64": glob(["usr/lib/x86_64-linux-gnu/glib-2.0/include/**/*.h"], allow_empty = True),
+ "@platforms//cpu:aarch64": glob(["usr/lib/aarch64-linux-gnu/glib-2.0/include/**/*.h"], allow_empty = True),
+ }),
+ strip_include_prefix = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/glib-2.0/include",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/glib-2.0/include",
+ }),
+ target_compatible_with = ["@platforms//os:linux"],
+)
+
+cc_import(
+ name = "glib",
+ system_provided = True,
+ interface_library = select({
+ "@platforms//cpu:x86_64": "usr/lib/x86_64-linux-gnu/libglib-2.0.so",
+ "@platforms//cpu:aarch64": "usr/lib/aarch64-linux-gnu/libglib-2.0.so",
+ }),
+ hdrs = glob(["usr/include/glib-2.0/**/*.h"]),
+ strip_include_prefix = "usr/include/glib-2.0",
+ target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ ":glibconfig-headers",
+ ],
+)
diff --git a/modules/opencv/5.0.0.bcr.6/overlay/utils.bzl b/modules/opencv/5.0.0.bcr.6/overlay/utils.bzl
new file mode 100644
index 0000000..fc5aec9
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/overlay/utils.bzl
@@ -0,0 +1,73 @@
+"""Utility Bazel rules for OpenCV."""
+
+def _blob2hdr_impl(ctx):
+ out = ctx.actions.declare_file(ctx.attr.out)
+
+ ctx.actions.run(
+ executable = ctx.executable._blob2hdr_tool,
+ inputs = [ctx.file.src],
+ outputs = [out],
+ arguments = [ctx.file.src.path, out.path, ctx.attr.cpp_variable],
+ mnemonic = "Blob2Hdr",
+ progress_message = "Generating %s from %s" % (ctx.attr.out, ctx.file.src.basename),
+ )
+
+ return [DefaultInfo(files = depset([out]))]
+
+_blob2hdr = rule(
+ implementation = _blob2hdr_impl,
+ attrs = {
+ "src": attr.label(
+ allow_single_file = True,
+ mandatory = True,
+ doc = "Binary input file to embed.",
+ ),
+ "out": attr.string(
+ mandatory = True,
+ doc = "Name of the generated header file.",
+ ),
+ "cpp_variable": attr.string(
+ mandatory = True,
+ doc = "Name of the C++ static array variable in the generated header.",
+ ),
+ "_blob2hdr_tool": attr.label(
+ default = Label("//:blob2hdr"),
+ executable = True,
+ cfg = "exec",
+ doc = "The blob2hdr conversion tool (py_binary, exec configuration).",
+ ),
+ },
+)
+
+def blob2hdr(name, src, out, cpp_variable, **kwargs):
+ """Converts a binary blob into a C header declaring a static unsigned char array.
+
+ Equivalent to the CMake ocv_blob2hdr() function. Reads a binary file and
+ generates a C header containing its contents as a static const unsigned char
+ array, with 16 bytes per line.
+
+ The generated header has the form:
+
+ // Auto generated file.
+ static const unsigned char <cpp_variable>[] =
+ {
+ 0xNN, 0xNN, ..., 0xNN,
+ ...
+ 0xNN, 0xNN, ..., 0xNN
+ };
+
+ Args:
+ name: The Bazel rule name.
+ src: The binary input file (label).
+ out: Filename for the generated header.
+ cpp_variable: Name of the C++ array variable in the header.
+ **kwargs: Additional arguments forwarded to the underlying rule
+ (e.g. visibility, compatible_with).
+ """
+ _blob2hdr(
+ name = name,
+ src = src,
+ out = out,
+ cpp_variable = cpp_variable,
+ **kwargs
+ )
diff --git a/modules/opencv/5.0.0.bcr.6/presubmit.yml b/modules/opencv/5.0.0.bcr.6/presubmit.yml
new file mode 100644
index 0000000..a80ecc9
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/presubmit.yml
@@ -0,0 +1,82 @@
+bcr_test_module:
+ module_path: test
+ matrix:
+ # Currently does not build in Windows due to SIMD dispatch flags not taking into account cl.exe
+ # Also, for HighGUI on Linux, a GTK3 is needed, which should be provided via @opencv//:gtk3 label flag.
+ # This is tested only on Ubuntu, where test module installs the GTK3 with system's package manager and
+ # then imports it to the workspace.
+ ubuntu_with_gtk3:
+ - ubuntu2404
+ - ubuntu2404_arm64
+ # Qt 6.8.3 x86_64 and and aarch64 on both Mac, Windows, and Linux.
+ # Note that linux-aarch64 requires a glibc version >= 2.34 that requires Ubuntu 24.04+.
+ qt6_platforms:
+ - ubuntu2204
+ - ubuntu2404_arm64
+ - macos_arm64
+ - windows
+ platform:
+ - rockylinux8
+ - debian11
+ - debian12
+ - ubuntu2404
+ - ubuntu2404_arm64
+ - macos_arm64
+ - windows
+ bazel:
+ - 8.x
+ - 9.x
+ tasks:
+ verify_targets:
+ name: Verify build targets
+ platform: ${{ platform }}
+ bazel: ${{ bazel }}
+ build_targets:
+ - '@opencv//:opencv'
+ verify_targets_gtk3:
+ name: Verify build targets on Ubuntu with system GTK3
+ platform: ${{ ubuntu_with_gtk3 }}
+ bazel: 9.x
+ shell_commands:
+ - sudo apt update && sudo apt install -y libgtk-3-dev
+ build_flags:
+ - "--@opencv//:gtk3=@ubuntu-gtk-deps//:gtk3"
+ - "--@opencv//:with_gtk3=True"
+ build_targets:
+ - '@opencv//:opencv'
+ verify_targets_qt6:
+ name: Verify build targets for Qt6
+ platform: ${{ qt6_platforms }}
+ bazel: 9.x
+ build_flags:
+ - "--@opencv//:with_qt=True"
+ build_targets:
+ - '@opencv//:opencv'
+ run_qt6_smoke_test_ubuntu_x86_64:
+ name: Run Qt6 smoke test on linux (x86_64)
+ platform: ubuntu2204
+ bazel: 9.x
+ shell_commands:
+ - sudo apt-get update && sudo apt-get install -y libegl-dev libegl1-mesa-dev libfontconfig1-dev libgl-dev libgl1-mesa-dev libpulse-dev libx11-xcb-dev libxcb-cursor-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxkbcommon-dev libxkbcommon-x11-dev
+ test_flags:
+ - "--@opencv//:with_qt=True"
+ test_targets:
+ - '//:qt6_smoke_test'
+ run_qt6_smoke_test_ubuntu_aarch64:
+ name: Run Qt6 smoke test on linux (arm64)
+ platform: ubuntu2404_arm64
+ bazel: 9.x
+ shell_commands:
+ - sudo apt-get update && sudo apt-get install -y libegl-dev libegl1-mesa-dev libfontconfig1-dev libgl-dev libgl1-mesa-dev libpulse-dev libx11-xcb-dev libxcb-cursor-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxkbcommon-dev libxkbcommon-x11-dev
+ test_flags:
+ - "--@opencv//:with_qt=True"
+ test_targets:
+ - '//:qt6_smoke_test'
+ run_qt6_smoke_test_macos_arm64:
+ name: Run Qt6 smoke test on macOS (arm64)
+ platform: macos_arm64
+ bazel: 9.x
+ test_flags:
+ - "--@opencv//:with_qt=True"
+ test_targets:
+ - '//:qt6_smoke_test'
diff --git a/modules/opencv/5.0.0.bcr.6/source.json b/modules/opencv/5.0.0.bcr.6/source.json
new file mode 100644
index 0000000..14fe73a
--- /dev/null
+++ b/modules/opencv/5.0.0.bcr.6/source.json
@@ -0,0 +1,17 @@
+{
+ "integrity": "sha256-4quqHqJEP7FjKZNpUGUhUY7gLY5RuIoUShKMTkkhI70=",
+ "strip_prefix": "opencv-5.0.0",
+ "url": "https://github.com/opencv/opencv/archive/refs/tags/5.0.0.zip",
+ "overlay": {
+ "BUILD.bazel": "sha256-Wchlqor/dF/HgfpxB2fWTHpzQHAje9p/HlWjotteXs4=",
+ "MODULE.bazel": "sha256-JezDWs3KlLvysHFHKUXzj0nMdqawJbmVkNXGLzCAhJA=",
+ "blob2hdr.py": "sha256-khIbzjIr/IaGkfttfjASvWWUW2uQ4JdDQeZQe8EVXgU=",
+ "modules/dnn/src/caffe/opencv-caffe.proto": "sha256-WBbQ+ih0u/o8olh4aUeV5TetjsjPslvVcP36YVsrp8A=",
+ "opencv.bzl": "sha256-4QO8Yc2vDqFF0J2UZpPFpfM8uGKO2VyvdH80nkR5hBk=",
+ "test/BUILD.bazel": "sha256-U1EfDc6Q/gd0pP+/wEzpAuYtHvTGZFCTAPXYetQ6Tzc=",
+ "test/MODULE.bazel": "sha256-blAvTb+E9sI7yFmjvMs1Ar7bVrwwp3Re/LPkzuIhhe8=",
+ "test/qt6_smoke_test.cpp": "sha256-xjWbsRR7yDGWs0+mYiI2WvzLLsGT13wI2Tdt3NU3dCs=",
+ "test/ubuntu-gtk-deps.BUILD.bazel": "sha256-coCXi1DH9iVC6q8qwiI3qndFVmUkNjtRhpIsSIXC9P0=",
+ "utils.bzl": "sha256-D4ve8ZSo0vvAZnUbAyQF977J7ayCPhQ7wFGLYaj57ks="
+ }
+}
diff --git a/modules/opencv/metadata.json b/modules/opencv/metadata.json
index cd70d0a..cd0d6a4 100644
--- a/modules/opencv/metadata.json
+++ b/modules/opencv/metadata.json
@@ -41,7 +41,8 @@
"5.0.0.bcr.2",
"5.0.0.bcr.3",
"5.0.0.bcr.4",
- "5.0.0.bcr.5"
+ "5.0.0.bcr.5",
+ "5.0.0.bcr.6"
],
"yanked_versions": {}
}