0

Just a beginner to python.. I'm trying to create array of images.

import cv2
import os
import numpy as np

PATH = os.getcwd()
data_path = PATH + '/data1'
data_path_folder = os.listdir(data_path)

X_data = []

for image in data_path:
   img = cv2.imread(data_path + "/" +image, cv2.IMREAD_COLOR)
   img_resize = cv2.resize(img,(128,128))
   X_data.append(img_resize)

img_data = np.array(X_data)
img_data = img_data.astype('float32')
img_data /=255
print(img_data.shape)

ERROR cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4044: error: (-215) ssize.width > 0 && ssize.height > 0 in function cv::resize

5
  • The error is telling you that your img is invalid, either it's duff or it doesn't have a valid size. Commented Jan 23, 2018 at 15:04
  • I've tried changing images, but still showing the same error. Can you tell solution for it. Commented Jan 23, 2018 at 15:10
  • Your error here is that you're failing to load the image, you need to debug that first Commented Jan 23, 2018 at 15:15
  • The result of os.listdir() contains the paths ., .. A similar question: stackoverflow.com/questions/48001890/why-cant-i-access-images/… Commented Jan 23, 2018 at 15:34
  • Solved! i was messing with the directory path. But now i'm using glob module. Much easier..Thanks everyone...! Commented Jan 23, 2018 at 17:34

1 Answer 1

0

It seems a tiny error.... error msg says there are invalid input for resize.

I think you have to get correct image file name from correct list.

import cv2
import os
import numpy as np

PATH = os.getcwd()
data_path = PATH + '/data1'
data_path_folder = os.listdir(data_path)

X_data = []

for image in data_path_folder:  # ADD '_folder'
   img = cv2.imread(data_path + "/" +image, cv2.IMREAD_COLOR)
   img_resize = cv2.resize(img,(128,128))
   X_data.append(img_resize)

img_data = np.array(X_data)
img_data = img_data.astype('float32')
img_data /=255
print(img_data.shape)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.