当前位置: 代码迷 >> 综合 >> Practical Python and OpenCV-使用opencv实现图片的加载,显示,保存
  详细解决方案

Practical Python and OpenCV-使用opencv实现图片的加载,显示,保存

热度:69   发布时间:2023-12-08 19:50:19.0

 cv2的三个方法

imread

imshow

imwrite

 
# Import the necessary packages
from __future__ import print_function
import argparse
import cv2# Construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
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[0]))
print("channels: {}".format(image.shape[2]))# Show the image and wait for a keypress
cv2.imshow("Image", image)
cv2.waitKey(0)# Save the image -- OpenCV handles converting filetypes
# automatically
cv2.imwrite("newimage.jpg", image)

运行结果如上,宽度350 高度243 ,3 channels RGB done!

同时该图片也被存为newimage