Skip to content

Commit

Permalink
Internal
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 684485873
  • Loading branch information
schmidt-sebastian authored and copybara-github committed Oct 10, 2024
1 parent a5d95fe commit 1850f43
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
10 changes: 8 additions & 2 deletions third_party/external_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def external_files():

http_file(
name = "com_google_mediapipe_efficientdet_lite0_fp16_no_nms_tflite",
sha256 = "237a58389081333e5cf4154e42b593ce7dd357445536fcaf4ca5bc51c2c50f1c",
urls = ["https://storage.googleapis.com/mediapipe-assets/efficientdet_lite0_fp16_no_nms.tflite?generation=1693610182046114"],
sha256 = "bcda125c96d3767bca894c8cbe7bc458379c9974c9fd8bdc6204e7124a74082a",
urls = ["https://storage.googleapis.com/mediapipe-assets/efficientdet_lite0_fp16_no_nms.tflite?generation=1728573738871723"],
)

http_file(
Expand Down Expand Up @@ -1018,6 +1018,12 @@ def external_files():
urls = ["https://storage.googleapis.com/mediapipe-assets/ocr_text.jpg?generation=1681244241009078"],
)

http_file(
name = "com_google_mediapipe_opencv2_xcframework_zip",
sha256 = "6b625f564b72fd7c0946de2ae61507bed5daf84f3dbb5296ef4fef19da491160",
urls = ["https://storage.googleapis.com/mediapipe-assets/opencv2.xcframework.zip?generation=1728573757773068"],
)

http_file(
name = "com_google_mediapipe_palm_detection_full_tflite",
sha256 = "1b14e9422c6ad006cde6581a46c8b90dd573c07ab7f3934b5589e7cea3f89a54",
Expand Down
1 change: 1 addition & 0 deletions third_party/prebuilts/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mediapipe_files(srcs = [
"libopencv_core.3.4.darwin_arm64.a",
"libopencv_imgproc.3.4.darwin.a",
"libopencv_imgproc.3.4.darwin_arm64.a",
"opencv2.xcframework.zip",
])

cc_import(
Expand Down
97 changes: 97 additions & 0 deletions third_party/prebuilts/opencv_ios_source.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Description:
# OpenCV xcframework for video/image processing on iOS.

load(
"@//third_party:opencv_ios_source.bzl",
"select_headers",
"unzip_opencv_xcframework",
)
load(
"@build_bazel_rules_apple//apple:apple.bzl",
"apple_static_xcframework_import",
)

licenses(["notice"]) # BSD license

exports_files(["LICENSE"])

genrule(
name = "build_opencv_xcframework",
srcs = ["@mediapipe//third_party/prebuilts:opencv2.xcframework.zip"],
outs = ["opencv2.xcframework.zip"],
cmd = "cp $(SRCS) $(OUTS)",
)

# Unzips `opencv2.xcframework.zip` built from source by `build_opencv_xcframework`
# genrule and returns an exhaustive list of all its files including symlinks.
unzip_opencv_xcframework(
name = "opencv2_unzipped_xcframework_files",
zip_file = "opencv2.xcframework.zip",
)

# Imports the files of the unzipped `opencv2.xcframework` as an apple static
# framework which can be linked to iOS targets.
apple_static_xcframework_import(
name = "opencv_xcframework",
visibility = ["//visibility:public"],
xcframework_imports = [":opencv2_unzipped_xcframework_files"],
)

# Filters the headers for each platform in `opencv2.xcframework` which will be
# used as headers in a `cc_library` that can be linked to C++ targets.
select_headers(
name = "opencv_xcframework_device_headers",
srcs = [":opencv_xcframework"],
platform = "ios-arm64",
)

select_headers(
name = "opencv_xcframework_simulator_headers",
srcs = [":opencv_xcframework"],
platform = "ios-arm64_x86_64-simulator",
)

# `cc_library` that can be linked to C++ targets to import opencv headers.
cc_library(
name = "opencv",
hdrs = select({
"@//mediapipe:ios_x86_64": [
":opencv_xcframework_simulator_headers",
],
"@//mediapipe:ios_sim_arm64": [
":opencv_xcframework_simulator_headers",
],
"@//mediapipe:ios_arm64": [
":opencv_xcframework_device_headers",
],
# A value from above is chosen arbitarily.
"//conditions:default": [
":opencv_xcframework_simulator_headers",
],
}),
copts = [
"-std=c++11",
"-x objective-c++",
],
include_prefix = "opencv2",
linkopts = [
"-framework AssetsLibrary",
"-framework CoreFoundation",
"-framework CoreGraphics",
"-framework CoreMedia",
"-framework Accelerate",
"-framework CoreImage",
"-framework AVFoundation",
"-framework CoreVideo",
"-framework QuartzCore",
],
strip_include_prefix = select({
"@//mediapipe:ios_x86_64": "opencv2.xcframework/ios-arm64_x86_64-simulator/opencv2.framework/Versions/A/Headers",
"@//mediapipe:ios_sim_arm64": "opencv2.xcframework/ios-arm64_x86_64-simulator/opencv2.framework/Versions/A/Headers",
"@//mediapipe:ios_arm64": "opencv2.xcframework/ios-arm64/opencv2.framework/Versions/A/Headers",
# Random value is selected for default cases.
"//conditions:default": "opencv2.xcframework/ios-arm64_x86_64-simulator/opencv2.framework/Versions/A/Headers",
}),
visibility = ["//visibility:public"],
deps = [":opencv_xcframework"],
)

0 comments on commit 1850f43

Please sign in to comment.