OpenCV 出现 Ruby 错误

OpenCV with Ruby error

我正在使用 ruby-opencv gem 在 ruby 上使用 opencv。我使用 Homebrew 来安装 opencv。 opencv 和 ruby 安装成功,但是当我尝试 运行 any example -

时出现以下错误
/usr/local/Cellar/ruby/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': dlopen(/usr/local/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0/ruby-opencv-0.0.14/opencv.bundle, 9): Library not loaded: /usr/local/lib/libpng16.16.dylib (LoadError)
  Referenced from: /usr/local/lib/libopencv_highgui.2.4.dylib
  Reason: Incompatible library version: libopencv_highgui.2.4.dylib requires version 34.0.0 or later, but libpng16.16.dylib provides version 33.0.0 - /usr/local/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0/ruby-opencv-0.0.14/opencv.bundle
    from /usr/local/Cellar/ruby/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/ruby-opencv-0.0.14/lib/opencv.rb:11:in `<top (required)>'
    from /usr/local/Cellar/ruby/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
    from /usr/local/Cellar/ruby/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
    from /usr/local/Cellar/ruby/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
    from opencv.rb:1:in `<main>'

我该怎么做才能解决这个问题?

如您在错误消息中所见(此处:requires version 34.0.0 or later, but libpng16.16.dylib provides version 33.0.0)OpenCV 需要 34.00 或更高版本的 libpng(而您有 33.0.0),因此您需要安装此库的更新版本。如果简单 brew install libpng 无法解决问题,请尝试卸载它,然后使用 this solution 重新安装它。