I have a txt file with 46 entries that looks like this -
2020-05-24T10:57:12.743606#[0.0, 0.0, 0.0653934553265572, 0.0, 1.0, 0.0]
2020-05-24T10:57:12.806380#[0.0, 0.0, 0.0, 0.0, 1.0, 0.0]
2020-05-24T10:57:12.869022#[0.0, 0.0, 0.0, 0.0, 1.0, 0.0]
The first argument is a timestamp of the camera image taken. For each timestamp, there are 3 RGB images.
My goal is to concatenate them along the channel axis(axis = 2). The image dimension is 70x320x3. So the desired output is 46x70x320x9.
I would need to wait till all 3 images are recognised, then append them to a list and feed that to a numpy array. I'm failing as the output dimension I'm getting is 46x138(for 3 images from append)x70x320x3 46x138x70x320x3
before concate. Concatenation doesn't work when implemented with axis =2 or 3
From this how can I get 46x70x320x9
?
Code -
with open("train.txt", 'r') as f:
data = f.readlines()[:]
images = []
image_concat = []
labels = []
for row in data:
for camera in ['center', 'left', 'right']:
img_id, label = row.strip("\n").split("#")
img_path = os.path.join(IMG_PATH, '{}-{}.jpg'.format(camera, img_id))
image = cv2.imread(img_path)
images.append(image)
if camera == 'right':
image_concat.append(images)
X_data = np.array(image_concat)
print(X_data.shape)
Referred links -
Need help combining two 3 channel images into 6 channel image Python
numpy: concatenate two arrays along the 3rd dimension
numpy concatenate multiple arrays arrays
numpy concatenate over dimension
Please help. Any help will be appreciated. Thank you.