Test system included into Android build
This commit is contained in:
parent
1a02877ab7
commit
b906ad3108
@ -511,6 +511,7 @@ if(WITH_JASPER AND NOT JASPER_FOUND)
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
#android camera support
|
||||
set(NativeCamera_DIR "${CMAKE_SOURCE_DIR}/android/native-camera/build")
|
||||
FIND_PACKAGE(NativeCamera QUIET)
|
||||
if(NativeCamera_FOUND)
|
||||
@ -1099,15 +1100,15 @@ endif()
|
||||
set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${CMAKE_CURRENT_SOURCE_DIR}/include\" \"${CMAKE_CURRENT_SOURCE_DIR}/include/opencv\"")
|
||||
set(CMAKE_BASE_INCLUDE_DIRS_CONFIGCMAKE "\"${CMAKE_CURRENT_SOURCE_DIR}\"")
|
||||
|
||||
set(CMAKE_LIB_DIRS_CONFIGCMAKE "${LIBRARY_OUTPUT_PATH}")
|
||||
|
||||
if (ANDROID)
|
||||
set(CMAKE_LIB_DIRS_CONFIGCMAKE "${LIBRARY_OUTPUT_PATH}")
|
||||
|
||||
if (ANDROID)
|
||||
if (NOT BUILD_SHARED_LIBS)
|
||||
set(CMAKE_LIB_DIRS_CONFIGCMAKE ${CMAKE_LIB_DIRS_CONFIGCMAKE} "${CMAKE_BINARY_DIR}/lib")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if( HAVE_ANDROID_NATIVE_CAMERA )
|
||||
set(CMAKE_LIB_DIRS_CONFIGCMAKE ${CMAKE_LIB_DIRS_CONFIGCMAKE} ${NativeCamera_LIB_DIR})
|
||||
set(CMAKE_LIB_DIRS_CONFIGCMAKE ${CMAKE_LIB_DIRS_CONFIGCMAKE} ${NativeCamera_LIB_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -82,7 +82,7 @@ macro(define_opencv_module name)
|
||||
DESTINATION include/opencv2/${name}
|
||||
COMPONENT main)
|
||||
|
||||
if(BUILD_TESTS AND NOT ANDROID AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/test"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
@ -25,7 +25,7 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" )
|
||||
set(OPENCV_BUILD_3RDPARTY_LIBS ON CACHE BOOL "" )
|
||||
|
||||
#Build tests
|
||||
set(BUILD_TESTS OFF CACHE BOOL "" )
|
||||
#set(BUILD_TESTS OFF CACHE BOOL "" )
|
||||
|
||||
#Choose the type of build, options are: None Debug Release RelWithDebInfo
|
||||
# MinSizeRel.
|
||||
|
@ -1,3 +1,7 @@
|
||||
if (ANDROID)
|
||||
ADD_DEFINITIONS(-DGTEST_HAS_STD_WSTRING=0)
|
||||
endif()
|
||||
|
||||
add_subdirectory(calib3d)
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(features2d)
|
||||
@ -9,9 +13,7 @@ if(MSVC OR MINGW)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT ANDROID)
|
||||
add_subdirectory(ts)
|
||||
endif()
|
||||
add_subdirectory(highgui)
|
||||
add_subdirectory(imgproc)
|
||||
add_subdirectory(legacy)
|
||||
|
@ -103,7 +103,7 @@ CV_EXPORTS string fromUtf16(const WString& str);
|
||||
CV_EXPORTS WString toUtf16(const string& str);
|
||||
|
||||
CV_EXPORTS string format( const char* fmt, ... );
|
||||
|
||||
CV_EXPORTS string tempfile( const char* suffix CV_DEFAULT(0));
|
||||
|
||||
// matrix decomposition types
|
||||
enum { DECOMP_LU=0, DECOMP_SVD=1, DECOMP_EIG=2, DECOMP_CHOLESKY=3, DECOMP_QR=4, DECOMP_NORMAL=16 };
|
||||
|
@ -349,6 +349,23 @@ string format( const char* fmt, ... )
|
||||
return string(buf);
|
||||
}
|
||||
|
||||
string tempfile( const char* suffix )
|
||||
{
|
||||
char buf[L_tmpnam];
|
||||
char* name = 0;
|
||||
#if ANDROID
|
||||
strcpy(buf, "/sdcard/__opencv_temp_XXXXXX");
|
||||
name = mktemp(buf);
|
||||
#else
|
||||
name = tmpnam(buf);
|
||||
#endif
|
||||
if (*name == '\\')
|
||||
++name;
|
||||
if (suffix != 0)
|
||||
return string(buf) + suffix;
|
||||
return buf;
|
||||
}
|
||||
|
||||
static CvErrorCallback customErrorCallback = 0;
|
||||
static void* customErrorCallbackData = 0;
|
||||
static bool breakOnError = false;
|
||||
|
@ -102,13 +102,9 @@ protected:
|
||||
|
||||
cvClearMemStorage(storage);
|
||||
|
||||
char buf[L_tmpnam+16];
|
||||
char* filename = tmpnam(buf);
|
||||
strcat(filename, idx % 2 ? ".yml" : ".xml");
|
||||
if(filename[0] == '\\')
|
||||
filename++;
|
||||
string filename = tempfile(idx % 2 ? ".yml" : ".xml");
|
||||
|
||||
FileStorage fs(filename, FileStorage::WRITE);
|
||||
FileStorage fs(filename.c_str(), FileStorage::WRITE);
|
||||
|
||||
int test_int = (int)cvtest::randInt(rng);
|
||||
double test_real = (cvtest::randInt(rng)%2?1:-1)*exp(cvtest::randReal(rng)*18-9);
|
||||
@ -185,9 +181,9 @@ protected:
|
||||
|
||||
fs.release();
|
||||
|
||||
if(!fs.open(filename, FileStorage::READ))
|
||||
if(!fs.open(filename.c_str(), FileStorage::READ))
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "filename %s can not be read\n", filename );
|
||||
ts->printf( cvtest::TS::LOG, "filename %s can not be read\n", filename.c_str() );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISSING_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
@ -374,7 +370,7 @@ protected:
|
||||
}
|
||||
|
||||
fs.release();
|
||||
remove(filename);
|
||||
remove(filename.c_str());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -502,13 +502,11 @@ void CV_FlannSavedIndexTest::createModel(const cv::Mat &data)
|
||||
//case 2: createIndex( data, AutotunedIndexParams() ); break; // possible linear index !
|
||||
default: assert(0);
|
||||
}
|
||||
char filename[50];
|
||||
tmpnam( filename );
|
||||
if(filename[0] == '\\') filename[0] = '_';
|
||||
string filename = tempfile();
|
||||
index->save( filename );
|
||||
|
||||
createIndex( data, SavedIndexParams(filename));
|
||||
remove( filename );
|
||||
createIndex( data, SavedIndexParams(filename.c_str()));
|
||||
remove( filename.c_str() );
|
||||
}
|
||||
|
||||
TEST(Features2d_LSH, regression) { CV_LSHTest test; test.safe_run(); }
|
||||
|
@ -153,7 +153,7 @@ install(FILES ${lib_hdrs}
|
||||
|
||||
# Test files processing is in the separated directory to avoid 'Src' source
|
||||
# filter creation in Visual Studio
|
||||
if(BUILD_TESTS AND NOT ANDROID AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
set(the_test_target "opencv_test_${name}")
|
||||
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
|
@ -183,16 +183,15 @@ CvCapture_OpenNI::CvCapture_OpenNI()
|
||||
// Write configuration to the temporary file.
|
||||
// This is a hack, because there is a bug in RunXmlScript().
|
||||
// TODO: remove hack when bug in RunXmlScript() will be fixed.
|
||||
char xmlFilename[100];
|
||||
tmpnam( xmlFilename );
|
||||
std::ofstream outfile( xmlFilename );
|
||||
string xmlFilename = tempfile();
|
||||
std::ofstream outfile( xmlFilename.c_str() );
|
||||
outfile.write( XMLConfig.c_str(), XMLConfig.length() );
|
||||
outfile.close();
|
||||
|
||||
status = context.RunXmlScriptFromFile( xmlFilename );
|
||||
status = context.RunXmlScriptFromFile( xmlFilename.c_str() );
|
||||
|
||||
// Remove temporary configuration file.
|
||||
remove( xmlFilename );
|
||||
remove( xmlFilename.c_str() );
|
||||
#else
|
||||
status = context.RunXmlScript( XMLConfig.c_str() );
|
||||
#endif
|
||||
|
@ -308,8 +308,8 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
|
||||
IplImage* image = 0;
|
||||
CvMat *matrix = 0;
|
||||
Mat temp, *data = &temp;
|
||||
char fnamebuf[L_tmpnam+1];
|
||||
const char* filename = 0;
|
||||
string filename = tempfile();
|
||||
bool removeTempFile = false;
|
||||
|
||||
ImageDecoder decoder = findDecoder(buf);
|
||||
if( decoder.empty() )
|
||||
@ -317,12 +317,10 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
|
||||
|
||||
if( !decoder->setSource(buf) )
|
||||
{
|
||||
filename = tmpnam(fnamebuf);
|
||||
if(filename[0] == '\\')
|
||||
filename++;
|
||||
FILE* f = fopen( filename, "wb" );
|
||||
FILE* f = fopen( filename.c_str(), "wb" );
|
||||
if( !f )
|
||||
return 0;
|
||||
removeTempFile = true;
|
||||
size_t bufSize = buf.cols*buf.rows*buf.elemSize();
|
||||
fwrite( &buf.data[0], 1, bufSize, f );
|
||||
fclose(f);
|
||||
@ -331,8 +329,8 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
|
||||
|
||||
if( !decoder->readHeader() )
|
||||
{
|
||||
if( filename )
|
||||
remove(filename);
|
||||
if( removeTempFile )
|
||||
remove(filename.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -373,8 +371,8 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
|
||||
}
|
||||
|
||||
bool code = decoder->readData( *data );
|
||||
if( filename )
|
||||
remove(filename);
|
||||
if( removeTempFile )
|
||||
remove(filename.c_str());
|
||||
|
||||
if( !code )
|
||||
{
|
||||
@ -425,15 +423,12 @@ bool imencode( const string& ext, const Mat& image,
|
||||
}
|
||||
else
|
||||
{
|
||||
char fnamebuf[L_tmpnam];
|
||||
const char* filename = tmpnam(fnamebuf);
|
||||
if(filename[0] == '\\')
|
||||
filename++;
|
||||
string filename = tempfile();
|
||||
code = encoder->setDestination(filename);
|
||||
CV_Assert( code );
|
||||
code = encoder->write(image, params);
|
||||
CV_Assert( code );
|
||||
FILE* f = fopen( filename, "rb" );
|
||||
FILE* f = fopen( filename.c_str(), "rb" );
|
||||
CV_Assert(f != 0);
|
||||
fseek( f, 0, SEEK_END );
|
||||
long pos = ftell(f);
|
||||
@ -441,7 +436,7 @@ bool imencode( const string& ext, const Mat& image,
|
||||
fseek( f, 0, SEEK_SET );
|
||||
buf.resize(fread( &buf[0], 1, buf.size(), f ));
|
||||
fclose(f);
|
||||
remove(filename);
|
||||
remove(filename.c_str());
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -68,9 +68,7 @@ struct TempDirHolder
|
||||
string temp_folder;
|
||||
TempDirHolder()
|
||||
{
|
||||
char* p = tmpnam(0);
|
||||
if(p[0] == '\\') p++;
|
||||
temp_folder = string(p);
|
||||
temp_folder = tempfile();
|
||||
exec_cmd("mkdir " + temp_folder);
|
||||
}
|
||||
~TempDirHolder() { exec_cmd("rm -rf " + temp_folder); }
|
||||
|
@ -23,10 +23,8 @@ protected:
|
||||
int checkPredictError(int test_num);
|
||||
int checkLoadSave();
|
||||
|
||||
//string model_file_name1;
|
||||
//string model_file_name2;
|
||||
char model_file_name1[50];
|
||||
char model_file_name2[50];
|
||||
string model_file_name1;
|
||||
string model_file_name2;
|
||||
string* datasets;
|
||||
string data_path;
|
||||
|
||||
@ -162,19 +160,14 @@ int CV_GBTreesTest::TestSaveLoad()
|
||||
if (!gtb)
|
||||
return cvtest::TS::FAIL_GENERIC;
|
||||
|
||||
tmpnam(model_file_name1);
|
||||
tmpnam(model_file_name2);
|
||||
model_file_name1 = cv::tempfile();
|
||||
model_file_name2 = cv::tempfile();
|
||||
|
||||
if(model_file_name1[0] == '\\')
|
||||
model_file_name1[0] = '_';
|
||||
if(model_file_name2[0] == '\\')
|
||||
model_file_name2[0] = '_';
|
||||
|
||||
gtb->save(model_file_name1);
|
||||
gtb->save(model_file_name1.c_str());
|
||||
gtb->calc_error(data, CV_TEST_ERROR, &test_resps1);
|
||||
gtb->load(model_file_name1);
|
||||
gtb->load(model_file_name1.c_str());
|
||||
gtb->calc_error(data, CV_TEST_ERROR, &test_resps2);
|
||||
gtb->save(model_file_name2);
|
||||
gtb->save(model_file_name2.c_str());
|
||||
|
||||
return checkLoadSave();
|
||||
|
||||
@ -187,7 +180,7 @@ int CV_GBTreesTest::checkLoadSave()
|
||||
int code = cvtest::TS::OK;
|
||||
|
||||
// 1. compare files
|
||||
ifstream f1( model_file_name1 ), f2( model_file_name2 );
|
||||
ifstream f1( model_file_name1.c_str() ), f2( model_file_name2.c_str() );
|
||||
string s1, s2;
|
||||
int lineIdx = 0;
|
||||
CV_Assert( f1.is_open() && f2.is_open() );
|
||||
@ -211,8 +204,8 @@ int CV_GBTreesTest::checkLoadSave()
|
||||
f1.close();
|
||||
f2.close();
|
||||
// delete temporary files
|
||||
remove( model_file_name1 );
|
||||
remove( model_file_name2 );
|
||||
remove( model_file_name1.c_str() );
|
||||
remove( model_file_name2.c_str() );
|
||||
|
||||
// 2. compare responses
|
||||
CV_Assert( test_resps1.size() == test_resps2.size() );
|
||||
|
@ -74,7 +74,7 @@ protected:
|
||||
virtual int validate_test_results( int testCaseIdx );
|
||||
|
||||
std::vector<float> test_resps1, test_resps2; // predicted responses for test data
|
||||
char fname1[50], fname2[50];
|
||||
std::string fname1, fname2;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -64,14 +64,12 @@ int CV_SLMLTest::run_test_case( int testCaseIdx )
|
||||
if( code == cvtest::TS::OK )
|
||||
{
|
||||
get_error( testCaseIdx, CV_TEST_ERROR, &test_resps1 );
|
||||
tmpnam(fname1);
|
||||
if(fname1[0] == '\\') fname1[0] = '_';
|
||||
save( fname1 );
|
||||
load( fname1);
|
||||
fname1 = tempfile();
|
||||
save( fname1.c_str() );
|
||||
load( fname1.c_str() );
|
||||
get_error( testCaseIdx, CV_TEST_ERROR, &test_resps2 );
|
||||
tmpnam(fname2);
|
||||
if(fname2[0] == '\\') fname2[0] = '_';
|
||||
save( fname2 );
|
||||
fname2 = tempfile();
|
||||
save( fname2.c_str() );
|
||||
}
|
||||
else
|
||||
ts->printf( cvtest::TS::LOG, "model can not be trained" );
|
||||
@ -84,7 +82,7 @@ int CV_SLMLTest::validate_test_results( int testCaseIdx )
|
||||
int code = cvtest::TS::OK;
|
||||
|
||||
// 1. compare files
|
||||
ifstream f1( fname1 ), f2( fname2 );
|
||||
ifstream f1( fname1.c_str() ), f2( fname2.c_str() );
|
||||
string s1, s2;
|
||||
int lineIdx = 0;
|
||||
CV_Assert( f1.is_open() && f2.is_open() );
|
||||
@ -108,8 +106,8 @@ int CV_SLMLTest::validate_test_results( int testCaseIdx )
|
||||
f1.close();
|
||||
f2.close();
|
||||
// delete temporary files
|
||||
remove( fname1 );
|
||||
remove( fname2 );
|
||||
remove( fname1.c_str() );
|
||||
remove( fname2.c_str() );
|
||||
|
||||
// 2. compare responses
|
||||
CV_Assert( test_resps1.size() == test_resps2.size() );
|
||||
|
@ -1 +1,13 @@
|
||||
#include "precomp.hpp"
|
||||
|
||||
#if ANDROID
|
||||
int wcscasecmp(const wchar_t* lhs, const wchar_t* rhs)
|
||||
{
|
||||
wint_t left, right;
|
||||
do {
|
||||
left = towlower(*lhs++);
|
||||
right = towlower(*rhs++);
|
||||
} while (left && left == right);
|
||||
return left == right;
|
||||
}
|
||||
#endif
|
||||
|
@ -6,3 +6,7 @@
|
||||
|
||||
#include "opencv2/ts/ts.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
|
||||
#if ANDROID
|
||||
int wcscasecmp(const wchar_t* lhs, const wchar_t* rhs);
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user