cv2.imread fails in script, not on command line
cv2.imread("some.jpg")
fails to read many different jpgs. I have checked a million different things:
3.4.3
and 3.1.0
. img/filename
exists with print(os.path.exists(filename)) # prints True
filename = random.choice(filename_list)
print("reading:", filename) # prints correct/verified jpg paths
sleep(.5)
img = cv2.imread(filename)
sleep(.3)
print(img) # none
read_image = cv2.resize(img, (IMAGE_WIDTH, IMAGE_HEIGHT), 3)
img
is none and the resize line fails with: OpenCV Error: Assertion failed (ssize.area() > 0) in resize, file /home/user/opencv/modules/imgproc/src/imgwarp.cpp, line 3229
This is Ubuntu 15.1 if it matters. Any thoughts on what could be causing this?
Yes, I know this question exists elsewhere. The existing answers have not helped me. I have quadruple checked everything. There seems to be something else going on.
The weirdest part is that cv2 reads the image just fine from the command line, with the same exact python and cv2 versions .
EDIT: this is a script, so I'm just doing python3 train.py
.
The script might be executed as a different user, with different privileges or at a different location than executing the code on the command line.
os.path.isfile
import cv2
img=cv2.imread("image.jpg")
cv2.imshow('Test',img)
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()
链接地址: http://www.djcxy.com/p/54722.html
上一篇: 检索python模块路径