Member-only story
Parsing Pascal VOC files with Scala
2 min readMar 16, 2021
Pascal VOC is an XML format used for defining rectangular regions of interest in images. Created for the Visual Object Challenge (VOC), it’s commonly used in machine learning communities as an interchange format for detection labels on images. Here’s an example VOC file:
It’s quick and easy to parse this using Scala. Recent versions of Scala do not ship with an XML parsing library, so be sure to include it in your project with these sbt coordinates:
"org.scala-lang.modules" %% "scala-xml" % "1.3.0"
Note that it’s possible to put other fields into a VOC file but, in general, the most useful bits of information are:
- filename — The location of the image
- objects— The bounding box location in pixel image coordinates. The index uses 1-based counting, and Scala is 0-based, so we’ll subtract 1 from the x and y position when we parse the bndbox.