From 3ed8e3918b71fd7580b673510c6e76f60e44d903 Mon Sep 17 00:00:00 2001 From: Mahmoud Ahmed Ali <mahmoudali2929@gmail.com> Date: Tue, 14 Feb 2023 17:59:23 +0000 Subject: [PATCH] Add resize file --- resize.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 resize.py diff --git a/resize.py b/resize.py new file mode 100644 index 0000000..7060013 --- /dev/null +++ b/resize.py @@ -0,0 +1,64 @@ +from matplotlib import image +import matplotlib.pyplot as plt +import cv2 +import numpy as np + + +if __name__ == '__main__': + + choice = "low" + + if choice == 'high': + camera = np.matrix([[1386.4138492513919, 0.0, 960.5], + [0.0, 1386.4138492513919, 540.5], + [0.0, 0.0, 1.0]]) + else: + camera = np.matrix([[1086.5054444841007, 0.0, 640.5], + [0.0, 1086.5054444841007, 360.5], + [0.0, 0.0, 1.0]]) + + # resize image to 640*480 + # The original size is 1280*720 + # (640/1280 = 0.5), (480/720 = 2/3) + trans = np.matrix([[0.5, 0.0, 0.0], + [0.0, (2 / 3), 0.0], + [0.0, 0.0, 1.0]]) + + new_camera = trans @ camera + + dataset_name = f"GUIMOD_{choice}" + new_size = (640, 480) + + for i in range(4995): + rgb = cv2.resize(cv2.imread(f"{dataset_name}/RGB/{i}.png"), new_size) + cv2.imwrite(f"rgb/{i}.png", rgb) + + mask = cv2.resize(cv2.imread(f"{dataset_name}/Mask/{i}.png"), new_size) + cv2.imwrite(f"mask/{i}.png", mask*255) + + depth = cv2.resize(cv2.imread(f"{dataset_name}/Depth/{i}.tiff"), new_size) + + banana_mask = cv2.resize(cv2.imread(f"{dataset_name}/Instance_Mask/Banana/{i}.png"), new_size) + cv2.imwrite(f"banana_mask/{i}.png", banana_mask*255) + + orange_mask = cv2.resize(cv2.imread(f"{dataset_name}/Instance_Mask/Orange/{i}.png"), new_size) + cv2.imwrite(f"orange_mask/{i}.png", orange_mask*255) + + Pear_mask = cv2.resize(cv2.imread(f"{dataset_name}/Instance_Mask/Pear/{i}.png"), new_size) + cv2.imwrite(f"pear_mask/{i}.png", Pear_mask*255) + + + print("Done") + + # Check 2d bbox to resize it + + # dataset_name = f"GUIMOD_low" + # new_size = (640, 480) + # + # img = cv2.resize(image.imread(f"{dataset_name}/RGB/0.png"), new_size) + # lis = [7.960000000000000000e+02, 1.980000000000000000e+02, 1.052000000000000000e+03, 3.560000000000000000e+02] + # cv2.rectangle(img, (int(lis[0] * 0.5), int(lis[1] * (2 / 3))), (int(lis[2] * 0.5), int(lis[3] * (2 / 3))), + # (255, 0, 0), 2) + # + # plt.imshow(img) + # plt.show() -- GitLab