google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.07k stars 5.11k forks source link

#include file `<opencv2/core/version.hpp>` can't be found #2634

Closed jld23 closed 3 years ago

jld23 commented 3 years ago

Please make sure that this is a build/installation issue and also refer to the troubleshooting documentation before raising any issues. I didn't find this issue in the troubleshooting section or in other recent open issues.

System information (Please provide as much relevant information as possible)

Describe the problem: I'm trying to build a docker container with CUDA support. I have built the opencv and tensorflow components but when I try and build mediapipe from source I get the following errror:

ERROR: /mediapipe/mediapipe/calculators/util/BUILD:762:11: C++ compilation of rule '//mediapipe/calculators/util:detection_projection_calculator' failed (Exit 1): crosstool_wrapper_driver_is_not_gcc failed: error executing command 
  (cd /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/execroot/mediapipe && \
  exec env - \
    LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64 \
    PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
    PYTHON_BIN_PATH=/usr/bin/python3 \
    TF_NEED_CUDA=1 \
  external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -MD -MF bazel-out/k8-opt/bin/mediapipe/calculators/util/_objs/detection_projection_calculator/detection_projection_calculator.pic.d '-frandom-seed=bazel-out/k8-opt/bin/mediapipe/calculators/util/_objs/detection_projection_calculator/detection_projection_calculator.pic.o' -DMEDIAPIPE_PROFILER_AVAILABLE -iquote . -iquote bazel-out/k8-opt/bin -iquote external/com_github_glog_glog -iquote bazel-out/k8-opt/bin/external/com_github_glog_glog -iquote external/com_github_gflags_gflags -iquote bazel-out/k8-opt/bin/external/com_github_gflags_gflags -iquote external/com_google_absl -iquote bazel-out/k8-opt/bin/external/com_google_absl -iquote external/com_google_protobuf -iquote bazel-out/k8-opt/bin/external/com_google_protobuf -iquote external/zlib -iquote bazel-out/k8-opt/bin/external/zlib -iquote external/linux_opencv -iquote bazel-out/k8-opt/bin/external/linux_opencv -Ibazel-out/k8-opt/bin/external/com_github_glog_glog/_virtual_includes/default_glog_headers -Ibazel-out/k8-opt/bin/external/com_github_gflags_gflags/_virtual_includes/gflags -isystem external/com_google_protobuf/src -isystem bazel-out/k8-opt/bin/external/com_google_protobuf/src -isystem external/zlib -isystem bazel-out/k8-opt/bin/external/zlib -isystem external/linux_opencv/include/opencv4 -isystem bazel-out/k8-opt/bin/external/linux_opencv/include/opencv4 -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -fPIC -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -fno-omit-frame-pointer -no-canonical-prefixes -fno-canonical-system-headers -DNDEBUG -g0 -O2 -ffunction-sections -fdata-sections -w -DNDEBUG -DMESA_EGL_NO_X11_HEADERS -DEGL_NO_X11 '-std=c++17' -c mediapipe/calculators/util/detection_projection_calculator.cc -o bazel-out/k8-opt/bin/mediapipe/calculators/util/_objs/detection_projection_calculator/detection_projection_calculator.pic.o)
Execution platform: @local_execution_config_platform//:platform
In file included from ./mediapipe/framework/formats/location.h:44,
                 from mediapipe/calculators/util/detection_projection_calculator.cc:23:
./mediapipe/framework/port/opencv_core_inc.h:18:10: fatal error: opencv2/core/version.hpp: No such file or directory
 #include <opencv2/core/version.hpp>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Target //mediapipe/modules/face_detection:face_detection_short_range_cpu failed to build

Based on the message, I think there is a path issue because the missing file is here:

root@3412f9bc6ebe:/mediapipe# find / -name version.hpp
/usr/local/include/opencv4/opencv2/dnn/version.hpp
/usr/local/include/opencv4/opencv2/core/version.hpp

I've tried all the combinations that seem reasonable in opencv_linux.BUILD but I always get the same result.

Provide the exact sequence of commands / steps that you executed before running into the problem: This error occurs when trying to run the final command in this sequence:

python3 -m pip install -r requirements.txt
python3 setup.py gen_protos
python3 setup.py install --link-opencv

Complete Logs: Include Complete Log information or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached:

Here is the log precceding the error:

