code: def annotations_rectangle(
      points, label, image_num, object_num, label_to_num
  ):
      annotation = {}
      seg_points = np.asarray(points).copy()
      seg_points[1, :] = np.asarray(points)[2, :]
      seg_points[2, :] = np.asarray(points)[1, :]
      annotation["segmentation"] = [list(seg_points.flatten())]
      annotation["iscrowd"] = 0
      annotation["image_id"] = image_num + 1
      annotation["bbox"] = list(
          map(
              float,
              [
                  points[0][0],
                  points[0][1],
                  points[1][0] - points[0][0],
                  points[1][1] - points[0][1],
              ],
          )
      )
      annotation["area"] = annotation["bbox"][2] * annotation["bbox"][3]
      annotation["category_id"] = label_to_num[label]
      annotation["id"] = object_num + 1
      return annotation
  
imports: import argparse
  import glob
  import json
  import os
  import os.path
  import shutil
  import xml.etree.ElementTree
  import numpy
  import PIL.ImageDraw
  from tqdm import tqdm
  import cv2
label_desc: Use image node_id 4 for calling a global function with example usage: annotations_rectangle(points, label, image_num, object_num, label_to_num) and returns: annotation