使用工具Python3.5
使用库numpy ; opencv,
从图片导入到另存为
cv2.IMREAD_COLOR() :读入彩色图像
cv2.IMREAD_GRAYSCALE() :以灰度模式读入图像
cv2.waitKey()等待键盘输入,为毫秒级
cv2.destroyAllWindows() 可以删除我们建立的任何窗口
cv2.namedwindows('image',cv2.WINDOWS_NARMAL)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('messigray.png',img)
import cv2 as cv
import numpy as np
img = cv.imread('111.jpg',0)
cv.imshow('input_image',img)
k = cv.waitKey(0)
if(k == 27){
cv.destroyAllWindows() #wait for ESC key to exit
}else if( k == ord('s')){
cv.imwrite('22.jpg',img) #wait for s key to save and exit
cv.destroyAllWindows()
}
注释:如果是64位系统,需要将k = cv2.waitKey(0)改为k = cv2.waitKey(0)&0xFF@!!
import numpy as np
import cv2 as cv
from matpoltlib import pyplot as plt
img = cv.imread('11.jpg',0)
plt.imshow(img,cmap = 'gray',interpolation = 'bicubic')
plt.xticks([])
plt.yticks([]) #to hide tick values on X and Y axis
plt.show()