A sample OpenCV C++ project demo built with Bazel on Windows.
- Acknowledgement to @Kristina & Rick Smith.
- Bazel 0.23.0 or later (https://www.bazel.build/)
- OpenCV 2.4.x or later (https://opencv.org/)
- Make sure OpenCV path is in your System Environment Variables.
- In the WORKSPACE file, change the value of "path" to the OpenCV install path. For example:
new_local_repository(
name = "opencv_install_path",
path = "C:\\opencv\\build", # add your OpenCV path here
build_file = "opencv.BUILD",
)
- In the opencv.BUILD file, locate the OpenCV libraries in "srcs" according to your C++ complier version:
- vc16 = Visual Studio 2019
- vc15 = Visual Studio 2017
- vc14 = Visual Studio 2015
- vc12 = Visual Studio 2013
cc_library(
name = "opencv_rule",
srcs = glob(["x64/vc14/lib/*.lib"]), # the lib location, under your OpenCV path
hdrs = glob(["include/**/*.hpp",
"include/**/*.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
linkstatic = 1,
)
Build the project:
bazel build //src:main
Run the binary:
\bazel-bin\src\main.exe