Commit 9221c575 authored by Maria Dimashova's avatar Maria Dimashova

fixed acalonder test for Win

parent 3bd00085
...@@ -41,13 +41,13 @@ ...@@ -41,13 +41,13 @@
//M*/ //M*/
#include "cvtest.h" #include "cvtest.h"
#include <fstream>
#include <iostream>
using namespace cv; using namespace cv;
using namespace std; using namespace std;
#define GET_RES 0 #define WRITE_KEYPOINTS 0
#define WRITE_DESCRIPTORS 0
class CV_CalonderTest : public CvTest class CV_CalonderTest : public CvTest
{ {
public: public:
...@@ -58,26 +58,29 @@ protected: ...@@ -58,26 +58,29 @@ protected:
void writeMatInBin( const Mat& mat, const string& filename ) void writeMatInBin( const Mat& mat, const string& filename )
{ {
ofstream os( filename.c_str() ); FILE* f = fopen( filename.c_str(), "wb");
int type = mat.type(); int type = mat.type();
os.write( (char*)&mat.rows, sizeof(int) ); fwrite( (void*)&mat.rows, sizeof(int), 1, f );
os.write( (char*)&mat.cols, sizeof(int) ); fwrite( (void*)&mat.cols, sizeof(int), 1, f );
os.write( (char*)&type, sizeof(int) ); fwrite( (void*)&type, sizeof(int), 1, f );
os.write( (char*)&mat.step, sizeof(int) ); fwrite( (void*)&mat.step, sizeof(int), 1, f );
os.write( (char*)mat.data, mat.step*mat.rows ); fwrite( (void*)mat.data, 1, mat.step*mat.rows, f );
fclose(f);
} }
Mat readMatFromBin( const string& filename ) Mat readMatFromBin( const string& filename )
{ {
ifstream is( filename.c_str() ); FILE* f = fopen( filename.c_str(), "rb" );
int rows, cols, type, step; int rows, cols, type, step;
is.read( (char*)&rows, sizeof(int) ); fread( (void*)&rows, sizeof(int), 1, f );
is.read( (char*)&cols, sizeof(int) ); fread( (void*)&cols, sizeof(int), 1, f );
is.read( (char*)&type, sizeof(int) ); fread( (void*)&type, sizeof(int), 1, f );
is.read( (char*)&step, sizeof(int) ); fread( (void*)&step, sizeof(int), 1, f );
uchar* data = (uchar*)cvAlloc(step*rows); uchar* data = (uchar*)cvAlloc(step*rows);
is.read( (char*)data, step*rows ); fread( (void*)data, 1, step*rows, f );
fclose(f);
return Mat( rows, cols, type, data ); return Mat( rows, cols, type, data );
} }
...@@ -93,7 +96,7 @@ void CV_CalonderTest::run(int) ...@@ -93,7 +96,7 @@ void CV_CalonderTest::run(int)
} }
vector<KeyPoint> keypoints; vector<KeyPoint> keypoints;
#if GET_RES #if WRITE_KEYPOINTS
FastFeatureDetector fd; FastFeatureDetector fd;
fd.detect(img, keypoints); fd.detect(img, keypoints);
...@@ -117,7 +120,7 @@ void CV_CalonderTest::run(int) ...@@ -117,7 +120,7 @@ void CV_CalonderTest::run(int)
ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA ); ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
return; return;
} }
#endif //GET_RES #endif //WRITE_KEYPOINTS
CalonderDescriptorExtractor<float> fde(dir + "/classifier.rtc"); CalonderDescriptorExtractor<float> fde(dir + "/classifier.rtc");
...@@ -127,16 +130,16 @@ void CV_CalonderTest::run(int) ...@@ -127,16 +130,16 @@ void CV_CalonderTest::run(int)
t = getTickCount() - t; t = getTickCount() - t;
ts->printf(CvTS::LOG, "\nAverage time of computiting float descriptor = %g ms\n", t/((double)cvGetTickFrequency()*1000.)/fdescriptors.rows ); ts->printf(CvTS::LOG, "\nAverage time of computiting float descriptor = %g ms\n", t/((double)cvGetTickFrequency()*1000.)/fdescriptors.rows );
#if GET_RES #if WRITE_DESCRIPTORS
assert(fdescriptors.type() == CV_32FC1); assert(fdescriptors.type() == CV_32FC1);
writeMatInBin( fdescriptors, "" ); writeMatInBin( fdescriptors, dir + "/ros_float_desc" );
#else #else
Mat ros_fdescriptors = readMatFromBin( dir + "/ros_float_desc" ); Mat ros_fdescriptors = readMatFromBin( dir + "/ros_float_desc" );
double fnorm = norm(fdescriptors, ros_fdescriptors, NORM_INF ); double fnorm = norm(fdescriptors, ros_fdescriptors, NORM_INF );
ts->printf(CvTS::LOG, "nofm (inf) BTW valid and calculated float descriptors = %f\n", fnorm ); ts->printf(CvTS::LOG, "nofm (inf) BTW valid and calculated float descriptors = %f\n", fnorm );
if( fnorm > FLT_EPSILON ) if( fnorm > FLT_EPSILON )
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY ); ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
#endif // GET_RES #endif // WRITE_DESCRIPTORS
CalonderDescriptorExtractor<uchar> cde(dir + "/classifier.rtc"); CalonderDescriptorExtractor<uchar> cde(dir + "/classifier.rtc");
Mat cdescriptors; Mat cdescriptors;
...@@ -145,16 +148,16 @@ void CV_CalonderTest::run(int) ...@@ -145,16 +148,16 @@ void CV_CalonderTest::run(int)
t = getTickCount() - t; t = getTickCount() - t;
ts->printf(CvTS::LOG, "Average time of computiting uchar descriptor = %g ms\n", t/((double)cvGetTickFrequency()*1000.)/cdescriptors.rows ); ts->printf(CvTS::LOG, "Average time of computiting uchar descriptor = %g ms\n", t/((double)cvGetTickFrequency()*1000.)/cdescriptors.rows );
#if GET_RES #if WRITE_DESCRIPTORS
assert(cdescriptors.type() == CV_8UC1); assert(cdescriptors.type() == CV_8UC1);
writeMatInBin( fdescriptors, "" ); writeMatInBin( cdescriptors, dir + "/ros_uchar_desc" );
#else #else
Mat ros_cdescriptors = readMatFromBin( dir + "/ros_uchar_desc" ); Mat ros_cdescriptors = readMatFromBin( dir + "/ros_uchar_desc" );
double cnorm = norm(cdescriptors, ros_cdescriptors, NORM_INF ); double cnorm = norm(cdescriptors, ros_cdescriptors, NORM_INF );
ts->printf(CvTS::LOG, "nofm (inf) BTW valid and calculated uchar descriptors = %f\n", cnorm ); ts->printf(CvTS::LOG, "nofm (inf) BTW valid and calculated uchar descriptors = %f\n", cnorm );
if( cnorm > FLT_EPSILON + 1 ) // + 1 because of quantization float to uchar if( cnorm > FLT_EPSILON + 1 ) // + 1 because of quantization float to uchar
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY ); ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
#endif // GET_RES #endif // WRITE_DESCRIPTORS
} }
#if CV_SSE2 #if CV_SSE2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment