Skip to content

Commit

Permalink
build: OpenCV 4 for macOS (arm64)
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Aug 24, 2024
1 parent b53971e commit 98b3281
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ new_local_repository(

new_local_repository(
name = "macos_opencv",
build_file = "@mediapipe//third_party:opencv_macos.BUILD",
build_file = "@//third_party:opencv_macos.BUILD",
path = "/usr/local",
)

new_local_repository(
name = "macos_arm64_opencv",
build_file = "@mediapipe//third_party:opencv_macos.BUILD",
build_file = "@//third_party:opencv_macos.BUILD",
path = "/opt/homebrew",
)

Expand Down
2 changes: 1 addition & 1 deletion third_party/opencv.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ cmake(
}) + select({
":dbg_cmake_static_win": ["staticlib/%sd.lib" % lib for lib in OPENCV_3RDPARTY_LIBS],
":cmake_static_win": ["staticlib/%s.lib" % lib for lib in OPENCV_3RDPARTY_LIBS],
"@cpuinfo//:macos_arm64": ["share/OpenCV/3rdparty/lib/lib%s.a" % lib for lib in OPENCV_3RDPARTY_LIBS_M1],
"@cpuinfo//:macos_arm64": ["lib/opencv4/3rdparty/lib%s.a" % lib for lib in OPENCV_3RDPARTY_LIBS_M1],
"//conditions:default": ["lib/opencv4/3rdparty/lib%s.a" % lib for lib in OPENCV_3RDPARTY_LIBS],
}),
out_shared_libs = [],
Expand Down
49 changes: 49 additions & 0 deletions third_party/opencv_macos.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2019 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# CHANGES:
# - support OpenCV 4

# Description:
# OpenCV libraries for video/image processing on MacOS

load("@bazel_skylib//lib:paths.bzl", "paths")

licenses(["notice"]) # BSD license

exports_files(["LICENSE"])

# The path to OpenCV is a combination of the path set for "macos_opencv"
# in the WORKSPACE file and the prefix here.
PREFIX = "opt/opencv@4"

cc_library(
name = "opencv",
srcs = glob(
[
paths.join(PREFIX, "lib/libopencv_core.dylib"),
paths.join(PREFIX, "lib/libopencv_calib3d.dylib"),
paths.join(PREFIX, "lib/libopencv_features2d.dylib"),
paths.join(PREFIX, "lib/libopencv_highgui.dylib"),
paths.join(PREFIX, "lib/libopencv_imgcodecs.dylib"),
paths.join(PREFIX, "lib/libopencv_imgproc.dylib"),
paths.join(PREFIX, "lib/libopencv_video.dylib"),
paths.join(PREFIX, "lib/libopencv_videoio.dylib"),
],
),
hdrs = glob([paths.join(PREFIX, "include/opencv4/opencv2/**/*.h*")]),
includes = [paths.join(PREFIX, "include/opencv4/")],
linkstatic = 1,
visibility = ["//visibility:public"],
)

0 comments on commit 98b3281

Please sign in to comment.