0

python數據增強問題

def plotImages(images_arr):
fig, axes = plt.subplots(1, 10, figsize=(20,20))
axes = axes.flatten()
for img, ax in zip( images_arr, axes):
ax.imshow(img)
ax.axis("off")
plt.tight_layout()
plt.show()

data_augmentation = True
datagen = ImageDataGenerator(

``````    rotation_range=10, #randomly rotate images in the range(degrees, 0 to 180)
width_shift_range=0.2, #randomly shift images horizontally (fraction of total width)
height_shift_range=0.2, #randomly shift images vertically (fraction of total height)
horizontal_flip=True, #randomly flip images

shear_range=0.15,
)
``````

chosen_image= random.choice(os.listdir(r"C:\Users\COSH.spyder-py3\train"))

image_path=r"C:\Users\COSH.spyder-py3\train/"+chosen_image
assert os.path.isfile(image_path)
print(plt.imshow(image[0]))
aug_iter=datagen.flow(image)
aug_images=[next(aug_iter)[0].astype('float32')for i in range(10)]

for i in range(10):
aug_images[i] = aug_images[i]*255
cv2.imwrite(r"C:\Users\COSH.spyder-py3\train\aug/test"+str(i)+".png",aug_images[i])

``````想請問各位大大 我存的圖片都會變GRB的顏色

``````

1 個回答

3
hokou
iT邦新手 4 級 ‧ 2021-03-13 22:14:23

``````RGB -> BGR
img_bgr = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)

BGR->RGB
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
``````