python cv2教程;读图像;显示一个img;写一个图像

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python cv2教程;读图像;显示一个img;写一个图像相关的知识,希望对你有一定的参考价值。

# Read Image
import numpy as np
import cv2

# Load an color image in grayscale
img = cv2.imread('messi5.jpg',0)

#Display an Image: Use the function cv2.imshow() to display an image in a window. The window automatically fits to the image size
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
'''
cv2.waitKey() is a keyboard binding function. Its argument is the time in milliseconds. 
The function waits for specified milliseconds for any keyboard event. 
cv2.destroyAllWindows() simply destroys all the windows we created. 
If you want to destroy any specific window, use the function cv2.destroyWindow() 
where you pass the exact window name as the argument.
'''

# Write an image: Use the function cv2.imwrite() to save an image.
#First argument is the file name, second argument is the image you want to save.
cv2.imwrite('messigray.png',img)

以上是关于python cv2教程;读图像;显示一个img;写一个图像的主要内容,如果未能解决你的问题,请参考以下文章

cv2 imshow 有时会显示黑色图像

Python OpenCV 实现图像滤波

基于python的OpenCV图像1

python opencv:像素运算

AI基础python:openCV——图像处理

python+OpenCV 图像滤波