Opencv + Hog + SVM... i want to know the recipe please
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);
}
please try to explain, where you're stuck now .
Thanks berak, i use this awesome post HERE to create this trainning.
but i cant use it yet because i get this error:
I understand the error, but my question is how can i use the trained data with the hog descriptor now.
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.
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:
i get this:
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