I have been working on this image classification(watermark detection) assignment I am trying to load a folder of images
from keras.preprocessing.image import load_img
import cv2
import matplotlib.pyplot as plt
DATADIR = 'F:\IMP.DATA\Task\Watermark_test_data'
CATEGORIES=['Watermark','No Watermark']
for category in CATEGORIES:
path= os.path.join(DATADIR,category)#path to test folder
for img in os.listdir(path):
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
plt.show(img_array)
break
break
img = load_img('F:/IMP.DATA/Task/Watermark_test_data/Watermark/1.jpg')
print(type(img))
print(img.format)
print(img.mode)
print(img.size)
img.show()
import numpy as np
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense,Dropout,Flatten
from keras.layers.convolutional import Conv2D,MaxPooling2D
from keras.utils import np_utils
from keras import backend as K
import os
import cv2
DATADIR = 'F:\IMP.DATA\Task\Watermark_test_data'
CATEGORIES=['Watermark','No Watermark']
for category in CATEGORIES:
path= os.path.join(DATADIR,category)#path to test folder
for img in os.listdir(path):
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
plt.show(img_array)
break
break
I have been using cv2 and load_img to load the image but in both the cases I get error in matplotlib plt.imshow (function) This is the error that I get
File "<ipython-input-51-2b07cb64d5a1>", line 11
plt.imshow(img_array,cmap="gray")
^
SyntaxError: invalid syntax
I can't see anything wrong in the syntax
The SyntaxError
is caused by a missing closing parenthesis in this line:
img_array = cv2.imread(os.path.dirname(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
Add )
after os.path.dirname(os.path.join(path,img)
to solve it.