• Mansour Moufid's avatar
    Cast some image coordinates and sizes to double. · b99f7a29
    Mansour Moufid authored
    Conflicts:
    	modules/gpu/perf/perf_imgproc.cpp
    
    Cast a long integer to double explicitly.
    
    Conflicts:
    	modules/python/src2/cv2.cpp
    
    Cast some matrix sizes to type int.
    
    Change some vector mask types to unsigned.
    
    Conflicts:
    	modules/core/src/arithm.cpp
    b99f7a29
test_undistort_badarg.cpp 16.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                        Intel License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of Intel Corporation may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#include "test_precomp.hpp"
#include "opencv2/imgproc/imgproc_c.h"

class CV_UndistortPointsBadArgTest : public cvtest::BadArgTest
{
public:
    CV_UndistortPointsBadArgTest();
protected:
    void run(int);
    void run_func();

private:
    //common
    cv::Size img_size;
    bool useCPlus;
    //static const int N_POINTS = 1;
    static const int N_POINTS2 = 2;

    //C
    CvMat* _camera_mat;
    CvMat* matR;
    CvMat* matP;
    CvMat* _distortion_coeffs;
    CvMat* _src_points;
    CvMat* _dst_points;


    //C++
    cv::Mat camera_mat;
    cv::Mat R;
    cv::Mat P;
    cv::Mat distortion_coeffs;
    cv::Mat src_points;
    std::vector<cv::Point2f> dst_points;

};

CV_UndistortPointsBadArgTest::CV_UndistortPointsBadArgTest ()
{
    useCPlus = false;
    _camera_mat = matR = matP = _distortion_coeffs = _src_points = _dst_points = NULL;
}

void CV_UndistortPointsBadArgTest::run_func()
{
    if (useCPlus)
    {
        cv::undistortPoints(src_points,dst_points,camera_mat,distortion_coeffs,R,P);
    }
    else
    {
        cvUndistortPoints(_src_points,_dst_points,_camera_mat,_distortion_coeffs,matR,matP);
    }
}

void CV_UndistortPointsBadArgTest::run(int)
{
    //RNG& rng = ts->get_rng();
    int errcount = 0;
    useCPlus = false;
//initializing
    img_size.width = 800;
    img_size.height = 600;
    double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
    double dist[4] = {0.01,0.02,0.001,0.0005};
    double s_points[N_POINTS2] = {
        static_cast<double>(img_size.width) / 4.0,
        static_cast<double>(img_size.height) / 4.0,
    };
    double d_points[N_POINTS2];
    double p[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
    double r[9] = {1,0,0,0,1,0,0,0,1};

    CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
    CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
    CvMat _P_orig = cvMat(3,3,CV_64F,p);
    CvMat _R_orig = cvMat(3,3,CV_64F,r);
    CvMat _src_points_orig = cvMat(1,4,CV_64FC2,s_points);
    CvMat _dst_points_orig = cvMat(1,4,CV_64FC2,d_points);

    _camera_mat = &_camera_mat_orig;
    _distortion_coeffs = &_distortion_coeffs_orig;
    matP = &_P_orig;
    matR = &_R_orig;
    _src_points = &_src_points_orig;
    _dst_points = &_dst_points_orig;

//tests
    CvMat* temp1;
    CvMat* temp;
    IplImage* temp_img = cvCreateImage(cvSize(img_size.width,img_size.height),8,3);

//-----------
    temp = (CvMat*)temp_img;
    _src_points = temp;
    errcount += run_test_case( CV_StsAssert, "Input data is not CvMat*" );
    _src_points = &_src_points_orig;

    temp = (CvMat*)temp_img;
    _dst_points = temp;
    errcount += run_test_case( CV_StsAssert, "Output data is not CvMat*" );
    _dst_points = &_dst_points_orig;

    temp = cvCreateMat(2,3,CV_64F);
    _src_points = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
    _src_points = &_src_points_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(2,3,CV_64F);
    _dst_points = temp;
    errcount += run_test_case(CV_StsAssert, "Invalid output data matrix size" );
    _dst_points = &_dst_points_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(1,3,CV_64F);
    temp1 = cvCreateMat(4,1,CV_64F);
    _dst_points = temp;
    _src_points = temp1;
    errcount += run_test_case(CV_StsAssert, "Output and input data sizes mismatch" );
    _dst_points = &_dst_points_orig;
    _src_points = &_src_points_orig;
    cvReleaseMat(&temp);
    cvReleaseMat(&temp1);

    temp = cvCreateMat(1,3,CV_32S);
    _dst_points = temp;
    errcount += run_test_case(CV_StsAssert, "Invalid output data matrix type" );
    _dst_points = &_dst_points_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(1,3,CV_32S);
    _src_points = temp;
    errcount += run_test_case(CV_StsAssert, "Invalid input data matrix type" );
    _src_points = &_src_points_orig;
    cvReleaseMat(&temp);
//------------
    temp = cvCreateMat(2,3,CV_64F);
    _camera_mat = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
    _camera_mat = &_camera_mat_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(3,4,CV_64F);
    _camera_mat = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
    _camera_mat = &_camera_mat_orig;
    cvReleaseMat(&temp);

    temp = (CvMat*)temp_img;
    _camera_mat = temp;
    errcount += run_test_case( CV_StsAssert, "Camera data is not CvMat*" );
    _camera_mat = &_camera_mat_orig;
//----------

    temp = (CvMat*)temp_img;
    _distortion_coeffs = temp;
    errcount += run_test_case( CV_StsAssert, "Distortion coefficients data is not CvMat*" );
    _distortion_coeffs = &_distortion_coeffs_orig;

    temp = cvCreateMat(1,6,CV_64F);
    _distortion_coeffs = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
    _distortion_coeffs = &_distortion_coeffs_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(3,3,CV_64F);
    _distortion_coeffs = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
    _distortion_coeffs = &_distortion_coeffs_orig;
    cvReleaseMat(&temp);
//----------
    temp = (CvMat*)temp_img;
    matR = temp;
    errcount += run_test_case( CV_StsAssert, "R data is not CvMat*" );
    matR = &_R_orig;

    temp = cvCreateMat(4,3,CV_64F);
    matR = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
    matR = &_R_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(3,2,CV_64F);
    matR = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
    matR = &_R_orig;
    cvReleaseMat(&temp);

//-----------
    temp = (CvMat*)temp_img;
    matP = temp;
    errcount += run_test_case( CV_StsAssert, "P data is not CvMat*" );
    matP = &_P_orig;

    temp = cvCreateMat(4,3,CV_64F);
    matP = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );
    matP = &_P_orig;
    cvReleaseMat(&temp);

    temp = cvCreateMat(3,2,CV_64F);
    matP = temp;
    errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );
    matP = &_P_orig;
    cvReleaseMat(&temp);
