OpenCV SVM,TypeError:不支持样本数据类型= 17

时间:2018-06-13 22:26:55

标签: python svm opencv3.0

我是一名中级程序员,最近我在OpenCV上使用直方图梯度图(HOG)和SVM。不幸的是,无论我到目前为止做了什么,我都遇到了这种类型错误。我无法找到可以解决这个问题的答案。

我的代码是用python编写的:

import cv2  
import numpy as np  
import glob  

neg = glob.glob('...')  
pos = glob.glob('...')  
trainingImages = []  
trainingLabels = []  

for img in neg[0:30]:  
    image = cv2.imread(img)  
    trainingImages.append(image)  
    trainingLabels.append(0)  

for img in pos[0:30]:  
    image = cv2.imread(img)  
    trainingImages.append(image)  
    trainingLabels.append(1)  

winSize = (800,600)  
blockSize = (200,150)  
blockStride = (100,75)  
cellSize = (100,75)  
nbins = 9  
derivAperture = 1  
winSigma = -1.  
histogramNormType = 0  
L2HysThreshold = 0.2  
gammaCorrection = 1  
nlevels = 64  
useSignedGradients = False  

hog = cv2.HOGDescriptor(winSize, blockSize, 
    blockStride, cellSize, nbins, 
    derivAperture, winSigma, histogramNormType
    , L2HysThreshold, gammaCorrection, nlevels, 
    useSignedGradients)  

trainingData = []  
for img in trainingImages:  
    descriptor = hog.compute(img)  
    trainingData.append(descriptor)  

svm = cv2.ml.SVM_create()  

svm.setType(cv2.ml.SVM_C_SVC)  
svm.setKernel(cv2.ml.SVM_RBF)  
svm.setC(12.5)  
svm.setGamma(0.50625)  

svm.trainAuto(np.array(trainingData), cv2.ml.ROW_SAMPLE, np.array(trainingLabels))

svm.save("digits_svm_model.yml")

我一直在遇到问题 svm.trainAuto(np.array(trainingData),cv2.ml.ROW_SAMPLE,np.array(trainingLabels)) 我一直被告知' TypeError:样本数据类型= 17不被支持'

有人可以帮忙吗?提前谢谢。

0 个答案:

没有答案