文章目录
opencv 将加载的图象进行灰度化处理
代码语言:javascript
复制# -*- coding:utf-8 -*-
# /usr/bin/python
'''
Date:2019-05-08--10:07
File:img2gray.py
Describe:将加载的图象进行灰度化处理
'''
print (__doc__)
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
def read_img(path):
# Load an color image in grayscale
img = cv.imread(path, 0)
return img
def show_img(img):
# matplot plt show img
plt.imshow(img, cmap='gray', interpolation='bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
def show_Digit(vector):
# 重新变形
img = vector.reshape((8, 8))
plt.imshow(img, cmap='gray')
plt.show()
def img2vect(img):
# 将灰度图变为向量
# 变换为 8×8
img = cv.resize(img, (8, 8), interpolation=cv.INTER_LINEAR