Load data from OpenCV.However, the following error occurred when compressing the image to size 28x28.
Error Contents
OpenCV Error: Assertion failed(ssize.area()>0) in resize, file/build/build/opencv-2.4.8+dfsg1/imgproc/src/imgwarp.cpp, line 1824
Traceback (most recent call last):
File "train.py", line 136, in<module>
img = cv2.resize(img, (28,28))
cv2.error: /build/build/opencv-2.4.8+dfsg1/imgproc/src/imgwarp.cpp, line 1824:
error:(-215)size.area()>0 in function resize
code (excerpts only near errors due to long sentences)
conding:utf-8
import cv2
(omitted)
if__name__=='__main__':
# open a file
f=open(FLAGS.train, 'r')#train.txt
train_image=[ ]
train_label = [ ]
for line inf:
line = line.rstrip()
l=line.split()
img = cv2.imread(l[0])
**img=cv2.resize(img, (28,28))**←Where the error occurred
train_image.append(img.flatten().astype(np.float32)/255.0)
tmp = np.zeros (NUM_CLASSES)
tmp[int(l[1])] = 1
train_label.append(tmp)
train_image=np.asarray(train_image)
train_label=np.asarray(train_label)
train_len=len(train_image)
f.close()
I think there is a possibility that the data could not be delivered on the way.
What are the possible causes?
Does anyone know?
Thank you for your cooperation.
Development Environment
Ubuntu 14.0.4 LTS
Python 2.7.6
OpenCV 2.4.8
Error Message
cv2.error:/build/build/opencv-2.4.8+dfsg1/imgproc/src/imgwarp.cpp, line 1824:
error:(-215)size.area()>0 in function resize
Therefore, if you check the source of OpenCV2.4.9 you have,
CV_Assert(ssize.area()>0);
appears to have failed.ssize is the size of the input image img,
ssize.area() is its area, so imread() failed img
The size of is likely to be 0..
imread() does not report an error even if it fails, and
image of size 0
It's just a return, so imread() returned it (not only in this case)
Make sure the image size is not zero.
The reason why imread() fails is because the image file is open
There are some things that can't be done, such as incorrect mode designation, but in this case
I think it's an open failure. l[0] is the expected value
Is that right?
I don't know because I've never used Python, but
(Like C/C++) Python can also use errno, so
If you look into this, you will find out why it failed to open.
errno —Standard errno system symbols
http://docs.python.jp/2/library/errno.html
© 2024 OneMinuteCode. All rights reserved.