I want to read every images in a folder into one list and then greyscale every image. All the greyscale images should be in one list as well. Currently, I am able to read images to one list, but I am not able to put all the greyscale images into one list.
Here is my code:
import cv2
import numpy as np
from os import listdir
from os.path import isfile, join
mypath = 'jpl_thomas'
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath,f)) ]
images = np.empty(len(onlyfiles), dtype=object)
for n in range(0, len(onlyfiles)):
images[n] =cv2.imread(join(mypath,onlyfiles[n]))
frames = np.zeros(len(images))
for i in range(0, len(images)):
frames[i] = cv2.cvtColor(images[i],cv2.COLOR_BGR2GRAY)
The error i get is as the following:
File "main.python", line 21, in <module>
frames[i] = cv2.cvtColor(images[i],cv2.COLOR_BGR2GRAY)
cv2.error: /Users/jenkins/miniconda/1/x64/conda-bld/conda_1486588158526/work/opencv-3.1.0/modules/imgproc/src/color.cpp:7456:
error: (-215) scn == 3 || scn == 4 in function ipp_cvtColor
I tried to debug small parts.
frames[0] = cv2.cvtColor(images[0],cv2.COLOR_BGR2GRAY)
returns the right value. But if I use for loop, the error above occurs.