root@3412f9bc6ebe:/mediapipe# python3 setup.py install --link-opencv
running install
running build_binary_graphs
generating binarypb: mediapipe/modules/face_detection/face_detection_short_range_cpu
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
INFO: SHA256 (https://github.com/bazelbuild/rules_foreign_cc/archive/0.1.0.zip) = c2cdcf55ffaf49366725639e45dedd449b8c3fe22b54e31625eb80ce3a240f1e
DEBUG: Rule 'rules_foreign_cc' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "c2cdcf55ffaf49366725639e45dedd449b8c3fe22b54e31625eb80ce3a240f1e"
DEBUG: Repository rules_foreign_cc instantiated at:
  /mediapipe/WORKSPACE:42:13: in <toplevel>
Repository rule http_archive defined at:
  /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
WARNING: Download from http://mirror.tensorflow.org/github.com/tensorflow/toolchains/archive/d781e89e2ee797ea7afd0c8391e761616fc5d50d.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
WARNING: Download from http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/cf1e44edb908e9616030cc83d085989b8e6cd6df.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
WARNING: Download from http://mirror.tensorflow.org/github.com/tensorflow/runtime/archive/0a8c6996bd6a58eb0e7e2fe049ac67bf663e1950.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/org_tensorflow/third_party/repo.bzl:109:14: 
Warning: skipping import of repository 'com_google_absl' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/org_tensorflow/third_party/repo.bzl:109:14: 
Warning: skipping import of repository 'com_google_protobuf' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/org_tensorflow/third_party/repo.bzl:109:14: 
Warning: skipping import of repository 'com_google_googletest' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/org_tensorflow/third_party/repo.bzl:109:14: 
Warning: skipping import of repository 'com_github_gflags_gflags' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/org_tensorflow/third_party/repo.bzl:109:14: 
Warning: skipping import of repository 'build_bazel_rules_apple' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/org_tensorflow/third_party/repo.bzl:109:14: 
Warning: skipping import of repository 'build_bazel_rules_swift' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/org_tensorflow/third_party/repo.bzl:109:14: 
Warning: skipping import of repository 'build_bazel_apple_support' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/org_tensorflow/third_party/repo.bzl:109:14: 
Warning: skipping import of repository 'bazel_skylib' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/org_tensorflow/third_party/repo.bzl:109:14: 
Warning: skipping import of repository 'pybind11' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:118:10: 
Auto-Configuration Warning: 'TMP' environment variable is not set, using 'C:\Windows\Temp' as default
INFO: SHA256 (https://github.com/bazelbuild/rules_cc/archive/main.zip) = 22c9b373a34a848c16d1b61c5f7be61ee2c905121e2a7eb7ac79756a3a22637e
DEBUG: Rule 'rules_cc' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "22c9b373a34a848c16d1b61c5f7be61ee2c905121e2a7eb7ac79756a3a22637e"
DEBUG: Repository rules_cc instantiated at:
  /mediapipe/WORKSPACE:36:13: in <toplevel>
Repository rule http_archive defined at:
  /root/.cache/bazel/_bazel_root/4884d566396e9b67b62185751879ad14/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/XNNPACK/archive/28407b24f04694a1353ffca91248e89bc250eb5b.zip failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
INFO: Analyzed target //mediapipe/modules/face_detection:face_detection_short_range_cpu (128 packages loaded, 7063 targets configured).
INFO: Found 1 target...
INFO: From ProtoCompile mediapipe/gpu/gl_context_options.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/tensor/tensors_to_detections_calculator.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/framework/calculator_profile.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/tensor/inference_calculator.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/framework/tool/field_data.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/framework/tool/calculator_graph_template.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/framework/calculator.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/internal/callback_packet_calculator.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/tensor/tensors_to_detections_calculator.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/internal/callback_packet_calculator.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/util/non_max_suppression_calculator.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/tflite/ssd_anchors_calculator.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/tflite/ssd_anchors_calculator.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/framework/tool/calculator_graph_template.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/framework/tool/field_data.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/framework/calculator_profile.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/util/non_max_suppression_calculator.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/tensor/image_to_tensor_calculator.pb.h:
bazel-out/k8-opt/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/tensor/inference_calculator.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/gpu/gl_context_options.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/calculators/tensor/image_to_tensor_calculator.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From ProtoCompile mediapipe/framework/calculator.pb.h [for host]:
bazel-out/host/bin/external/com_google_protobuf/src: warning: directory does not exist.
INFO: From Compiling org_tensorflow/tensorflow/lite/delegates/gpu/api.cc:
In file included from external/opencl_headers/CL/cl.h:32,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/api.h:42,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/api.cc:16:
external/opencl_headers/CL/cl_version.h:34:104: note: #pragma message: cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)
 #pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)")

Any help in resolving this issue would be greatly appreciated.

sgowroji commented 3 years ago

Hi @jld23, Above issue might be with opencv installed successfully and not linked properly. Can you try the workaround mentioned here https://github.com/google/mediapipe/issues/2624#issuecomment-934325347

jld23 commented 3 years ago

Thanks @sgowroji With the hint from #2624 I was able to get it to build. For those that might run into this issue later. I ran a setup_opencv.sh (modified with CUDA parts) this in turn updated ./third-party/opencv_linux.BUILD

The key line was in the linkopts section

linkopts = [
        "-L/usr/local/lib",
        "-l:libopencv_core.so",
        "-l:libopencv_calib3d.so",

The first line was what I was missing.

google-ml-butler[bot] commented 3 years ago

Are you satisfied with the resolution of your issue? Yes No

VieiraJardel commented 1 year ago

Hi @jld23 ! Could you help-me? Where can I find 'setup_opencv.sh' (modified with CUDA parts)?