Skip to main content

Country Flag Classifier.

Project description

Flagpy - World Flag Identifier

Flagpy is a python library that allows the user to identify the flags of countries from all over the world. It also has support for seeing how similar two different flags are and finding which two countries have the most/least similar flag.

Installation

Flagpy can be installed simply using pip.

$ pip install flagpy

Usage

Identify

Flagpy can take in a url which links to an image and then determine which flag is being displayed in the image. It is most accurate when the flag takes up the whole image. The type of method to find the closest flag can be specified, but the default (and most accurate) method is "mse". Supported methods as of right now are "mse", "ssim", and "hash".

>>> import flagpy as fp
>>> fp.identify('https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Flag_of_Canada_%28Pantone%29.svg/1200px-Flag_of_Canada_%28Pantone%29.svg.png')
'Canada'
>>> fp.identify('https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Flag_of_Canada_%28Pantone%29.svg/1200px-Flag_of_Canada_%28Pantone%29.svg.png', method = 'ssim')
'Canada'
>>> fp.identify('https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Flag_of_Canada_%28Pantone%29.svg/1200px-Flag_of_Canada_%28Pantone%29.svg.png', method = 'hash')
'Canada'

Closest/Farthest Flag

Flagpy can take in a name of a country and return which country's flag is most/least similar to the given country's flag. Once again, the method to find the most/least similar flag can be specified, but the default is "mse". The name of the country must match one of the items in flagpy's list of countries, which can be acquired with get_country_list().

>>> fp.get_country_list()
['Afghanistan', 'Albania', ... , 'Zambia', 'Zimbabwe']
>>> fp.closest_flag("India")
'Niger'
>>> fp.closest_flag('India', method = 'ssim')
'Luxembourg'
>>> fp.farthest_flag('India')
'Estonia'
>>> fp.farthest_flag('India', method = 'hash')
'Armenia'

Displaying Flags

Flagpy has support for both displaying a country's flag and storing it as an Image object.

>>> fp.display('Ivory Coast')

alt text

>>> img = fp.get_flag_img('Yemen')
>>> img.show()

alt text

Difference Between Flags

Flagpy allows the user to find the quantitative difference between two countries' flags. There are three possible methods to calculate this difference: mean-squared error (the default), structural similarity index measurement, and hash difference. For both mse and hash, smaller values indicate higher similarity between the two flags, and a difference of 0 means the images are identical. However, the hash difference will always be an integer. For ssim, the value must be between -1 and 1, so higher values indicate a higher similarity.

>>> fp.flag_dist('Denmark', 'Germany')
57595.77333333333
>>> fp.flag_dist('Denmark', 'Germany', method = 'ssim')
0.25852880532772604
>>> fp.flag_dist('Denmark', 'Germany', method = 'hash')
40

Flag DataFrame

Flagpy can supply the user with a pandas DataFrame of all the countries and their flag image (scraped from Wikipedia).

>>> df = fp.get_flag_df()
>>> df.shape
(195, 1)
>>> df["flag"].loc["The United States"]
array([[[ 51,  51, 102],
        [ 51,  51, 102],
        [ 51,  51, 102],
        ...
        [153,  51,  51],
        [153,  51,  51],
        [153,  51,  51]]]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flagpy-1.0.3.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flagpy-1.0.3-py3-none-any.whl (222.5 kB view details)

Uploaded Python 3

File details

Details for the file flagpy-1.0.3.tar.gz.

File metadata

  • Download URL: flagpy-1.0.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.1

File hashes

Hashes for flagpy-1.0.3.tar.gz
Algorithm Hash digest
SHA256 4888480241ade6a0e42b8192572034f370b9514675385a33583a57eb4fe26e97
MD5 2b3d2df2e2675923042f55088e72146e
BLAKE2b-256 798d4cf508fdb9ead90266295356dde9d8834391bfbdbed0933bf1e351be8205

See more details on using hashes here.

File details

Details for the file flagpy-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: flagpy-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 222.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.1

File hashes

Hashes for flagpy-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4dc9d1bf5d641188a1ab33607311041436102aa346999f1c6b6c30395342ab7f
MD5 9eb31080836e66759dd48e677996a95c
BLAKE2b-256 9055f97efd9128251a62de26b996b3470a5e00c15d4db38ab3382ed2d45e7c42

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page