2008-08-19 11:01:28 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# inpaint.rb
|
|
|
|
require "rubygems"
|
|
|
|
require "opencv"
|
|
|
|
|
|
|
|
include OpenCV
|
|
|
|
|
|
|
|
owindow = GUI::Window.new "original"
|
|
|
|
mwindow = GUI::Window.new "mask"
|
|
|
|
iwindow = GUI::Window.new "inpaint"
|
|
|
|
|
|
|
|
image = IplImage::load "inpaint.png"
|
|
|
|
b, g, r = image.split
|
2011-07-08 07:48:24 -04:00
|
|
|
original_mask = r.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV) & b.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV)
|
2008-08-19 11:01:28 -04:00
|
|
|
mask = original_mask.copy
|
|
|
|
|
|
|
|
num_dilate = 3
|
|
|
|
radius = 5
|
|
|
|
dilate_bar = 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 = v
|
|
|
|
}
|
|
|
|
|
|
|
|
owindow.show image
|
|
|
|
mwindow.show mask
|
|
|
|
|
|
|
|
while key = GUI::wait_key
|
|
|
|
case key.chr
|
|
|
|
when "\e" # esc
|
|
|
|
exit
|
|
|
|
when "n"
|
|
|
|
iwindow.show image.inpaint_ns(mask, radius)
|
|
|
|
when "t"
|
|
|
|
iwindow.show image.inpaint_telea(mask, radius)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|