mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add alpha blending sample (examples/alpha_blend.rb)
This commit is contained in:
parent
b02022287e
commit
8a0e60bc50
2 changed files with 21 additions and 0 deletions
21
examples/alpha_blend.rb
Executable file
21
examples/alpha_blend.rb
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
# -*- mode: ruby; coding: utf-8-unix -*-
|
||||||
|
|
||||||
|
# Alpha blending sample with GUI
|
||||||
|
|
||||||
|
require 'opencv'
|
||||||
|
include OpenCV
|
||||||
|
|
||||||
|
img1 = IplImage.load('lenna.jpg', CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||||
|
img2 = IplImage.load('tiffany.jpg', CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||||
|
|
||||||
|
window = GUI::Window.new('Alpha blend')
|
||||||
|
max = 100.0
|
||||||
|
val = max / 2.0
|
||||||
|
window.set_trackbar("Alpha", max, val) { |v|
|
||||||
|
a = v.to_f / max
|
||||||
|
window.show CvMat.add_weighted(img1, a, img2, 1.0 - a, 0)
|
||||||
|
}
|
||||||
|
window.show CvMat.add_weighted(img1, val / max, img2, 1.0 - val / max, 0)
|
||||||
|
GUI::wait_key
|
||||||
|
|
BIN
examples/tiffany.jpg
Normal file
BIN
examples/tiffany.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 74 KiB |
Loading…
Add table
Add a link
Reference in a new issue