Ask Your Question
0

Can't input Support vectors to HogDescriptor (opencv/python)

asked 2018-05-24 14:11:29 -0600

POMOPO gravatar image

I want to input SVM model to cv2.HogDescriptor.

here is my code

svm = trainSVM() #load image and train cv2.ml.svm
rho, _, _ = svm.model.getDecisionFunction(0)
hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins,derivAperture,winSigma,histogramNormType,L2HysThreshold,gammaCorrection,nlevels)
SV = svm.model.getSupportVectors()

To input support vector to HogDescriptor, I used 3 ways.

hog.setSVMDetector(SV)

It returns error

cv2.error: C:\projects\opencv-python\opencv\modules\core\src\matrix.cpp:2558: error: (-215) d == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0) in function cv::_OutputArray::create

This post said that I must input -rho to end of the array

http://answers.opencv.org/question/16...

So I tried like this

SV2 = np.insert(SV, 64, h, axis = 1)
hog.setSVMDetector(SV2)

SV2 looks like 2 dimensions array SV2 looks like 2 dimensions array

and SV2 returns the same error

cv2.error: C:\projects\opencv-python\opencv\modules\core\src\matrix.cpp:2558: error: (-215) d == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0) in function cv::_OutputArray::create

so I make SV3 like below

SV3 = np.append(SV, -rho)
hog.setSVMDetector(SV3)

SV3 looks like 1 line array SV3

SV3 returns no error message, but it doesn't work. when I use SV3 at Linux, It returns just one line error message. image description

Maybe there is something wrong with Numpy array... But I don't know what's wrong. How can I solve this problem?

edit retag flag offensive close merge delete

Comments

why reinvent the train_hog app ? that already looks silly (sorry)

also, please show, what your trainHog() finction does, exactly. it is supposed to deliver a single supprt vector from a linear , regression svm, your output looks wrong.

berak gravatar imageberak ( 2018-05-24 14:19:47 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-05-24 15:35:39 -0600

POMOPO gravatar image

Wow! your feedback is very fast. Actually, I couldn't think about using C++ code in python. I guess I'm a real fool. (T . T) I'll try it from there.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-24 14:11:29 -0600

Seen: 460 times

Last updated: May 24 '18