1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00
ruby-opencv/examples/snake.rb
ser1zw 7add8ec805 removed some unnecessary CvMat methods
Removed methods are:
  CvMat#rb_morphology_*
  CvMat#rb_copy_make_border_*
  CvMat#rb_hough_lines_*
  CvMat#rb_hough_circles_*
  CvMat#rb_inpaint_*
  CvMat#rb_match_shapes_*
  CvMat#rb_threshold_*
  CvMat#rb_find_fundamental_mat_*
  CvMat#rb_smooth_*
  CvMat#rb_slice_width
  CvMat#rb_slice_height
  CvMat#rb_mix_channels
2011-07-08 20:48:24 +09:00

42 lines
947 B
Ruby
Executable file

#!/usr/bin/env ruby
# snake.rb
require "rubygems"
require "opencv"
include OpenCV
puts <<USAGE
usage:
left-click: set point
right-click: do snake
USAGE
window = GUI::Window.new "snake demo"
image = CvMat.new(256, 256, :cv8u, 1).clear!
image.circle!(CvPoint.new(128,128), 40, :color => CvColor::White, :thickness => -1)
display = image.GRAY2BGR
window.show display
points = []
window.on_mouse{|mouse|
case mouse.event
when :left_button_down
display[mouse.x, mouse.y] = CvColor::Red
puts "set point (#{mouse.x},#{mouse.y})"
points << CvPoint.new(mouse.x, mouse.y)
window.show display
when :right_button_down
if points.length < 3
puts "please set more point!"
next
end
points = image.snake_image(points, 1.0, 0.5, 1.5, CvSize.new(3, 3), 100)
display = image.GRAY2BGR
display.poly_line!(points, :color => CvColor::Red, :is_closed => true)
window.show display
end
}
GUI::wait_key