//------------
    //C++ tests
    useCPlus = true;

    camera_mat = cv::cvarrToMat(&_camera_mat_orig);
    distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
    P = cv::cvarrToMat(&_P_orig);
    R = cv::cvarrToMat(&_R_orig);
    src_points = cv::cvarrToMat(&_src_points_orig);

    temp = cvCreateMat(2,2,CV_32FC2);
    src_points = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
    src_points = cv::cvarrToMat(&_src_points_orig);
    cvReleaseMat(&temp);

    temp = cvCreateMat(1,4,CV_64FC2);
    src_points = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid input data matrix type" );
    src_points = cv::cvarrToMat(&_src_points_orig);
    cvReleaseMat(&temp);

    src_points = cv::Mat();
    errcount += run_test_case( CV_StsAssert, "Input data matrix is not continuous" );
    src_points = cv::cvarrToMat(&_src_points_orig);
    cvReleaseMat(&temp);



//------------
    cvReleaseImage(&temp_img);
    ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
}


//=========
class CV_InitUndistortRectifyMapBadArgTest : public cvtest::BadArgTest
{
public:
    CV_InitUndistortRectifyMapBadArgTest();
protected:
    void run(int);
    void run_func();

private:
    //common
    cv::Size img_size;
    bool useCPlus;

    //C
    CvMat* _camera_mat;
    CvMat* matR;
    CvMat* _new_camera_mat;
    CvMat* _distortion_coeffs;
    CvMat* _mapx;
    CvMat* _mapy;


    //C++
    cv::Mat camera_mat;
    cv::Mat R;
    cv::Mat new_camera_mat;
    cv::Mat distortion_coeffs;
    cv::Mat mapx;
    cv::Mat mapy;
    int mat_type;

};

CV_InitUndistortRectifyMapBadArgTest::CV_InitUndistortRectifyMapBadArgTest ()
{
    useCPlus = false;
    _camera_mat = matR = _new_camera_mat = _distortion_coeffs = _mapx = _mapy = NULL;
}

void CV_InitUndistortRectifyMapBadArgTest::run_func()
{
    if (useCPlus)
    {
        cv::initUndistortRectifyMap(camera_mat,distortion_coeffs,R,new_camera_mat,img_size,mat_type,mapx,mapy);
    }
    else
    {
        cvInitUndistortRectifyMap(_camera_mat,_distortion_coeffs,matR,_new_camera_mat,_mapx,_mapy);
    }
}

void CV_InitUndistortRectifyMapBadArgTest::run(int)
{
    int errcount = 0;
//initializing
    img_size.width = 800;
    img_size.height = 600;
    double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
    double dist[4] = {0.01,0.02,0.001,0.0005};
    float* arr_mapx = new float[img_size.width*img_size.height];
    float* arr_mapy = new float[img_size.width*img_size.height];
    double arr_new_camera_mat[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
    double r[9] = {1,0,0,0,1,0,0,0,1};

    CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
    CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
    CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
    CvMat _R_orig = cvMat(3,3,CV_64F,r);
    CvMat _mapx_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapx);
    CvMat _mapy_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapy);
    int mat_type_orig = CV_32FC1;

    _camera_mat = &_camera_mat_orig;
    _distortion_coeffs = &_distortion_coeffs_orig;
    _new_camera_mat = &_new_camera_mat_orig;
    matR = &_R_orig;
    _mapx = &_mapx_orig;
    _mapy = &_mapy_orig;
    mat_type = mat_type_orig;

