将下面文档存为load_display_save.py
#-*- coding:utf-8 -*-
from __future__ import print_function #1
import argparse #2
import cv2 #3
ap= argparse.ArgumentParser() #4
ap.add_argument("-i", "--image", required =True,
help= "Path to the image") #5
args = vars(ap.parse_args()) #6
image1= cv2.imread(args["image"]) #7
print("width: {}pixels".format(image1.shape[1])) #8
print("hight: {}pixels".format(image1.shape[0])) #9
print("channels: {}".format(image1.shape[2])) #10
cv2.imshow("恐龙啊", image1) #11
cv2.waitKey(0) #12
cv2.imwrite("恐龙图片.jpg", image1) #13
详细解释
#1:
引入future包,以便于我们使用print(),而不是print,这会让我们的程序在python2.7或者python3下都可以运行
#2:
引入argparse包,是为了在命令行中解析所输入的命令
#3