int CV_CalcBackProjectTest::validate_test_results( int /*test_case_idx*/ ) { int code = CvTS::OK; cvTsCalcBackProject( images, images[CV_MAX_DIM+2], hist[0], channels ); code = cvTsCmpEps2( ts, images[CV_MAX_DIM+1], images[CV_MAX_DIM+2], 0, true, "Back project image" ); if( code < 0 ) ts->set_failed_test_info( code ); return code; }
int CV_CalcBackProjectPatchTest::validate_test_results( int /*test_case_idx*/ ) { int code = CvTS::OK; double err_level = 5e-3; cvTsCalcBackProjectPatch( images, images[CV_MAX_DIM+1], patch_size, hist[0], method, factor, channels ); code = cvTsCmpEps2( ts, images[CV_MAX_DIM], images[CV_MAX_DIM+1], err_level, true, "BackProjectPatch result" ); if( code < 0 ) ts->set_failed_test_info( code ); return code; }
void CV_PyrSegmentationTest::run( int /*start_from*/ ) { const int level = 5; const double range = 20; int code = CvTS::OK; CvPoint _cp[] ={{33,33}, {43,33}, {43,43}, {33,43}}; CvPoint _cp2[] ={{50,50}, {70,50}, {70,70}, {50,70}}; CvPoint* cp = _cp; CvPoint* cp2 = _cp2; CvConnectedComp *dst_comp[3]; CvRect rect[3] = {{50,50,21,21}, {0,0,128,128}, {33,33,11,11}}; double a[3] = {441.0, 15822.0, 121.0}; /* ippiPoint cp3[] ={130,130, 150,130, 150,150, 130,150}; */ /* CvPoint cp[] ={0,0, 5,5, 5,0, 10,5, 10,0, 15,5, 15,0}; */ int nPoints = 4; int block_size = 1000; CvMemStorage *storage; /* storage for connected component writing */ CvSeq *comp; CvRNG* rng = ts->get_rng(); int i, j, iter; IplImage *image, *image_f, *image_s; CvSize size = {128, 128}; const int threshold1 = 50, threshold2 = 50; rect[1].width = size.width; rect[1].height = size.height; a[1] = size.width*size.height - a[0] - a[2]; OPENCV_CALL( storage = cvCreateMemStorage( block_size ) ); for( iter = 0; iter < 2; iter++ ) { int channels = iter == 0 ? 1 : 3; int mask[] = {0,0,0}; image = cvCreateImage(size, 8, channels ); image_s = cvCloneImage( image ); image_f = cvCloneImage( image ); if( channels == 1 ) { int color1 = 30, color2 = 110, color3 = 180; cvSet( image, cvScalarAll(color1)); cvFillPoly( image, &cp, &nPoints, 1, cvScalar(color2)); cvFillPoly( image, &cp2, &nPoints, 1, cvScalar(color3)); } else { CvScalar color1 = CV_RGB(30,30,30), color2 = CV_RGB(255,0,0), color3 = CV_RGB(0,255,0); assert( channels == 3 ); cvSet( image, color1 ); cvFillPoly( image, &cp, &nPoints, 1, color2); cvFillPoly( image, &cp2, &nPoints, 1, color3); } cvRandArr( rng, image_f, CV_RAND_UNI, cvScalarAll(0), cvScalarAll(range*2) ); cvAddWeighted( image, 1, image_f, 1, -range, image_f ); cvPyrSegmentation( image_f, image_s, storage, &comp, level, threshold1, threshold2 ); if(comp->total != 3) { ts->printf( CvTS::LOG, "The segmentation function returned %d (not 3) components\n", comp->total ); code = CvTS::FAIL_INVALID_OUTPUT; goto _exit_; } /* read the connected components */ dst_comp[0] = (CvConnectedComp*)CV_GET_SEQ_ELEM( CvConnectedComp, comp, 0 ); dst_comp[1] = (CvConnectedComp*)CV_GET_SEQ_ELEM( CvConnectedComp, comp, 1 ); dst_comp[2] = (CvConnectedComp*)CV_GET_SEQ_ELEM( CvConnectedComp, comp, 2 ); /*{ for( i = 0; i < 3; i++ ) { CvRect r = dst_comp[i]->rect; cvRectangle( image_s, cvPoint(r.x,r.y), cvPoint(r.x+r.width,r.y+r.height), CV_RGB(255,255,255), 3, 8, 0 ); } cvNamedWindow( "test", 1 ); cvShowImage( "test", image_s ); cvWaitKey(0); }*/ code = cvTsCmpEps2( ts, image, image_s, 10, false, "the output image" ); if( code < 0 ) goto _exit_; for( i = 0; i < 3; i++) { for( j = 0; j < 3; j++ ) { if( !mask[j] && dst_comp[i]->area == a[j] && dst_comp[i]->rect.x == rect[j].x && dst_comp[i]->rect.y == rect[j].y && dst_comp[i]->rect.width == rect[j].width && dst_comp[i]->rect.height == rect[j].height ) { mask[j] = 1; break; } } if( j == 3 ) { ts->printf( CvTS::LOG, "The component #%d is incorrect\n", i ); code = CvTS::FAIL_BAD_ACCURACY; goto _exit_; } } cvReleaseImage(&image_f); cvReleaseImage(&image); cvReleaseImage(&image_s); } _exit_: cvReleaseMemStorage( &storage ); cvReleaseImage(&image_f); cvReleaseImage(&image); cvReleaseImage(&image_s); if( code < 0 ) ts->set_failed_test_info( code ); }
void CV_POSITTest::run( int start_from ) { int code = CvTS::OK; /* fixed parameters output */ /*float rot[3][3]={ 0.49010f, 0.85057f, 0.19063f, -0.56948f, 0.14671f, 0.80880f, 0.65997f, -0.50495f, 0.55629f }; float trans[3] = { 0.0f, 0.0f, 40.02637f }; */ /* Some variables */ int i, counter; CvTermCriteria criteria; CvPoint3D32f* obj_points; CvPoint2D32f* img_points; CvPOSITObject* object; float angleX, angleY, angleZ; CvRNG* rng = ts->get_rng(); int progress = 0; CvMat* true_rotationX = cvCreateMat( 3, 3, CV_32F ); CvMat* true_rotationY = cvCreateMat( 3, 3, CV_32F ); CvMat* true_rotationZ = cvCreateMat( 3, 3, CV_32F ); CvMat* tmp_matrix = cvCreateMat( 3, 3, CV_32F ); CvMat* true_rotation = cvCreateMat( 3, 3, CV_32F ); CvMat* rotation = cvCreateMat( 3, 3, CV_32F ); CvMat* translation = cvCreateMat( 3, 1, CV_32F ); CvMat* true_translation = cvCreateMat( 3, 1, CV_32F ); const float flFocalLength = 760.f; const float flEpsilon = 0.1f; /* Initilization */ criteria.type = CV_TERMCRIT_EPS|CV_TERMCRIT_ITER; criteria.epsilon = flEpsilon; criteria.max_iter = 10000; /* Allocating source arrays; */ obj_points = (CvPoint3D32f*)cvAlloc( 8 * sizeof(CvPoint3D32f) ); img_points = (CvPoint2D32f*)cvAlloc( 8 * sizeof(CvPoint2D32f) ); /* Fill points arrays with values */ /* cube model with edge size 10 */ obj_points[0].x = 0; obj_points[0].y = 0; obj_points[0].z = 0; obj_points[1].x = 10; obj_points[1].y = 0; obj_points[1].z = 0; obj_points[2].x = 10; obj_points[2].y = 10; obj_points[2].z = 0; obj_points[3].x = 0; obj_points[3].y = 10; obj_points[3].z = 0; obj_points[4].x = 0; obj_points[4].y = 0; obj_points[4].z = 10; obj_points[5].x = 10; obj_points[5].y = 0; obj_points[5].z = 10; obj_points[6].x = 10; obj_points[6].y = 10; obj_points[6].z = 10; obj_points[7].x = 0; obj_points[7].y = 10; obj_points[7].z = 10; /* Loop for test some random object positions */ for( counter = start_from; counter < test_case_count; counter++ ) { ts->update_context( this, counter, true ); progress = update_progress( progress, counter, test_case_count, 0 ); /* set all rotation matrix to zero */ cvZero( true_rotationX ); cvZero( true_rotationY ); cvZero( true_rotationZ ); /* fill random rotation matrix */ angleX = (float)(cvTsRandReal(rng)*2*CV_PI); angleY = (float)(cvTsRandReal(rng)*2*CV_PI); angleZ = (float)(cvTsRandReal(rng)*2*CV_PI); true_rotationX->data.fl[0 *3+ 0] = 1; true_rotationX->data.fl[1 *3+ 1] = (float)cos(angleX); true_rotationX->data.fl[2 *3+ 2] = true_rotationX->data.fl[1 *3+ 1]; true_rotationX->data.fl[1 *3+ 2] = -(float)sin(angleX); true_rotationX->data.fl[2 *3+ 1] = -true_rotationX->data.fl[1 *3+ 2]; true_rotationY->data.fl[1 *3+ 1] = 1; true_rotationY->data.fl[0 *3+ 0] = (float)cos(angleY); true_rotationY->data.fl[2 *3+ 2] = true_rotationY->data.fl[0 *3+ 0]; true_rotationY->data.fl[0 *3+ 2] = -(float)sin(angleY); true_rotationY->data.fl[2 *3+ 0] = -true_rotationY->data.fl[0 *3+ 2]; true_rotationZ->data.fl[2 *3+ 2] = 1; true_rotationZ->data.fl[0 *3+ 0] = (float)cos(angleZ); true_rotationZ->data.fl[1 *3+ 1] = true_rotationZ->data.fl[0 *3+ 0]; true_rotationZ->data.fl[0 *3+ 1] = -(float)sin(angleZ); true_rotationZ->data.fl[1 *3+ 0] = -true_rotationZ->data.fl[0 *3+ 1]; cvMatMul( true_rotationX, true_rotationY, tmp_matrix); cvMatMul( tmp_matrix, true_rotationZ, true_rotation); /* fill translation vector */ true_translation->data.fl[2] = (float)(cvRandReal(rng)*(2*flFocalLength-40) + 40); true_translation->data.fl[0] = (float)((cvRandReal(rng)*2-1)*true_translation->data.fl[2]); true_translation->data.fl[1] = (float)((cvRandReal(rng)*2-1)*true_translation->data.fl[2]); /* calculate perspective projection */ for ( i = 0; i < 8; i++ ) { float vec[3]; CvMat Vec = cvMat( 3, 1, CV_MAT32F, vec ); CvMat Obj_point = cvMat( 3, 1, CV_MAT32F, &obj_points[i].x ); cvMatMul( true_rotation, &Obj_point, &Vec ); vec[0] += true_translation->data.fl[0]; vec[1] += true_translation->data.fl[1]; vec[2] += true_translation->data.fl[2]; img_points[i].x = flFocalLength * vec[0] / vec[2]; img_points[i].y = flFocalLength * vec[1] / vec[2]; } /*img_points[0].x = 0 ; img_points[0].y = 0; img_points[1].x = 80; img_points[1].y = -93; img_points[2].x = 245;img_points[2].y = -77; img_points[3].x = 185;img_points[3].y = 32; img_points[4].x = 32; img_points[4].y = 135; img_points[5].x = 99; img_points[5].y = 35; img_points[6].x = 247; img_points[6].y = 62; img_points[7].x = 195; img_points[7].y = 179; */ object = cvCreatePOSITObject( obj_points, 8 ); cvPOSIT( object, img_points, flFocalLength, criteria, rotation->data.fl, translation->data.fl ); cvReleasePOSITObject( &object ); code = cvTsCmpEps2( ts, rotation, true_rotation, flEpsilon, false, "rotation matrix" ); if( code < 0 ) goto _exit_; code = cvTsCmpEps2( ts, translation, true_translation, flEpsilon, false, "translation vector" ); if( code < 0 ) goto _exit_; } _exit_: cvFree( &obj_points ); cvFree( &img_points ); cvReleaseMat( &true_rotationX ); cvReleaseMat( &true_rotationY ); cvReleaseMat( &true_rotationZ ); cvReleaseMat( &tmp_matrix ); cvReleaseMat( &true_rotation ); cvReleaseMat( &rotation ); cvReleaseMat( &translation ); cvReleaseMat( &true_translation ); if( code < 0 ) ts->set_failed_test_info( code ); }