Skip to content Skip to sidebar Skip to footer

Extract Keywords Form Images Using Python

still learning python. I am currently working on a python code that will extracts metadata (usermade keywords) from images. I already tried Pillow AND exif but this excludes the us

Solution 1:

Focusing only on your XML parsing not PIL metadata work, three issues are your problem:

  1. You need to define the namespace prefixes when using findall which you can do with the namespaces arg. And then your xpath must include the prefixes.
  2. When using findall do not include the root as that is the starting point but from its child downward.
  3. There is no Bags local name with plural but only Bag and its length would be one. If you want its children, go one level deeper.

Consider adjusted script:

import xml.etree.ElementTree as ET

tree = ET.parse('mytags.xml')

nmspdict = {'x':'adobe:ns:meta/',            
            'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
            'dc': 'http://purl.org/dc/elements/1.1/'}

tags = tree.findall('rdf:RDF/rdf:Description/dc:subject/rdf:Bag/rdf:li',
                    namespaces = nmspdict)

print (type(tags))
print (len(tags))

# <class 'list'># 6for i in tags:
    print(i.text)
# Kumasi# Summer 2016# Charlestone# SC# Beach# Olivjana

Post a Comment for "Extract Keywords Form Images Using Python"