int ArrayTest::prepare_test_case( int test_case_idx ) { int code = 1; size_t max_arr = test_array.size(); vector<vector<Size> > sizes(max_arr); vector<vector<Size> > whole_sizes(max_arr); vector<vector<int> > types(max_arr); size_t i, j; RNG& rng = ts->get_rng(); bool is_image = false; for( i = 0; i < max_arr; i++ ) { size_t sizei = std::max(test_array[i].size(), (size_t)1); sizes[i].resize(sizei); types[i].resize(sizei); whole_sizes[i].resize(sizei); } get_test_array_types_and_sizes( test_case_idx, sizes, types ); for( i = 0; i < max_arr; i++ ) { size_t sizei = test_array[i].size(); for( j = 0; j < sizei; j++ ) { unsigned t = randInt(rng); bool create_mask = true, use_roi = false; CvSize size = cvSize(sizes[i][j]), whole_size = size; CvRect roi = CV_STRUCT_INITIALIZER; is_image = !cvmat_allowed ? true : iplimage_allowed ? (t & 1) != 0 : false; create_mask = (t & 6) == 0; // ~ each of 3 tests will use mask use_roi = (t & 8) != 0; if( use_roi ) { whole_size.width += randInt(rng) % 10; whole_size.height += randInt(rng) % 10; } cvRelease( &test_array[i][j] ); if( size.width > 0 && size.height > 0 && types[i][j] >= 0 && (i != MASK || create_mask) ) { if( use_roi ) { roi.width = size.width; roi.height = size.height; if( whole_size.width > size.width ) roi.x = randInt(rng) % (whole_size.width - size.width); if( whole_size.height > size.height ) roi.y = randInt(rng) % (whole_size.height - size.height); } if( is_image ) { test_array[i][j] = cvCreateImage( whole_size, icvTsTypeToDepth[CV_MAT_DEPTH(types[i][j])], CV_MAT_CN(types[i][j]) ); if( use_roi ) cvSetImageROI( (IplImage*)test_array[i][j], roi ); } else { test_array[i][j] = cvCreateMat( whole_size.height, whole_size.width, types[i][j] ); if( use_roi ) { CvMat submat, *mat = (CvMat*)test_array[i][j]; cvGetSubRect( test_array[i][j], &submat, roi ); submat.refcount = mat->refcount; *mat = submat; } } } } } test_mat.resize(test_array.size()); for( i = 0; i < max_arr; i++ ) { size_t sizei = test_array[i].size(); test_mat[i].resize(sizei); for( j = 0; j < sizei; j++ ) { CvArr* arr = test_array[i][j]; test_mat[i][j] = cv::cvarrToMat(arr); if( !test_mat[i][j].empty() ) fill_array( test_case_idx, (int)i, (int)j, test_mat[i][j] ); } } return code; }
int CvArrTest::prepare_test_case( int test_case_idx ) { int code = 1; CvSize** sizes = (CvSize**)malloc( max_arr*sizeof(sizes[0]) ); CvSize** whole_sizes = (CvSize**)malloc( max_arr*sizeof(whole_sizes[0]) ); int** types = (int**)malloc( max_arr*sizeof(types[0]) ); int i, j, total = 0; CvRNG* rng = ts->get_rng(); bool is_image = false; bool is_timing_test = false; CV_FUNCNAME( "CvArrTest::prepare_test_case" ); __BEGIN__; is_timing_test = ts->get_testing_mode() == CvTS::TIMING_MODE; if( is_timing_test ) { if( !get_next_timing_param_tuple() ) { code = -1; EXIT; } } for( i = 0; i < max_arr; i++ ) { int count = test_array[i].size(); count = MAX(count, 1); sizes[i] = (CvSize*)malloc( count*sizeof(sizes[i][0]) ); types[i] = (int*)malloc( count*sizeof(types[i][0]) ); whole_sizes[i] = (CvSize*)malloc( count*sizeof(whole_sizes[i][0]) ); } if( !is_timing_test ) get_test_array_types_and_sizes( test_case_idx, sizes, types ); else { get_timing_test_array_types_and_sizes( test_case_idx, sizes, types, whole_sizes, &is_image ); } for( i = 0; i < max_arr; i++ ) { int count = test_array[i].size(); total += count; for( j = 0; j < count; j++ ) { unsigned t = cvRandInt(rng); bool create_mask = true, use_roi = false; CvSize size = sizes[i][j], whole_size = size; CvRect roi = {0,0,0,0}; if( !is_timing_test ) { is_image = !cvmat_allowed ? true : iplimage_allowed ? (t & 1) != 0 : false; create_mask = (t & 6) == 0; // ~ each of 3 tests will use mask use_roi = (t & 8) != 0; if( use_roi ) { whole_size.width += cvRandInt(rng) % 10; whole_size.height += cvRandInt(rng) % 10; } } else { whole_size = whole_sizes[i][j]; use_roi = whole_size.width != size.width || whole_size.height != size.height; create_mask = cvReadInt(find_timing_param( "use_mask" ),0) != 0; } cvRelease( &test_array[i][j] ); if( size.width > 0 && size.height > 0 && types[i][j] >= 0 && (i != MASK || create_mask) ) { if( use_roi ) { roi.width = size.width; roi.height = size.height; if( whole_size.width > size.width ) { if( !is_timing_test ) roi.x = cvRandInt(rng) % (whole_size.width - size.width); else roi.x = 1; } if( whole_size.height > size.height ) { if( !is_timing_test ) roi.y = cvRandInt(rng) % (whole_size.height - size.height); else roi.y = 1; } } if( is_image ) { CV_CALL( test_array[i][j] = cvCreateImage( whole_size, icvTsTypeToDepth[CV_MAT_DEPTH(types[i][j])], CV_MAT_CN(types[i][j]) )); if( use_roi ) cvSetImageROI( (IplImage*)test_array[i][j], roi ); } else { CV_CALL( test_array[i][j] = cvCreateMat( whole_size.height, whole_size.width, types[i][j] )); if( use_roi ) { CvMat submat, *mat = (CvMat*)test_array[i][j]; cvGetSubRect( test_array[i][j], &submat, roi ); submat.refcount = mat->refcount; *mat = submat; } } } } } if( total > max_hdr ) { delete hdr; max_hdr = total; hdr = new CvMat[max_hdr]; } total = 0; for( i = 0; i < max_arr; i++ ) { int count = test_array[i].size(); test_mat[i] = count > 0 ? hdr + total : 0; for( j = 0; j < count; j++ ) { CvArr* arr = test_array[i][j]; CvMat* mat = &test_mat[i][j]; if( !arr ) memset( mat, 0, sizeof(*mat) ); else if( CV_IS_MAT( arr )) { *mat = *(CvMat*)arr; mat->refcount = 0; } else cvGetMat( arr, mat, 0, 0 ); if( mat->data.ptr ) fill_array( test_case_idx, i, j, mat ); } total += count; } __END__; for( i = 0; i < max_arr; i++ ) { if( sizes ) free( sizes[i] ); if( whole_sizes ) free( whole_sizes[i] ); if( types ) free( types[i] ); } free( sizes ); free( whole_sizes ); free( types ); return code; }