Class to read a database from a xml file and to write a database to a xml file. More...
Public Member Functions | |
def | __init__ |
The constructor. | |
def | append |
Append a new entry to the database. | |
def | load |
Load a xml file and add all entries to the images list. | |
def | load_file |
Load the database from an xml file. | |
def | max_reached |
Return true if max_size is reached for this database. | |
def | write_file |
Write a xml file to path. | |
def | write_pretty_xml |
Write the database to the writer object. | |
Public Attributes | |
images | |
the list containing the images: images is a list of dictionaries. | |
max_size | |
the maximum amount of images stores in the images list | |
Static Private Member Functions | |
def | __create_image_node |
internal method to create an "image" node | |
def | __information_entry_to_node |
internal method to create an "entry" node | |
def | __pretty_write_entry |
internalt method: writes an "entry" node to the writer object (should have a write method) | |
def | __pretty_write_image |
internal method to write an "image" node to writer (should have a write method) |
Class to read a database from a xml file and to write a database to a xml file.
A image database ist a list of dictionaries. Such a dictionary maps property names to tuples where the first component of the tuple is the value of this property and the second component is the type as string. Allowed types are "int", "float" and "string". For example if the only information for one image is the MaxPixelValue the dictionary has the form
{ "MaxPixelValue" : (200, "int") }
which means that the max pixel value in the image is 200 and the result is of type int. A list of such dictionaries is saved in a field called images.
There is also a max_size parameter to restrict the size of images that can be stored in a database.
Definition at line 23 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.__init__ | ( | self, | |
max_size = None |
|||
) |
The constructor.
self | the object pointer |
max_size | If max_size is not None it is an integer >= 1. The append() method takes care that there are not more than max_size elements in the list. Also the load() method loads only max_size elements, even if there are more in the xml file. If it's None the database has no limit. |
Definition at line 27 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.__create_image_node | ( | doc, | |
entries | |||
) | [static, private] |
internal method to create an "image" node
Definition at line 105 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.__information_entry_to_node | ( | doc, | |
type_name, | |||
name, | |||
content | |||
) | [static, private] |
internal method to create an "entry" node
Definition at line 85 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.__pretty_write_entry | ( | typename, | |
name, | |||
content, | |||
writer, | |||
indent, | |||
addindent, | |||
newl | |||
) | [static, private] |
internalt method: writes an "entry" node to the writer object (should have a write method)
Definition at line 113 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.__pretty_write_image | ( | entries, | |
writer, | |||
indent, | |||
addindent, | |||
newl | |||
) | [static, private] |
internal method to write an "image" node to writer (should have a write method)
Definition at line 140 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.append | ( | self, | |
entry | |||
) |
Append a new entry to the database.
self | the object pointer |
entry | The new entry to add (a dictionary as defined in preface) |
Adds a new element to the list. If max_size is reached the new entry will displace the oldest entry in the list. Which is assumed to be the first entry in the list.
Definition at line 205 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.load | ( | self, | |
doc | |||
) |
Load a xml file and add all entries to the images list.
self | the object pointer |
doc | a xml object as received by xml.dom.minidom.parse |
Parses a xml file and adds all images images list. The xml file must follow the XML Schema of imageInformationDatabase as defined in image_information.xsd. This means that the root note is "imageInformationDatabase". This node has subnodes with name "image". A image node has "entry" subnodes where each entry node has two child nodes: "name" (with the name of the property) and "content" (the value of this property). An entry also has an attribute "type" which is "int", "float" or "string".
Also max_size value is checked so if there are more than max_size elements in the file you only have max_size elements in the list (following the order of the document).
XMLValueError | if the root node is not "imageInformationDatabase" |
XMLValueError | if the type attribute of entry is not "int", "float" or "string" |
Exception | An exception may be thrown if there is no attribute "type" in entry or if an entry has no name or no content subnode. We also assume that if entry is if type int the int function of python can translate the content of this entry to an integer (also for float). |
Definition at line 48 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.load_file | ( | self, | |
path | |||
) |
Load the database from an xml file.
path | path of the xml file |
Exception | if file does not exists |
Just calls load() method with xml.dom.minidom.parse(path)
Definition at line 190 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.max_reached | ( | self | ) |
Return true if max_size is reached for this database.
self | the object pointer |
Definition at line 195 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.write_file | ( | self, | |
path | |||
) |
Write a xml file to path.
self | the object pointer |
path | file path to the xml file |
Definition at line 181 of file xml_image_information.py.
def face_contour_detector.image_information.xml_image_information.XMLImageInformationDatabase.write_pretty_xml | ( | self, | |
writer, | |||
addindent = "\t" , |
|||
newl = "\n" |
|||
) |
Write the database to the writer object.
self | the object pointer |
writer | a object that has e "write" functions (file object interface) |
addindent | a string that is the incremental idention for subnodes |
newl | a string that is used as newline (after most nodes) |
Writes a xml file that satisfies the imageInformationDatabase type as defined in image_information.xsd
Definition at line 157 of file xml_image_information.py.
the list containing the images: images is a list of dictionaries.
Such a dictionary maps property names to tuples where the first component of the tuple is the value of this property and the second component is the type as string. Allowed types are "int", "float" and "string". For example if the only information for one image is the MaxPixelValue the dictionary has the form
{ "MaxPixelValue" : (200, "int") }
which means that the max pixel value in the image is 200 and the result is of type int. A list of such dictionaries is saved in a field called images.
Definition at line 27 of file xml_image_information.py.
the maximum amount of images stores in the images list
Definition at line 27 of file xml_image_information.py.