i new python , opencv world. trying read , show image error:
error: d:\build\opencv\opencv-3.1.0\modules\highgui\src\window.cpp:289: error: (-215) size.width>0 && size.height>0 in function cv::imshow
i have created module named test.py. in module, tried read image "car.png" in system path "c:\cv\images" , show below:
import cv2; import sys; sys.path.append('c:\\cv\\images'); im = cv2.imread('car.png'); cv2.imshow('car figure',im); cv2.waitkey(0);
when debug code, can see im variable never initialized why error code. however, when type sys.path in interpreter shows path added many times tried run module. , when copy/paste module contents directly in interpreter, code works fine , image appears.
it seems inside module, sys.path not taken consideration , python unable read image.
any idea if normal behavior, or should inside module let interpreter read sys.path contents?
what makes imagine sys.path
settings affect directories read files? it's purely used locate python modules import. answer question, behaviour seeing normal , expected. if have directory in dir
, filename in filename
file should opening be
os.path.join(dir, filename)
so shoudl try
im = cv2.imread(os.path.join(dir, filename))
Comments
Post a Comment