11class Opencv < Formula
22 desc "Open source computer vision library"
33 homepage "https://opencv.org/"
4- url "https://github.com/FastTrackOrg/opencv/archive/refs/tags/v4.10.0.tar.gz"
5- sha256 "38fa471707522ab4b36ef761c95a322a09bbf397fc3860516294664d6392a1a5"
64 license "Apache-2.0"
7- revision 4
5+ revision 1
6+
7+ stable do
8+ url "https://github.com/opencv/opencv/archive/refs/tags/4.11.0.tar.gz"
9+ sha256 "9a7c11f924eff5f8d8070e297b322ee68b9227e003fd600d4b8122198091665f"
10+
11+ resource "contrib" do
12+ url "https://github.com/opencv/opencv_contrib/archive/refs/tags/4.11.0.tar.gz"
13+ sha256 "2dfc5957201de2aa785064711125af6abb2e80a64e2dc246aca4119b19687041"
14+ end
15+ end
816
917 livecheck do
1018 url :stable
1119 regex ( /^v?(\d +(?:\. \d +)+)$/i )
1220 end
1321
14- bottle do
15- sha256 arm64_sonoma : "3b056a2b5fe47fbad4128abfe9ca30e207116359fbad459a1492d6eb6ba72c74"
16- sha256 arm64_ventura : "5bfc81f73ec3a3c66fd8bdf79f9d95f7d5d3315120cc29216f6ccbb11b9ffa34"
17- sha256 sonoma : "41f609f5ed694a68d6771b11fa9dad0ba985b1400151845d2d7deb89bf0178b6"
18- sha256 ventura : "aae4e6d2de588e94c26471d1235ee73057228e18397b1076cf98bb12cd832602"
19- sha256 x86_64_linux : "f8ba815fc2d4bb80709b5a3bd7476cea23d30b09cc5cfe75ad8e72119e779fc7"
20- end
21-
2222 depends_on "cmake" => :build
23- depends_on "pkg-config" => :build
24- depends_on "python-setuptools" => :build
25- depends_on "abseil"
26- depends_on "ceres-solver"
23+ depends_on "pkgconf" => :build
2724 depends_on "eigen"
2825 depends_on "ffmpeg"
29- depends_on "freetype"
30- depends_on "gflags"
31- depends_on "glog"
32- depends_on "harfbuzz"
3326 depends_on "jpeg-turbo"
34- depends_on "jsoncpp"
3527 depends_on "libpng"
3628 depends_on "libtiff"
37- depends_on "numpy"
3829 depends_on "openblas"
39- depends_on "openjpeg"
40- depends_on "protobuf"
41- depends_on "python@3.12"
30+ depends_on "webp"
31+ depends_on "zlib"
4232
4333 uses_from_macos "zlib"
4434
45- fails_with gcc : "5" # ffmpeg is compiled with GCC
46-
47- resource "contrib" do
48- url "https://github.com/opencv/opencv_contrib/archive/refs/tags/4.10.0.tar.gz"
49- sha256 "65597f8fb8dc2b876c1b45b928bbcc5f772ddbaf97539bf1b737623d0604cba1"
50- end
51-
52- def python3
53- "python3.12"
54- end
55-
5635 def install
36+ resource ( "contrib" ) . stage buildpath /"opencv_contrib"
5737
58- # Avoid Accelerate.framework
5938 ENV [ "OpenBLAS_HOME" ] = Formula [ "openblas" ] . opt_prefix
60-
61- # Reset PYTHONPATH, workaround for https://github.com/Homebrew/homebrew-science/pull/4885
6239 ENV . delete ( "PYTHONPATH" )
6340
64- # Remove bundled libraries to make sure formula dependencies are used
65- libdirs = %w[ ffmpeg libjasper libjpeg libjpeg-turbo libpng libtiff libwebp openexr openjpeg protobuf zlib ]
66- libdirs . each { |l | rm_r ( buildpath /"3rdparty" /l ) }
41+ # Delete bundled 3rdparty
42+ %w[ ffmpeg libjasper libjpeg libjpeg-turbo libpng libtiff libwebp openexr openjpeg protobuf tbb zlib ] . each do |l |
43+ rm_r ( buildpath /"3rdparty" /l )
44+ end
6745
6846 args = %W[
6947 -DCMAKE_CXX_STANDARD=17
7048 -DCMAKE_OSX_DEPLOYMENT_TARGET=
71- -DBUILD_JASPER=OFF
72- -DBUILD_JPEG=OFF
73- -DBUILD_OPENEXR=OFF
74- -DBUILD_OPENJPEG=OFF
75- -DBUILD_PERF_TESTS=OFF
76- -DBUILD_PNG=OFF
77- -DBUILD_PROTOBUF=OFF
78- -DBUILD_TBB=OFF
49+ -DBUILD_LIST=core,imgproc,highgui,imgcodecs,videoio,video,calib3d,photo,features2d
7950 -DBUILD_TESTS=OFF
80- -DBUILD_TIFF=OFF
81- -DBUILD_WEBP=OFF
82- -DBUILD_ZLIB=OFF
83- -DBUILD_opencv_hdf=OFF
84- -DBUILD_opencv_java=OFF
85- -DBUILD_opencv_text=OFF
51+ -DBUILD_PERF_TESTS=OFF
52+ -DBUILD_EXAMPLES=OFF
53+ -DBUILD_opencv_python3=OFF
8654 -DOPENCV_ENABLE_NONFREE=OFF
55+ -DOPENCV_EXTRA_MODULES_PATH=#{ buildpath } /opencv_contrib/modules
8756 -DOPENCV_GENERATE_PKGCONFIG=ON
88- -DPROTOBUF_UPDATE_FILES=ON
8957 -DWITH_1394=OFF
9058 -DWITH_CUDA=OFF
91- -DWITH_EIGEN=OFF
59+ -DWITH_EIGEN=ON
9260 -DWITH_FFMPEG=ON
9361 -DWITH_GPHOTO2=OFF
9462 -DWITH_GSTREAMER=OFF
@@ -99,65 +67,36 @@ def install
9967 -DWITH_QT=OFF
10068 -DWITH_TBB=OFF
10169 -DWITH_VTK=OFF
102- -DBUILD_opencv_python2=OFF
103- -DBUILD_opencv_python3=OFF
104- ]
105-
106- args += [
107- "-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON" , # https://github.com/protocolbuffers/protobuf/issues/12292
108- "-Dprotobuf_MODULE_COMPATIBLE=ON" , # https://github.com/protocolbuffers/protobuf/issues/1931
70+ -DWITH_JPEG=ON
71+ -DWITH_PNG=ON
72+ -DWITH_TIFF=ON
73+ -DWITH_WEBP=ON
74+ -DWITH_ZLIB=ON
75+ -DBUILD_JPEG=OFF
76+ -DBUILD_PNG=OFF
77+ -DBUILD_TIFF=OFF
78+ -DBUILD_WEBP=OFF
79+ -DBUILD_ZLIB=OFF
10980 ]
11081
111- # Disable precompiled headers and force opencv to use brewed libraries on Linux
112- if OS . linux?
113- args += %W[
114- -DENABLE_PRECOMPILED_HEADERS=OFF
115- -DJPEG_LIBRARY=#{ Formula [ "jpeg-turbo" ] . opt_lib } /libjpeg.so
116- -DOpenBLAS_LIB=#{ Formula [ "openblas" ] . opt_lib } /libopenblas.so
117- -DOPENEXR_ILMIMF_LIBRARY=#{ Formula [ "openexr" ] . opt_lib } /libIlmImf.so
118- -DOPENEXR_ILMTHREAD_LIBRARY=#{ Formula [ "openexr" ] . opt_lib } /libIlmThread.so
119- -DPNG_LIBRARY=#{ Formula [ "libpng" ] . opt_lib } /libpng.so
120- -DPROTOBUF_LIBRARY=#{ Formula [ "protobuf" ] . opt_lib } /libprotobuf.so
121- -DTIFF_LIBRARY=#{ Formula [ "libtiff" ] . opt_lib } /libtiff.so
122- -DWITH_V4L=OFF
123- -DZLIB_LIBRARY=#{ Formula [ "zlib" ] . opt_lib } /libz.so
124- ]
125- end
126-
127- # Ref: https://github.com/opencv/opencv/wiki/CPU-optimizations-build-options
128- ENV . runtime_cpu_detection
129- if Hardware ::CPU . intel? && build . bottle?
130- cpu_baseline = MacOS . version . requires_sse42? ? "SSE4_2" : "SSSE3"
131- args += %W[ -DCPU_BASELINE=#{ cpu_baseline } -DCPU_BASELINE_REQUIRE=#{ cpu_baseline } ]
132- end
133-
134- system "cmake" , "-S" , "." , "-B" , "build_shared" , *args , *std_cmake_args
135- inreplace "build_shared/modules/core/version_string.inc" , "#{ Superenv . shims_path } /" , ""
136- system "cmake" , "--build" , "build_shared"
137- system "cmake" , "--install" , "build_shared"
82+ system "cmake" , "-S" , "." , "-B" , "build" , *args , *std_cmake_args
83+ system "cmake" , "--build" , "build"
84+ system "cmake" , "--install" , "build"
13885
139- system "cmake" , "-S" , "." , "-B" , "build_static" , *args , *std_cmake_args , "-DBUILD_SHARED_LIBS=OFF"
140- inreplace "build_static/modules/core/version_string.inc" , "#{ Superenv . shims_path } /" , ""
141- system "cmake" , "--build" , "build_static"
142- lib . install buildpath . glob ( "build_static/{lib,3rdparty/**}/*.a" )
143-
144- # Prevent dependents from using fragile Cellar paths
86+ # Fix .pc file
14587 inreplace lib /"pkgconfig/opencv#{ version . major } .pc" , prefix , opt_prefix
14688 end
14789
14890 test do
149- ( testpath /"test.cpp" ) . write <<~EOS
91+ ( testpath /"test.cpp" ) . write <<~CPP
15092 #include <opencv2/opencv.hpp>
15193 #include <iostream>
15294 int main() {
15395 std::cout << CV_VERSION << std::endl;
15496 return 0;
15597 }
156- EOS
157- system ENV . cxx , "-std=c++11" , "test.cpp" , "-I#{ include } /opencv4" , "-o" , "test"
158- assert_equal shell_output ( "./test" ) . strip , version . to_s
159-
160- output = shell_output ( "#{ python3 } -c 'import cv2; print(cv2.__version__)'" )
161- assert_equal version . to_s , output . chomp
98+ CPP
99+ system ENV . cxx , "-std=c++17" , "test.cpp" , "-I#{ include } /opencv4" , "-o" , "test"
100+ assert_equal version . to_s , shell_output ( "./test" ) . strip
162101 end
163102end
0 commit comments