将AxeImage直方图转换为阵列直方图

2024-04-27 21:28:08 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好,下面是我的代码

import cv2
import numpy as np
import PIL
from matplotlib import pyplot

img1 = cv2.imread('D:/MyProject/SeniorProject/Mushroom Pictures/train/Class A/IMG_9604.jpg')
img2 = cv2.imread('D:/MyProject/SeniorProject/Mushroom Pictures/train/Class A/IMG_9605.jpg')

img1_hsv = cv2.cvtColor(img1,cv2.COLOR_BGR2HSV)
img2_hsv = cv2.cvtColor(img2,cv2.COLOR_BGR2HSV)

h_bins = 18
s_bins = 32
histSize = [h_bins, s_bins]

h_ranges = [0,180]
s_ranges = [0,256]
ranges = h_ranges + s_ranges

channels = [0,1]

hist1c = cv2.calcHist([img1_hsv],channels,None,histSize,ranges,accumulate=False)
hist2c = cv2.calcHist([img2_hsv],[0],None,[180],[0,180],accumulate=False)
pyplot.imshow(hist1c,interpolation = 'nearest')
pyplot.show()

我得到了作为AxeImage的hs直方图,但我想转换为数组以应用于机器学习模型训练输入。你能帮我吗。 为什么我没有使用hist1c和hist2c是模型的输入,因为它不是单独的H-s,每个直径只保存在H箱中。 非常感谢:) 大的


Tags: importmyprojecttraincv2hsvimg1img2ranges