mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
modified a sample (paint.rb) to avoid some errors
This commit is contained in:
parent
206ae1ba97
commit
9555aa34a6
1 changed files with 8 additions and 9 deletions
|
@ -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 =<<USAGE
|
||||
[mouse]
|
||||
|
@ -22,15 +22,14 @@ esc - exit
|
|||
USAGE
|
||||
puts usage
|
||||
|
||||
point = nil
|
||||
|
||||
# drawing option
|
||||
opt = {
|
||||
:color => 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
|
||||
|
||||
|
|
Loading…
Reference in a new issue