Exemple #1
0
void CV_BaseHistTest::init_hist( int /*test_case_idx*/, int hist_i )
{
    if( gen_random_hist )
    {
        CvRNG* rng = ts->get_rng();
        CvArr* h = hist[hist_i]->bins;
        
        if( hist_type == CV_HIST_ARRAY )
        {
            cvRandArr( rng, h, CV_RAND_UNI,
                cvScalarAll(0), cvScalarAll(gen_hist_max_val) );
        }
        else
        {
            int i, j, total_size = 1, nz_count;
            int idx[CV_MAX_DIM];
            for( i = 0; i < cdims; i++ )
                total_size *= dims[i];

            nz_count = cvTsRandInt(rng) % MAX( total_size/4, 100 );
            nz_count = MIN( nz_count, total_size );

            // a zero number of non-zero elements should be allowed
            for( i = 0; i < nz_count; i++ )
            {
                for( j = 0; j < cdims; j++ )
                    idx[j] = cvTsRandInt(rng) % dims[j];
                cvSetRealND( h, idx, cvTsRandReal(rng)*gen_hist_max_val );
            }
        }
    }
}
Exemple #2
0
void CV_MinMaxHistTest::init_hist(int test_case_idx, int hist_i)
{
    int i, eq = 1;
    CvRNG* rng = ts->get_rng();
    CV_BaseHistTest::init_hist( test_case_idx, hist_i );

    for(;;)
    {
        for( i = 0; i < cdims; i++ )
        {
            min_idx0[i] = cvTsRandInt(rng) % dims[i];
            max_idx0[i] = cvTsRandInt(rng) % dims[i];
            eq &= min_idx0[i] == max_idx0[i];
        }
        if( !eq || total_size == 1 )
            break;
    }        

    min_val0 = (float)(-cvTsRandReal(rng)*10 - FLT_EPSILON);
    max_val0 = (float)(cvTsRandReal(rng)*10 + FLT_EPSILON + gen_hist_max_val);

    if( total_size == 1 )
        min_val0 = max_val0;

    cvSetRealND( hist[0]->bins, min_idx0, min_val0 );
    cvSetRealND( hist[0]->bins, max_idx0, max_val0 );
}
Exemple #3
0
int CV_CalcHistTest::prepare_test_case( int test_case_idx )
{
    int code = CV_BaseHistTest::prepare_test_case( test_case_idx );

    if( code > 0 )
    {
        CvRNG* rng = ts->get_rng();
        int i;

        for( i = 0; i <= CV_MAX_DIM; i++ )
        {
            if( i < cdims )
            {
                int nch = 1; //cvTsRandInt(rng) % 3 + 1;
                images[i] = cvCreateImage( img_size,
                    img_type == CV_8U ? IPL_DEPTH_8U : IPL_DEPTH_32F, nch );
                channels[i] = cvTsRandInt(rng) % nch;

                cvRandArr( rng, images[i], CV_RAND_UNI,
                    cvScalarAll(low), cvScalarAll(high) );
            }
            else if( i == CV_MAX_DIM && cvTsRandInt(rng) % 2 )
            {
                // create mask
                images[i] = cvCreateImage( img_size, IPL_DEPTH_8U, 1 );
                // make ~25% pixels in the mask non-zero
                cvRandArr( rng, images[i], CV_RAND_UNI,
                    cvScalarAll(-2), cvScalarAll(2) );
            }
        }
    }

    return code;
}
Exemple #4
0
int CV_CalcBackProjectTest::prepare_test_case( int test_case_idx )
{
    int code = CV_BaseHistTest::prepare_test_case( test_case_idx );

    if( code > 0 )
    {
        CvRNG* rng = ts->get_rng();
        int i, j, n, img_len = img_size.width*img_size.height;

        for( i = 0; i < CV_MAX_DIM + 3; i++ )
        {
            if( i < cdims )
            {
                int nch = 1; //cvTsRandInt(rng) % 3 + 1;
                images[i] = cvCreateImage( img_size,
                    img_type == CV_8U ? IPL_DEPTH_8U : IPL_DEPTH_32F, nch );
                channels[i] = cvTsRandInt(rng) % nch;

                cvRandArr( rng, images[i], CV_RAND_UNI,
                    cvScalarAll(low), cvScalarAll(high) );
            }
            else if( i == CV_MAX_DIM && cvTsRandInt(rng) % 2 )
            {
                // create mask
                images[i] = cvCreateImage( img_size, IPL_DEPTH_8U, 1 );
                // make ~25% pixels in the mask non-zero
                cvRandArr( rng, images[i], CV_RAND_UNI,
                    cvScalarAll(-2), cvScalarAll(2) );
            }
            else if( i > CV_MAX_DIM )
            {
                images[i] = cvCreateImage( img_size, images[0]->depth, 1 );
            }
        }

        cvTsCalcHist( images, hist[0], images[CV_MAX_DIM], channels );

        // now modify the images a bit to add some zeros go to the backprojection
        n = cvTsRandInt(rng) % (img_len/20+1);
        for( i = 0; i < cdims; i++ )
        {
            char* data = images[i]->imageData;
            for( j = 0; j < n; j++ )
            {
                int idx = cvTsRandInt(rng) % img_len;
                double val = cvTsRandReal(rng)*(high - low) + low;
                
                if( img_type == CV_8U )
                    ((uchar*)data)[idx] = (uchar)cvRound(val);
                else
                    ((float*)data)[idx] = (float)val;
            }
        }
    }

    return code;
}
Exemple #5
0
int CV_BayesianProbTest::prepare_test_case( int test_case_idx )
{
    CvRNG* rng = ts->get_rng();
    
    hist_count = (cvTsRandInt(rng) % (MAX_HIST/2-1) + 2)*2;
    hist_count = MIN( hist_count, MAX_HIST );
    int code = CV_BaseHistTest::prepare_test_case( test_case_idx );

    return code;
}
Exemple #6
0
void CV_CannyTest::get_test_array_types_and_sizes( int test_case_idx,
                                                CvSize** sizes, int** types )
{
    CvRNG* rng = ts->get_rng();
    double thresh_range;

    CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
    types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_8U;

    aperture_size = cvTsRandInt(rng) % 2 ? 5 : 3;
    thresh_range = aperture_size == 3 ? 300 : 1000;

    threshold1 = cvTsRandReal(rng)*thresh_range;
    threshold2 = cvTsRandReal(rng)*thresh_range*0.3;

    if( cvTsRandInt(rng) % 2 )
        CV_SWAP( threshold1, threshold2, thresh_range );

    use_true_gradient = cvTsRandInt(rng) % 2;
}
Exemple #7
0
void CV_BaseHistTest::get_hist_params( int /*test_case_idx*/ )
{
    CvRNG* rng = ts->get_rng();
    int i, max_dim_size, max_ni_dim_size = 31;
    double hist_size;

    cdims = cvTsRandInt(rng) % max_cdims + 1;
    hist_size = exp(cvTsRandReal(rng)*max_log_size*CV_LOG2);
    max_dim_size = cvRound(pow(hist_size,1./cdims));
    total_size = 1;
    uniform = cvTsRandInt(rng) % 2;
    hist_type = cvTsRandInt(rng) % 2 ? CV_HIST_SPARSE : CV_HIST_ARRAY; 
    
    for( i = 0; i < cdims; i++ )
    {
        dims[i] = cvTsRandInt(rng) % (max_dim_size + 2) + 2;
        if( !uniform )
            dims[i] = MIN(dims[i], max_ni_dim_size);    
        total_size *= dims[i];
    }

    img_type = cvTsRandInt(rng) % 2 ? CV_32F : CV_8U;
    img_size.width = cvRound( exp(cvRandReal(rng) * img_max_log_size*CV_LOG2) );
    img_size.height = cvRound( exp(cvRandReal(rng) * img_max_log_size*CV_LOG2) );

    low = cvTsMinVal(img_type);
    high = cvTsMaxVal(img_type);

    range_delta = (cvTsRandInt(rng) % 2)*(high-low)*0.05;
}
void CV_MHIGradientTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
{
    CvRNG* rng = ts->get_rng();
    CV_MHIBaseTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );

    types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_8UC1;
    types[OUTPUT][1] = types[REF_OUTPUT][1] = CV_32FC1;
    delta1 = exp(cvTsRandReal(rng)*delta_range_log + 1.);
    delta2 = exp(cvTsRandReal(rng)*delta_range_log + 1.);
    aperture_size = (cvTsRandInt(rng)%3)*2+3;
    //duration = exp(cvTsRandReal(rng)*max_log_duration);
    //timestamp = duration + cvTsRandReal(rng)*30.-10.;
}
Exemple #9
0
void CV_ThreshTest::get_test_array_types_and_sizes( int test_case_idx,
                                                CvSize** sizes, int** types )
{
    CvRNG* rng = ts->get_rng();
    int depth = cvTsRandInt(rng) % 2, cn = cvTsRandInt(rng) % 4 + 1;
    CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
    depth = depth == 0 ? CV_8U : CV_32F;

    types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_MAKETYPE(depth,cn);
    thresh_type = cvTsRandInt(rng) % 5;

    if( depth == CV_8U )
    {
        thresh_val = (float)(cvTsRandReal(rng)*350. - 50.);
        max_val = (float)(cvTsRandReal(rng)*350. - 50.);
        if( cvTsRandInt(rng)%4 == 0 )
            max_val = 255;
    }
    else
    {
        thresh_val = (float)(cvTsRandReal(rng)*1000. - 500.);
        max_val = (float)(cvTsRandReal(rng)*1000. - 500.);
    }
}
Exemple #10
0
int CV_BaseHistTest::prepare_test_case( int test_case_idx )
{
    int i;
    float** r;

    clear();

    CvTest::prepare_test_case( test_case_idx );
    get_hist_params( test_case_idx );
    r = get_hist_ranges( test_case_idx );

    for( i = 0; i < hist_count; i++ )
    {
        hist[i] = cvCreateHist( cdims, dims, hist_type, r, uniform );
        init_hist( test_case_idx, i );
    }
    test_cpp = (cvTsRandInt(ts->get_rng()) % 2) != 0;

    return 1;
}
Exemple #11
0
int CV_QueryHistTest::prepare_test_case( int test_case_idx )
{
    int code = CV_BaseHistTest::prepare_test_case( test_case_idx );

    if( code > 0 )
    {
        int i, j, iters;
        float default_value = 0.f;
        CvRNG* rng = ts->get_rng();
        CvMat* bit_mask = 0;
        int* idx;

        iters = (cvTsRandInt(rng) % MAX(total_size/10,100)) + 1;
        iters = MIN( iters, total_size*9/10 + 1 );
        
        indices = cvCreateMat( 1, iters*cdims, CV_32S );
        values = cvCreateMat( 1, iters, CV_32F );
        values0 = cvCreateMat( 1, iters, CV_32F );
        idx = indices->data.i;

        //printf( "total_size = %d, cdims = %d, iters = %d\n", total_size, cdims, iters );

        bit_mask = cvCreateMat( 1, (total_size + 7)/8, CV_8U );
        cvZero( bit_mask );

        #define GET_BIT(n) (bit_mask->data.ptr[(n)/8] & (1 << ((n)&7)))
        #define SET_BIT(n) bit_mask->data.ptr[(n)/8] |= (1 << ((n)&7))

        // set random histogram bins' values to the linear indices of the bins
        for( i = 0; i < iters; i++ )
        {
            int lin_idx = 0;
            for( j = 0; j < cdims; j++ )
            {
                int t = cvTsRandInt(rng) % dims[j];
                idx[i*cdims + j] = t;
                lin_idx = lin_idx*dims[j] + t;
            }

            if( cvTsRandInt(rng) % 8 || GET_BIT(lin_idx) )
            {
                values0->data.fl[i] = (float)(lin_idx+1);
                SET_BIT(lin_idx);
            }
            else
                // some histogram bins will not be initialized intentionally,
                // they should be equal to the default value
                values0->data.fl[i] = default_value;
        }

        // do the second pass to make values0 consistent with bit_mask
        for( i = 0; i < iters; i++ )
        {
            int lin_idx = 0;
            for( j = 0; j < cdims; j++ )
                lin_idx = lin_idx*dims[j] + idx[i*cdims + j];

            if( GET_BIT(lin_idx) )
                values0->data.fl[i] = (float)(lin_idx+1);
        }
    
        cvReleaseMat( &bit_mask );
    }

    return code;
}
Exemple #12
0
int CV_CalcBackProjectPatchTest::prepare_test_case( int test_case_idx )
{
    int code = CV_BaseHistTest::prepare_test_case( test_case_idx );

    if( code > 0 )
    {
        CvRNG* rng = ts->get_rng();
        int i, j, n, img_len = img_size.width*img_size.height;

        patch_size.width = cvTsRandInt(rng) % img_size.width + 1;
        patch_size.height = cvTsRandInt(rng) % img_size.height + 1;
        patch_size.width = MIN( patch_size.width, 30 );
        patch_size.height = MIN( patch_size.height, 30 );

        factor = 1.;
        method = cvTsRandInt(rng) % CV_CompareHistTest::MAX_METHOD;

        for( i = 0; i < CV_MAX_DIM + 2; i++ )
        {
            if( i < cdims )
            {
                int nch = 1; //cvTsRandInt(rng) % 3 + 1;
                images[i] = cvCreateImage( img_size,
                    img_type == CV_8U ? IPL_DEPTH_8U : IPL_DEPTH_32F, nch );
                channels[i] = cvTsRandInt(rng) % nch;

                cvRandArr( rng, images[i], CV_RAND_UNI,
                    cvScalarAll(low), cvScalarAll(high) );
            }
            else if( i >= CV_MAX_DIM )
            {
                images[i] = cvCreateImage(
                    cvSize(img_size.width - patch_size.width + 1,
                           img_size.height - patch_size.height + 1),
                    IPL_DEPTH_32F, 1 );
            }
        }

        cvTsCalcHist( images, hist[0], 0, channels );
        cvNormalizeHist( hist[0], factor );

        // now modify the images a bit
        n = cvTsRandInt(rng) % (img_len/10+1);
        for( i = 0; i < cdims; i++ )
        {
            char* data = images[i]->imageData;
            for( j = 0; j < n; j++ )
            {
                int idx = cvTsRandInt(rng) % img_len;
                double val = cvTsRandReal(rng)*(high - low) + low;
                
                if( img_type == CV_8U )
                    ((uchar*)data)[idx] = (uchar)cvRound(val);
                else
                    ((float*)data)[idx] = (float)val;
            }
        }
    }

    return code;
}