用SVM+HOG识别图片出现错误: error: (-215:Assertion failed) dims <= 2 && step[0] > 0 in function ‘cv::Mat::locateROI’
错误提示:
error Traceback (most recent call last)
in
17 fileName = ‘Po/z’+str(i+1)+’.jpg’
18 img = cv2.imread(fileName)
—> 19 hist = hog.compute(img,(8,8))
20 for j in range(0,featureNum):
21 featureArray[i,j] = hist[j]
error: OpenCV(3.4.2) C:\Miniconda3\conda-bld\opencv-suite_1534379934306\work\modules\core\src\matrix.cpp:755: error: (-215:Assertion failed) dims <= 2 && step[0] > 0 in function ‘cv::Mat::locateROI’
错误原因:图片的名称错误。
代码:
import cv2
import numpy as np
import matplotlib.pyplot as plt
PosNum = 820
NegNum = 1931
winSize = (64,128)
blockSize = (16,16)
blockStride = (8,8)
cellSize = (8,8)
nBin = 9
hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nBin)
svm = cv2.ml.SVM_create()
featureNum = int(((128-16)/8+1)*((64-16)/8+1)*4*</