本文整理汇总了Python中elementtree.SimpleXMLWriter.XMLWriter.declaration方法的典型用法代码示例。如果您正苦于以下问题:Python XMLWriter.declaration方法的具体用法?Python XMLWriter.declaration怎么用?Python XMLWriter.declaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.SimpleXMLWriter.XMLWriter
的用法示例。
在下文中一共展示了XMLWriter.declaration方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: intWriter
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import declaration [as 别名]
def intWriter(path, camMat, distCoe, calibError={}):
try:
print 'Generating Intrinsic Parameters to:', path, '...'
with open(path, 'w') as int_xml:
w = XMLWriter(int_xml)
w.declaration()
# Camera Intrinsic (Root)
root = w.start('StdIntrinsic')
# Camera Matrix
w.element('CamMat',
fx=str(camMat[0][0]), fy=str(camMat[1][1]),
cx=str(camMat[0][2]), cy=str(camMat[1][2]))
# Distortion Coefficients
if (len(distCoe[0]) == 8): # 8 coefficients Rational Model, k4 k5 k6 enabled
w.element('DistCoe', k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
k3=str(distCoe[0][4]), k4=str(distCoe[0][5]),
k5=str(distCoe[0][6]), k6=str(distCoe[0][7]))
elif (len(distCoe[0]) == 12): # 12 coefficients Prism Model, c1, c2, c3, c4 enabled, new in OpenCV 3.0.0
w.element('DistCoe', k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
k3=str(distCoe[0][4]), k4=str(distCoe[0][5]),
k5=str(distCoe[0][6]), k6=str(distCoe[0][7]),
c1=str(distCoe[0][8]), c2=str(distCoe[0][9]),
c3=str(distCoe[0][10]),c4=str(distCoe[0][11]))
else:
w.element('DistCoe', k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
k3=str(distCoe[0][4]))
# Error values
if len(calibError) > 0:
w.element('Error', rms=str(calibError['rms']), total=str(calibError['tot_err']), arth=str(calibError['arth_err']))
w.close(root)
print 'Intrinsic calibration has been generated successfully.'
except Exception as e:
print 'ERROR: occurred in writing intrinsic XML file.'
raise e # keep it bubbling up, to catch in main()
示例2: writeXML
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import declaration [as 别名]
def writeXML(frames, path, args):
out_xml = XMLWriter(path)
out_xml.declaration()
doc = out_xml.start("AnnotationEvaluation")
# source information
out_xml.element("video", mark_in=str(args[4]), mark_out=str(args[5]))
out_xml.element("mapper", os.path.basename(args[1]))
out_xml.element("annotation", os.path.basename(args[2]))
out_xml.element("comparison", mean_err=str(calMean(frames)))
# compared points
out_xml.start("frames", total=str((args[5]-1) - (args[4]+1)+1), compared=str(len(frames)))
for f in frames.keys():
out_xml.start("frame", num=str(f))
for key in frames[f]:
out_xml.start("object", lens=Theta.name(frames[f][key]["lens"]), name=key, err=str(frames[f][key]["err"]))
out_xml.element("annotatedCentroid", x=str(frames[f][key]["ann_x"]), y=str(frames[f][key]["ann_y"]))
out_xml.element("mappedCentroid", x=str(frames[f][key]["map_x"]), y=str(frames[f][key]["map_y"]))
out_xml.end() # object
out_xml.end() # frames
# clean up
out_xml.close(doc)
示例3: intWriter
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import declaration [as 别名]
def intWriter(path, buttonside=None, backside=None):
try:
status = ""
print 'Generating Intrinsic Parameters to:', path, '...'
with open(path, 'w') as int_xml:
w = XMLWriter(int_xml)
w.declaration()
# Camera Intrinsic (Root)
root = w.start('dual_intrinsic')
num_sides = range(0, 2)
#num_sides = range(0, 1) if buttonside is None or backside is None else range(0, 2)
for i in num_sides:
w.start("Buttonside" if i == 0 else "Backside")
if i == 0 and buttonside[0].size > 0 and buttonside[1].size > 0:
status += 'Buttonside'
camMat = buttonside[0]
distCoe = buttonside[1]
calibError = buttonside[2]
elif i == 1 and backside[0].size > 0 and backside[1].size > 0:
if status == "": status += 'Backside'
else: status += ' & Backside'
camMat = backside[0]
distCoe = backside[1]
calibError = backside[2]
else:
w.end()
continue
# Camera Matrix
w.element('CamMat',
fx=str(camMat[0][0]), fy=str(camMat[1][1]),
cx=str(camMat[0][2]), cy=str(camMat[1][2]))
# Distortion Coefficients
if (len(distCoe[0]) == 8): # 8 coefficients Rational Model, k4 k5 k6 enabled
w.element('DistCoe',
k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
k3=str(distCoe[0][4]), k4=str(distCoe[0][5]),
k5=str(distCoe[0][6]), k6=str(distCoe[0][7]))
elif (len(distCoe[0]) == 12): # 12 coefficients Prism Model, c1, c2, c3, c4 enabled, new in OpenCV 3.0.0
w.element('DistCoe',
k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
k3=str(distCoe[0][4]), k4=str(distCoe[0][5]),
k5=str(distCoe[0][6]), k6=str(distCoe[0][7]),
c1=str(distCoe[0][8]), c2=str(distCoe[0][9]),
c3=str(distCoe[0][10]),c4=str(distCoe[0][11]))
else:
w.element('DistCoe',
k1=str(distCoe[0][0]), k2=str(distCoe[0][1]),
p1=str(distCoe[0][2]), p2=str(distCoe[0][3]),
k3=str(distCoe[0][4]))
# Error values
if len(calibError) > 0:
w.element('Error',
rms=str(calibError['rms']),
total=str(calibError['tot_err']),
arth=str(calibError['arth_err']))
w.end() #buttonside/backside
w.close(root)
print status, 'Intrinsic calibration has been generated successfully.'
except Exception as e:
# keep it bubbling up, to catch in main()
raise Exception("{}: {}\n'ERROR: occurred in writing intrinsic XML file.'".format(type(e), e.message))
示例4: XMLWriter
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import declaration [as 别名]
#Write datastreams manifest to XML
#example datastream chunk
'''
<foxml:datastream CONTROL_GROUP="M" ID="ORIGINAL" STATE="A">
<foxml:datastreamVersion ID="ORIGINAL.0" MIMETYPE="image/jpeg" LABEL="Page#">
<foxml:contentLocation TYPE="URL">
<xsl:attribute name="REF">http://image.url/Sketches_and_scraps0000#.jpg</xsl:attribute>
</foxml:contentLocation>
</foxml:datastreamVersion>
</foxml:datastream>
'''
fhand = item_path + "/" + item_ID + "_FOXML.xml"
w = XMLWriter(fhand, encoding="utf-8")
w.declaration()
#namespace dictionary
namespace={}
namespace['xmlns:foxml'] = "info:fedora/fedora-system:def/foxml#"
namespace['xmlns:xsi']="http://www.w3.org/2001/XMLSchema-instance"
manifest = w.start("ebook_item", namespace)
# iterate through parent collections and create <collection> elements for each
for collection_name in collections:
w.element("collection", Template("$collection_name").substitute(collection_name=collection_name))
w.element("PID_prefix", Template("$PID_prefix").substitute(PID_prefix=PID_prefix))
w.element("book_title", Template("$item_ID").substitute(item_ID=item_ID))
w.element("item_ID", Template("$item_ID").substitute(item_ID=item_ID))
示例5: main
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import declaration [as 别名]
#.........这里部分代码省略.........
elif key == Key.right:
params['status'] = Status.skip
elif key == Key.left:
params['status'] = Status.back
elif key == Key.backspace:
params['status'] = Status.remove
elif Key.char(key, '1') and cfg.dual_mode:
params['status'] = Status.still
lens = Theta.Left
elif Key.char(key, '2') and cfg.dual_mode:
params['status'] = Status.still
lens = Theta.Right
# catch exit status
if params['status'] == Status.stop:
print "\nprocess aborted!"
break
# write data
if params['status'] == Status.record \
and len(trainer_points[lens]) != max_clicks: # TODO: does this disable recording clicks on the last frame
if dataQuality == 0:
trainer_points[lens][in_vid.at()] = (params['pos'], in_csv.row()[2:5], in_csv.row()[8:10])
params['status'] = Status.skip
# or remove it
elif params['status'] == Status.remove \
and in_vid.at() in trainer_points[lens]:
del trainer_points[lens][in_vid.at()]
print "\nremoved dot"
# load next csv frame
if params['status'] == Status.skip:
if in_vid.next():
in_csv.next()
else:
write_xml = True
print "\nend of video: {}/{}".format(in_vid.at() -1, mark_out -1)
break
# or load previous csv frame
elif params['status'] == Status.back:
if in_vid.back():
in_csv.back()
# reset status
params['status'] = Status.wait
# clean up
cv2.destroyAllWindows()
## write xml
if write_xml:
out_xml = XMLWriter(args[3])
out_xml.declaration()
doc = out_xml.start("TrainingSet")
# source information
out_xml.start("video", mark_in=str(mark_in), mark_out=str(mark_out))
out_xml.data(os.path.basename(args[1]))
out_xml.end()
out_xml.element("csv", os.path.basename(args[2]))
# training point data
for lens in trainer_points:
if lens == Theta.Right:
out_xml.start("buttonside", points=str(len(trainer_points[lens])))
elif lens == Theta.Left:
out_xml.start("backside", points=str(len(trainer_points[lens])))
else: # non dualmode
out_xml.start("frames", points=str(len(trainer_points[lens])))
for i in trainer_points[lens]:
pos, row, markers = trainer_points[lens][i]
x, y = pos
out_xml.start("frame", num=str(i))
out_xml.element("plane",
x=str(x),
y=str(y))
out_xml.element("vicon",
x=str(row[0]), y=str(row[1]), z=str(row[2]))
out_xml.element("visibility",
visibleMax=str(markers[0]),
visible=str(markers[1]))
out_xml.end()
out_xml.end() # frames
# clean up
out_xml.close(doc)
print "Data was written."
else:
print "No data was written"
print "\nDone."
return 0
示例6: main
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import declaration [as 别名]
def main(sysargs):
args = EasyArgs(sysargs)
cfg = EasyConfig(args.config, group="mapper")
if "help" in args:
usage()
return 0
if ["calib", "trainer", "output"] not in args:
print "Must specify: -calib, -trainer, -output files"
usage()
return 1
if len(args) == 1:
print "Not enough input CSV files"
usage()
return 1
if len(args) > 2 and args.map_trainer_mode:
print "Too many CSV for trainer-mapping mode"
usage()
return 1
if "force_side" in args:
side = Theta.resolve(args.force_side)
if side == Theta.NonDual:
print "Invalid force_side argument:", args.force_side
usage()
return 1
# set side overrides
force_button = (side == Theta.Buttonside)
force_back = not force_button
else:
force_button = force_back = False
# working vars
csvs = {}
frame_num = 0
# open source CSV datasets
for i in range(1, len(args)):
print args[i]
csvs[i] = Memset(args[i])
# reel all the files up to their first flash
for i in csvs:
csvs[i].restrict()
if len(csvs[i].row()) < 10:
print "CSV file:", args[i], "contains no marker data!\nAborting."
return 1
# override csv name
if args.map_trainer_mode:
csvs[1]._name = cfg.trainer_target
# open calib files
try:
buttonside = Mapper(args.calib, args.trainer, cfg, Theta.Buttonside)
backside = Mapper(args.calib, args.trainer, cfg, Theta.Backside)
except Exception as e:
print e.message
return 1
count = {'bts':0, 'bks':0, 'rej':0}
# open destination XML
with open(args.output, "w") as xmlfile:
w = XMLWriter(xmlfile)
w.declaration()
xmlfile.write("<!DOCTYPE dataset SYSTEM \"http://storage.gwillz.com.au/eagleeye_v2.dtd\">")
doc = w.start("dataset")
# main loop
while True:
w.start("frameInformation")
w.element("frame", number=str(frame_num))
for i in csvs:
c = csvs[i]
# determine marker quality
try:
max_reflectors = int(c.row()[8])
visible_reflectors = int(c.row()[9])
except:
print "Error in reading quality at row {}".format(i)
return 1
try:
# read VICON data
x = float(c.row()[2])
y = float(c.row()[3])
z = float(c.row()[4])
# TODO: is this necessary? We never use the object's rotation
rx = float(c.row()[5])
ry = float(c.row()[6])
rz = float(c.row()[7])
except:
#.........这里部分代码省略.........