From 205dae176b4dbcdee31874f6158fa66bdb3a5c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=9F=D0=B8=D0=B2=D0=B5?= =?UTF-8?q?=D0=BD=D1=8C?= Date: Mon, 18 Jul 2022 21:33:44 -0500 Subject: [PATCH] feat: :sparkles: fixed facemesh app and added profiling --- .bazelversion | 2 +- WORKSPACE | 4 +- mediapipe/.DS_Store | Bin 0 -> 6148 bytes .../Configs/MediaPipe.tulsigen | 3 + .../MediaPipe.tulsiproj/project.tulsiconf | 4 + .../beauty/smooth_face_calculator.cc | 105 +++++++++--------- mediapipe/examples/desktop/beauty/BUILD | 8 ++ mediapipe/graphs/beauty/BUILD | 4 +- mediapipe/graphs/beauty/beauty_desktop.pbtxt | 7 ++ .../graphs/beauty/beauty_desktop_cpu.pbtxt | 7 ++ .../graphs/beauty/beauty_mobile_gpu.pbtxt | 10 +- .../beauty/subgraphs/face_renderer_cpu.pbtxt | 3 - .../beauty/subgraphs/face_renderer_gpu.pbtxt | 86 ++++++++++++++ .../face_mesh/face_mesh_desktop_live.pbtxt | 7 ++ .../graphs/face_mesh/face_mesh_mobile.pbtxt | 6 + .../face_mesh/face_mesh_mobile_gpu.pbtxt | 6 + mediapipe/util/annotation_renderer.cc | 8 +- third_party/opencv_linux.BUILD | 54 ++++----- third_party/opencv_macos.BUILD | 2 +- 19 files changed, 230 insertions(+), 96 deletions(-) create mode 100644 mediapipe/.DS_Store create mode 100644 mediapipe/graphs/beauty/subgraphs/face_renderer_gpu.pbtxt diff --git a/.bazelversion b/.bazelversion index 0062ac971..91ff57278 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.0.0 +5.2.0 diff --git a/WORKSPACE b/WORKSPACE index e85e34d84..1e7cf07a4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -205,13 +205,13 @@ new_local_repository( # For local MacOS builds, the path should point to an opencv@3 installation. # If you edit the path here, you will also need to update the corresponding # prefix in "opencv_macos.BUILD". - path = "/usr/local", + path = "/opt/homebrew/Cellar/", ) new_local_repository( name = "macos_ffmpeg", build_file = "@//third_party:ffmpeg_macos.BUILD", - path = "/usr/local/opt/ffmpeg", + path = "/opt/homebrew/Cellar/ffmpeg", ) new_local_repository( diff --git a/mediapipe/.DS_Store b/mediapipe/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..dcbb44cbd1cc8605f4cf8321da0f35be08608ba6 GIT binary patch literal 6148 zcmeHK!Ab)$5S`H;7Q7UC=`mkW=nqIN+oK@#=1J>{R<>kOd(R)}NBLpC$&Av)Jt%^R z&Oq{Jle}c|V3Q0H@nYA^iN-`!p$M`#118ObT?aOJ1mrTuC7scRI=ZIWz(l{XNn)SS zDI#tV`F{M5w4;_D%6{%C(Or8pUtOhbr`wpO&oj5FuGei^gHg?%&!4*Emy@rsn{TkY z+x@5`mUVLlTme_W75L{0;LaASjugFi1zZ7F;9UVZ9|DSCG|Yi`Cwc5EqURxI_3{$IB`_;+7)mG`U)KC z=UDFlC4QN~B)?DbFIT`7_+tw2s9x0zY|8G|58IQwHlSRfh{?Dt4h(+p5r7XlN2aAy c`-Aux7Y(zb%p&cD4)ljW5yUH3;0F|V1(m@*qW}N^ literal 0 HcmV?d00001 diff --git a/mediapipe/MediaPipe.tulsiproj/Configs/MediaPipe.tulsigen b/mediapipe/MediaPipe.tulsiproj/Configs/MediaPipe.tulsigen index f3b74900c..8e05d5cb7 100644 --- a/mediapipe/MediaPipe.tulsiproj/Configs/MediaPipe.tulsigen +++ b/mediapipe/MediaPipe.tulsiproj/Configs/MediaPipe.tulsigen @@ -2,6 +2,7 @@ "additionalFilePaths" : [ "/BUILD", "mediapipe/BUILD", + "mediapipe/examples/ios/beauty/BUILD", "mediapipe/examples/ios/common/BUILD", "mediapipe/examples/ios/facedetectioncpu/BUILD", "mediapipe/examples/ios/facedetectiongpu/BUILD", @@ -23,6 +24,7 @@ "mediapipe/objc/testing/app/BUILD" ], "buildTargets" : [ + "//mediapipe/examples/ios/beauty:BeautyApp", "//mediapipe/examples/ios/facedetectioncpu:FaceDetectionCpuApp", "//mediapipe/examples/ios/facedetectiongpu:FaceDetectionGpuApp", "//mediapipe/examples/ios/faceeffect:FaceEffectApp", @@ -93,6 +95,7 @@ "mediapipe/examples/ios", "mediapipe/examples/ios/common", "mediapipe/examples/ios/common/Base.lproj", + "mediapipe/examples/ios/beauty", "mediapipe/examples/ios/facedetectioncpu", "mediapipe/examples/ios/facedetectiongpu", "mediapipe/examples/ios/faceeffect", diff --git a/mediapipe/MediaPipe.tulsiproj/project.tulsiconf b/mediapipe/MediaPipe.tulsiproj/project.tulsiconf index a2fe886cf..70a8a0d2d 100644 --- a/mediapipe/MediaPipe.tulsiproj/project.tulsiconf +++ b/mediapipe/MediaPipe.tulsiproj/project.tulsiconf @@ -3,6 +3,9 @@ "optionSet" : { "CLANG_CXX_LANGUAGE_STANDARD" : { "p" : "c++14" + }, + "EnvironmentVariables" : { + "p" : "MEDIAPIPE_PROFILING=1" } } }, @@ -10,6 +13,7 @@ "", "mediapipe", "mediapipe/examples/ios", + "mediapipe/examples/ios/beauty", "mediapipe/examples/ios/facedetectioncpu", "mediapipe/examples/ios/facedetectiongpu", "mediapipe/examples/ios/faceeffect", diff --git a/mediapipe/calculators/beauty/smooth_face_calculator.cc b/mediapipe/calculators/beauty/smooth_face_calculator.cc index 33b578dd1..76210c305 100644 --- a/mediapipe/calculators/beauty/smooth_face_calculator.cc +++ b/mediapipe/calculators/beauty/smooth_face_calculator.cc @@ -295,65 +295,65 @@ namespace mediapipe part_forehead_mask.convertTo(part_forehead_mask, CV_8U); cv::Mat image_sm, image_sm_hsv, skinMask; - - cv::resize(mat_image_, image_sm, cv::Size(image_width_, image_height_)); - cv::cvtColor(image_sm, image_sm_hsv, cv::COLOR_BGR2HSV); - - std::vector x, y; - std::vector location; - +// +// cv::resize(mat_image_, image_sm, cv::Size(image_width_, image_height_)); +// cv::cvtColor(image_sm, image_sm_hsv, cv::COLOR_BGR2HSV); +// +// std::vector x, y; +// std::vector location; +// cv::Vec3d hsv_min, hsv_max; - - std::vector channels(3); - cv::split(image_sm_hsv, channels); - std::vector> minx(3), maxx(3); - int c = 0; - for (auto ch : channels) - { - cv::Mat row, mask_row; - double min, max; - for (int i = 0; i < ch.rows; i++) - { - row = ch.row(i); - mask_row = part_forehead_mask.row(i); - cv::minMaxLoc(row, &min, &max, 0, 0, mask_row); - minx[c].push_back(min); - maxx[c].push_back(max); - } - c++; - } - for (int i = 0; i < 3; i++) - { - hsv_min[i] = *std::min_element(minx[i].begin(), minx[i].end()); - } - for (int i = 0; i < 3; i++) - { - hsv_max[i] = *std::max_element(maxx[i].begin(), maxx[i].end()); - } - +// +// std::vector channels(3); +// cv::split(image_sm_hsv, channels); +// std::vector> minx(3), maxx(3); +// int c = 0; +// for (auto ch : channels) +// { +// cv::Mat row, mask_row; +// double min, max; +// for (int i = 0; i < ch.rows; i++) +// { +// row = ch.row(i); +// mask_row = part_forehead_mask.row(i); +// cv::minMaxLoc(row, &min, &max, 0, 0, mask_row); +// minx[c].push_back(min); +// maxx[c].push_back(max); +// } +// c++; +// } +// for (int i = 0; i < 3; i++) +// { +// hsv_min[i] = *std::min_element(minx[i].begin(), minx[i].end()); +// } +// for (int i = 0; i < 3; i++) +// { +// hsv_max[i] = *std::max_element(maxx[i].begin(), maxx[i].end()); +// } +// cv::Mat _forehead_kernel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(1, 1)); - cv::inRange(image_sm_hsv, hsv_min, hsv_max, skinMask); +// cv::inRange(image_sm_hsv, hsv_min, hsv_max, skinMask); cv::erode(skinMask, skinMask, _forehead_kernel, cv::Point(-1, -1), 2); cv::dilate(skinMask, skinMask, _forehead_kernel, cv::Point(-1, -1), 2); - skinMask.convertTo(skinMask, CV_8U, 1.0 / 255); - - cv::findNonZero(skinMask, location); - - double max_part_f, x_min_part, x_max_part; - - for (auto &i : location) - { - x.push_back(i.x); - y.push_back(i.y); - } - - cv::minMaxLoc(y, NULL, &max_part_f); - cv::minMaxLoc(x, &x_min_part, &x_max_part); +// skinMask.convertTo(skinMask, CV_8U, 1.0 / 255); +// +// cv::findNonZero(skinMask, location); +// +// double max_part_f, x_min_part, x_max_part; +// +// for (auto &i : location) +// { +// x.push_back(i.x); +// y.push_back(i.y); +// } +// +// cv::minMaxLoc(y, NULL, &max_part_f); +// cv::minMaxLoc(x, &x_min_part, &x_max_part); cv::Mat new_skin_mask = cv::Mat::zeros(skinMask.size(), CV_8U); - new_skin_mask(cv::Range(face_box_min_y, max_part_f), cv::Range(x_min_part, x_max_part)) = - skinMask(cv::Range(face_box_min_y, max_part_f), cv::Range(x_min_part, x_max_part)); +// new_skin_mask(cv::Range(face_box_min_y, max_part_f), cv::Range(x_min_part, x_max_part)) = +// skinMask(cv::Range(face_box_min_y, max_part_f), cv::Range(x_min_part, x_max_part)); return new_skin_mask; } @@ -399,6 +399,7 @@ namespace mediapipe cv::Mat patch_new, patch_wow; cv::cvtColor(patch_face, patch_wow, cv::COLOR_RGBA2RGB); cv::bilateralFilter(patch_wow, patch_new, 12, 50, 50); + //patch_wow.copyTo(patch_new); cv::Mat patch_new_nff, patch_new_mask, patch, patch_face_nff; diff --git a/mediapipe/examples/desktop/beauty/BUILD b/mediapipe/examples/desktop/beauty/BUILD index f09321e79..761940617 100644 --- a/mediapipe/examples/desktop/beauty/BUILD +++ b/mediapipe/examples/desktop/beauty/BUILD @@ -32,6 +32,14 @@ cc_binary( ], ) +cc_binary( + name = "beauty_mobile", + deps = [ + "//mediapipe/examples/desktop:demo_run_graph_main", + "//mediapipe/graphs/beauty:mobile_calculators", + ], +) + cc_binary( name = "beauty_cpu_over", deps = [ diff --git a/mediapipe/graphs/beauty/BUILD b/mediapipe/graphs/beauty/BUILD index dc024140e..8e8409f59 100644 --- a/mediapipe/graphs/beauty/BUILD +++ b/mediapipe/graphs/beauty/BUILD @@ -68,8 +68,8 @@ cc_library( "//mediapipe/gpu:gpu_buffer_to_image_frame_calculator", "//mediapipe/gpu:image_frame_to_gpu_buffer_calculator", "//mediapipe/calculators/core:flow_limiter_calculator", - #"//mediapipe/graphs/beauty/subgraphs:face_renderer_cpu", - "//mediapipe/graphs/face_mesh/subgraphs:face_renderer_cpu", + "//mediapipe/graphs/beauty/subgraphs:face_renderer_cpu", + "//mediapipe/graphs/beauty/subgraphs:face_renderer_gpu", "//mediapipe/modules/face_landmark:face_landmark_front_gpu", ], ) diff --git a/mediapipe/graphs/beauty/beauty_desktop.pbtxt b/mediapipe/graphs/beauty/beauty_desktop.pbtxt index f6d407303..3a00401a7 100644 --- a/mediapipe/graphs/beauty/beauty_desktop.pbtxt +++ b/mediapipe/graphs/beauty/beauty_desktop.pbtxt @@ -9,6 +9,13 @@ output_stream: "output_video" # landmarks. (std::vector) output_stream: "multi_face_landmarks" +profiler_config { + trace_enabled: true + enable_profiler: true + trace_log_interval_count: 200 + trace_log_path: "/Users/alena/Workdir/mediapipe/logs/beauty/" +} + node { calculator: "FlowLimiterCalculator" input_stream: "input_video" diff --git a/mediapipe/graphs/beauty/beauty_desktop_cpu.pbtxt b/mediapipe/graphs/beauty/beauty_desktop_cpu.pbtxt index 4b963ef88..816f01638 100644 --- a/mediapipe/graphs/beauty/beauty_desktop_cpu.pbtxt +++ b/mediapipe/graphs/beauty/beauty_desktop_cpu.pbtxt @@ -9,6 +9,13 @@ output_stream: "output_video" # landmarks. (std::vector) output_stream: "multi_face_landmarks" +profiler_config { + trace_enabled: true + enable_profiler: true + trace_log_interval_count: 200 + trace_log_path: "/Users/alena/Workdir/mediapipe/logs/beauty/" +} + # Throttles the images flowing downstream for flow control. It passes through # the very first incoming image unaltered, and waits for downstream nodes # (calculators and subgraphs) in the graph to finish their tasks before it diff --git a/mediapipe/graphs/beauty/beauty_mobile_gpu.pbtxt b/mediapipe/graphs/beauty/beauty_mobile_gpu.pbtxt index 96d72d04d..ebed553b2 100644 --- a/mediapipe/graphs/beauty/beauty_mobile_gpu.pbtxt +++ b/mediapipe/graphs/beauty/beauty_mobile_gpu.pbtxt @@ -12,6 +12,12 @@ output_stream: "output_video" # landmarks. (std::vector) output_stream: "multi_face_landmarks" +profiler_config { + trace_enabled: true + enable_profiler: true + trace_log_interval_count: 200 +} + # Throttles the images flowing downstream for flow control. It passes through # the very first incoming image unaltered, and waits for downstream nodes # (calculators and subgraphs) in the graph to finish their tasks before it @@ -58,6 +64,9 @@ node { input_side_packet: "NUM_FACES:num_faces" input_side_packet: "WITH_ATTENTION:with_attention" output_stream: "LANDMARKS:multi_face_landmarks" + output_stream: "ROIS_FROM_LANDMARKS:face_rects_from_landmarks" + output_stream: "DETECTIONS:face_detections" + output_stream: "ROIS_FROM_DETECTIONS:face_rects_from_detections" } # Subgraph that renders face-landmark annotation onto the input image. @@ -68,7 +77,6 @@ node { output_stream: "IMAGE:output_video_cpu" } -# Defines side packets for further use in the graph. node { calculator: "ImageFrameToGpuBufferCalculator" input_stream: "output_video_cpu" diff --git a/mediapipe/graphs/beauty/subgraphs/face_renderer_cpu.pbtxt b/mediapipe/graphs/beauty/subgraphs/face_renderer_cpu.pbtxt index 866754f72..f910775cc 100644 --- a/mediapipe/graphs/beauty/subgraphs/face_renderer_cpu.pbtxt +++ b/mediapipe/graphs/beauty/subgraphs/face_renderer_cpu.pbtxt @@ -80,6 +80,3 @@ node { input_stream: "FACEBOX:0:multi_face_box" output_stream: "IMAGE:output_image" } - - - diff --git a/mediapipe/graphs/beauty/subgraphs/face_renderer_gpu.pbtxt b/mediapipe/graphs/beauty/subgraphs/face_renderer_gpu.pbtxt new file mode 100644 index 000000000..a2651a3d5 --- /dev/null +++ b/mediapipe/graphs/beauty/subgraphs/face_renderer_gpu.pbtxt @@ -0,0 +1,86 @@ +# MediaPipe face mesh rendering subgraph. + +type: "FaceRendererGpu" + +# GPU image. (GpuBuffer) +input_stream: "IMAGE:input_image" +# Collection of detected/predicted faces, each represented as a list of +# landmarks. (std::vector) +input_stream: "LANDMARKS:multi_face_landmarks" +# Regions of interest calculated based on palm detections. +# (std::vector) +input_stream: "NORM_RECTS:rects" +# Detected palms. (std::vector) +input_stream: "DETECTIONS:detections" + +# GPU image with rendered data. (GpuBuffer) +output_stream: "IMAGE:output_image" + +node { + calculator: "ImagePropertiesCalculator" + input_stream: "IMAGE_GPU:input_image" + output_stream: "SIZE:image_size" +} +# Outputs each element of multi_face_landmarks at a fake timestamp for the rest +# of the graph to process. At the end of the loop, outputs the BATCH_END +# timestamp for downstream calculators to inform them that all elements in the +# vector have been processed. +node { + calculator: "BeginLoopNormalizedLandmarkListVectorCalculator" + input_stream: "ITERABLE:multi_face_landmarks" + input_stream: "IMAGE_GPU:input_image" + output_stream: "ITEM:face_landmarks" + output_stream: "IMAGE_GPU:loop_image" + output_stream: "BATCH_END:landmark_timestamp" +} + +# Converts landmarks to face part masks. +node { + calculator: "LandmarksToMaskCalculator" + input_stream: "IMAGE_GPU:loop_image" + input_stream: "NORM_LANDMARKS:face_landmarks" + output_stream: "FACEBOX:face_box" + output_stream: "MASK:mask" +} + +# Collects a MapMask object for each hand into a vector. Upon receiving the +# BATCH_END timestamp, outputs the vector of RenderData at the BATCH_END +# timestamp. +node { + calculator: "EndLoopMapMaskCalculator" + input_stream: "ITEM:mask" + input_stream: "BATCH_END:landmark_timestamp" + output_stream: "ITERABLE:multi_mask" +} + +node { + calculator: "EndLoopFaceBoxCalculator" + input_stream: "ITEM:face_box" + input_stream: "BATCH_END:landmark_timestamp" + output_stream: "ITERABLE:multi_face_box" +} + +#Applies lipstick to the face on the IMAGE using MASK. +node { + calculator: "DrawLipstickCalculator" + input_stream: "IMAGE_GPU:input_image" + input_stream: "MASK:0:multi_mask" + output_stream: "IMAGE_GPU:input_image_1" +} + +#Whitens teeth of the face on the IMAGE using MASK. +node { + calculator: "WhitenTeethCalculator" + input_stream: "IMAGE_GPU:input_image_1" + input_stream: "MASK:0:multi_mask" + output_stream: "IMAGE_GPU:input_image_2" +} + +#Smoothes face on the IMAGE using MASK. +node { + calculator: "SmoothFaceCalculator" + input_stream: "IMAGE_GPU:input_image_2" + input_stream: "MASK:0:multi_mask" + input_stream: "FACEBOX:0:multi_face_box" + output_stream: "IMAGE_GPU:output_image" +} diff --git a/mediapipe/graphs/face_mesh/face_mesh_desktop_live.pbtxt b/mediapipe/graphs/face_mesh/face_mesh_desktop_live.pbtxt index 2cc563424..3186a145d 100644 --- a/mediapipe/graphs/face_mesh/face_mesh_desktop_live.pbtxt +++ b/mediapipe/graphs/face_mesh/face_mesh_desktop_live.pbtxt @@ -9,6 +9,13 @@ output_stream: "output_video" # landmarks. (std::vector) output_stream: "multi_face_landmarks" +profiler_config { + trace_enabled: true + enable_profiler: true + trace_log_interval_count: 200 + trace_log_path: "/Users/alena/Workdir/mediapipe/logs" +} + # Throttles the images flowing downstream for flow control. It passes through # the very first incoming image unaltered, and waits for downstream nodes # (calculators and subgraphs) in the graph to finish their tasks before it diff --git a/mediapipe/graphs/face_mesh/face_mesh_mobile.pbtxt b/mediapipe/graphs/face_mesh/face_mesh_mobile.pbtxt index 73314f3dd..0350324a5 100644 --- a/mediapipe/graphs/face_mesh/face_mesh_mobile.pbtxt +++ b/mediapipe/graphs/face_mesh/face_mesh_mobile.pbtxt @@ -12,6 +12,12 @@ output_stream: "output_video" # landmarks. (std::vector) output_stream: "multi_face_landmarks" +profiler_config { + trace_enabled: true + enable_profiler: true + trace_log_interval_count: 200 +} + # Throttles the images flowing downstream for flow control. It passes through # the very first incoming image unaltered, and waits for downstream nodes # (calculators and subgraphs) in the graph to finish their tasks before it diff --git a/mediapipe/graphs/face_mesh/face_mesh_mobile_gpu.pbtxt b/mediapipe/graphs/face_mesh/face_mesh_mobile_gpu.pbtxt index e9711e192..7a19e45a9 100644 --- a/mediapipe/graphs/face_mesh/face_mesh_mobile_gpu.pbtxt +++ b/mediapipe/graphs/face_mesh/face_mesh_mobile_gpu.pbtxt @@ -12,6 +12,12 @@ output_stream: "output_video" # landmarks. (std::vector) output_stream: "multi_face_landmarks" +profiler_config { + trace_enabled: true + enable_profiler: true + trace_log_interval_count: 200 +} + # Throttles the images flowing downstream for flow control. It passes through # the very first incoming image unaltered, and waits for downstream nodes # (calculators and subgraphs) in the graph to finish their tasks before it diff --git a/mediapipe/util/annotation_renderer.cc b/mediapipe/util/annotation_renderer.cc index b7bbfd550..cc4976128 100644 --- a/mediapipe/util/annotation_renderer.cc +++ b/mediapipe/util/annotation_renderer.cc @@ -108,7 +108,7 @@ void AnnotationRenderer::RenderDataOnImage(const RenderData &render_data) if (render_data.render_annotations().size()){ DrawLipstick(render_data); WhitenTeeth(render_data); -// SmoothFace(render_data); + //SmoothFace(render_data); } else { @@ -170,6 +170,7 @@ cv::Mat AnnotationRenderer::FormFacePartMask(std::vector orderList, const R } if (points_array.size() != orderList.size()){ + mask.convertTo(mask, CV_8U); return mask; } @@ -290,7 +291,6 @@ cv::Mat AnnotationRenderer::predict_forehead_mask(const RenderData &render_data, void AnnotationRenderer::SmoothFace(const RenderData &render_data) { - cv::Mat not_full_face = cv::Mat(FormFacePartMask(FACE_OVAL, render_data)) + cv::Mat(predict_forehead_mask(render_data, std::get<1>(GetFaceBox(render_data)))) - cv::Mat(FormFacePartMask(LEFT_EYE, render_data)) - @@ -324,7 +324,9 @@ void AnnotationRenderer::SmoothFace(const RenderData &render_data) cv::Mat patch_nff = not_full_face(cv::Range(min_y, max_y), cv::Range(min_x, max_x)); cv::Mat patch_new, patch_wow; cv::cvtColor(patch_face, patch_wow, cv::COLOR_RGBA2RGB); - cv::bilateralFilter(patch_wow, patch_new, 12, 50, 50); + if (patch_wow.data != patch_new.data) { + cv::bilateralFilter(patch_wow, patch_new, 12, 50, 50); + } cv::Mat patch_new_nff, patch_new_mask, patch, patch_face_nff; diff --git a/third_party/opencv_linux.BUILD b/third_party/opencv_linux.BUILD index 844585541..3b101ef91 100644 --- a/third_party/opencv_linux.BUILD +++ b/third_party/opencv_linux.BUILD @@ -1,41 +1,33 @@ # Description: -# OpenCV libraries for video/image processing on Linux +# OpenCV libraries for video/image processing on MacOS licenses(["notice"]) # BSD license exports_files(["LICENSE"]) -# The following build rule assumes that OpenCV is installed by -# 'apt-get install libopencv-core-dev libopencv-highgui-dev \' -# ' libopencv-calib3d-dev libopencv-features2d-dev \' -# ' libopencv-imgproc-dev libopencv-video-dev' -# on Debian Buster/Ubuntu 18.04. -# If you install OpenCV separately, please modify the build rule accordingly. +load("@bazel_skylib//lib:paths.bzl", "paths") + +# The path to OpenCV is a combination of the path set for "macos_opencv" +# in the WORKSPACE file and the prefix here. +PREFIX = "opencv@3/3.4.16_3/" + cc_library( name = "opencv", - hdrs = glob([ - # For OpenCV 4.x - #"include/aarch64-linux-gnu/opencv4/opencv2/cvconfig.h", - #"include/arm-linux-gnueabihf/opencv4/opencv2/cvconfig.h", - #"include/x86_64-linux-gnu/opencv4/opencv2/cvconfig.h", - #"include/opencv4/opencv2/**/*.h*", - ]), - includes = [ - # For OpenCV 4.x - #"include/aarch64-linux-gnu/opencv4/", - #"include/arm-linux-gnueabihf/opencv4/", - #"include/x86_64-linux-gnu/opencv4/", - #"include/opencv4/", - ], - linkopts = [ - "-l:libopencv_core.so", - "-l:libopencv_calib3d.so", - "-l:libopencv_features2d.so", - "-l:libopencv_highgui.so", - "-l:libopencv_imgcodecs.so", - "-l:libopencv_imgproc.so", - "-l:libopencv_video.so", - "-l:libopencv_videoio.so", - ], + 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/opencv2/**/*.h*")]), + includes = [paths.join(PREFIX, "include/")], + linkstatic = 1, visibility = ["//visibility:public"], ) + diff --git a/third_party/opencv_macos.BUILD b/third_party/opencv_macos.BUILD index 3c17155d2..cb8fd4c57 100644 --- a/third_party/opencv_macos.BUILD +++ b/third_party/opencv_macos.BUILD @@ -9,7 +9,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths") # 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@3" +PREFIX = "opencv@3/3.4.16_3/" cc_library( name = "opencv",