image basics简单输入输出
使用命令行切到该代码目录,然后使用python load_display_save.py --image ../images/trex.png
命令运行。
注意,在切换盘符的时候要用cd /d D:\python\...
这个命令
最核心的几个函数片段:
# 读取文件
image = cv2.imread(args["image"])
# 图像显示
cv2.imshow("Image", image)
cv2.waitKey(0)
# 图像导出
cv2.imwrite("newimage.jpg", image)
完整代码
# USAGE
# python load_display_save.py --image ../images/trex.png
# Import the necessary packages
from __future__ import print_function
import argparse # 用来解析命令行的库
import cv2
# Construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
# 主要是去获取image在硬盘上的相对位置,存在一个dictionary中
ap.add_argument("-i", "--image", required = True,
help = "Path to the image")
args = vars(ap.parse_args())
# Load the image and show some basic information on it
image = cv2.imread(args["image"])
print("width: {} pixels".format(image.shape[1]))
print("height: {} pixels".format(image.shape[