You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/installation.md
+29-69Lines changed: 29 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,74 +2,67 @@
2
2
3
3
## Prerequisites
4
4
5
-
Before installing opencv-ruby, you need:
6
-
7
-
-**Ruby 3.2** or later
8
-
-**OpenCV 4.x** installed on your system
9
-
- A C++17 compatible compiler:
10
-
- GCC 13 or 14
11
-
- Clang 17 or 18
12
-
- MSVC 2022 (Visual Studio 17)
13
-
- Apple Clang (Xcode 15 or 16)
5
+
OpenCV is a large, complex C++ code base that makes heavy use of templates. Therefore, to build the Ruby bindings you will need a machine that has at least 32GB of memory, a decent amount of disk space and an up-to-date-date C++ compiler (C++17 or higher). Expect compile times to range from 5 minutes on the latest Macs to 30 minutes for relativey new x86 laptops. Older hardware will of course be slower and compile times vary greatly by compiler (MSVC and Clang are much faster than gcc).
14
6
15
7
## Installing OpenCV
16
8
17
-
### Windows (RubyInstaller + DevKit)
18
-
19
-
Most Ruby developers on Windows use [RubyInstaller](https://rubyinstaller.org/) with the MSYS2 DevKit. This is the recommended approach.
9
+
### macOS
20
10
21
-
1.**Install Ruby with DevKit** from [rubyinstaller.org](https://rubyinstaller.org/downloads/). Choose the version with DevKit (e.g., "Ruby+Devkit 3.3.x (x64)").
11
+
On a MacBook Pro M4, it will take about 5 minutes to build the extension. It will be approximately 140MB.
22
12
23
-
2.**Open the MSYS2 UCRT64 terminal** (run "MSYS2 UCRT64" from the Start menu or run `ridk enable` then use your terminal).
13
+
You will first need to install [HomeBrew](https://brew.sh/)
Notice you MUST install qt6-base because the highgui module is built with Qt6 support by default for mingw64 but its not a depdency of opencv.
15
+
Then:
30
16
31
-
4.**Verify installation**:
32
-
```bash
33
-
pkg-config --modversion opencv4
34
-
```
17
+
```bash
18
+
brew install libffi opencv
19
+
gem install opencv-ruby --preset macos-release
20
+
```
35
21
36
-
### macOS
22
+
### Fedora
37
23
38
-
Using Homebrew:
24
+
On a Meteor Lake (Intel Core Ultra 7 165U) laptop with 64GB memory, it will take about 30 minutes to build the extension with g++. The extension will be roughly 200MB. Note that g++ uses *a lot* of memory, with some processes taking up to 17GB of memory. At most 6 concurrent g++ instances can at once with 64GB. If you have a machine with 32GB of memory you will need to reduce the number of concurrent jobs. Do this by overriding the setting in the CMakePresets.json file.
39
25
40
26
```bash
41
-
brew install opencv
27
+
sudo apt-get install libffi-devel opencv
28
+
gem install opencv-ruby --preset linux-release
42
29
```
43
30
44
31
### Ubuntu/Debian
45
32
46
33
```bash
47
-
sudo apt-get install libopencv-dev
34
+
sudo apt-get install libffi-dev libopencv-dev
35
+
gem install opencv-ruby --preset linux-release
48
36
```
49
37
50
-
### Windows (Alternative: vcpkg)
38
+
### Windows (RubyInstaller + DevKit)
51
39
52
-
If you prefer vcpkg over MSYS2/MinGW64:
40
+
Most Ruby developers on Windows use the [RubyInstaller](https://rubyinstaller.org/) which installs a MSYS2/Mingw64 environment. On a Meteor Lake (Intel Core Ultra 7 165U) laptop with 64GB memory, it will take about 30 minutes to build the extension with g++. The size will be about 200MB.
You MUST install qt6-base because the OpenCV highgui module is built with it. However, it is not listed as dependency so you have to install it manually.
48
+
49
+
### Windows Visual Studio (MSVC)
59
50
60
-
## Installing the Gem
51
+
You can also use Visual Studio on Windows in combination with vcpkg. On a Meteor Lake (Intel Core Ultra 7 165U) laptop with 64GB memory, it will take about 10 minutes to build the extension. It will rougly GB.
61
52
62
-
Once OpenCV is installed, install the gem:
53
+
After installing Visual Studio and vcpkg, install the gem like this:
63
54
64
55
```bash
65
-
gem install opencv-ruby
56
+
gem install opencv-ruby --preset msvc-release
66
57
```
67
58
68
-
The gem includes a native extension that will be compiled during installation using CMake.
59
+
Notice you don't have to install any dependencies first. This is because the build system uses vcpkg in manifest mode, which will download and build all dependencies like libffi and OpenCV. The first time you do this, it can take quite a while, up to an hour (it is a one time cost).
60
+
61
+
This has been tested with Visual Studio 2022 and 2026, with Visual Studio 2026 being strongly preferred (it is quite a bit faster).
69
62
70
63
## Verifying Installation
71
64
72
-
Test that the installation was successful:
65
+
To test that the installation was successful:
73
66
74
67
```ruby
75
68
require'opencv-ruby'
@@ -82,36 +75,3 @@ puts Cv.get_version_string
82
75
mat =Cv::Mat.new(3, 3, CV_8UC1, Cv::Scalar.new(255))
83
76
puts"Created #{mat.rows}x#{mat.cols} matrix"
84
77
```
85
-
86
-
## Troubleshooting
87
-
88
-
### OpenCV Not Found
89
-
90
-
If CMake cannot find OpenCV, ensure:
91
-
92
-
1. OpenCV is properly installed
93
-
2. The `OpenCV_DIR` environment variable points to your OpenCV installation
94
-
3. On Linux/macOS, pkg-config can find OpenCV: `pkg-config --modversion opencv4`
95
-
96
-
### Compiler Issues
97
-
98
-
The extension requires C++17 support. Ensure your compiler is recent enough:
99
-
100
-
- GCC 7+
101
-
- Clang 5+
102
-
- MSVC 2017+
103
-
104
-
### Missing libffi
105
-
106
-
The extension uses libffi for some functionality. Install it if missing:
0 commit comments