Reading in images, typeError: mat is not numpy nor scalar
So as part of a larger project here I've got this function meant to iterate through a directory of images and then perform some operations on them, mainly the function imageToPoints which is currently commented out for testing purposes but which basically runs a findContour, extracts the points and appends them to a list.
So as it currently stands the code is meant to read in one image at a time, print its name (which it does) then display the image (which it doesn't) suggesting the image isn't being read correctly. I figure I need to include cv.imread somehow but not sure exactly how.
def imagesToList():
# Iterates through directory and processes each image into array
for img in os.listdir(DIRECTORY + 'TestPhotos/'):
# Filters out any rogue files (e.g. hidden)
if img.endswith(".png"):
camNum, imgNum = os.path.splitext(img)[0].split('img')
# print 'Camera is ', camNum
# print 'Image is ', imgNum
# Correction of values will be different for cams 1 & 2
if camNum == 1:
# Correction values here
zVal = imgNum*numMoves
#imageToPoints(img)
print img
cv.imshow('image',img)
else: #camNum == 2:
# Correction values here
zVal = imgNum*numMoves
#imageToPoints(img)
print img
cv.imshow('image',img)
#else: print '''not of format [x]img[y]'''
Returns:
2img1.png
Traceback (most recent call last):
File "I2LTEST5.py", line 81, in <module>
imagesToList()
File "I2LTEST5.py", line 76, in imagesToList
cv.imshow('image',img)
TypeError: mat is not a numpy array, neither a scalar
Which suggests to me that the image isn't being read in correctly.
Many thanks for your help and if you're willing to help a university student finish his honours project then your help at my GitHub would be really appreciated!