Skip to content
Snippets Groups Projects
Commit 3ed8e391 authored by Mahmoud Ahmed Ali's avatar Mahmoud Ahmed Ali
Browse files

Add resize file

parent 8e3536c6
No related branches found
No related tags found
No related merge requests found
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment