From 9555aa34a6ef9c353017a9a6ec285239f824ce28 Mon Sep 17 00:00:00 2001 From: ser1zw Date: Sat, 7 May 2011 08:41:47 +0900 Subject: [PATCH] modified a sample (paint.rb) to avoid some errors --- examples/paint.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/paint.rb b/examples/paint.rb index 91cd28d..ef7c466 100755 --- a/examples/paint.rb +++ b/examples/paint.rb @@ -6,10 +6,10 @@ require "opencv" include OpenCV window = GUI::Window.new("free canvas") -canvas = CvMat.new(500, 500, 0, 3).fill!(0xFF) # create white canvas +canvas = CvMat.new(500, 500, CV_8U, 3).fill!(CvColor::White) # create white canvas window.show canvas -colors = CvColor::constants.collect{|i| i.to_s } +colors = CvColor::constants.collect{ |i| i.to_s } usage =< CvColor::Black, :tickness => 1 } -window.on_mouse{|m| +point = nil +window.on_mouse{ |m| case m.event when :move if m.left_button? @@ -50,22 +49,22 @@ window.on_mouse{|m| color_name = '' while key = GUI.wait_key - next if key < 0 + next if key < 0 or key > 255 case key.chr when "\e" # [esc] - exit exit when '1'..'9' puts "change thickness to #{key.chr.to_i}." opt[:thickness] = key.chr.to_i - else + when /[A-Za-z]/ color_name << key.chr - choice = colors.find_all{|i| i =~ /\A#{color_name}/i} + choice = colors.find_all{ |i| i =~ /\A#{color_name}/i } if choice.size == 1 color,= choice puts "change color to #{color}." opt[:color] = CvColor::const_get(color) end - color_name = '' if choice.length < 2 + color_name = '' if choice.size < 2 end end