Repository: opencv
Issue: Issue compiling opencv 4.4.0 with VTK 9.0
Labels: category: build/install,platform: ios/osx,category: viz,category: 3rdparty,Hackathon

##### System information (version)

- OpenCV => 4.4.0
- Operating System / Platform => MacOS Catalina 10.15.6
- Compiler => GCC

##### Detailed description
I am trying to install opencv 4.4.0 using the following brew tap


```
class Opencv < Formula
    desc "Open source computer vision library"
    homepage "https://opencv.org/"
    url "https://github.com/opencv/opencv/archive/4.4.0.tar.gz"
    sha256 "bb95acd849e458be7f7024d17968568d1ccd2f0681d47fd60d34ffb4b8c52563"
    license "BSD-3-Clause"

    bottle do
      sha256 "7524401992a83c2a5ad655a27a153b027b9fc1a72bdc564842a4b9e32eb27201" => :catalina
      sha256 "f229e1f1cfdd547b38addb5ceed3e43277a823dd06860116a1059a1209623407" => :mojave
      sha256 "7353af965d428d1e2a22f3c641b3a2bd25740d5f6476e88ba8fc9564029926b0" => :high_sierra
    end

    depends_on "cmake" => :build
    depends_on "pkg-config" => :build
    depends_on "ceres-solver"
    depends_on "eigen"
    depends_on "ffmpeg"
    depends_on "glog"
    depends_on "harfbuzz"
    depends_on "jpeg"
    depends_on "libpng"
    depends_on "libtiff"
    depends_on "numpy"
    depends_on "openblas"
    depends_on "openexr"
    depends_on "protobuf"
    depends_on "python@3.8"
    depends_on "tbb"
    depends_on "vtk"
    depends_on "webp"

    resource "contrib" do
      url "https://github.com/opencv/opencv_contrib/archive/4.4.0.tar.gz"
      sha256 "a69772f553b32427e09ffbfd0c8d5e5e47f7dab8b3ffc02851ffd7f912b76840"
    end

    def install
      ENV.cxx11

      resource("contrib").stage buildpath/"opencv_contrib"

      # Avoid Accelerate.framework
      ENV["OpenBLAS_HOME"] = Formula["openblas"].opt_prefix

      # Reset PYTHONPATH, workaround for https://github.com/Homebrew/homebrew-science/pull/4885
      ENV.delete("PYTHONPATH")

      args = std_cmake_args + %W[
        -DCMAKE_OSX_DEPLOYMENT_TARGET=
        -DBUILD_JASPER=OFF
        -DBUILD_JPEG=OFF
        -DBUILD_OPENEXR=OFF
        -DBUILD_PERF_TESTS=OFF
        -DBUILD_PNG=OFF
        -DBUILD_PROTOBUF=OFF
        -DBUILD_TESTS=OFF
        -DBUILD_TIFF=OFF
        -DBUILD_WEBP=OFF
        -DBUILD_ZLIB=OFF
        -DBUILD_opencv_hdf=OFF
        -DBUILD_opencv_java=OFF
        -DBUILD_opencv_text=ON
        -DOPENCV_ENABLE_NONFREE=ON
        -DOPENCV_EXTRA_MODULES_PATH=#{buildpath}/opencv_contrib/modules
        -DOPENCV_GENERATE_PKGCONFIG=ON
        -DPROTOBUF_UPDATE_FILES=ON
        -DWITH_1394=OFF
        -DWITH_CUDA=OFF
        -DWITH_EIGEN=ON
        -DWITH_FFMPEG=ON
        -DWITH_GPHOTO2=OFF
        -DWITH_GSTREAMER=ON
        -DWITH_JASPER=OFF
        -DWITH_OPENEXR=ON
        -DWITH_OPENGL=OFF
        -DWITH_QT=OFF
        -DWITH_TBB=ON
        -DWITH_VTK=ON
        -DBUILD_opencv_python2=OFF
        -DBUILD_opencv_python3=ON
        -DPYTHON3_EXECUTABLE=#{Formula["python@3.8"].opt_bin}/python3
      ]

      # The compiler on older Mac OS cannot build some OpenCV files using AVX2
      # extensions, failing with errors such as
      # "error: use of undeclared identifier '_mm256_cvtps_ph'"
      # Work around this by not trying to build AVX2 code.
      args << "-DCPU_DISPATCH=SSE4_1,SSE4_2,AVX" if MacOS.version <= :yosemite

      args << "-DENABLE_AVX=OFF" << "-DENABLE_AVX2=OFF"
      args << "-DENABLE_SSE41=OFF" << "-DENABLE_SSE42=OFF" unless MacOS.version.requires_sse42?

      mkdir "build" do
        system "cmake", "..", *args
        inreplace "modules/core/version_string.inc", "#{HOMEBREW_SHIMS_PATH}/mac/super/", ""
        system "make"
        system "make", "install"
        system "make", "clean"
        system "cmake", "..", "-DBUILD_SHARED_LIBS=OFF", *args
        inreplace "modules/core/version_string.inc", "#{HOMEBREW_SHIMS_PATH}/mac/super/", ""
        system "make"
        lib.install Dir["lib/*.a"]
        lib.install Dir["3rdparty/**/*.a"]
      end
    end

    test do
      (testpath/"test.cpp").write <<~EOS
        #include <opencv2/opencv.hpp>
        #include <iostream>
        int main() {
          std::cout << CV_VERSION << std::endl;
          return 0;
        }
      EOS
      system ENV.cxx, "-std=c++11", "test.cpp", "-I#{include}/opencv4",
                      "-o", "test"
      assert_equal `./test`.strip, version.to_s

      output = shell_output(Formula["python@3.8"].opt_bin/"python3 -c 'import cv2; print(cv2.__version__)'")
      assert_equal version.to_s, output.chomp
    end
  end
```

