如何使用 OpenCV 將影像寫入檔案?
在本程式中,我們將使用 OpenCV 將影像或圖片寫入檔案。
演算法
Step 1: Import cv2 Step 2: Read the image using opencv.imread() Step 3: Save the image using opencv.imwrite(filename, image)
示例程式碼
import cv2 import os image = cv2.imread('testimage.jpg') directory = r'C:\Users\prasa\Desktop' os.chdir(directory) cv2.imwrite('CAMERAMAN.jpg', image)
輸出
This program will save the image in the directory as same as the original image directory
說明
確保已經設定了適當的目錄,以便程式可以無錯誤地執行。
廣告