1.读取、显示、存储图像
- cv2.imread()
- cv2.imshow()
- cv2.imwrite()
def read_show_save_img(self, outfile):
img = cv2.imread(self.infile, 0)
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image', img)
k = cv2.waitKey(0)
if k == 27:
cv2.destroyWindow('image')
cv2.destroyAllWindows()
elif k == ord('s'):
cv2.imwrite(outfile, img)
cv2.destroyAllWindows()
2.使用matplotlib显示图像
显示灰度图像
def show_gray_img_in_plt(self,img):
img = cv2.imread(self.infile, 0)
plt.imshow(img, cmap='gray', interpolation='bicubic')
plt.show()
显示彩色图像
def show_color_img_in_plt(self,img):
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img2)
plt.xticks([]), plt.yticks([])
plt.title('RGB')
plt.show()