#!/usr/bin/env ruby # snake.rb require "rubygems" require "opencv" include OpenCV puts < 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