train_HOG not able to detect all images.
I picked the code for train_HOG.cpp from openCV site. I went through all the steps carefully, but not able to get the accuracy even in same resolution image (original image from which I created positive images.). Attaching output images and code here to analyse. I put red circle on area that was not found by HOG utility. I need the image should be recognized if source images is of different scale (e.g. 50%, 75%, 125%, 150%). Awaiting response/feed back/comments.
#include "stdafx.h"
#include "TrainHOGEx.h"
TrainHOGEx::TrainHOGEx()
{
}
TrainHOGEx::~TrainHOGEx()
{
}
int mainTestEx();
void get_svm_detectorex(const Ptr< SVM > & svm, vector< float > & hog_detector);
void convert_to_mlex(const std::vector< Mat > & train_samples, Mat& trainData);
void load_images(const String & dirname, vector< Mat > & img_lst, bool showImages);
void sample_negex(const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, const Size & size);
void computeHOGs(const Size wsize, const vector< Mat > & img_lst, vector< Mat > & gradient_lst);
int test_trained_detector(String obj_det_filename, String test_dir, String videofilename);
void get_svm_detectorex(const Ptr< SVM >& svm, vector< float > & hog_detector)
{
// get the support vectors
Mat sv = svm->getSupportVectors();
const int sv_total = sv.rows;
// get the decision function
Mat alpha, svidx;
double rho = svm->getDecisionFunction(0, alpha, svidx);
CV_Assert(alpha.total() == 1 && svidx.total() == 1 && sv_total == 1);
CV_Assert((alpha.type() == CV_64F && alpha.at<double>(0) == 1.) ||
(alpha.type() == CV_32F && alpha.at<float>(0) == 1.f));
CV_Assert(sv.type() == CV_32F);
hog_detector.clear();
hog_detector.resize(sv.cols + 1);
memcpy(&hog_detector[0], sv.ptr(), sv.cols * sizeof(hog_detector[0]));
hog_detector[sv.cols] = (float)-rho;
}
/*
* Convert training/testing set to be used by OpenCV Machine Learning algorithms.
* TrainData is a matrix of size (#samples x max(#cols,#rows) per samples), in 32FC1.
* Transposition of samples are made if needed.
*/
void convert_to_mlex(const vector< Mat > & train_samples, Mat& trainData)
{
//--Convert data
const int rows = (int)train_samples.size();
const int cols = (int)std::max(train_samples[0].cols, train_samples[0].rows);
Mat tmp(1, cols, CV_32FC1); //< used for transposition if needed
trainData = Mat(rows, cols, CV_32FC1);
for (size_t i = 0; i < train_samples.size(); ++i)
{
CV_Assert(train_samples[i].cols == 1 || train_samples[i].rows == 1);
if (train_samples[i].cols == 1)
{
transpose(train_samples[i], tmp);
tmp.copyTo(trainData.row((int)i));
}
else if (train_samples[i].rows == 1)
{
train_samples[i].copyTo(trainData.row((int)i));
}
}
}
void load_images(const String & dirname, vector< Mat > & img_lst, bool showImages = false)
{
try {
vector< String > files;
try {
glob(dirname, files);
}
catch (...)
{
AfxMessageBox("exception");
}
for (size_t i = 0; i < files.size(); ++i)
{
Mat img = imread(files[i]); // load the image
if (img.empty()) // invalid image, skip it.
{
cout << files[i] << " is invalid!" << endl;
continue;
}
if (showImages)
{
imshow("image", img);
waitKey(1);
}
img_lst.push_back(img);
}
}
catch (...)
{
AfxMessageBox("exception");
}
}
void sample_negex(const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, const Size & size)
{
Rect box;
box.width = size.width;
box.height = size.height;
const int size_x = box.width;
const int size_y = box ...
please do NOT post screenshots of code. if you think, we need to see it, add it to your question as text
" I went through all the steps carefully," -- no, you did something entirely different.
(maybe that's "creative", but it won't deliver here)
instead of collecting many positive images, you tried to use the code from the (cascade) createsamples tool, to augment positives from a single image, using rotation/scaling. not helpful here, probably even counter productive (because the "real world" logos do not look like this).
also, looking for the google logo in a webpage, you're probably better off, using (scaled) template matching instead.