text: import numpy as np
  import cv2
  colors = {
      'green': (0, 255, 0),
      'pink': (255, 0, 255),
      'blue': (0, 0, 255)
  }
  def get_calibration_cam_to_image(cab_f):
      for line in open(cab_f):
          if 'P2:' in line:
              cam_to_img = line.strip().split(' ')
              cam_to_img = np.asarray([float(number) for number in cam_to_img[1:]])
              cam_to_img = np.reshape(cam_to_img, (3, 4))
      return cam_to_img
  
  def plot_3d_bbox(img, label_info, cam_to_img, is_gt=True):
  #    print('current label info: ', label_info)
      alpha = label_info['alpha']
      # theta_ray = label_info['theta_ray']
      box_3d = []
      center = label_info['location']
      box_2d = label_info['box_2d']
      dims = label_info['dimension'] 
      
      
      cam_to_img = cam_to_img#label_info['calib']
  
      if is_gt:
          rot_y = label_info['rot_y']
      else:
          rot_y = alpha / 180 * np.pi + np.arctan(center[0] / center[2])
          # import pdb; pdb.set_trace()
  
      for i in [1, -1]:
          for j in [1, -1]:
              for k in [0, 1]:
                  point = np.copy(center)
                  point[0] = center[0] + i * dims[1] / 2 * np.cos(-rot_y + np.pi / 2) + (j * i) * dims[2] / 2 * np.cos(
                      -rot_y)
                  point[2] = center[2] + i * dims[1] / 2 * np.sin(-rot_y + np.pi / 2) + (j * i) * dims[2] / 2 * np.sin(
                      -rot_y)
                  point[1] = center[1] - k * dims[0]
                  
                  point = np.append(point, 1)
                  point = np.dot(cam_to_img, point)
                  point = point[:2] / point[2]
                  point = point.astype(np.int16)
                  box_3d.append(point)
      front_mark = []
      for i in range(4):
          point_1_ = box_3d[2 * i]
          point_2_ = box_3d[2 * i + 1]
          cv2.line(img, (point_1_[0], point_1_[1]), (point_2_[0], point_2_[1]), colors['pink'], 1)
          
  
  
      for i in range(8):
          point_1_ = box_3d[i]
          point_2_ = box_3d[(i + 2) % 8]
          cv2.line(img, (point_1_[0], point_1_[1]), (point_2_[0], point_2_[1]), colors['pink'], 1)
  
      return img
  
      
  def main():
      # img_file = 'dataset/KITTI/object/training/image_2/000008.png'
      # label_file = 'dataset/KITTI/object/training/label_2/000008.txt'
      # calib_file = 'dataset/KITTI/object/training/calib/000008.txt'
  
      
      img_file = 'dataset/KITTI/object/training/image_2/000008.png'
      label_file = 'train/detection_results_v1/data/000008.txt'
      calib_file = 'dataset/KITTI/object/training/calib/000008.txt'
  
      image = cv2.imread(img_file, cv2.COLOR_BGR2RGB)
      
      box_2d = ''
      with open(label_file, 'r') as f:
          label_info = dict()
          for l in f.readlines():
              l = l.strip().split(' ')
  
              # this angle need a preprocess
              label_info['alpha'] = float(l[3])
              label_info['box_2d'] = np.asarray(l[4:8], dtype=float)
              box_2d = label_info['box_2d']
              label_info['location'] = np.asarray(l[11: 14], dtype=float)
              label_info['dimension'] = np.asarray(l[8: 11], dtype=float)
              camp_to_img = get_calibration_cam_to_image(calib_file)
              label_info['rot_y'] = float(l[14])
              label_info['box'] = np.asarray(l[4: 7], dtype=float)
              
              
              image = plot_3d_bbox(image, label_info, camp_to_img)
  
      
      return image
      
  if __name__ == '__main__':
      img = main()
      cv2.imshow('cc', img)
      cv2.waitKey()