OpenCV不保存图像(imwrite)

时间:2018-02-14 14:06:23

标签: python-2.7 opencv

我正在更改尺寸并保存新图像

def ResizeImage(filepath, newFileName):
    image = cv2.imread(filepath)
    height, width = image.shape[:2]
    image2 = cv2.resize(image, (width/2, height/2), interpolation = cv2.INTER_AREA)
    filename = newFileName
    cv2.imwrite(filename,image2)
    return filename

当我尝试打开这个新文件时

def ShowImage(filepath):
    image = cv2.imread(filepath)
    if image is None:
        print "Cant Load Image"
    else:
        print "Showing {}".format(filepath)
        cv2.imshow("Image", image)
        cv2.waitKey(0)

它会打开旧文件,但不会打开新文件(未保存)

已经尝试将新图像保存为bmp,png,jpg,但没有工作

我从这里打电话给他们

if __name__ == '__main__':
    DirPath = ".\PythonScripts\QRReader"
    filename = "HD_qr_example.jpg"
    newfile = ResizeImage(DirPath+"\{}".format(filename),"thumbnail.jpg")
    ShowImage(DirPath+"\{}".format(filename))
    ShowImage(newfile)

仅在第二个ShowImage

上失败

0 个答案:

没有答案