I am installing using this command:

```
brew install --build-from-source ./opencv.rb
```

It is failing with the following error due to an interaction with VTK. How do I fix this issue? It seems like this was fixed previously, not sure what is wrong. 


```

/tmp/opencv-20210106-50710-v604sb/opencv-4.4.0/opencv_contrib/modules/viz/src/vtk/vtkCocoaInteractorFix.mm:192:81: error: no member named 'GetCocoaServer' in 'cv::viz::vtkCocoaRenderWindowInteractorFix'
        vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (this->GetCocoaServer ());
                                                                          ~~~~  ^
/tmp/opencv-20210106-50710-v604sb/opencv-4.4.0/opencv_contrib/modules/viz/src/vtk/vtkCocoaInteractorFix.mm:193:20: error: no member named 'GetCocoaServer' in 'cv::viz::vtkCocoaRenderWindowInteractorFix'
        if (!this->GetCocoaServer ())
             ~~~~  ^
/tmp/opencv-20210106-50710-v604sb/opencv-4.4.0/opencv_contrib/modules/viz/src/vtk/vtkCocoaInteractorFix.mm:196:19: error: no member named 'SetCocoaServer' in 'cv::viz::vtkCocoaRenderWindowInteractorFix'
            this->SetCocoaServer (reinterpret_cast<void*> (server));
            ~~~~  ^
/tmp/opencv-20210106-50710-v604sb/opencv-4.4.0/opencv_contrib/modules/viz/src/vtk/vtkCocoaInteractorFix.mm:208:81: error: no member named 'GetCocoaServer' in 'cv::viz::vtkCocoaRenderWindowInteractorFix'
        vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (this->GetCocoaServer ());
                                                                          ~~~~  ^
4 errors generated.
```

A similar issue is referenced here: https://github.com/opencv/opencv/issues/6315

##### Issue submission checklist

 - [x] I report the issue, it's not a question
   <!--
   OpenCV team works with answers.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with question without real issue statement will be
   closed.
   -->
 - [x] I checked the problem with documentation, FAQ, open issues,
       answers.opencv.org, Stack Overflow, etc and have not found solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://answers.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [x] I updated to latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only latest release for each branch.
   The ticket is closed, if the problem is not reproduced with modern version.
   -->
 - [x] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as archive to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->