在本文中,我們將了解OpenCV 庫的haveImageWriter() 函數。
haveImageWriter()函數
有時我們需要在繼續操作之前檢測指定的圖像文件是否被正確寫入,在這種情況下我們可以使用OpenCV,它可以幫助我們處理圖像和視頻來識別對象。當openCV與haveImageWriter()函數等方法集成時。它可以幫助我們檢查指定的圖像是否可以成功編碼或寫入。以下是 hasImageWriter 函數的語法。
用法: cv.haveImageWriter(filename)
參數:
- 文件名:圖像的文件名。
返回:True,如果指定圖像寫入成功,否則返回False。
示例1:
我們將在代碼中使用以下圖像擴展名並檢查它是否可以正確讀取。任何擴展名為 jpg、png 和 jpeg 的圖像文件都將返回 True。
Python3
# Import the library OpenCV
import cv2
# Use haveImageWriter() function to check
# provided image file can be encoded or not
return_val = cv2.haveImageWriter("gfg.png")
# Print the returned value
print(return_val)
輸出:
True
示例2:
任何擴展名為 GIF 的圖像文件都將返回 False。
Python3
# Import the library OpenCV
import cv2
# Use haveImageWriter() function to check
# provided image file can be encoded or not
return_val = cv2.haveImageWriter("apple.gif")
# Print the returned value
print(return_val)
輸出:
False
示例3:
任何擴展名不是 jpg、png 和 jpeg 的圖像文件都將返回 False。
Python3
# Import the library OpenCV
import cv2
# Use haveImageWriter() function to check
# provided image file can be encoded or not
return_val = cv2.haveImageWriter("apple.mp4")
# Print the returned value
print(return_val)
輸出:
False
相關用法
- Python OpenCV haveImageReader()用法及代碼示例
- Python OpenCV cv2.circle()用法及代碼示例
- Python OpenCV cv2.blur()用法及代碼示例
- Python OpenCV cv2.ellipse()用法及代碼示例
- Python OpenCV cv2.cvtColor()用法及代碼示例
- Python OpenCV cv2.copyMakeBorder()用法及代碼示例
- Python OpenCV cv2.imread()用法及代碼示例
- Python OpenCV cv2.imshow()用法及代碼示例
- Python OpenCV cv2.imwrite()用法及代碼示例
- Python OpenCV cv2.putText()用法及代碼示例
- Python OpenCV cv2.rectangle()用法及代碼示例
- Python OpenCV cv2.arrowedLine()用法及代碼示例
- Python OpenCV cv2.erode()用法及代碼示例
- Python OpenCV cv2.line()用法及代碼示例
- Python OpenCV cv2.flip()用法及代碼示例
- Python OpenCV cv2.transpose()用法及代碼示例
- Python OpenCV cv2.rotate()用法及代碼示例
- Python OpenCV cv2.polylines()用法及代碼示例
- Python OpenCV Canny()用法及代碼示例
- Python OpenCV destroyAllWindows()用法及代碼示例
- Python OpenCV Filter2D()用法及代碼示例
- Python OpenCV getgaussiankernel()用法及代碼示例
- Python OpenCV getRotationMatrix2D()用法及代碼示例
- Python OpenCV getTrackbarPos()用法及代碼示例
- Python OpenCV imdecode()用法及代碼示例
注:本文由純淨天空篩選整理自vin8rai大神的英文原創作品 Python OpenCV – haveImageWriter() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。