mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
fixed some bugs of examples/snake.rb
This commit is contained in:
parent
23a35e8cc4
commit
fcc66a0180
1 changed files with 6 additions and 5 deletions
|
@ -6,13 +6,13 @@ include OpenCV
|
|||
|
||||
puts <<USAGE
|
||||
usage:
|
||||
left-click: set point
|
||||
left-click: set a 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)
|
||||
image.circle!(CvPoint.new(128,128), 40, :color => CvColor::White, :thickness => -1)
|
||||
display = image.GRAY2BGR
|
||||
|
||||
window.show display
|
||||
|
@ -22,7 +22,7 @@ points = []
|
|||
window.on_mouse{|mouse|
|
||||
case mouse.event
|
||||
when :left_button_down
|
||||
display[mouse.x, mouse.y] = CvColor::Red
|
||||
display.circle!(mouse, 1, :color => CvColor::Red, :thickness => 2)
|
||||
puts "set point (#{mouse.x},#{mouse.y})"
|
||||
points << CvPoint.new(mouse.x, mouse.y)
|
||||
window.show display
|
||||
|
@ -31,10 +31,11 @@ window.on_mouse{|mouse|
|
|||
puts "please set more point!"
|
||||
next
|
||||
end
|
||||
points = image.snake_image(points, 1.0, 0.5, 1.5, CvSize.new(3, 3), 100)
|
||||
snake_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)
|
||||
display.poly_line!([snake_points], :color => CvColor::Red, :is_closed => true, :thickness => 2)
|
||||
window.show display
|
||||
points.clear
|
||||
end
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue