opencv 4.6.0
* migrate `ffmpeg@4` to `ffmpeg` * migrate `jpeg` to `jpeg-turbo` * migrate `python@3.9` to `python@3.10` * enable CPU runtime detectionmaster
parent
e000d6e2f6
commit
77d4ea9043
|
@ -1,10 +1,9 @@
|
|||
class Opencv < Formula
|
||||
desc "Open source computer vision library"
|
||||
homepage "https://opencv.org/"
|
||||
url "https://github.com/opencv/opencv/archive/4.5.5.tar.gz"
|
||||
sha256 "a1cfdcf6619387ca9e232687504da996aaa9f7b5689986b8331ec02cb61d28ad"
|
||||
url "https://github.com/opencv/opencv/archive/refs/tags/4.6.0.tar.gz"
|
||||
sha256 "1ec1cba65f9f20fe5a41fda1586e01c70ea0c9a6d7b67c9e13edf0cfe2239277"
|
||||
license "Apache-2.0"
|
||||
revision 3
|
||||
|
||||
livecheck do
|
||||
url :stable
|
||||
|
@ -24,17 +23,18 @@ class Opencv < Formula
|
|||
depends_on "pkg-config" => :build
|
||||
depends_on "ceres-solver"
|
||||
depends_on "eigen"
|
||||
depends_on "ffmpeg@4"
|
||||
depends_on "ffmpeg"
|
||||
depends_on "glog"
|
||||
depends_on "harfbuzz"
|
||||
depends_on "jpeg"
|
||||
depends_on "jpeg-turbo"
|
||||
depends_on "libpng"
|
||||
depends_on "libtiff"
|
||||
depends_on "numpy"
|
||||
depends_on "openblas"
|
||||
depends_on "openexr"
|
||||
depends_on "openjpeg"
|
||||
depends_on "protobuf"
|
||||
depends_on "python@3.9"
|
||||
depends_on "python@3.10"
|
||||
depends_on "tbb"
|
||||
depends_on "vtk"
|
||||
depends_on "webp"
|
||||
|
@ -44,13 +44,30 @@ class Opencv < Formula
|
|||
fails_with gcc: "5" # ffmpeg is compiled with GCC
|
||||
|
||||
resource "contrib" do
|
||||
url "https://github.com/opencv/opencv_contrib/archive/4.5.5.tar.gz"
|
||||
sha256 "a97c2eaecf7a23c6dbd119a609c6d7fae903e5f9ff5f1fe678933e01c67a6c11"
|
||||
url "https://github.com/opencv/opencv_contrib/archive/refs/tags/4.6.0.tar.gz"
|
||||
sha256 "1777d5fd2b59029cf537e5fd6f8aa68d707075822f90bde683fcde086f85f7a7"
|
||||
|
||||
# Fix build error: cannot initialize a parameter of type 'ceres::LocalParameterization *'
|
||||
# Remove in the next release.
|
||||
patch do
|
||||
url "https://github.com/opencv/opencv_contrib/commit/4c93cc9925ece6c4a38cf8b869c8217d15104fe5.patch?full_index=1"
|
||||
sha256 "9761c48d1c6f19fa0a2bf5a55cf7a0501a1e85fe595006ec5bd1929d9602f702"
|
||||
end
|
||||
end
|
||||
|
||||
# Fix build error: use of undeclared identifier 'CODEC_ID_H264'; did you mean 'AV_CODEC_ID_H264'
|
||||
# Using commit from related PR for 3.4 branch: https://github.com/opencv/opencv/pull/22357
|
||||
# Remove when fix is in 4.x branch and available in a release.
|
||||
patch do
|
||||
url "https://github.com/opencv/opencv/commit/496eed950f6d0e7fd92619d47e3cec8f06e96ace.patch?full_index=1"
|
||||
sha256 "f9a5dac14d54b699383328a2d28b2d86f7274db8a603974ca5e9076d77490d49"
|
||||
end
|
||||
|
||||
def python3
|
||||
"python3.10"
|
||||
end
|
||||
|
||||
def install
|
||||
ENV.cxx11
|
||||
|
||||
resource("contrib").stage buildpath/"opencv_contrib"
|
||||
|
||||
# Avoid Accelerate.framework
|
||||
|
@ -59,14 +76,21 @@ class Opencv < Formula
|
|||
# Reset PYTHONPATH, workaround for https://github.com/Homebrew/homebrew-science/pull/4885
|
||||
ENV.delete("PYTHONPATH")
|
||||
|
||||
# Remove bundled libraries to make sure formula dependencies are used
|
||||
libdirs = %w[ffmpeg libjasper libjpeg libjpeg-turbo libpng libtiff libwebp openexr openjpeg protobuf tbb zlib]
|
||||
libdirs.each { |l| (buildpath/"3rdparty"/l).rmtree }
|
||||
|
||||
args = std_cmake_args + %W[
|
||||
-DCMAKE_CXX_STANDARD=11
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET=
|
||||
-DBUILD_JASPER=OFF
|
||||
-DBUILD_JPEG=OFF
|
||||
-DBUILD_OPENEXR=OFF
|
||||
-DBUILD_OPENJPEG=OFF
|
||||
-DBUILD_PERF_TESTS=OFF
|
||||
-DBUILD_PNG=OFF
|
||||
-DBUILD_PROTOBUF=OFF
|
||||
-DBUILD_TBB=OFF
|
||||
-DBUILD_TESTS=OFF
|
||||
-DBUILD_TIFF=OFF
|
||||
-DBUILD_WEBP=OFF
|
||||
|
@ -92,43 +116,41 @@ class Opencv < Formula
|
|||
-DWITH_VTK=ON
|
||||
-DBUILD_opencv_python2=OFF
|
||||
-DBUILD_opencv_python3=ON
|
||||
-DPYTHON3_EXECUTABLE=#{Formula["python@3.9"].opt_bin}/python3
|
||||
-DPYTHON3_EXECUTABLE=#{which(python3)}
|
||||
]
|
||||
|
||||
# Disable precompiled headers and force opencv to use brewed libraries on Linux
|
||||
if OS.linux?
|
||||
args << "-DENABLE_PRECOMPILED_HEADERS=OFF"
|
||||
args << "-DJPEG_LIBRARY=#{Formula["libjpeg"].opt_lib}/libjpeg.so"
|
||||
args << "-DOpenBLAS_LIB=#{Formula["openblas"].opt_lib}/libopenblas.so"
|
||||
args << "-DOPENEXR_ILMIMF_LIBRARY=#{Formula["openexr"].opt_lib}/libIlmImf.so"
|
||||
args << "-DOPENEXR_ILMTHREAD_LIBRARY=#{Formula["openexr"].opt_lib}/libIlmThread.so"
|
||||
args << "-DPNG_LIBRARY=#{Formula["libpng"].opt_lib}/libpng.so"
|
||||
args << "-DPROTOBUF_LIBRARY=#{Formula["protobuf"].opt_lib}/libprotobuf.so"
|
||||
args << "-DTIFF_LIBRARY=#{Formula["libtiff"].opt_lib}/libtiff.so"
|
||||
args << "-DWITH_V4L=OFF"
|
||||
args << "-DZLIB_LIBRARY=#{Formula["zlib"].opt_lib}/libz.so"
|
||||
args += %W[
|
||||
-DENABLE_PRECOMPILED_HEADERS=OFF
|
||||
-DJPEG_LIBRARY=#{Formula["jpeg-turbo"].opt_lib}/libjpeg.so
|
||||
-DOpenBLAS_LIB=#{Formula["openblas"].opt_lib}/libopenblas.so
|
||||
-DOPENEXR_ILMIMF_LIBRARY=#{Formula["openexr"].opt_lib}/libIlmImf.so
|
||||
-DOPENEXR_ILMTHREAD_LIBRARY=#{Formula["openexr"].opt_lib}/libIlmThread.so
|
||||
-DPNG_LIBRARY=#{Formula["libpng"].opt_lib}/libpng.so
|
||||
-DPROTOBUF_LIBRARY=#{Formula["protobuf"].opt_lib}/libprotobuf.so
|
||||
-DTIFF_LIBRARY=#{Formula["libtiff"].opt_lib}/libtiff.so
|
||||
-DWITH_V4L=OFF
|
||||
-DZLIB_LIBRARY=#{Formula["zlib"].opt_lib}/libz.so
|
||||
]
|
||||
end
|
||||
|
||||
if Hardware::CPU.intel?
|
||||
args << "-DENABLE_AVX=OFF" << "-DENABLE_AVX2=OFF"
|
||||
args << "-DENABLE_SSE41=OFF" << "-DENABLE_SSE42=OFF" unless MacOS.version.requires_sse42?
|
||||
# Ref: https://github.com/opencv/opencv/wiki/CPU-optimizations-build-options
|
||||
ENV.runtime_cpu_detection
|
||||
if Hardware::CPU.intel? && build.bottle?
|
||||
cpu_baseline = MacOS.version.requires_sse42? ? "SSE4_2" : "SSSE3"
|
||||
args += %W[-DCPU_BASELINE=#{cpu_baseline} -DCPU_BASELINE_REQUIRE=#{cpu_baseline}]
|
||||
end
|
||||
|
||||
mkdir "build" do
|
||||
system "cmake", "..", *args
|
||||
inreplace "modules/core/version_string.inc", Superenv.shims_path, ""
|
||||
system "cmake", "-S", ".", "-B", "build_shared", *args
|
||||
inreplace "build_shared/modules/core/version_string.inc", "#{Superenv.shims_path}/", ""
|
||||
system "cmake", "--build", "build_shared"
|
||||
system "cmake", "--install", "build_shared"
|
||||
|
||||
system "make"
|
||||
system "make", "install"
|
||||
|
||||
system "make", "clean"
|
||||
system "cmake", "..", "-DBUILD_SHARED_LIBS=OFF", *args
|
||||
inreplace "modules/core/version_string.inc", Superenv.shims_path, ""
|
||||
|
||||
system "make"
|
||||
lib.install Dir["lib/*.a"]
|
||||
lib.install Dir["3rdparty/**/*.a"]
|
||||
end
|
||||
system "cmake", "-S", ".", "-B", "build_static", *args, "-DBUILD_SHARED_LIBS=OFF"
|
||||
inreplace "build_static/modules/core/version_string.inc", "#{Superenv.shims_path}/", ""
|
||||
system "cmake", "--build", "build_static"
|
||||
lib.install buildpath.glob("build_static/{lib,3rdparty/**}/*.a")
|
||||
|
||||
# Prevent dependents from using fragile Cellar paths
|
||||
inreplace lib/"pkgconfig/opencv#{version.major}.pc", prefix, opt_prefix
|
||||
|
@ -143,11 +165,10 @@ class Opencv < Formula
|
|||
return 0;
|
||||
}
|
||||
EOS
|
||||
system ENV.cxx, "-std=c++11", "test.cpp", "-I#{include}/opencv4",
|
||||
"-o", "test"
|
||||
assert_equal `./test`.strip, version.to_s
|
||||
system ENV.cxx, "-std=c++11", "test.cpp", "-I#{include}/opencv4", "-o", "test"
|
||||
assert_equal shell_output("./test").strip, version.to_s
|
||||
|
||||
output = shell_output(Formula["python@3.9"].opt_bin/"python3 -c 'import cv2; print(cv2.__version__)'")
|
||||
output = shell_output("#{python3} -c 'import cv2; print(cv2.__version__)'")
|
||||
assert_equal version.to_s, output.chomp
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
"libvpx",
|
||||
"luajit",
|
||||
"openblas",
|
||||
"opencv",
|
||||
"open-mpi"
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue