Skip to content

Instantly share code, notes, and snippets.

@donalod
Created June 12, 2019 20:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donalod/8778e2c137e858eb5e8aadab2657bca2 to your computer and use it in GitHub Desktop.
Save donalod/8778e2c137e858eb5e8aadab2657bca2 to your computer and use it in GitHub Desktop.
submit_to_rekognition.rb
#!/usr/bin/env ruby
require "aws-sdk-rekognition"
require "catpix"
# Images from https://thispersondoesnotexist.com/image and https://archive.org/details/1mFakeFaces
p "Running face rekog script at #{Time.now.to_s}"
image_ids = Array.new(10) { rand(1...482) }
#image_ids=ARGV
image_ids.each do |id|
image_file="./face_#{id}.jpeg"
client = Aws::Rekognition::Client.new
response = client.detect_faces({
image: {
bytes: File.read(image_file)
},
attributes: ["ALL"],
})
Catpix::print_image image_file,
:limit_x => 0.9,
:limit_y => 0.9,
:center_x => false,
:center_y => false,
:bg => "black",
:bg_fill => true,
:resolution => "high"
response.face_details.each do |detail|
puts "Gender guess: #{detail.gender.value.to_s} (with #{(detail.gender.confidence).round.to_s}% confidence)"
puts "Age guess: #{detail.age_range.low.to_s}-#{detail.age_range.high.to_s}\n"
detail.smile.value ? (puts "Smiling (with #{(detail.smile.confidence).round.to_s}% confidence)") : ""
detail.eyeglasses.value ? (puts "Wearing glasses (with #{(detail.eyeglasses.confidence).round.to_s}% confidence)") : ""
detail.sunglasses.value ? (puts "Wearing sunglasses (with #{(detail.sunglasses.confidence).round.to_s}% confidence)") : ""
detail.beard.value ? (puts "Beard (with #{(detail.beard.confidence).round.to_s}% confidence)") : ""
detail.mustache.value ? (puts "Wearing glasses (with #{(detail.mustache.confidence).round.to_s}% confidence)") : ""
detail.eyes_open.value ? (puts "Open eyes (with #{(detail.eyes_open.confidence).round.to_s}% confidence)") : ""
detail.mouth_open.value ? (puts "Mouth open (with #{(detail.mouth_open.confidence).round.to_s}% confidence)") : ""
detail.emotions.each do |emotion|
if emotion.confidence > 80
puts "Emotion: #{emotion.type} (with #{(emotion.confidence).round.to_s}% confidence)"
end
end
puts "\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment