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
|
include OpenCV
|
||||||
|
|
||||||
window = GUI::Window.new("free canvas")
|
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
|
window.show canvas
|
||||||
|
|
||||||
colors = CvColor::constants.collect{|i| i.to_s }
|
colors = CvColor::constants.collect{ |i| i.to_s }
|
||||||
|
|
||||||
usage =<<USAGE
|
usage =<<USAGE
|
||||||
[mouse]
|
[mouse]
|
||||||
|
@ -22,15 +22,14 @@ esc - exit
|
||||||
USAGE
|
USAGE
|
||||||
puts usage
|
puts usage
|
||||||
|
|
||||||
point = nil
|
|
||||||
|
|
||||||
# drawing option
|
# drawing option
|
||||||
opt = {
|
opt = {
|
||||||
:color => CvColor::Black,
|
:color => CvColor::Black,
|
||||||
:tickness => 1
|
:tickness => 1
|
||||||
}
|
}
|
||||||
|
|
||||||
window.on_mouse{|m|
|
point = nil
|
||||||
|
window.on_mouse{ |m|
|
||||||
case m.event
|
case m.event
|
||||||
when :move
|
when :move
|
||||||
if m.left_button?
|
if m.left_button?
|
||||||
|
@ -50,22 +49,22 @@ window.on_mouse{|m|
|
||||||
|
|
||||||
color_name = ''
|
color_name = ''
|
||||||
while key = GUI.wait_key
|
while key = GUI.wait_key
|
||||||
next if key < 0
|
next if key < 0 or key > 255
|
||||||
case key.chr
|
case key.chr
|
||||||
when "\e" # [esc] - exit
|
when "\e" # [esc] - exit
|
||||||
exit
|
exit
|
||||||
when '1'..'9'
|
when '1'..'9'
|
||||||
puts "change thickness to #{key.chr.to_i}."
|
puts "change thickness to #{key.chr.to_i}."
|
||||||
opt[:thickness] = key.chr.to_i
|
opt[:thickness] = key.chr.to_i
|
||||||
else
|
when /[A-Za-z]/
|
||||||
color_name << key.chr
|
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
|
if choice.size == 1
|
||||||
color,= choice
|
color,= choice
|
||||||
puts "change color to #{color}."
|
puts "change color to #{color}."
|
||||||
opt[:color] = CvColor::const_get(color)
|
opt[:color] = CvColor::const_get(color)
|
||||||
end
|
end
|
||||||
color_name = '' if choice.length < 2
|
color_name = '' if choice.size < 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue