00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef ASRL_SURF_TESTS_HPP
00032 #define ASRL_SURF_TESTS_HPP
00033
00034 #include "GpuSurfOctave.hpp"
00035 #include "fasthessian.h"
00036 #include "GpuSurfDetectorInternal.hpp"
00037 #include <opencv/highgui.h>
00038 #include <opencv/highgui.hpp>
00039 #include <boost/lexical_cast.hpp>
00040 #include "gpu_utils.h"
00041
00042 bool interesting(cv::KeyPoint const & lhs, cv::KeyPoint const & rhs)
00043 {
00044 return lhs.response > rhs.response;
00045 }
00046
00047 void load_keypoints(std::string const & inputKeypointFile, std::vector<cv::KeyPoint> & inKeypoints, std::vector<float> & inDescriptors, int imRows, int imCols)
00048 {
00049 std::ifstream fin(inputKeypointFile.c_str());
00050 ASRL_ASSERT(fin.good(),"Unable to open keypoint file " << inputKeypointFile << " for reading");
00051
00052
00053 std::string line;
00054 std::getline(fin,line);
00055 int i = 1;
00056 while(!fin.eof())
00057 {
00058 std::istringstream lin(line);
00059 cv::KeyPoint k;
00060 lin >> k.pt.x;
00061 lin >> k.pt.y;
00062 lin >> k.size;
00063 lin >> k.response;
00064 lin >> k.angle;
00065 lin >> k.octave;
00066 int laplacian;
00067 lin >> laplacian;
00068 if(laplacian == 1)
00069 {
00070 setLastBit(k.response);
00071 }
00072 else
00073 {
00074 clearLastBit(k.response);
00075 }
00076
00077 ASRL_ASSERT_GE_LT(k.pt.x,0,imCols,"Keypoint " << i << " is out of bounds");
00078 ASRL_ASSERT_GE_LT(k.pt.y,0,imRows,"Keypoint " << i << " is out of bounds");
00079 ASRL_ASSERT_GE_LT(k.angle,-3.15,3.15,"Keypoint " << i << " angle is out of bounds");
00080 ASRL_ASSERT_GE_LT(k.size,1,100,"Keypoint " << i << " size is out of bounds");
00081 inKeypoints.push_back(k);
00082
00083 for(int d = 0; d < 64; d++)
00084 {
00085 float di;
00086 lin >> di;
00087 ASRL_ASSERT(lin.good(),"Problem getting data from the string stream");
00088 inDescriptors.push_back(di);
00089 }
00090
00091 std::getline(fin,line);
00092 i++;
00093 }
00094 }
00095
00097 BOOST_AUTO_TEST_SUITE(asrl_surf)
00098
00099 BOOST_AUTO_TEST_CASE(test_surf)
00100 {
00101
00102
00103 cv::Mat img = cv::imread("../testdata/seq-lt-g-000001.pgm",CV_LOAD_IMAGE_GRAYSCALE);
00104 asrl::GpuSurfConfiguration config;
00105
00106 asrl::GpuSurfDetectorInternal detector(config);
00107
00108 detector.buildIntegralImage(img);
00109 detector.detectKeypoints();
00110 detector.findOrientationFast();
00111 detector.computeDescriptors();
00112
00113 std::vector<cv::KeyPoint> kpGpu;
00114 detector.getKeypoints(kpGpu);
00115
00116 for(int i = 0; i < kpGpu.size(); i++) kpGpu[i].octave = i;
00117 std::sort(kpGpu.begin(), kpGpu.end(), &interesting);
00118
00119 std::vector<float> dsGpu;
00120 detector.getDescriptors(dsGpu);
00121
00122 std::vector<cv::KeyPoint> kpFile;
00123 std::vector<float> dsFile;
00124 load_keypoints("../testdata/seq-lt-g-000001-gpusurf.key", kpFile, dsFile, img.rows, img.cols);
00125
00126 for(int i = 0; i < kpFile.size(); i++) kpFile[i].octave = i;
00127 std::sort(kpFile.begin(),kpFile.end(), &interesting);
00128
00129 double tolerance = 0.001;
00130 BOOST_REQUIRE_EQUAL(kpGpu.size(),kpFile.size());
00131 BOOST_REQUIRE_EQUAL(dsGpu.size(),dsFile.size());
00132 BOOST_REQUIRE_EQUAL(dsGpu.size(),kpGpu.size()*64);
00133
00134 for(int i = 0; i < kpFile.size(); i++)
00135 {
00136 try{
00137 ASRL_ASSERT_EQ_TOL(kpGpu[i].pt.x, kpFile[i].pt.x, tolerance, "deviation from reference keypoint. i = " << i);
00138 ASRL_ASSERT_EQ_TOL(kpGpu[i].pt.y, kpFile[i].pt.y, tolerance, "deviation from reference keypoint. i = " << i);
00139 ASRL_ASSERT_EQ_TOL(kpGpu[i].response, kpFile[i].response, tolerance, "deviation from reference keypoint. i = " << i);
00140 ASRL_ASSERT_EQ_TOL(kpGpu[i].angle, kpFile[i].angle, tolerance, "deviation from reference keypoint. i = " << i);
00141 ASRL_ASSERT_EQ_TOL(kpGpu[i].size, kpFile[i].size, tolerance, "deviation from reference keypoint. i = " << i);
00142 ASRL_ASSERT_EQ(isLastBitSet(kpGpu[i].response), isLastBitSet(kpFile[i].response), "deviation from reference keypoint. i = " << i);
00143
00144 int gpuOffset = kpGpu[i].octave*64;
00145 int fileOffset = kpFile[i].octave*64;
00146 for(int d = 0; d < 64; d++)
00147 {
00148 ASRL_ASSERT_EQ_TOL(dsGpu[gpuOffset + d],dsFile[fileOffset + d], tolerance, "Descriptor mismatch, feature " << i << ", component " << d);
00149 }
00150
00151 }
00152 catch(std::exception const & e)
00153 {
00154 BOOST_ERROR(e.what());
00155 }
00156 }
00157
00158
00159
00160
00161 }
00162
00163 BOOST_AUTO_TEST_SUITE_END()
00164
00165 #endif // ASRL_SURF_TESTS_HPP