//tests
    useCPlus = true;
    CvMat* temp;

    //C++ tests
    useCPlus = true;

    camera_mat = cv::cvarrToMat(&_camera_mat_orig);
    distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
    new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
    R = cv::cvarrToMat(&_R_orig);
    mapx = cv::cvarrToMat(&_mapx_orig);
    mapy = cv::cvarrToMat(&_mapy_orig);


    mat_type = CV_64F;
    errcount += run_test_case( CV_StsAssert, "Invalid map matrix type" );
    mat_type = mat_type_orig;

    temp = cvCreateMat(3,2,CV_32FC1);
    camera_mat = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
    camera_mat = cv::cvarrToMat(&_camera_mat_orig);
    cvReleaseMat(&temp);

    temp = cvCreateMat(4,3,CV_32FC1);
    R = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
    R = cv::cvarrToMat(&_R_orig);
    cvReleaseMat(&temp);

    temp = cvCreateMat(6,1,CV_32FC1);
    distortion_coeffs = cv::cvarrToMat(temp);
    errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
    distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
    cvReleaseMat(&temp);

//------------
    delete[] arr_mapx;
    delete[] arr_mapy;
    ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
}


//=========
class CV_UndistortBadArgTest : public cvtest::BadArgTest
{
public:
    CV_UndistortBadArgTest();
protected:
    void run(int);
    void run_func();

private:
    //common
    cv::Size img_size;
    bool useCPlus;

    //C
    CvMat* _camera_mat;
    CvMat* _new_camera_mat;
    CvMat* _distortion_coeffs;
    CvMat* _src;
    CvMat* _dst;


    //C++
    cv::Mat camera_mat;
    cv::Mat new_camera_mat;
    cv::Mat distortion_coeffs;
    cv::Mat src;
    cv::Mat dst;

};

CV_UndistortBadArgTest::CV_UndistortBadArgTest ()
{
    useCPlus = false;
    _camera_mat = _new_camera_mat = _distortion_coeffs = _src = _dst = NULL;
}

void CV_UndistortBadArgTest::run_func()
{
    if (useCPlus)
    {
        cv::undistort(src,dst,camera_mat,distortion_coeffs,new_camera_mat);
    }
    else
    {
        cvUndistort2(_src,_dst,_camera_mat,_distortion_coeffs,_new_camera_mat);
    }
}

void CV_UndistortBadArgTest::run(int)
{
    int errcount = 0;
//initializing
    img_size.width = 800;
    img_size.height = 600;
    double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
    double dist[4] = {0.01,0.02,0.001,0.0005};
    float* arr_src = new float[img_size.width*img_size.height];
    float* arr_dst = new float[img_size.width*img_size.height];
    double arr_new_camera_mat[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};

    CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
    CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
    CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
    CvMat _src_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_src);
    CvMat _dst_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_dst);

    _camera_mat = &_camera_mat_orig;
    _distortion_coeffs = &_distortion_coeffs_orig;
    _new_camera_mat = &_new_camera_mat_orig;
    _src = &_src_orig;
    _dst = &_dst_orig;

//tests
    useCPlus = true;
    CvMat* temp;
    CvMat* temp1;

//C tests
    useCPlus = false;

    temp = cvCreateMat(800,600,CV_32F);
    temp1 = cvCreateMat(800,601,CV_32F);
    _src = temp;
    _dst = temp1;
    errcount += run_test_case( CV_StsAssert, "Input and output data matrix sizes mismatch" );
    _src = &_src_orig;
    _dst = &_dst_orig;
    cvReleaseMat(&temp);
    cvReleaseMat(&temp1);

    temp = cvCreateMat(800,600,CV_32F);
    temp1 = cvCreateMat(800,600,CV_64F);
    _src = temp;
    _dst = temp1;
    errcount += run_test_case( CV_StsAssert, "Input and output data matrix types mismatch" );
    _src = &_src_orig;
    _dst = &_dst_orig;
    cvReleaseMat(&temp);
    cvReleaseMat(&temp1);

    //C++ tests
    useCPlus = true;

    camera_mat = cv::cvarrToMat(&_camera_mat_orig);
    distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
    new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
    src = cv::cvarrToMat(&_src_orig);
    dst = cv::cvarrToMat(&_dst_orig);

//------------
    delete[] arr_src;
    delete[] arr_dst;
    ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
}

TEST(Calib3d_UndistortPoints, badarg) { CV_UndistortPointsBadArgTest test; test.safe_run(); }
TEST(Calib3d_InitUndistortRectifyMap, badarg) { CV_InitUndistortRectifyMapBadArgTest test; test.safe_run(); }
TEST(Calib3d_Undistort, badarg) { CV_UndistortBadArgTest test; test.safe_run(); }

/* End of file. */