Giter VIP home page Giter VIP logo

britishmuseumfacesdetection's Introduction

DOI

A demonstration script for facial detection

This repository holds a sample terminal script for interacting with the British Museum's RDF endpoint to retrieve images and then using OpenCV, recognise faces within the images. These are then cropped and stored in a directory on your machine.

This is a very simple example and pulls busts (100 of them) from the British Museum collection and uses them to create image montages. Within the folder are all the files pulled from the example script.

This example script uses a very simple SPARQL query to retrieve 100 British Museum records of busts, where an image exists. The query is now stored in the SPARQL directory as a text file. Take note of the format with curly braces doubled up.

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX crm: <http://erlangen-crm.org/current/>
PREFIX fts: <http://www.ontotext.com/owlim/fts#>
PREFIX bmo: <http://collection.britishmuseum.org/id/ontology/>
SELECT DISTINCT ?image
WHERE {
  ?object bmo:PX_object_type ?object_type .
  ?object_type skos:prefLabel "bust" .
  ?object bmo:PX_has_main_representation ?image .
} LIMIT 100

An example detected face can be shown below:

Original image

Detected face

There are also two montages created at the end of this script:

All images originally pulled from RDF:

All faces identified within the original images:

To use

Clone this folder to your computer:

$ git clone https://github.com/BritishMuseumDH/britishMuseumFacesDetection.git

Change to the directory:

$ cd britishMuseumFacesDetection

Install the requirements (I recommend doing this in a virtual environment):

$ pip install -r requirements.txt

Now run the script (for example):

$ python britishMuseumFaces.py -p . -d bmimages -f facesDetected -r bmimagesResized -m montages -s 200 -o 'bmImages' -t 'default' -q "bust"

There are several arguments that you use for this script:

Mandatory:

  • Path: -p or --path
  • Download directory: -d or --directory
  • Faces directory: -f or --faces
  • Resize directory: -r or --resized
  • Montages directory: -m or --montages

Optional

  • Size of cropped image: -s or --size (default 300)
  • Output file: -o or --output (default bmImages)
  • SPARQL template to use: -t or --template (default.txt is used)
  • The query to use: -q or --query (default "bust")
  • The endpoint to use: -e or --endpoint (default http://collection.britishmuseum.org/sparql)

This should run and output any error messages to your terminal. Within the script, progress is printed into your terminal window. You should see the following messages when running for the first time:

  • Your sparql query reads as: {query string}
  • Image {filename} downloaded Multiple times
  • Image path written to file Multiple times
  • {filename} resized Multiple times
  • Detecting faces in {filename} Multiple times
  • Found {number of} faces within the image Multiple times
  • Written cropped face {filename} Multiple times
  • Written highlighted face {filename} Multiple times
  • The time taken to process face detection was: --- {x} seconds ---
  • {Total number of } faces were identified in total
  • The dimensions of the montage are {XbyY}
  • Now creating image montage of all retrieved images
  • Now resizing image montage of all retrieved images
  • Now creating image montage of all faces detected in images
  • Now resizing image montage of all faces detected in images
  • Facial detection complete

License

MIT for script. CC-BY-NC-SA for all image content, copyright the Trustees of the British Museum.

Authors

  • Daniel Pett, The British Museum @portableant
  • Harrison Pim, The British Museum @harrisonpim
  • Ben O'Steen, The British Library @benosteen
  • Richard Wareham, Cambridge University @rjw57
  • Matthew Vincent, Rekrei @neshmi

To do

  • PEP 8
  • Face matching
  • Use of apis as well as SPARQL

britishmuseumfacesdetection's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

britishmuseumfacesdetection's Issues

Script does not work in Python 3

The following lines don't work in Python 3:
https://github.com/BritishMuseumDH/britishMuseumFacesDetection/blob/master/britishMuseumFaces.py#L259
https://github.com/BritishMuseumDH/britishMuseumFacesDetection/blob/master/britishMuseumFaces.py#L290

I think this is because the synax for using urllib changed from Python 2:
urllib.urlretrieve()
to Python 3:
urllib.request.urlretrieve()

If you have the images downloaded already you won't see this error when testing with Python 3 because it's only necessary to use urllib when fetching the images for the first time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.