Ruby Bindings for OpenCV (ropencv)

Unlike other OpenCV ruby binding projects like ruby-opencv or opencv-ffi this binding is automatically generated by parsing the OpenCV C++ headers. - D-Alex/ropencv

doc

Install

$ VERSION=4.5.4 git clone https://github.com/opencv/opencv.git -b $VERSION --depth 1
  • Install Ruby - no need to sudo using 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

Written on June 3, 2017, Last update on March 11, 2023
ruby opencv