fix inpaint example

This commit is contained in:
ser1zw 2012-06-03 00:39:37 +09:00
parent 873a848acf
commit 96c63eac86
1 changed files with 25 additions and 10 deletions

View File

@ -2,41 +2,56 @@
# inpaint.rb
require "rubygems"
require "opencv"
include OpenCV
owindow = GUI::Window.new "original"
mwindow = GUI::Window.new "mask"
iwindow = GUI::Window.new "inpaint"
puts <<EOS
Inpainting sample
image = IplImage::load "inpaint.png"
Usage:
'dilate' bar - Adjust mask to inpaint (Non-black areas indicate the area that needs to be inpainted).
'radius' bar - Adjust radius of a circular neighborhood of each point inpainted.
'n' key - Inpaint using Navier-Stokes based method
't' key - Inpaint using Alexandru Telea's method
'c' key - Clear the inpaint window
'ESC' key - exit"
EOS
owindow = GUI::Window.new('original')
mwindow = GUI::Window.new('mask')
iwindow = GUI::Window.new('inpaint')
image = IplImage::load('inpaint.png')
noimage = image.zero
b, g, r = image.split
original_mask = r.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV) & b.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV)
mask = original_mask.copy
num_dilate = 3
radius = 5
dilate_bar = mwindow.set_trackbar("dilate", 10, num_dilate){|v|
mwindow.set_trackbar("dilate", 10, num_dilate) { |v|
num_dilate = v
mask = original_mask.dilate(nil, num_dilate)
mwindow.show mask
}
radius_bar = mwindow.set_trackbar("radius", 30, radius){|v|
radius = 5
mwindow.set_trackbar("radius", 10, radius) { |v|
radius = v
}
owindow.show image
mwindow.show mask
iwindow.show noimage
while key = GUI::wait_key
case key.chr
when "\e" # esc
exit
when "n"
iwindow.show image.inpaint_ns(mask, radius)
iwindow.show image.inpaint(:ns, mask, radius)
when "t"
iwindow.show image.inpaint_telea(mask, radius)
iwindow.show image.inpaint(:telea, mask, radius)
when "c"
iwindow.show noimage
end
end