# -*- coding: utf-8 -*-
import cv2
img = cv2.imread('1.jpg')
#Python: cv2.imread(filename[, flags]) → retva 技术手册显示的函数原型,
# imread 表示图片读入 其函数含义为 image read ===>imread
# 其参数为 第一个为图片名 第二个为参数可选 具体含义参考手册
# Parameters:
# filename – Name of file to be loaded.
# flags –
# Flags specifying the color type of a loaded image:
# CV_LOAD_IMAGE_ANYDEPTH - If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
# CV_LOAD_IMAGE_COLOR - If set, always convert image to the color one
# CV_LOAD_IMAGE_GRAYSCALE - If set, always convert image to the grayscale one
# >0 Return a 3-channel color image.
# Note In the current implementation the alpha channel, if any, is stripped from the output image. Use negative value if you need the alpha channel.
# =0 Return a grayscale image.
# <0 Return the loaded image as is (with alpha channel).
print(img.shape)
#图像矩阵的shape属性表示图像的大小,shape会返回tuple元组,
# 第一个元素表示矩阵行数,第二个元组表示矩阵列数,第三个元素是3,表示像素值由光的三原色组成
print(img.size) #返回图像的大小,size的具体值为shape三个元素的乘积
print(img.dtype) #数组元素的类型通过dtype属性获得
print(img) # 打印图片矩阵 数组对象即矩阵对象
cv2.imshow('result',img)
# Python: cv2.imshow(winname, mat) → None
# imshow 表示图片显示 其函数含义为 image show ===>imshow
# 其参数为 第一个为窗口名 第二个为参数可选 具体含义参考手册
# Parameters:
# winname – Name of the window.
# image – Image to be shown.
# The function imshow displays an image in the specified window. If the window was created with the CV_WINDOW_AUTOSIZE flag, the image is shown with its original size, however it is still limited by the screen resolution. Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its depth:
# If the image is 8-bit unsigned, it is displayed as is.
# If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the value range [0,255*256] is mapped to [0,255].
# If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].
# If the window was not created before this function, it is assumed creating a window with CV_WINDOW_AUTOSIZE.
k=cv2.waitKey(0)&0xff
print k
#等待按键按下,很类似单片机的按键等待操作;在手册中没有找到。。。。
if k==27: #27==ESC
cv2.destroyAllWindows()#销毁窗口
elif k==ord('s'):
cv2.imwrite('mypicture.png',img)##保存新的名字图片
cv2.destroyAllWindows()
# Parameters:
# filename – Name of the file.
# image – Image to be saved.
# params –
# Format-specific save parameters encoded as pairs paramId_1, paramValue_1, paramId_2, paramValue_2, ... . The following parameters are currently supported:
# For JPEG, it can be a quality ( CV_IMWRITE_JPEG_QUALITY ) from 0 to 100 (the higher is the better). Default value is 95.
# For PNG, it can be the compression level ( CV_IMWRITE_PNG_COMPRESSION ) from 0 to 9. A higher value means a smaller size and longer compression time. Default value is 3.
# For PPM, PGM, or PBM, it can be a binary format flag ( CV_IMWRITE_PXM_BINARY ), 0 or 1. Default value is 1.
原图片
显示图片
大部分参考函数参考手册 https://docs.opencv.org/2.4/modules/refman.html