class_docstr: Creates temporary XML files from masks for testing. Intended to be used
  as a context so that the XML files are automatically deleted when the
  execution goes out of scope.
  
  Example:
  
      >>> with BBFromMasks(root="/tmp/datasets/MVTec", datast_name="MVTec"):
      >>>     tests_case()
  
  Args:
      root (str, optional): Path to the dataset location. Defaults to "datasets/MVTec".
      dataset_name (str, optional): Name of the dataset to write to the XML file. Defaults to "MVTec".
docstr: Generate XML files.
docstr_tok: ["Generate","XML","files","."]
code: def __enter__(self):
      """Generate XML files."""
      for mask_path in glob(
          os.path.join(self.root, "*/ground_truth/*/*_mask.png")
      ):
          path_tree = mask_path.split("/")
          image = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE)
          image = np.array(image, dtype=np.uint8)
          im_size = image.shape
          contours, _ = cv2.findContours(image, 1, 1)
  
          boxes = []
          for contour in contours:
              p1 = [np.min(contour[..., 0]), np.min(contour[..., 1])]
              p2 = [np.max(contour[..., 0]), np.max(contour[..., 1])]
              boxes.append([p1, p2])
  
          contents = self._create_xml_contents(
              boxes, path_tree, im_size
          )
          tree = ET.ElementTree(contents)
          output_loc = (
              "/".join(path_tree[:-1])
              + f"/{path_tree[-1].rstrip('_mask.png')}.xml"
          )
          tree.write(output_loc)
          # write the xml
          self.generated_xml_files.append(output_loc)
  
file_path: anomalib/tests/helpers/detection.py
imports: import os
  import xml.etree.ElementTree
  from glob import glob
  from typing import List, Tuple
  import cv2
  import numpy
label_desc: Use image node_id 2 for calling the BBFromMasks obj's underlying member method code with example usage: obj.__enter__() without return types