def export_task_results(db, task_data=None, denormalize=False):
  """ Export the bbox task results. Saves a list of task results to `output_path`.
  Args:
    task_data: Use this to specify which task results to export.
    denormalize: Should the annotations be stored in image coordinates?
  """
  if task_data != None:
    assert 'tasks' in task_data,  "Failed to find `tasks` in task_data object."
    task_ids = list(set([task['id'] for task in task_data['tasks']]))
    task_results = list(db.bbox_task_result.find({'task_id' : {"$in" : task_ids}}, projection={'_id' : False}))
  else:
    task_results = list(db.bbox_task_result.find(projection={'_id' : False}))

  if denormalize:
    for task_result in task_results:
      for image_result in task_result['results']:
        image = image_result['image']
        width = image['width']
        height = image['height']
        for anno in image_result['annotations']:
          x, y, w, h = anno['bbox']
          anno['bbox'] = [x * width, y * height, w * width, h * height]

  return task_results