homebrew-core/Formula/opencv.rb

139 lines
4.3 KiB
Ruby

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"
# watch for license change to Apache-2.0 with next release
license "BSD-3-Clause"
revision 2
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 "b9199ca20007959fff87ca117ca89588d19dcefb8f5166c53ef78217b3b0f886" => :catalina
sha256 "cdb1117c188d79f14197d1739fdf2d20aa4e873ba790a164f62c712afdd75f99" => :mojave
sha256 "86961a17c5defdf6c2c8311915ce4e9a374a81cd3f7968967ba60b7f76ab6b31" => :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"
# additional vtk 9 support, remove after next release
# upstream PR https://github.com/opencv/opencv_contrib/pull/2659
patch do
url "https://github.com/opencv/opencv_contrib/commit/aace65cc1269629f32874389b33e85fdb7819b02.diff?full_index=1"
sha256 "af98e588626cb79e5064995e6cf22f55e40518649cf3eed0d5bd6963f2a19e20"
end
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=OFF
-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