Ask Your Question
1

OpenCV+PYTHON: HOGDescriptor readALTModel(filename)

asked 2016-01-23 05:59:52 -0600

daniele2688 gravatar image

Hi, does anybody know if there is a way to use the function readALTModel(filename) in the HOGDescriptor class with python/opencv?

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-01-23 06:15:50 -0600

berak gravatar image

updated 2016-01-23 06:32:42 -0600

unfortunately, it's not wrapped into python yet.

if you're serious about it, add a CV_WRAP here , so it looks like:

    CV_WRAP void readALTModel(String modelfile);

and re-run the whole build pipeline(cmake, make, make install). if it works, consider contributing to trunk ;)

edit flag offensive delete link more

Comments

Thank you, but maybe I have not enough experience to re-build all. I simply would to use HOGDescriptor to detect upper bodies, in python. I have found the right SVM to do that (check here), but I can't understand how to set it in the HOGDescriptor python object :(

daniele2688 gravatar imagedaniele2688 ( 2016-01-23 06:45:28 -0600 )edit
1

i'm having some doubts, if this is doable ..

did you check, if it works from c++ (at all) ?

berak gravatar imageberak ( 2016-01-23 06:59:59 -0600 )edit

I am not skilled in c++, but I suppose it is doable because the model is "model_4BiSVMLight.H90.alt" and the description of function readALTModel(filename) says that it reads/parses Dalal's alt model file. I am not an expert, just a student, could you explain your doubts please?

daniele2688 gravatar imagedaniele2688 ( 2016-01-23 07:09:12 -0600 )edit

It seems that the linked code indeed includes a SVMLight model that could be loaded with realALTModel(). However, I doubt it will work, because they use another enhanced version of HOG, and you don't even know the right HOG params (they say min detection size is 90x100, that's all...)

LorenaGdL gravatar imageLorenaGdL ( 2016-01-23 07:11:19 -0600 )edit

Thanks for the reply, now it is clear for me. Is it possible to infer the parameters from the shell script that they include in the package?

    WIDTH=100; export WIDTH
    HEIGHT=90; export HEIGHT
    THR=0.0001; export THR

allOptions="-W $WIDTH,$HEIGHT -C 8,8 -N 2,2 -B 9 -G 8,8 -S 0 --wtscale 2 --maxvalue 0.2 --epsilon 1 --fullcirc 0 -v 3 --proc rgb_sqrt_grad --norm norml2hys -p 1,0 --no_nonmax 0 -z 8,16,1.3 --cachesize 152 --scaleratio 1.05 --stride 8 --margin 4,4 --avsize 0,70 -t $THR -m 0 "
daniele2688 gravatar imagedaniele2688 ( 2016-01-23 07:21:53 -0600 )edit

It seems possible, although you'll need to dive into OLT software to find the meaning of each param. More important, you'll need to check that OpenCV's implementation support all the options (seems so for what I see, though I'd have to carefully check)

LorenaGdL gravatar imageLorenaGdL ( 2016-01-23 07:36:26 -0600 )edit

I have tried to re-build opencv following the suggestion of @berak, but when I run the code I get an error:

>>> hog = cv2.HOGDescriptor()
>>> hog.readALTModel("/Users/lele/Desktop/UB_release/HOGub/model_4BiSVMLight.H90.alt")
OpenCV Error: Assertion failed (checkDetectorSize()) in setSVMDetector, file /Users/lele/opencv/modules/objdetect/src/hog.cpp, line 117
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: /Users/lele/opencv/modules/objdetect/src/hog.cpp:117: error: (-215) checkDetectorSize() in function setSVMDetector
daniele2688 gravatar imagedaniele2688 ( 2016-01-25 09:53:30 -0600 )edit

You need to configure all the HOG params before reading the model, because it checks if the vector produced by your HOG configuration has the same size as the one expected by the SVM model. You'll run into this error until you figure out all the proper param values

LorenaGdL gravatar imageLorenaGdL ( 2016-01-25 10:19:43 -0600 )edit

Thank you, I have tried to set the proper parameters -- winsize=(100,90), blocksize=(16,16),blockstride=(8,8),cellsize(8,8),nbins=9. I am sure that OLT software runs with them. By the way, it seems that these parameters are not accepted by opencv:

OpenCV Error: Assertion failed ((winSize.width - blockSize.width) % blockStride.width == 0 && (winSize.height - blockSize.height) % blockStride.height == 0) in getDescriptorSize, file /Users/lele/opencv/modules/objdetect/src/hog.cpp, line 92
daniele2688 gravatar imagedaniele2688 ( 2016-01-25 12:12:47 -0600 )edit

Yep, bummer... Some sizes need to be perfectly divisible in OpenCV's implementation. I see no solution here, it was a long shot from the beginning. You may want to train your own upper-body detector

LorenaGdL gravatar imageLorenaGdL ( 2016-01-25 12:26:10 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-23 05:59:52 -0600

Seen: 1,499 times

Last updated: Jan 23 '16