import cv2
file_path = '/Users/guojun/Desktop/cute.jpeg'
# 讀取圖片
retval = cv2.imread(file_path, cv2.IMREAD_GRAYSCALE)
# 創建顯示的視窗名稱
cv2.namedWindow('cute')
# 在視窗上顯示圖片
cv2.imshow('cute', retval)
# 等待按鍵,0表示無限等待
cv2.waitKey(0)
# 參考一個不存在的視窗來顯示影像也是ok的
cv2.imshow('winname',retval)
# cv2.waitKey(0)
# 等待鍵盤出發的時間,單位是ms,當是負數或0時,表示無限等待
result = cv2.waitKey(0)
# 銷毀指定的視窗
cv2.destroyWindow('winname')
# 銷毀所有的顯示視窗
cv2.destroyAllWindows()
# 保存影像,回傳值為true或false
result_new = cv2.imwrite(file_path.split('.')[0]+'01.jpeg',retval)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/292145.html
標籤:其他
