Getting error in calculating hog features of multiple images and writing it in a text file

时间:2018-02-01 18:34:04

标签: python opencv computer-vision

I am trying to calculate HOG feature vectors of multiple images and writing in a text file column wise .But I ma getting this error: np.savetxt('hog.txt',out) File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 132 0, in savetxt "Expected 1D or 2D array, got %dD array instead" % X.ndim) ValueError: Expected 1D or 2D array, got 3D array instead

Here is my code:

import cv2
import numpy as np
winSize = (64,64)
blockSize = (16,16)
blockStride = (8,8)
cellSize = (8,8)
nbins = 9
derivAperture = 1
winSigma = 4.
histogramNormType = 0
L2HysThreshold = 2.0000000000000001e-01
gammaCorrection = 0
nlevels = 64
hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins,derivAperture,winSigma,
                        histogramNormType,L2HysThreshold,gammaCorrection,nlevels)
#compute(img[, winStride[, padding[, locations]]]) -> descriptors
winStride = (8,8)
padding = (8,8)
locations = ((10,20),)


out = []
for x in range(0,20):
    image = cv2.imread("{}.jpg".format(x),0)
    hist = hog.compute(image,winStride,padding,locations)
    #print (hist)
#print (len(hist))
#print (len(hist[0]))
    out.append(hist)
#   print ("***********")
np.savetxt('hog.txt',out)

0 个答案:

没有答案