4

I have a file locations.xml which contains image filenames, and positions of rectangles drawn on the corresponding image. The XML node structure is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<tagset>
  <image>
    <imageName>ryoungt_05.08.2002/aPICT0034.JPG</imageName>
    <resolution x="960" y="1280" />
    <taggedRectangles>
      <taggedRectangle x="196.0" y="901.0" width="111.0" height="67.0" offset="0.0" rotation="0.0" userName="admin" />
      <taggedRectangle x="116.0" y="896.0" width="59.0" height="69.0" offset="0.0" rotation="0.0" userName="admin" />
      <taggedRectangle x="442.0" y="794.0" width="424.0" height="67.0" offset="0.0" rotation="0.0" userName="admin" />
      <taggedRectangle x="212.0" y="793.0" width="200.0" height="66.0" offset="0.0" rotation="0.0" userName="admin" />
      <taggedRectangle x="99.0" y="560.0" width="302.0" height="76.0" offset="0.0" rotation="0.0" userName="admin" />
      <taggedRectangle x="107.0" y="791.0" width="84.0" height="66.0" offset="0.0" rotation="0.0" userName="admin" />
      <taggedRectangle x="512.0" y="682.0" width="366.0" height="74.0" offset="0.0" rotation="0.0" userName="admin" />
      <taggedRectangle x="104.0" y="678.0" width="376.0" height="73.0" offset="0.0" rotation="0.0" userName="admin" />
    </taggedRectangles>
  </image>

I need to open this file in OpenCV and read it such that for every image filename in the XML file, the corresponding image will be opened in a window, and the rectangles will be drawn on the corresponding image.

Basically I need to open these files and see the rectangles to match them with rectangles drawn on the same images using a text detection algorithm. But it's handling the XML files that have me stumped. Any help is appreciated.

Andrey Rubshtein
  • 20,557
  • 10
  • 65
  • 102
Riddhiman Dasgupta
  • 308
  • 1
  • 6
  • 21
  • if it's your xml file, you could switch from json to xml and save parsing time. because json parsing is much simpler and faster than xml. :) – Evgen Bodunov Feb 11 '12 at 11:41
  • 1
    JSON is not an option. Because all the files are not mine. And I do not know anything about JSON yet. And I'll have to figure out how ti incorporate the JSON parser results into OpenCV function arguments. – Riddhiman Dasgupta Feb 11 '12 at 15:31

2 Answers2

2

OpenCV has some (de-)serialization tool which support XML, YAML and JSON file format

You can deserialize your XML into OpenCV objects directly. Take a look at the example here.

But this is only useful when OpenCV is involved on both sides. XML parser requires the <opencv_storage> tag.

antoine
  • 1,293
  • 9
  • 22
2

OpenCV is OpenCV and XML is XML. One has not much to do with the other.

Check this thread

What is the best open XML parser for C++?

I personally used pugixml and I was content

Community
  • 1
  • 1
Jakub M.
  • 30,095
  • 43
  • 103
  • 169
  • 1
    Yes, I've thought of using TinyXML or something more full-fledged, but do I need to use a different parser for my rather simple needs? Is there no way to do it using the inbuilt XML/YAML handling functions in OpenCV? – Riddhiman Dasgupta Feb 11 '12 at 15:30