내가 보려고 만든 블로그

OpenCV를 사용하여 이미지 읽기, 표시 및 쓰기(python) 본문

OpenCV/python

OpenCV를 사용하여 이미지 읽기, 표시 및 쓰기(python)

hjh1023 2024. 5. 27. 20:35
반응형

python -V

Python 3.10.12

사용함

 

readWrite.py

# import the cv2 library
import cv2
 
# The function cv2.imread() is used to read an image.
img_grayscale = cv2.imread('test.jpg',0)
 
# The function cv2.imshow() is used to display an image in a window.
cv2.imshow('graycsale image',img_grayscale)
 
# waitKey() waits for a key press to close the window and 0 specifies indefinite loop
cv2.waitKey(0)
 
# cv2.destroyAllWindows() simply destroys all the windows we created.
cv2.destroyAllWindows()
 
# The function cv2.imwrite() is used to write an image.
cv2.imwrite('grayscale.jpg',img_grayscale)

 

python3 readWrite.py

 

저장됨

 

반응형