示例#1
0
END_TEST

START_TEST (document_type)
{
    reset_errno();
    size_t c = model_size(model);
    assert_noerr();
    assert_uint_eq(1, c);
    
    reset_errno();
    Document *d = model_document(model, 0);
    assert_noerr();
    assert_not_null(d);
    
    reset_errno();
    Node *bogus = model_document(model, 1);
    assert_errno(EINVAL);
    assert_null(bogus);
    
    reset_errno();
    Node *r1 = model_document_root(model, 0);
    assert_noerr();
    assert_not_null(r1);
    assert_node_kind(r1, MAPPING);

    reset_errno();
    Node *r2 = document_root(d);
    assert_noerr();
    assert_not_null(r2);
    assert_ptr_eq(r1, r2);
}
示例#2
0
void ICFDetector::train(const vector<string>& image_filenames,
                        const vector< vector<Rect> >& labelling,
                        ICFDetectorParams params)
{
    Size model_size(params.model_n_cols, params.model_n_rows);

    vector<Mat> samples; /* positive samples + negative samples */
    Mat sample, resized_sample;
    int pos_count = 0;
    for( size_t i = 0; i < image_filenames.size(); ++i, ++pos_count )
    {
        Mat img = imread(String(image_filenames[i].c_str()));
        for( size_t j = 0; j < labelling[i].size(); ++j )
        {
            Rect r = labelling[i][j];
            if( r.x > img.cols || r.y > img.rows )
                continue;

            sample = img.colRange(max(r.x, 0), min(r.width, img.cols))
                        .rowRange(max(r.y, 0), min(r.height, img.rows));

            resize(sample, resized_sample, model_size);

            samples.push_back(resized_sample);
        }
    }

    int neg_count = 0;
    RNG rng;
    for( size_t i = 0; i < image_filenames.size(); ++i )
    {
        Mat img = imread(String(image_filenames[i].c_str()));
        for( int j = 0; j < (int)(pos_count / image_filenames.size() + 1); )
        {
            Rect r;
            r.x = rng.uniform(0, img.cols);
            r.width = rng.uniform(r.x + 1, img.cols);
            r.y = rng.uniform(0, img.rows);
            r.height = rng.uniform(r.y + 1, img.rows);

            if( !overlap(r, labelling[i]) )
            {
                sample = img.colRange(r.x, r.width).rowRange(r.y, r.height);
                //resize(sample, resized_sample);
                samples.push_back(resized_sample);
                ++neg_count;
                ++j;
            }
        }
    }

    Mat_<int> labels(1, pos_count + neg_count);
    for( int i = 0; i < pos_count; ++i)
        labels(0, i) = 1;
    for( int i = pos_count; i < pos_count + neg_count; ++i )
        labels(0, i) = -1;

    vector<Point3i> features = generateFeatures(model_size);
    Ptr<ACFFeatureEvaluator> feature_evaluator = createACFFeatureEvaluator(features);

    Mat_<int> data((int)features.size(), (int)samples.size());
    Mat_<int> feature_col;

    vector<Mat> channels;
    for( int i = 0; i < (int)samples.size(); ++i )
    {
        computeChannels(samples[i], channels);
        feature_evaluator->setChannels(channels);
        feature_evaluator->evaluateAll(feature_col);
        for( int j = 0; j < feature_col.rows; ++j )
            data(i, j) = feature_col(0, j);
    }

    WaldBoostParams wparams;
    wparams.weak_count = params.weak_count;
    wparams.alpha = 0.001f;

    Ptr<WaldBoost> waldboost = createWaldBoost(wparams);
    waldboost->train(data, labels);
}