a_image_path = os.path.join(im_dir, a_subdir, a_image_name) print(a_image_path) a_image = cv2.imread(a_image_path) #-----count the number of images---- idx += 1 if idx % 100 == 0: print(idx, "images done") #---------------------------------- neg_num = 0 while neg_num < 100: a_image_copy = a_image.copy() bboxes_copy = bboxes.copy() select_angle = np.random.choice(angle_vecs) a_image_copy, bboxes_copy = rotate_images(a_image_copy, bboxes_copy, select_angle) height, width, channel = a_image_copy.shape size = npr.randint(40, min(width, height) / 2) nx = npr.randint(0, width - size) ny = npr.randint(0, height - size) crop_box = np.array([nx, ny, nx + size, ny + size]) Iou = IoU(crop_box, bboxes_copy) cropped_im = a_image_copy[ny:ny + size, nx:nx + size, :].copy() resized_im = cv2.resize(cropped_im, (IMAGE_SIZE, IMAGE_SIZE), interpolation=cv2.INTER_LINEAR) if np.max(Iou) < 0.3: # Iou with all gts must below 0.3
print(idx, "images done") #---------------------------------- #if DEBUG: # for a_box in bboxes: # x1, y1, w, h = a_box # x2 = x1 + w - 1 # y2 = y1 + h - 1 # x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) # cv2.rectangle(a_image, (x1, y1), (x2, y2), (0, 255, 0), 1) # # a_target_image_path = os.path.join(target_image_dir, a_image_name) # cv2.imwrite(a_target_image_path, a_image) select_angle = np.random.choice(angle_vecs) a_image, bboxes = rotate_images(a_image, bboxes, select_angle) select_angle = 0 height, width, channel = a_image.shape if DEBUG: a_image_copy = a_image.copy() for a_box in bboxes: x1, y1, x2, y2 = a_box x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) cv2.rectangle(a_image_copy, (x1, y1), (x2, y2), (0, 255, 0), 1) a_target_image_path = os.path.join(target_image_dir, a_image_name) cv2.imwrite(a_target_image_path, a_image_copy) if select_angle in face_up: #----faceing up or down face_up_down_label = 1 elif select_angle in face_down:
plt.subplot(222) plt.title('label') io.imshow(label) plt.subplot(223) plt.title('invert') io.imshow(img_tf) plt.subplot(224) plt.title('invert') io.imshow(label_tf) if 0: ix = 367 angle = 270 img = X_train[ix] label = np.squeeze(Y_train[ix]) X_rot, Y_rot = rotate_images(X_train, Y_train, angle) img_tf = X_rot[ix] label_tf = np.squeeze(Y_rot[ix]) plt.figure(figsize=(8, 8)) plt.subplot(221) plt.title('image') io.imshow(img) plt.subplot(222) plt.title('label') io.imshow(label) plt.subplot(223) plt.title('rotate') io.imshow(img_tf) plt.subplot(224) plt.title('rotate') io.imshow(label_tf)