Ask Your Question
0

Empty parsing results (opencv xml output)

asked 2019-08-04 07:19:44 -0600

chinesestud gravatar image

Iam trying to parse xml (with standart python xml.etree.ElementTree) output from opencv 3.4.2 with python 3.7, results are empty.

Maybe the problem is about data type, which iam trying to extract?

XML sample: https://yadi.sk/d/DFTMQU5jz7MxNQ

Code sample:

import xml.etree.ElementTree as ET
root = ET.parse('new.xml').getroot()  
data = opencv_lbphfaces.find('histograms').text
print('histograms : ', data)

I also tried this (its still show empty result at histograms):

import xml.etree.ElementTree as ET
root = ET.parse('new.xml').getroot()  
for opencv_lbphfaces in root.findall('opencv_lbphfaces'):
for element in opencv_lbphfaces:
     ele_name = element.tag
     ele_value = opencv_lbphfaces.find(element.tag).text
     print(ele_name, ' : ', ele_value)

I want to extract opencv_lbphfaces/histograms/data, after save into file and convert from exponential to integer. But stack at extraction part.

Please give me advice how to solve this histograms extraction problem

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-08-04 09:01:36 -0600

berak gravatar image

updated 2019-08-04 09:03:46 -0600

maybe use opencv's builtin FileStorage parser, not a 3rd party lib (we can't help you with that, anyway)

something like this:

 f = cv2.FileStorage("new.xml", 0)
 L = f.getNode("opencv_lbphfaces")
 h = L.getNode("histograms") # a sequence of histogram mat's
 hist0 = h.at(0).mat() 


 # please check this too !
 help( cv2.FileStorage)
 help( cv2.FileNode)
edit flag offensive delete link more

Comments

1

Thank you! It works! I used like that:

import cv2
f = cv2.FileStorage("new.xml", 0)
L = f.getNode("opencv_lbphfaces")
h = L.getNode("histograms") # a sequence of histogram mat's
hist0 = h.at(0).mat()
print (hist0)

Result was: [[0.02497399 0.00832466 0. ... 0.00728408 0.01144641 0.06243497]] . Also i try

hist0 = h.at(1).mat()

Result was: [[0.01836547 0.00275482 0. ... 0.00091827 0.00550964 0.06519743]] - with ... and some elements is missed.

As i understood it works with indicated part of node, is there way how to extract all node without miss elements?

chinesestud gravatar imagechinesestud ( 2019-08-04 09:54:40 -0600 )edit

please explain, where and why elements would be missing ?

berak gravatar imageberak ( 2019-08-05 06:41:17 -0600 )edit

Everything is good. It was my bad, it works correctly. Thank you!

chinesestud gravatar imagechinesestud ( 2019-08-06 00:50:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-08-04 07:19:44 -0600

Seen: 504 times

Last updated: Aug 04 '19