Skip to content

Instantly share code, notes, and snippets.

@kga
Created Jul 7, 2009
Embed
What would you like to do?
#!/usr/bin/env perl
use strict;
use warnings;
use File::Temp;
use Image::ObjectDetect;
use LWP::Simple;
use XML::Feed;
use XML::Feed::Deduper;
use YAML;
my $cascade = '/opt/local/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml';
my $detector = Image::ObjectDetect->new($cascade);
my $rss = 'http://f.hatena.ne.jp/twitter/rss';
my $feed = XML::Feed->parse( URI->new($rss) );
my $deduper = XML::Feed::Deduper->new( path => "$ENV{HOME}/.shatsu.db" );
my $tmp = File::Temp->new( SUFFIX => '.jpg' );
my @found;
for my $entry ( $deduper->dedup($feed->entries) ) {
my $imageurl = $entry->{entry}{'http://www.hatena.ne.jp/info/xmlns#'}{imageurl};
LWP::Simple::getstore($imageurl, $tmp->filename);
my @faces = $detector->detect($tmp->filename);
push @found, $imageurl if scalar @faces;
}
print Dump @found;
__END__
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708020211.jpg?1246986183
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708015745.jpg?1246986183
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708015326.jpg?1246986183
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708015307.jpg?1246986183
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708015024.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708014711.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708014412.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708014315.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708014041.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708013626.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708013019.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708012830.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708011645.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708011510.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708011223.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708010428.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708010055.jpg
--- http://img.f.hatena.ne.jp/images/fotolife/t/twitter/20090708/20090708005500.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment