#-*- encoding:utf-8 -*-
'''
python 绘制颜色直方图
'''
import cv2
import numpy as np
from matplotlib import pyplot as plt
def readImage():
#读取图片 B,G,R,返回一个ndarray类型
#cv2.IMREAD_COLOR # 以彩色模式读入 1
#cv2.IMREAD_GRAYSCALE # 以灰色模式读入 0
img = cv2.imread('../../data/home.jpg',cv2.IMREAD_COLOR)
#返回多维矩阵,#(384, 512, 3),
print type(img), img.shape, img.size, img.dtype
#ravel()展平n维矩阵的所有
print img.ravel(), len(img.ravel())
def cvt():
'''
经常用到的颜色转换BGR->Gray 和BGR->HSV
'''
# 读取图片 B,G,R,返回一个ndarray类型
img = cv2.imread('../../data/home.jpg')
#cv2.COLOR_BGR2GRAY;cv2.COLOR_BGR2HSV
# 彩色图像转灰度图像YUV(Y即为灰度图) Y = 0.299R + 0.587G + 0.114B
img1 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 彩色图像转灰度图像YUV(Y->亮度;U,V->色度)
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
print img1
print img2
cvt()