fabian fabian - 5 months ago 30
Ruby Question

How: Use cvCanny with ruby-opencv

I was wondering how to use cvCanny with ruby-opencv. I couldn't find any proper documentation.
That's what I have to far…

require "rubygems"
require "opencv"
include OpenCV

original_window = GUI::Window.new "original"
hough_window = GUI::Window.new "hough circles"

image = IplImage::load "stuff.jpg"
gray = image.canny(0.3, 0.8)

hough_window.show gray
GUI::wait_key


Error:

$ ruby houghcircle.rb
houghcircle.rb:11:in `canny': /Users/someuser/Development/Workspaces/2012/Libs/OpenCV-2.4.3/modules/imgproc/src/canny.cpp:282: error: (-215) src.size == dst.size && src.depth() == CV_8U && dst.type() == CV_8U in function cvCanny (OpenCV::CvStsAssert)
from houghcircle.rb:11

Answer
error: (-215) src.size == dst.size && src.depth() == CV_8U && dst.type() == CV_8U in function cvCanny (OpenCV::CvStsAssert)

That's because you should convert image to grayscale (single-channel image) using cvtColor with parameter CV_BGR2GRAY. Canny can be applied only to such images.