Slide 16
Slide 16 text
class FaceDetectionWorker
include Sidekiq::Worker
MODEL_PATH = Rails.root.join('vendor', 'mmod_human_face_detector.dat').to_s
def perform(image_id)
image = Image.find(id: image_id)
frames = image.download { |file| detect(file) }
frames.each { |f| Face.create!(image_id: image.id, x: f.left, y: f.top, width: f.width, height: f.height) }
end
def detect(file)
detector = Dlib::DNNFaceDetector.new(MODEL_PATH)
detector.detect(Dlib::Image.load(file.path))
ensure
GC.start
end
end