说明:博主使用的是jupyter工具编写的代码,纯属个人爱好
使用的方法介绍
# 创建名为'img'的可调整窗口
cv2.namedWindow('img', cv2.WINDOW_NORMAL)
# 设置窗口大小为640x480像素
cv2.resizeWindow('img', 640, 480)
# 读取图像文件
cv2.imread('image_path')
# 将图像保存为PNG格式
cv2.imwrite('./123.png', img)
# 关闭所有OpenCV窗口
cv2.destroyAllWindows()
1、下边是完全版代码
当用户输入s的时候在目录下方保存一个名为123.png的一个图片
退出的时候使用输入q来进行推出
import cv2
#创建窗口
cv2.namedWindow('img',cv2.WINDOW_NORMAL)
cv2.resizeWindow('img',640,480)
#读取图片
img = cv2.imread('./cat.png')
while True:
cv2.imshow('img',img)
key = cv2.waitKey(0)
if key == ord('q'):
break
elif key == ord('s'):
cv2.imwrite('./123.png',img)
else:
print(key)
cv2.destroyAllWindows()