用Python和OpenCV提取颜色直方图特征

用OpenCV中自带的cv2.calHist()函数求图像的颜色直方图特征

import cv2  
import numpy 
  
image = cv2.imread("D:/lena.jpg", 0)  
hist = cv2.calcHist([image], [0], None, [256], [0.0,255.0])

上面程序是以灰度图的方式计算颜色直方图特征,cv2.calcHist()函数的参数

第一个参数[image],必须带[], 是读入后的图像

第二个参数[0],必须带[],指定通道,若为灰度图则为[0],若彩色图,则[0]、[1]、[2]分别对应于B、G、R通道

第三个参数是掩膜Mask,指定ROI区域,若对整张图像取特征,则置为None

第四个参数是bins的个数,必须带[]

第五个参数是像素值范围


来看一下hist的内容:

>>> hist
array([[  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  1.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  1.00000000e+00],
       [  2.00000000e+00],
       [  5.00000000e+00],
       [  8.00000000e+00],
       [  1.70000000e+01],
       [  2.40000000e+01],
       [  5.50000000e+01],
       [  8.30000000e+01],
       [  1.12000000e+02],
       [  1.60000000e+02],
       [  2.02000000e+02],
       [  2.81000000e+02],
       [  3.41000000e+02],
       [  4.20000000e+02],
       [  5.28000000e+02],
       [  6.11000000e+02],
       [  7.09000000e+02],
       [  8.85000000e+02],
       [  1.03200000e+03],
       [  1.28200000e+03],
       [  1.44100000e+03],
       [  1.61700000e+03],
       [  1.68600000e+03],
       [  1.90500000e+03],
       [  1.88700000e+03],
       [  2.00000000e+03],
       [  2.00000000e+03],
       [  2.07200000e+03],
       [  2.01000000e+03],
       [  2.02500000e+03],
       [  1.89100000e+03],
       [  1.88400000e+03],
       [  1.76200000e+03],
       [  1.71400000e+03],
       [  1.53300000e+03],
       [  1.44200000e+03],
       [  1.26100000e+03],
       [  1.26800000e+03],
       [  1.18500000e+03],
       [  1.09800000e+03],
       [  9.70000000e+02],
       [  9.78000000e+02],
       [  9.10000000e+02],
       [  8.83000000e+02],
       [  8.23000000e+02],
       [  8.02000000e+02],
       [  7.42000000e+02],
       [  8.03000000e+02],
       [  8.42000000e+02],
       [  8.16000000e+02],
       [  7.85000000e+02],
       [  8.78000000e+02],
       [  8.59000000e+02],
       [  8.70000000e+02],
       [  8.72000000e+02],
       [  8.67000000e+02],
       [  9.57000000e+02],
       [  8.88000000e+02],
       [  9.79000000e+02],
       [  9.06000000e+02],
       [  8.35000000e+02],
       [  9.76000000e+02],
       [  9.40000000e+02],
       [  9.53000000e+02],
       [  9.58000000e+02],
       [  9.96000000e+02],
       [  1.06100000e+03],
       [  1.15800000e+03],
       [  1.14400000e+03],
       [  1.16600000e+03],
       [  1.22200000e+03],
       [  1.25300000e+03],
       [  1.44600000e+03],
       [  1.46600000e+03],
       [  1.59400000e+03],
       [  1.85500000e+03],
       [  1.81000000e+03],
       [  1.93400000e+03],
       [  1.96400000e+03],
       [  1.89900000e+03],
       [  2.00200000e+03],
       [  1.87200000e+03],
       [  1.82300000e+03],
       [  1.68900000e+03],
       [  1.59800000e+03],
       [  1.53900000e+03],
       [  1.39800000e+03],
       [  1.44100000e+03],
       [  1.37500000e+03],
       [  1.33400000e+03],
       [  1.38900000e+03],
       [  1.37600000e+03],
       [  1.38000000e+03],
       [  1.41300000e+03],
       [  1.40200000e+03],
       [  1.45500000e+03],
       [  1.46400000e+03],
       [  1.62700000e+03],
       [  1.62600000e+03],
       [  1.60400000e+03],
       [  1.80800000e+03],
       [  1.82700000e+03],
       [  2.03400000e+03],
       [  2.09700000e+03],
       [  2.21300000e+03],
       [  2.35200000e+03],
       [  2.43300000e+03],
       [  2.36800000e+03],
       [  2.46700000e+03],
       [  2.30400000e+03],
       [  2.27600000e+03],
       [  2.05000000e+03],
       [  1.96000000e+03],
       [  1.91000000e+03],
       [  1.88900000e+03],
       [  1.92500000e+03],
       [  2.05800000e+03],
       [  2.04300000e+03],
       [  2.33100000e+03],
       [  2.30200000e+03],
       [  2.34000000e+03],
       [  2.39100000e+03],
       [  2.47500000e+03],
       [  2.43100000e+03],
       [  2.25300000e+03],
       [  2.27100000e+03],
       [  2.23300000e+03],
       [  2.19300000e+03],
       [  2.27900000e+03],
       [  2.30300000e+03],
       [  2.42600000e+03],
       [  2.67100000e+03],
       [  2.64700000e+03],
       [  2.71900000e+03],
       [  2.73300000e+03],
       [  2.58300000e+03],
       [  2.43700000e+03],
       [  2.25600000e+03],
       [  2.07600000e+03],
       [  1.91100000e+03],
       [  1.74400000e+03],
       [  1.64400000e+03],
       [  1.47100000e+03],
       [  1.43000000e+03],
       [  1.39500000e+03],
       [  1.28800000e+03],
       [  1.23000000e+03],
       [  1.19300000e+03],
       [  1.17000000e+03],
       [  1.24400000e+03],
       [  1.26800000e+03],
       [  1.22900000e+03],
       [  1.23700000e+03],
       [  1.26300000e+03],
       [  1.24200000e+03],
       [  1.16400000e+03],
       [  1.11500000e+03],
       [  1.03900000e+03],
       [  9.53000000e+02],
       [  8.19000000e+02],
       [  7.48000000e+02],
       [  6.62000000e+02],
       [  6.37000000e+02],
       [  6.41000000e+02],
       [  5.97000000e+02],
       [  6.63000000e+02],
       [  6.25000000e+02],
       [  7.11000000e+02],
       [  7.87000000e+02],
       [  7.77000000e+02],
       [  8.10000000e+02],
       [  8.73000000e+02],
       [  9.09000000e+02],
       [  9.61000000e+02],
       [  9.53000000e+02],
       [  8.37000000e+02],
       [  8.52000000e+02],
       [  8.67000000e+02],
       [  8.39000000e+02],
       [  9.10000000e+02],
       [  8.33000000e+02],
       [  9.02000000e+02],
       [  9.20000000e+02],
       [  9.46000000e+02],
       [  9.68000000e+02],
       [  1.01000000e+03],
       [  1.09300000e+03],
       [  1.08000000e+03],
       [  9.57000000e+02],
       [  9.67000000e+02],
       [  1.02200000e+03],
       [  8.74000000e+02],
       [  7.03000000e+02],
       [  5.66000000e+02],
       [  4.62000000e+02],
       [  3.97000000e+02],
       [  3.65000000e+02],
       [  3.35000000e+02],
       [  2.54000000e+02],
       [  2.07000000e+02],
       [  2.13000000e+02],
       [  1.76000000e+02],
       [  1.20000000e+02],
       [  1.06000000e+02],
       [  7.70000000e+01],
       [  6.50000000e+01],
       [  3.60000000e+01],
       [  3.50000000e+01],
       [  2.50000000e+01],
       [  1.80000000e+01],
       [  1.00000000e+01],
       [  9.00000000e+00],
       [  3.00000000e+00],
       [  4.00000000e+00],
       [  1.00000000e+00],
       [  2.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  1.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  1.00000000e+00],
       [  0.00000000e+00],
       [  1.00000000e+00],
       [  0.00000000e+00],
       [  1.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00],
       [  0.00000000e+00]], dtype=float32)
>>>


你可能感兴趣的:(python,提取,opencv,特征,颜色直方图)