2008-08-19 11:01:28 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# face_detect.rb
|
|
|
|
require "rubygems"
|
|
|
|
require "opencv"
|
|
|
|
|
|
|
|
include OpenCV
|
|
|
|
|
|
|
|
window = GUI::Window.new("face detect")
|
|
|
|
capture = CvCapture.open
|
2011-08-21 10:16:59 -04:00
|
|
|
detector = CvHaarClassifierCascade::load("./data/haarcascades/haarcascade_frontalface_alt.xml")
|
2008-08-19 11:01:28 -04:00
|
|
|
|
2011-08-21 10:16:59 -04:00
|
|
|
loop {
|
2008-08-19 11:01:28 -04:00
|
|
|
image = capture.query
|
2011-08-21 10:16:59 -04:00
|
|
|
detector.detect_objects(image).each { |rect|
|
|
|
|
image.rectangle! rect.top_left, rect.bottom_right, :color => CvColor::Red
|
2008-08-19 11:01:28 -04:00
|
|
|
}
|
|
|
|
window.show image
|
2011-08-21 10:16:59 -04:00
|
|
|
break if GUI::wait_key(100)
|
|
|
|
}
|
|
|
|
|