1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00
ruby-opencv/examples/video.rb
2016-04-03 05:19:48 +09:00

22 lines
510 B
Ruby

require 'opencv'
capture = Cv::VideoCapture.new
w = Cv::Window.new('video')
classifier = Cv::CascadeClassifier.new
classifier.load('haarcascade_frontalface_alt.xml')
color = Cv::Scalar.new(0, 255, 255)
loop do
m = capture.read
rects = classifier.detect_multi_scale(m)
rects.each do |r|
pt1 = Cv::Point.new(r.x, r.y)
pt2 = Cv::Point.new(r.x + r.width, r.y + r.height)
m.rectangle!(pt1, pt2, color, thickness: 3, line_type: Cv::CV_AA)
end
w.show(m)
break if Cv::wait_key(10) > 0
end