Ask Your Question
0

Opencv + Hog + SVM... i want to know the recipe please

asked 2015-02-12 06:39:02 -0600

VonTalavang gravatar image

updated 2015-02-17 09:22:47 -0600

I train my SVM and create a vector file:

clasificador = new CvSVM(); clasificador.train_auto(trainingData, classes, new Mat(), new Mat(), params); clasificador.save("asdf.xml");

now am lost... ok, i load the xml file with CVSVM

how i implement the CVSVM with the HogDescriptor ?

This is my LOAD and image analisis. Where "imag" its the captured frame, "clasificador" its a CVSVM, "hog" its a HogDescriptor

private static void buscar_hog_svm() {

    if (clasificador == null) {
        clasificador = new CvSVM();
        clasificador.load(path_vectores);
    }

    Mat img_gray = new Mat();

    Imgproc.cvtColor(imag, img_gray, Imgproc.COLOR_BGR2GRAY);

    hog = new HOGDescriptor(
            _winSize //new Size(32, 16)
            , _blockSize, _blockStride, _cellSize, _nbins);
    MatOfFloat descriptorsValues = new MatOfFloat();
    MatOfPoint locations = new MatOfPoint();
    hog.compute(img_gray,
            descriptorsValues,
            _winSize,
            _padding, locations);
    Mat fm = descriptorsValues;
    float result = clasificador.predict(fm);
}
edit retag flag offensive close merge delete

Comments

1

please try to explain, where you're stuck now .

berak gravatar imageberak ( 2015-02-12 07:09:38 -0600 )edit

Thanks berak, i use this awesome post HERE to create this trainning.

but i cant use it yet because i get this error:

error: (-209) The sample size is different from what has been used for training in function cvPreparePredictData

I understand the error, but my question is how can i use the trained data with the hog descriptor now.

VonTalavang gravatar imageVonTalavang ( 2015-02-17 09:26:17 -0600 )edit

Mat fm = descriptorsValues.reshape(1,1);

in other words, you have to flatten your prediction Mat to 1d in the same way, as you (hopefully) did during the training.

berak gravatar imageberak ( 2015-02-17 09:54:11 -0600 )edit

i think thats not the problem.

i trained all the project with pos and neg images in 96 X 160 pxl images.

adding some outputs:

System.out.println("tamano descriptorsValues: " + descriptorsValues.size());
    Mat fm = descriptorsValues;

    System.out.println("tamano fm: " + fm.size());

    float result = clasificador.predict(fm);

i get this:

tamano descriptorsValues: 1x581256

tamano fm: 1x581256

I dont get it... i should create a LARGE descriptor mat ( captured frame )... to be compared with a smaller one mat of 1x (96*160) ??

so there i get this error. Am missing some concepts may be ?

i almost forgot... all images trained in 1D matrix of 1 x (nm) with reshape 1,1

VonTalavang gravatar imageVonTalavang ( 2015-02-17 11:25:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-02-24 09:46:49 -0600

VonTalavang gravatar image

Ok, i found the solution here

You just have to create 2 folders for pos images and neg images. Just keep adding positive and negatives images until the trainning is complete.

Right now... looking for the GPU CUDA version of this.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-02-12 06:39:02 -0600

Seen: 1,019 times

Last updated: Feb 24 '15