def show_image_with_boxes(img, objects_res, object_gt, calib, save_path, height_threshold=0): img2 = np.copy(img) for obj in objects_res: box3d_pts_2d, _ = compute_box_3d(obj, calib.P) color_tmp = tuple( [int(tmp * 255) for tmp in colors[obj.id % max_color]]) img2 = draw_projected_box3d(img2, box3d_pts_2d, color=color_tmp) text = 'ID: %d' % obj.id if box3d_pts_2d is not None: img2 = cv2.putText( img2, text, (int(box3d_pts_2d[4, 0]), int(box3d_pts_2d[4, 1]) - 8), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color=color_tmp) img = Image.fromarray(img2) img = img.resize((width, height)) img.save(save_path)
def show_image_with_boxes(self, img, objects_res, calib, save_path, height_threshold=0): img2 = np.copy(img) for obj in objects_res: #box3d_pts_2d = compute_box_3d(obj, calib.P, calib.V2C) box3d_pts_2d = compute_box_3d(obj, calib.P, calib.V2C) color_tmp = tuple( [int(tmp * 255) for tmp in colors[obj.id % max_color]]) #print("box3d_pts_2d", box3d_pts_2d) img2 = draw_projected_box3d(img2, box3d_pts_2d, color=color_tmp) text = 'ID: %d' % obj.id # + ', s: %.2f' % obj.score if box3d_pts_2d is not None: img2 = cv2.putText( img2, text, (int(box3d_pts_2d[4, 0]), int(box3d_pts_2d[4, 1]) - 8), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color=color_tmp) #img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB) #cv2.imwrite(save_path, img2) self.image_pub.publish(self.bridge.cv2_to_imgmsg(img2, "rgb8"))
filecontent = np.array([f.split() for f in open(file_path, 'r')]) alllabels = np.unique(filecontent[:, 2]) labels = ['Car', 'Pedestrian', 'Cyclist'] finalset = [x for x in alllabels if x not in labels] for val in finalset: filecontent = filecontent[filecontent[:, 2] != val, :] data = (Object3d(getstringfromarray(line[2:])) for line in filecontent[filecontent[:, 0] == '0', :]) calib = Calibration('/home/eshan/Pictures/calib.txt') velo = load_velo_scan('/home/eshan/Pictures/000009.bin', np.float32, n_vec=4)[:, 0:4] img2 = np.copy(img) show_lidar_with_boxes(velo, data, calib) for obj in data: print("here") box3d_pts_2d, _ = compute_box_3d(obj, calib.P) img2 = draw_projected_box3d(img2, box3d_pts_2d, color=(0, 0, 0)) text = 'gt ID: %d, Type: %s' % (0, obj.type) if box3d_pts_2d is not None: print("also") img2 = cv2.putText( img2, text, (int(box3d_pts_2d[4, 0]), int(box3d_pts_2d[4, 1]) - 8), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color=(0, 0, 0)) # img = Image.fromarray(img2) # img = img.resize((width, height)) cv2.imshow("image", img2) cv2.waitKey()
def show_image_with_boxes(img, velo, objects_res, objects_res_det, objects_res_raw, labeldata, object_gt, calib, save_path, height_threshold=0, show_lidar=True, save_image=False): img2 = np.copy(img) for obj in objects_res: box3d_pts_2d, _ = compute_box_3d(obj, calib.P) color_tmp = tuple( [int(tmp * 255) for tmp in colors[obj.id % max_color]]) img2 = draw_projected_box3d(img2, box3d_pts_2d, color=(0, 0, 255)) text = 'Tracked ID: %d, Type: %s' % (obj.id, obj.type) if box3d_pts_2d is not None: img2 = cv2.putText( img2, text, (int(box3d_pts_2d[4, 0]), int(box3d_pts_2d[4, 1]) - 8), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color=(0, 0, 255)) for obj in objects_res_det: box3d_pts_2d, _ = compute_box_3d(obj, calib.P) color_tmp = tuple( [int(tmp * 255) for tmp in colors[obj.id % max_color]]) img2 = draw_projected_box3d(img2, box3d_pts_2d, color=(0, 255, 0)) text = 'Detection ID: %d, Type: %s' % (obj.id, obj.type) if box3d_pts_2d is not None: img2 = cv2.putText( img2, text, (int(box3d_pts_2d[3, 0]), int(box3d_pts_2d[3, 1]) - 8), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color=(0, 255, 0)) import itertools labeldata, labeldata2 = itertools.tee(labeldata) for obj in labeldata: # print("here") box3d_pts_2d, _ = compute_box_3d(obj, calib.P) img2 = draw_projected_box3d(img2, box3d_pts_2d, color=(255, 0, 0)) text = 'GT, Type: %s' % (obj.type) if box3d_pts_2d is not None: # print("also") print(text) img2 = cv2.putText( img2, text, (int(box3d_pts_2d[4, 0]), int(box3d_pts_2d[4, 1]) - 8), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color=(255, 0, 0)) # for obj in objects_res_raw: # box3d_pts_2d, _ = compute_box_3d(obj, calib.P) # color_tmp = tuple([int(tmp * 255) # for tmp in colors[obj.id % max_color]]) # img2 = draw_projected_box3d(img2, box3d_pts_2d, color=(255,0,0)) # text = 'Estimate ID: %d' % obj.id # if box3d_pts_2d is not None: # img2 = cv2.putText(img2, text, (int(box3d_pts_2d[2, 0]), int( # box3d_pts_2d[2, 1]) - 8), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color=(255,0,0)) if show_lidar: show_lidar_with_boxes(velo, objects=labeldata2, calib=calib, objects_pred=objects_res) img = Image.fromarray(img2) img = img.resize((width, height)) cv2.imshow("Image", img2) cv2.waitKey() if save_image: print("Saving Image at", save_path) img.save(save_path) return img2