1 回答

TA貢獻1865條經驗 獲得超7個贊
你必須先閱讀圖像cv2.imread()然后 cv2.imwrite() 這是一個小例子
import
cv2
# read image as grey scale
grey_img=cv2.imread('/home/img/python.png',cv2.IMREAD_GRAYSCALE)
# save image
status=cv2.imwrite('/home/img/python_grey.png',grey_img)
print("Image written to file-system : ",status)
如果您沒有文件夾路徑,那么使用它 status=cv2.imwrite('python_grey.png',grey_img) 會將照片保存在您保存.py文件的默認文件夾中
如果你想在這里保存不同的圖像是代碼
import cv2
import time
# for number of images you need different names so set name automatically
name=str(time.time())+str(.png))
# read image as grey scale
grey_img=cv2.imread('/home/img/python.png',cv2.IMREAD_GRAYSCALE)
# save image
status=cv2.imwrite('%s'%name,grey_img)
print("Image written to file-system : ",status)
添加回答
舉報