Skip to content

Commit

Permalink
build: enable optflow
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Aug 24, 2024
1 parent 572eb97 commit b53971e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ http_archive(
urls = ["https://github.com/opencv/opencv/archive/4.5.5.tar.gz"],
)

http_archive(
name = "opencv_contrib",
build_file = "@//third_party:opencv_contrib.BUILD",
strip_prefix = "opencv_contrib-4.5.5",
urls = ["https://github.com/opencv/opencv_contrib/archive/4.5.5.tar.gz"],
)

new_local_repository(
name = "linux_opencv",
build_file = "@//third_party:opencv_linux.BUILD",
Expand Down
2 changes: 1 addition & 1 deletion docker/windows/x86_64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ RUN curl -L --retry 4 --connect-timeout 10 https://www.python.org/ftp/python/%PY
FROM base as opencv

# Install OpenCV
RUN curl -L --retry 4 --connect-timeout 10 https://github.com/opencv/opencv/releases/download/3.4.16/opencv-3.4.16-vc14_vc15.exe -o C:\TEMP\opencv-installer.exe && `
RUN curl -L --retry 4 --connect-timeout 10 https://github.com/opencv/opencv/releases/download/4.5.5/opencv-4.5.5-vc14_vc15.exe -o C:\TEMP\opencv-installer.exe && `
start /wait C:\TEMP\opencv-installer.exe -gm2 -y -oC:\ && `
del C:\TEMP\opencv-installer.exe

Expand Down
17 changes: 14 additions & 3 deletions third_party/opencv.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ OPENCV_MODULES = [
"calib3d",
"features2d",
"highgui",
"optflow",
"video",
"videoio",
"imgcodecs",
Expand All @@ -96,6 +97,7 @@ OPENCV_MODULES = [
OPENCV_3RDPARTY_LIBS = [
"IlmImf",
"libjpeg-turbo",
"libopenjp2",
"libpng",
"libtiff",
"zlib",
Expand All @@ -111,11 +113,13 @@ COMMON_CACHE_ENTRIES = {
"BUILD_opencv_apps": "OFF",
"BUILD_opencv_python": "OFF",
"BUILD_opencv_world": "ON",
"BUILD_opencv_optflow": "ON",
"BUILD_EXAMPLES": "OFF",
"BUILD_PERF_TESTS": "OFF",
"BUILD_TESTS": "OFF",
"BUILD_JPEG": "ON",
"BUILD_OPENEXR": "ON",
"BUILD_OPENJPEG": "ON",
"BUILD_PNG": "ON",
"BUILD_TIFF": "ON",
"BUILD_ZLIB": "ON",
Expand All @@ -137,6 +141,7 @@ COMMON_CACHE_ENTRIES = {
"BUILD_SHARED_LIBS": "OFF",
"OPENCV_SKIP_PYTHON_LOADER": "ON",
"OPENCV_SKIP_VISIBILITY_HIDDEN": "ON",
"OPENCV_EXTRA_MODULES_PATH": "$$EXT_BUILD_ROOT$$/external/opencv_contrib/modules",
}

CACHE_ENTRIES = COMMON_CACHE_ENTRIES | select({
Expand Down Expand Up @@ -171,6 +176,9 @@ CACHE_ENTRIES = COMMON_CACHE_ENTRIES | select({

cmake(
name = "opencv_cmake",
data = [
"@opencv_contrib//:all",
],
build_args = [
"--verbose",
"--parallel",
Expand All @@ -189,14 +197,17 @@ cmake(
"//conditions:default": [],
}),
lib_source = "@opencv//:all",
out_include_dir = "include/opencv4",
out_include_dir = select({
"@bazel_tools//src/conditions:windows": "include",
"//conditions:default": "include/opencv4",
}),
out_lib_dir = select({
"@bazel_tools//src/conditions:windows": "x64/vc16",
"//conditions:default": ".", # need to include lib/ when building static libs
}),
out_static_libs = select({
":dbg_cmake_static_win": ["staticlib/opencv_world3416d.lib"],
":cmake_static_win": ["staticlib/opencv_world3416.lib"],
":dbg_cmake_static_win": ["staticlib/opencv_world455d.lib"],
":cmake_static_win": ["staticlib/opencv_world455.lib"],
"//conditions:default": ["lib/libopencv_world.a"],
}) + select({
":dbg_cmake_static_win": ["staticlib/%sd.lib" % lib for lib in OPENCV_3RDPARTY_LIBS],
Expand Down
5 changes: 5 additions & 0 deletions third_party/opencv_contrib.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "all",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
6 changes: 3 additions & 3 deletions third_party/opencv_windows.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ licenses(["notice"]) # BSD license

exports_files(["LICENSE"])

OPENCV_VERSION = "3416" # 3.4.16
OPENCV_VERSION = "455" # 4.5.5

# The following build rule assumes that the executable "opencv-3.4.16-vc14_vc15.exe"
# The following build rule assumes that the executable "opencv-4.5.5-vc14_vc15.exe"
# is downloaded and the files are extracted to local.
# If you install OpenCV separately, please modify the build rule accordingly.
cc_library(
Expand All @@ -30,7 +30,7 @@ cc_library(
"x64/vc15/lib/opencv_world" + OPENCV_VERSION + ".lib",
"x64/vc15/bin/opencv_world" + OPENCV_VERSION + ".dll",
],
hdrs = glob(["include/opencv2/**/*.h*"]),
hdrs = glob(["include/opencv4/opencv2/**/*.h*"]),
includes = ["include/"],
linkstatic = 1,
visibility = ["//visibility:public"],
Expand Down

0 comments on commit b53971e

Please sign in to comment.