cv2.imwrite(filename, img) 修改为 cv2.imencode('.jpg', img)[1].tofile(filename) cv2.imread(filename, cv2.IMREAD_GRAYSCALE) 修改为 cv2.imdecode(np.fromfile(filename, dtype=np.uint8), cv2.IMREAD_GRAYSCALE)