Path: blob/master/modules/calib3d/test/test_undistort_badarg.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// Intel License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000, Intel Corporation, all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of Intel Corporation may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "test_precomp.hpp"42#include "opencv2/calib3d/calib3d_c.h"4344namespace opencv_test { namespace {4546class CV_UndistortPointsBadArgTest : public cvtest::BadArgTest47{48public:49CV_UndistortPointsBadArgTest();50protected:51void run(int);52void run_func();5354private:55//common56cv::Size img_size;57bool useCPlus;58//static const int N_POINTS = 1;59static const int N_POINTS2 = 2;6061//C62CvMat* _camera_mat;63CvMat* matR;64CvMat* matP;65CvMat* _distortion_coeffs;66CvMat* _src_points;67CvMat* _dst_points;686970//C++71cv::Mat camera_mat;72cv::Mat R;73cv::Mat P;74cv::Mat distortion_coeffs;75cv::Mat src_points;76std::vector<cv::Point2f> dst_points;7778};7980CV_UndistortPointsBadArgTest::CV_UndistortPointsBadArgTest ()81{82useCPlus = false;83_camera_mat = matR = matP = _distortion_coeffs = _src_points = _dst_points = NULL;84}8586void CV_UndistortPointsBadArgTest::run_func()87{88if (useCPlus)89{90cv::undistortPoints(src_points,dst_points,camera_mat,distortion_coeffs,R,P);91}92else93{94cvUndistortPoints(_src_points,_dst_points,_camera_mat,_distortion_coeffs,matR,matP);95}96}9798void CV_UndistortPointsBadArgTest::run(int)99{100//RNG& rng = ts->get_rng();101int errcount = 0;102useCPlus = false;103//initializing104img_size.width = 800;105img_size.height = 600;106double 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};107double dist[4] = {0.01,0.02,0.001,0.0005};108double s_points[N_POINTS2] = {109static_cast<double>(img_size.width) / 4.0,110static_cast<double>(img_size.height) / 4.0,111};112double d_points[N_POINTS2];113double 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};114double r[9] = {1,0,0,0,1,0,0,0,1};115116CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);117CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);118CvMat _P_orig = cvMat(3,3,CV_64F,p);119CvMat _R_orig = cvMat(3,3,CV_64F,r);120CvMat _src_points_orig = cvMat(1,4,CV_64FC2,s_points);121CvMat _dst_points_orig = cvMat(1,4,CV_64FC2,d_points);122123_camera_mat = &_camera_mat_orig;124_distortion_coeffs = &_distortion_coeffs_orig;125matP = &_P_orig;126matR = &_R_orig;127_src_points = &_src_points_orig;128_dst_points = &_dst_points_orig;129130//tests131CvMat* temp1;132CvMat* temp;133IplImage* temp_img = cvCreateImage(cvSize(img_size.width,img_size.height),8,3);134135//-----------136temp = (CvMat*)temp_img;137_src_points = temp;138errcount += run_test_case( CV_StsAssert, "Input data is not CvMat*" );139_src_points = &_src_points_orig;140141temp = (CvMat*)temp_img;142_dst_points = temp;143errcount += run_test_case( CV_StsAssert, "Output data is not CvMat*" );144_dst_points = &_dst_points_orig;145146temp = cvCreateMat(2,3,CV_64F);147_src_points = temp;148errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );149_src_points = &_src_points_orig;150cvReleaseMat(&temp);151152temp = cvCreateMat(2,3,CV_64F);153_dst_points = temp;154errcount += run_test_case(CV_StsAssert, "Invalid output data matrix size" );155_dst_points = &_dst_points_orig;156cvReleaseMat(&temp);157158temp = cvCreateMat(1,3,CV_64F);159temp1 = cvCreateMat(4,1,CV_64F);160_dst_points = temp;161_src_points = temp1;162errcount += run_test_case(CV_StsAssert, "Output and input data sizes mismatch" );163_dst_points = &_dst_points_orig;164_src_points = &_src_points_orig;165cvReleaseMat(&temp);166cvReleaseMat(&temp1);167168temp = cvCreateMat(1,3,CV_32S);169_dst_points = temp;170errcount += run_test_case(CV_StsAssert, "Invalid output data matrix type" );171_dst_points = &_dst_points_orig;172cvReleaseMat(&temp);173174temp = cvCreateMat(1,3,CV_32S);175_src_points = temp;176errcount += run_test_case(CV_StsAssert, "Invalid input data matrix type" );177_src_points = &_src_points_orig;178cvReleaseMat(&temp);179//------------180temp = cvCreateMat(2,3,CV_64F);181_camera_mat = temp;182errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );183_camera_mat = &_camera_mat_orig;184cvReleaseMat(&temp);185186temp = cvCreateMat(3,4,CV_64F);187_camera_mat = temp;188errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );189_camera_mat = &_camera_mat_orig;190cvReleaseMat(&temp);191192temp = (CvMat*)temp_img;193_camera_mat = temp;194errcount += run_test_case( CV_StsAssert, "Camera data is not CvMat*" );195_camera_mat = &_camera_mat_orig;196//----------197198temp = (CvMat*)temp_img;199_distortion_coeffs = temp;200errcount += run_test_case( CV_StsAssert, "Distortion coefficients data is not CvMat*" );201_distortion_coeffs = &_distortion_coeffs_orig;202203temp = cvCreateMat(1,6,CV_64F);204_distortion_coeffs = temp;205errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );206_distortion_coeffs = &_distortion_coeffs_orig;207cvReleaseMat(&temp);208209temp = cvCreateMat(3,3,CV_64F);210_distortion_coeffs = temp;211errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );212_distortion_coeffs = &_distortion_coeffs_orig;213cvReleaseMat(&temp);214//----------215temp = (CvMat*)temp_img;216matR = temp;217errcount += run_test_case( CV_StsAssert, "R data is not CvMat*" );218matR = &_R_orig;219220temp = cvCreateMat(4,3,CV_64F);221matR = temp;222errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );223matR = &_R_orig;224cvReleaseMat(&temp);225226temp = cvCreateMat(3,2,CV_64F);227matR = temp;228errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );229matR = &_R_orig;230cvReleaseMat(&temp);231232//-----------233temp = (CvMat*)temp_img;234matP = temp;235errcount += run_test_case( CV_StsAssert, "P data is not CvMat*" );236matP = &_P_orig;237238temp = cvCreateMat(4,3,CV_64F);239matP = temp;240errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );241matP = &_P_orig;242cvReleaseMat(&temp);243244temp = cvCreateMat(3,2,CV_64F);245matP = temp;246errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );247matP = &_P_orig;248cvReleaseMat(&temp);249//------------250//C++ tests251useCPlus = true;252253camera_mat = cv::cvarrToMat(&_camera_mat_orig);254distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);255P = cv::cvarrToMat(&_P_orig);256R = cv::cvarrToMat(&_R_orig);257src_points = cv::cvarrToMat(&_src_points_orig);258259temp = cvCreateMat(2,2,CV_32FC2);260src_points = cv::cvarrToMat(temp);261errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );262src_points = cv::cvarrToMat(&_src_points_orig);263cvReleaseMat(&temp);264265temp = cvCreateMat(1,4,CV_64FC2);266src_points = cv::cvarrToMat(temp);267errcount += run_test_case( CV_StsAssert, "Invalid input data matrix type" );268src_points = cv::cvarrToMat(&_src_points_orig);269cvReleaseMat(&temp);270271src_points = cv::Mat();272errcount += run_test_case( CV_StsAssert, "Input data matrix is not continuous" );273src_points = cv::cvarrToMat(&_src_points_orig);274cvReleaseMat(&temp);275276277278//------------279cvReleaseImage(&temp_img);280ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);281}282283284//=========285class CV_InitUndistortRectifyMapBadArgTest : public cvtest::BadArgTest286{287public:288CV_InitUndistortRectifyMapBadArgTest();289protected:290void run(int);291void run_func();292293private:294//common295cv::Size img_size;296bool useCPlus;297298//C299CvMat* _camera_mat;300CvMat* matR;301CvMat* _new_camera_mat;302CvMat* _distortion_coeffs;303CvMat* _mapx;304CvMat* _mapy;305306307//C++308cv::Mat camera_mat;309cv::Mat R;310cv::Mat new_camera_mat;311cv::Mat distortion_coeffs;312cv::Mat mapx;313cv::Mat mapy;314int mat_type;315316};317318CV_InitUndistortRectifyMapBadArgTest::CV_InitUndistortRectifyMapBadArgTest ()319{320useCPlus = false;321_camera_mat = matR = _new_camera_mat = _distortion_coeffs = _mapx = _mapy = NULL;322}323324void CV_InitUndistortRectifyMapBadArgTest::run_func()325{326if (useCPlus)327{328cv::initUndistortRectifyMap(camera_mat,distortion_coeffs,R,new_camera_mat,img_size,mat_type,mapx,mapy);329}330else331{332cvInitUndistortRectifyMap(_camera_mat,_distortion_coeffs,matR,_new_camera_mat,_mapx,_mapy);333}334}335336void CV_InitUndistortRectifyMapBadArgTest::run(int)337{338int errcount = 0;339//initializing340img_size.width = 800;341img_size.height = 600;342double 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};343double dist[4] = {0.01,0.02,0.001,0.0005};344float* arr_mapx = new float[img_size.width*img_size.height];345float* arr_mapy = new float[img_size.width*img_size.height];346double 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};347double r[9] = {1,0,0,0,1,0,0,0,1};348349CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);350CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);351CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);352CvMat _R_orig = cvMat(3,3,CV_64F,r);353CvMat _mapx_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapx);354CvMat _mapy_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapy);355int mat_type_orig = CV_32FC1;356357_camera_mat = &_camera_mat_orig;358_distortion_coeffs = &_distortion_coeffs_orig;359_new_camera_mat = &_new_camera_mat_orig;360matR = &_R_orig;361_mapx = &_mapx_orig;362_mapy = &_mapy_orig;363mat_type = mat_type_orig;364365//tests366useCPlus = true;367CvMat* temp;368369//C++ tests370useCPlus = true;371372camera_mat = cv::cvarrToMat(&_camera_mat_orig);373distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);374new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);375R = cv::cvarrToMat(&_R_orig);376mapx = cv::cvarrToMat(&_mapx_orig);377mapy = cv::cvarrToMat(&_mapy_orig);378379380mat_type = CV_64F;381errcount += run_test_case( CV_StsAssert, "Invalid map matrix type" );382mat_type = mat_type_orig;383384temp = cvCreateMat(3,2,CV_32FC1);385camera_mat = cv::cvarrToMat(temp);386errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );387camera_mat = cv::cvarrToMat(&_camera_mat_orig);388cvReleaseMat(&temp);389390temp = cvCreateMat(4,3,CV_32FC1);391R = cv::cvarrToMat(temp);392errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );393R = cv::cvarrToMat(&_R_orig);394cvReleaseMat(&temp);395396temp = cvCreateMat(6,1,CV_32FC1);397distortion_coeffs = cv::cvarrToMat(temp);398errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );399distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);400cvReleaseMat(&temp);401402//------------403delete[] arr_mapx;404delete[] arr_mapy;405ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);406}407408409//=========410class CV_UndistortBadArgTest : public cvtest::BadArgTest411{412public:413CV_UndistortBadArgTest();414protected:415void run(int);416void run_func();417418private:419//common420cv::Size img_size;421bool useCPlus;422423//C424CvMat* _camera_mat;425CvMat* _new_camera_mat;426CvMat* _distortion_coeffs;427CvMat* _src;428CvMat* _dst;429430431//C++432cv::Mat camera_mat;433cv::Mat new_camera_mat;434cv::Mat distortion_coeffs;435cv::Mat src;436cv::Mat dst;437438};439440CV_UndistortBadArgTest::CV_UndistortBadArgTest ()441{442useCPlus = false;443_camera_mat = _new_camera_mat = _distortion_coeffs = _src = _dst = NULL;444}445446void CV_UndistortBadArgTest::run_func()447{448if (useCPlus)449{450cv::undistort(src,dst,camera_mat,distortion_coeffs,new_camera_mat);451}452else453{454cvUndistort2(_src,_dst,_camera_mat,_distortion_coeffs,_new_camera_mat);455}456}457458void CV_UndistortBadArgTest::run(int)459{460int errcount = 0;461//initializing462img_size.width = 800;463img_size.height = 600;464double 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};465double dist[4] = {0.01,0.02,0.001,0.0005};466float* arr_src = new float[img_size.width*img_size.height];467float* arr_dst = new float[img_size.width*img_size.height];468double 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};469470CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);471CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);472CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);473CvMat _src_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_src);474CvMat _dst_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_dst);475476_camera_mat = &_camera_mat_orig;477_distortion_coeffs = &_distortion_coeffs_orig;478_new_camera_mat = &_new_camera_mat_orig;479_src = &_src_orig;480_dst = &_dst_orig;481482//tests483useCPlus = true;484CvMat* temp;485CvMat* temp1;486487//C tests488useCPlus = false;489490temp = cvCreateMat(800,600,CV_32F);491temp1 = cvCreateMat(800,601,CV_32F);492_src = temp;493_dst = temp1;494errcount += run_test_case( CV_StsAssert, "Input and output data matrix sizes mismatch" );495_src = &_src_orig;496_dst = &_dst_orig;497cvReleaseMat(&temp);498cvReleaseMat(&temp1);499500temp = cvCreateMat(800,600,CV_32F);501temp1 = cvCreateMat(800,600,CV_64F);502_src = temp;503_dst = temp1;504errcount += run_test_case( CV_StsAssert, "Input and output data matrix types mismatch" );505_src = &_src_orig;506_dst = &_dst_orig;507cvReleaseMat(&temp);508cvReleaseMat(&temp1);509510//C++ tests511useCPlus = true;512513camera_mat = cv::cvarrToMat(&_camera_mat_orig);514distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);515new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);516src = cv::cvarrToMat(&_src_orig);517dst = cv::cvarrToMat(&_dst_orig);518519//------------520delete[] arr_src;521delete[] arr_dst;522ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);523}524525TEST(Calib3d_UndistortPoints, badarg) { CV_UndistortPointsBadArgTest test; test.safe_run(); }526TEST(Calib3d_InitUndistortRectifyMap, badarg) { CV_InitUndistortRectifyMapBadArgTest test; test.safe_run(); }527TEST(Calib3d_Undistort, badarg) { CV_UndistortBadArgTest test; test.safe_run(); }528529}} // namespace530/* End of file. */531532533