Skip to content

martinohanlon/quickdraw_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

quickdraw

Latest Version number Docs

Quick Draw is a drawing game which is training a neural network to recognise doodles.

Quick Draw logo and banner

quickdraw is a Python API for accessing the Quick Draw data - it downloads the data files as and when needed, caches them locally and interprets them so they can be used.

examples drawings created using Quick Draw

Created by Martin O'Hanlon (@martinohanlon, stuffaboutco.de).

Getting started

Install the quickdraw python library using pip.

  • Windows
pip install quickdraw
  • macOS
pip3 install quickdraw
  • Linux / Raspberry Pi
sudo pip3 install quickdraw

Use

Here are some examples of how to use quickdraw but be sure to also checkout the API documentation for more information.

Open the Quick Draw data using QuickDrawData and pull back a drawing of an anvil.

from quickdraw import QuickDrawData
qd = QuickDrawData()
anvil = qd.get_drawing("anvil")

print(anvil)

quickdraw will download the anvil.bin data file and return the data for a random drawing of an anvil (well a doodle of an anvil anyway).

Drawings are returned as QuickDrawing objects which exposes the properties of the drawing.

print(anvil.name)
print(anvil.key_id)
print(anvil.countrycode)
print(anvil.recognized)
print(anvil.timestamp)
print(anvil.no_of_strokes)
print(anvil.image_data)
print(anvil.strokes)

You can save the drawing using the image property.

anvil.image.save("my_anvil.gif")

A Quick Draw drawing of a anvil

You can save an animation of the drawing using the animation property.

anvil.animation.save("my_anvil_animation.gif")

An animation of a Quick Draw drawing being drawn

You can open a group of Quick Draw drawings using QuickDrawDataGroup passing the name of the drawing ("anvil", "aircraft", "baseball", etc).

from quickdraw import QuickDrawDataGroup

anvils = QuickDrawDataGroup("anvil")
print(anvils.drawing_count)
print(anvils.get_drawing())

By default only 1000 drawings are opened, you can change this by modifying the max_drawings parameter of QuickDrawDataGroup, setting it to None will open all the drawings in that group.

from quickdraw import QuickDrawDataGroup

anvils = QuickDrawDataGroup("anvil", max_drawings=None)
print(anvils.drawing_count)

To iterate through all the drawings in a group use the drawings generator.

from quickdraw import QuickDrawDataGroup

qdg = QuickDrawDataGroup("anvil")
for drawing in qdg.drawings:
    print(drawing)

You can get a list of all the drawing names using the drawing_names property of QuickDrawData.

from quickdraw import QuickDrawData

qd = QuickDrawData()
print(qd.drawing_names)

Examples

Code examples can be found in the quickdraw GitHub repository.

Documentation

API documentation can be found at quickdraw.readthedocs.io

Warning

The drawings have been moderated but there is no guarantee it'll actually be a picture of what you are asking it for (although in my experience they are)!

Status

Stable.

Raise any issues in the github repository.