导入numpy模块
import numpy
img = cv2.imread(img_path) if not img: img = cv2.imdecode(numpy.fromfile(img_path, dtype=numpy.uint8), -1)
这样就解决了