我希望能够使用openCV Python自动化和过滤灰度和彩色图像。我已经尝试在彩色和灰度图像上运行直方图,以下是结果。
我可以不为每个文件创建直方图图表而自动化相同的过程吗?
尝试的代码:
import cv2
import numpy as np
import sys
img = cv2.imread(sys.argv[1])
h = np.zeros((300,256,3))
bins = np.arange(256).reshape(256,1)
color = [ (255,0,0),(0,255,0),(0,0,255) ]
for ch, col in enumerate(color):
hist_item = cv2.calcHist([img],[ch],None,[256],[0,256])
cv2.normalize(hist_item,hist_item,0,255,cv2.NORM_MINMAX)
hist=np.int32(np.around(hist_item))
pts = np.column_stack((bins,hist))
cv2.polylines(h,[pts],False,col)
h=np.flipud(h)
cv2.imshow('colorhist',h)
cv2.waitKey(0)
我可以不为每个文件创建直方图图表而自动化相同的过程吗?
height,width,channel = img.shape
现在程序可以运行。但是我得到了一个"IndexError"错误。 - jOSe