文件的简单读取
img_path = os.path.join(os.getcwd(), 'yao.jpg')
# 简单粗暴一点的方法
image = cv2.imread(img_path)
cv2.imshow('demo', image)
cv2.waitKey()
# 来个稍微复杂点的
image = cv2.imread(filename=img_path)
# 定义一个显示框
cv2.namedWindow('input image', cv2.WINDOW_AUTOSIZE)
# 显示,step1 找窗口, step2 放文件
cv2.imshow('input image', image)
cv2.waitKey()
# 清除之前的窗口
cv2.destroyAllWindows()
def get_image_info(image):
print('type of image is : ', type(image))
print('shape of image is ; ', image.shape)
print('size of image is :', image.size)
print('dtype of image is', image.dtype)
return 0
# 我们在显示这个图像之前call 一下上面的api
get_image_info(image=my_image)
根据你所给的格式opencv 有自己的方法来保存
jpg 和 png 都有专属于自己的那一套,
# 保存一个灰度的
gray_it = cv2.cvtColor(images, cv2.COLOR_BGR2GRAY)
cv2.imwrite('d:/tf36/yao_g.png', gray_it)