Ask Your Question
0

Haar Feature

asked 2015-12-06 19:36:29 -0600

JunjieHPU gravatar image

updated 2015-12-07 09:22:59 -0600

Hi guys,

I recently trained my own haar-feature xml file for detecting balloons. Then I wrote a script to parse the xml file and draw out all the haar features. However, some of them seem impossible like the following:

image description image description

Are both of these two still considered as haar feature?

Thanks.

image description

Here's my script.

edit retag flag offensive close merge delete

Comments

2

Can you post your script? Are you sure you are not missing something when drawing?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-12-07 03:31:09 -0600 )edit

Hi, I just posted my script. Please take a look.

JunjieHPU gravatar imageJunjieHPU ( 2015-12-07 09:24:02 -0600 )edit
1

For a starter, do not post screens of code. Noone is going to type over your code to test it.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-12-08 03:59:18 -0600 )edit
1

Apology about that Steven.

JunjieHPU gravatar imageJunjieHPU ( 2015-12-08 18:47:42 -0600 )edit

No problem!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-12-09 01:40:23 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-12-08 04:01:50 -0600

updated 2015-12-08 04:08:13 -0600

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)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-12-06 19:36:29 -0600

Seen: 785 times

Last updated: Dec 08 '15