Project - Codenamed: [Raccoon]

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Project - Codenamed: [Raccoon]

Post by maboroshi »

I had made a post earlier about this project but ended up deleting the post because I wasn't 100% sure it was working properly.

After a bit of testing, I can determine that the Facial Recognition algorithm is able to determine (at least at a basic level) if faces are blurred.

About the project:

Raccoon is a script which searches through Google Street Image View given the coordinates you provide and downloads images taken at those locations.

After the photos have been downloaded the script will then look in to the directory of saved images for a plausible match trying to identify a face based on a photo provided to the recognition function.

Google Street Image View currently accepts 25 000 requests per day if you supply an API key. For this script to be functional you will need the PyFaces library, which is available here http://code.google.com/p/pyfaces/. Pyfaces implements a face recognition technique that uses eigenfaces http://en.wikipedia.org/wiki/Eigenface

I have attached the code as well as put it in code tags on this post. Enjoy! I should point out that PyFaces is included in the download provided and I have cleaned up error messages in it and the script as well.

Code: Select all

from pyfaces import pyfaces
import urllib2
import datetime
from threading import *
import time
import os, sys, errno

### For the api specifics visit 
### https://developers.google.com/maps/documentation/streetview/

### GLOBALS ###

### Latitude and Longitude list
latitude = ["40.655100", "40,6766200", "40,6768200"]
longitude = ["-73.945100", "-73.946100", "-73.947100"] 
### Image size to download to
width = "600"
height = "287"
### Compass view of the camera
heading = "360"
### Zoom
fov = "30"
### pitch - specifies the up or down angle of the camera relative to the Street View vehicle.
### This is often, but not always, flat horizontal.
pitch = "1"
### indicates whether or not the request came from a device using a
### location sensor (e.g. a GPS) to determine the location sent in this request.
sensor = "false"

### Your api key
key = ""

### Get current date
today = time.strftime("%Y-%m-%d")

### Create a directory of that date
try:
    os.mkdir(today)
except OSError as exception:
    if exception.errno != errno.EEXIST:
        pass

### Function to run PyFaces
def analyze(imgname, dirname, egfaces, thrshld):         
    try:
        start = time.time()
        imgname = imgname
        dirname = dirname
        egfaces = int(egfaces)
        thrshld = float(thrshld)
        pyf = pyfaces.PyFaces(imgname, dirname, egfaces, thrshld)
        end = time.time()
        print("[+] Time it took to analyze: %f secs" % (end - start))
    except Exception, e:
        print(e)
    
def raccoon():
    count = 0
    for lat, lon in zip(latitude, longitude):
        if len(latitude) != len(longitude):
            print("[-] Error: The length of latitude and longitude values are unequal")
            print("[-} You need to enter both values for each location to check") 
            sys.exit(1)
        
        # Some basic info for urllib function 
        user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
        headers = { 'User-Agent' : user_agent }
        url = "http://maps.googleapis.com/maps/api/streetview?size=%sx%s&location=%s,%s&heading=%s&fov=%s&pitch=%s&sensor=%s&key=%s" % (width, height, str(lat), str(lon),heading, fov, pitch, sensor, key)
        
        # request the document
        r = urllib2.Request(url, headers=headers)
        page = urllib2.urlopen(r).read()

        now = time.strftime("%H %M %S")

        # write output
        fname = os.getcwd() + "\\" + today + "\\" + str(now) + ".jpg"
        if os.path.exists(fname):
            print("[-] File already exists")
        else:
            output = open(fname, "wb")
            output.write(page)
            output.close()
            print("[+] Image captured")

        count += 1
        print("[+] Number of images saved: %d" % count)

        print("[+] Sleeping 6 seconnds")
        time.sleep(6)
        
    count = count - 1
    print("[+] Analyzing")
    analyze(os.getcwd() + "\\"+ "faces_orig.jpg", today, count, 300)
    print("[+] Finished")


if __name__ == '__main__':
    raccoon()
Edit * It's a good idea to check your code before posting LOL
Attachments
raccoon.7z
(89.55 KiB) Downloaded 89 times

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: Project - [raccoon]

Post by bad_brain »

whoah...you're firing scripts out like a battleship at the moment... :o

good work as usual buddy... :D
Image

Post Reply