Ruby Bindings for OpenCV (ropencv)
Unlike other OpenCV ruby binding projects like
ruby-opencvoropencv-ffithis binding is automatically generated by parsing the OpenCV C++ headers. - D-Alex/ropencv
# Install
- Install opencv librairies
- tested with 4.5.4 / releases / release notes
$ VERSION=4.5.4 git clone https://github.com/opencv/opencv.git -b $VERSION --depth 1- Install Ruby - no need to
sudousing rbenv - prerequesite
sudo apt-get install ruby-dev- needed to compile native gem- set a default python
update-alternatives --install /usr/bin/python python /usr/bin/python3 1- it will be used to parse the c++ export define for python binding, and recreate the interface for ruby binding
gem install ropencv
The last command will pick the opencv version installed and build binding to it.
# Test installation
Test some opencv call in ruby
# Display Video stream from first camera
require 'ropencv'
include OpenCV
video_file = cv::VideoCapture.new( 0)
cv::namedWindow("edges",1)
frame = cv::Mat.new
while true do
video_file.read( frame)
cv::imshow("edges", frame)
cv::wait_key( 1)
end# Known issue
# see also
- How OpenCV-Python bindings are generated? - OpenCV generates these wrapper functions automatically from the C++ headers using some Python scripts which are located in modules/python/src2.
- D-Alex/rbind - automatically genereating ffi-bindings for c/c++ libraries
Written on June 3, 2017, Last update on March 22, 2025
ruby
opencv