The following code sample will be pushed into OpenCV in the near future and is part of the OpenCV 3 Blueprints book, Chapter 5 - written by me -, where these models are evaluated in detail. I have used it on all my models and none of them have features like that, it is not possible with the included training software to have values like that...
More software can be found on our books GitHub repo.
/****************************************************************************************************
This code is part of the code supplied with the OpenCV Blueprints book.
It was written by Steven Puttemans, who can be contacted via steven.puttemans[at]kuleuven.be
License can be found at https://github.com/OpenCVBlueprints/OpenCVBlueprints/blob/master/license.txt
*****************************************************************************************************
This is a software alpha release of the OpenCV interface for visualising object models and
the used features to perform their detections.
USAGE:
./visualise_models -model <model.xml> -image <ref.png> -data <output folder>
LIMITS
- Only handles cascade classifier models
- Handles stumps only for the moment
- Needs a valid training/test sample window with the original model dimensions
- Can handle HAAR and LBP features
***********************************************************************************************/
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <fstream>
#include <iostream>
using namespace std;
using namespace cv;
struct rect_data{
int x;
int y;
int w;
int h;
float weight;
};
int main( int argc, const char** argv )
{
// If no parameters are give, then a usage template should be provided
if(argc == 1){
cout << "This is a software alpha release of the OpenCV interface for visualising object models and the used features to perform their detections." << endl;
cout << "USAGE ./visualise_models -model <model.xml> -image <ref.png> -data <output folder>" << endl;
cout << "LIMITS: only cascade classifier models / only stump features for now / valid sample window with model dimensions needed / HAAR and LBP features" << endl;
return 0;
}
// Read in the input arguments
string model = "";
string output_folder = "";
string image_ref = "";
for(int i = 1; i < argc; ++i )
{
if( !strcmp( argv[i], "-model" ) )
{
model = argv[++i];
}else if( !strcmp( argv[i], "-image" ) ){
image_ref = argv[++i];
}else if( !strcmp( argv[i], "-data" ) ){
output_folder = argv[++i];
}
}
// Value for timing
int timing = 1;
// Value for cols of storing elements
int cols_prefered = 5;
// Open the XML model
FileStorage fs;
fs.open(model, FileStorage::READ);
// Get a the required information
// First decide which feature type we are using
FileNode cascade = fs["cascade"];
string feature_type = cascade["featureType"];
bool haar = false, lbp = false;
if (feature_type.compare("HAAR") == 0){
haar = true;
}
if (feature_type.compare("LBP") == 0){
lbp = true;
}
if ( feature_type.compare("HAAR") != 0 && feature_type.compare("LBP")){
cerr << "The model is not an HAAR or LBP feature based model!" << endl;
cerr << "Please select a model that can be visualized by the software." << endl;
return -1;
}
// We make a visualisation mask - which increases the window to make it at least a bit more visible
int resize_factor = 10;
int resize_storage_factor = 10;
Mat reference_image = imread(image_ref, CV_LOAD_IMAGE_GRAYSCALE);
Mat visualization;
resize(reference_image, visualization, Size(reference_image.cols * resize_factor, reference_image.rows * resize_factor), 0, 0, CV_INTER_CUBIC);
// First recover for each stage the number of weak features and their ...
(more)
Can you post your script? Are you sure you are not missing something when drawing?
Hi, I just posted my script. Please take a look.
For a starter, do not post screens of code. Noone is going to type over your code to test it.
Apology about that Steven.
No problem!