In a book, I saw the following code to load images from a directory:
1.image = cv2.imread(imagePath) 2.image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 3.image = cv2.resize(image, (28,28)) 4.image = img_to_array(image) 5.data.append(image)
It converts image to a numpys array in BGR format
It converts PIL instance to numpy array, but in this case image will stay in BGR format as the image is loaded by cv2.
What is the use of img_to_array() (from keras.preprocessing.image module) after cv2.imread(), as it is already in numpy array.
To double check, I displayed images before and after applying img_to_array() using cv2.imshow().
BEFORE applying img_to_array()
AFTER applying img_to_array()###
But, if I try to save the images using cv2.imwrite into a file, they both are saved as normal (ie. like the first image). Why is this happening?