Skip to content

Commit e810466

Browse files
committed
Update installation notes.
1 parent c188902 commit e810466

1 file changed

Lines changed: 29 additions & 69 deletions

File tree

docs/installation.md

Lines changed: 29 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,67 @@
22

33
## Prerequisites
44

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).
146

157
## Installing OpenCV
168

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
2010

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.
2212

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/)
2414

25-
3. **Install OpenCV and dependencies**:
26-
```bash
27-
pacman -S mingw-w64-ucrt-x86_64-opencv mingw-w64-ucrt-x86_64-qt6-base mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-libffi
28-
```
29-
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:
3016

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+
```
3521

36-
### macOS
22+
### Fedora
3723

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.
3925

4026
```bash
41-
brew install opencv
27+
sudo apt-get install libffi-devel opencv
28+
gem install opencv-ruby --preset linux-release
4229
```
4330

4431
### Ubuntu/Debian
4532

4633
```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
4836
```
4937

50-
### Windows (Alternative: vcpkg)
38+
### Windows (RubyInstaller + DevKit)
5139

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.
5341

5442
```bash
55-
vcpkg install opencv4 libffi
43+
pacman -S mingw-w64-ucrt-x86_64-opencv mingw-w64-ucrt-x86_64-qt6-base mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-libffi
44+
gem install opencv-ruby --preset mingw-release
5645
```
5746

58-
You'll need Visual Studio 2022 for this approach.
47+
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)
5950

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.
6152

62-
Once OpenCV is installed, install the gem:
53+
After installing Visual Studio and vcpkg, install the gem like this:
6354

6455
```bash
65-
gem install opencv-ruby
56+
gem install opencv-ruby --preset msvc-release
6657
```
6758

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).
6962

7063
## Verifying Installation
7164

72-
Test that the installation was successful:
65+
To test that the installation was successful:
7366

7467
```ruby
7568
require 'opencv-ruby'
@@ -82,36 +75,3 @@ puts Cv.get_version_string
8275
mat = Cv::Mat.new(3, 3, CV_8UC1, Cv::Scalar.new(255))
8376
puts "Created #{mat.rows}x#{mat.cols} matrix"
8477
```
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:
107-
108-
```bash
109-
# macOS
110-
brew install libffi
111-
112-
# Ubuntu/Debian
113-
sudo apt-get install libffi-dev
114-
115-
# Windows (via vcpkg)
116-
vcpkg install libffi
117-
```

0 commit comments

Comments
 (0)