Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOGDescriptor #109

Closed
pefi9 opened this issue Nov 2, 2015 · 19 comments
Closed

HOGDescriptor #109

pefi9 opened this issue Nov 2, 2015 · 19 comments

Comments

@pefi9
Copy link

pefi9 commented Nov 2, 2015

Hi,
I can't get HOG descriptors, respectively it's all zeros.

 opencv_objdetect.HOGDescriptor hogDesc = new opencv_objdetect.HOGDescriptor(
            new Size(64, 128)
            , new Size(16, 16)
            , new Size(8, 8)
            , new Size(8, 8)
            , 9);

 float[] desc = new float[(int)hogDesc.getDescriptorSize()];
  Mat temp = cvarrToMat(img);
  hogDesc.compute(temp, desc);
@pefi9 pefi9 changed the title HOGDecriptior HOGDescriptor Nov 2, 2015
@saudet
Copy link
Member

saudet commented Nov 3, 2015

Have you tried to do the same thing as shown in this OpenCV sample?
https://github.com/Itseez/opencv/blob/3.0.0/samples/tapi/hog.cpp

@pefi9
Copy link
Author

pefi9 commented Nov 3, 2015

My understanding of this sample is that it`s for detecting people with pre-trained SVM classificator:

hog.setSVMDetector( HOGDescriptor::getDaimlerPeopleDetector() );

I`m trying to create simple OCR where HOG descriptor would provide me gradients of the different parts of an image and svm would be trained based on these descriptors.
More like the 2nd answer here: http://answers.opencv.org/question/10374/how-to-training-hog-and-use-my-hogdescriptor/

@saudet
Copy link
Member

saudet commented Nov 3, 2015

Ok, so would you have some code in C++ that is known to be working? And if you cannot find anything, please ask the authors of HOGDescriptor for usage guidelines. It's not like I'm supposed to know how to use that undocumented API.

@pefi9
Copy link
Author

pefi9 commented Nov 3, 2015

Sure, thanks.

@saudet saudet added the question label Nov 3, 2015
@saudet
Copy link
Member

saudet commented Nov 3, 2015

I've tried this here and it returns something else than zeros:

    Mat image = imread("/home/saudet/projects/bytedeco/javacv/samples/pic1.png");
    HOGDescriptor hog = new HOGDescriptor();
    FloatPointer descriptors = new FloatPointer();
    hog.compute(image, descriptors);

But descriptors.limit() is much larger than hog.getDescriptorSize(), so I guess you're only getting the beginning of the data. You need to specify a larger array if you want to use float[] instead of FloatPointer.

@saudet saudet closed this as completed Nov 3, 2015
@pefi9
Copy link
Author

pefi9 commented Nov 3, 2015

I see, thanks a lot.

@pefi9
Copy link
Author

pefi9 commented Nov 3, 2015

I tried it with "FloatPointer" instead of float[]. The size is just the same however FloatPointer is populated with number after calling hogDescriptor.comput while float[] is empty (all zeros).

Anyway, FloatPointer works - thanks for the hind.

@saudet saudet added the bug label Nov 8, 2015
@saudet
Copy link
Member

saudet commented Nov 8, 2015

@pefi9 Yes, it seems there's a problem there... I'll have to look into that.

@saudet saudet reopened this Nov 8, 2015
@pefi9
Copy link
Author

pefi9 commented Nov 8, 2015

Hi @saudet,
how can I load trained svm model? I saved the model by using svm.save(path), but I can`t figure out how to load it (something like svm.load(path)?).

@saudet
Copy link
Member

saudet commented Nov 9, 2015 via email

@pefi9
Copy link
Author

pefi9 commented Nov 9, 2015

void CvStatModel::load(const char* filename, const char* name=0 )

Taken from:
http://docs.opencv.org/2.4/modules/ml/doc/statistical_models.html

Example:

CvSVM *SVM = new CvSVM;
SVM->load("SVM.xml");
SVM->predict(DataRow);

http://answers.opencv.org/question/13418/machine-learning-saveload-problem/

@saudet
Copy link
Member

saudet commented Nov 9, 2015

That's for OpenCV 2.4. Any examples for OpenCV 3.0?

@pefi9
Copy link
Author

pefi9 commented Nov 9, 2015

saudet added a commit to bytedeco/javacpp that referenced this issue Nov 10, 2015
… when used as arguments with adapters (issue bytedeco/javacpp-presets#109)

 * Remove confusing and now unnecessary empty constructors
@saudet
Copy link
Member

saudet commented Nov 10, 2015

I see, they've moved the load() methods to function templates. I've added something to the commit above. Let me know if this satisfactory! I've also fixed the problem with the HOGDescriptor.compute() and int[] in the other commit. Thanks for reporting!

@taobupt
Copy link

taobupt commented Apr 3, 2016

there is still no function load() in SVM, so what should I do if I want to load a classifier file from a path. please give a hand

@saudet
Copy link
Member

saudet commented Apr 3, 2016

@taobupt It's all here: https://github.com/bytedeco/javacpp-presets/blob/master/opencv/src/main/java/org/bytedeco/javacpp/helper/opencv_ml.java#L48

@taobupt
Copy link

taobupt commented Apr 3, 2016

there is no opencv_ml.java in *javacv-1.1-bin.zip (140 MB), *which means
that I have to compile the source code by myself? you can add it to the
javacv-1.1-bin.zip if you have some free time. Thanks for help.

@saudet
Copy link
Member

saudet commented Apr 5, 2016

Please follow the build instructions here, if you have some free time:
https://github.com/bytedeco/javacpp-presets/#build-instructions

@saudet
Copy link
Member

saudet commented May 19, 2016

This has all been fixed and included in the just released version 1.2. Thanks for reporting all this guys!

@saudet saudet closed this as completed May 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants