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 #include "fasthessian.h"
00032 #ifndef ASRL_NONMAX_TEST_HPP
00033 #define ASRL_NONMAX_TEST_HPP
00034
00035 #include "GpuSurfOctave.hpp"
00036 #include "fasthessian.h"
00037 #include "GpuSurfDetectorInternal.hpp"
00038 #include "non_max_suppression.h"
00039 #include <opencv/highgui.h>
00040 #include <opencv/highgui.hpp>
00041 #include <boost/lexical_cast.hpp>
00042
00043
00044
00046 BOOST_AUTO_TEST_SUITE(asrl_non_max_suppression)
00047
00048 BOOST_AUTO_TEST_CASE(test_non_max_suppression)
00049 {
00050
00051
00052
00053
00054
00055
00056 int imwidth = 101;
00057 int imheight = 99;
00058
00059 const int nOctaves = 3;
00060 asrl::GpuSurfOctave olist[nOctaves];
00061 olist[0].init(imwidth, imheight, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 0, 1, 4);
00062 olist[1].init(imwidth, imheight, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1, 1, 4);
00063 olist[2].init(imwidth, imheight, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 2, 1, 4);
00064 init_globals(imwidth,imheight,olist,nOctaves);
00065
00066 asrl::CudaSynchronizedMemory<float> hessian;
00067 hessian.init(olist[0].stride() * olist[0].height() * olist[0].width() * olist[0].intervals());
00068
00069 asrl::GpuSurfFeatures features;
00070 features.featureCounterMem().pullFromDevice();
00071 BOOST_CHECK_EQUAL(features.featureCounterMem()[1],0);
00072 BOOST_CHECK_EQUAL(features.featureCounterMem()[0],0);
00073
00074
00075 float threshold = -0.1f;
00076
00077
00078
00079
00080 hessian.memset(0);
00081
00082 dim3 threads, grid;
00083 threads.x = 16;
00084 threads.y = 4;
00085 threads.z = olist[0].intervals();
00086
00087
00088 grid.x = ( (olist[0].width() + (threads.x-2) - 1) / (threads.x-2));
00089 grid.y = ( (olist[0].height() + (threads.y-2) - 1) / (threads.y-2));
00090 grid.z = 1;
00091 size_t sharedBytes = (threads.x+2)*threads.y*olist[0].intervals()*sizeof(float);
00092
00093 asrl::run_surf_nonmaxonly_kernel(grid, threads, sharedBytes, hessian.d_get(), 0, features.rawFeatureMem().d_get(), features.featureCounterMem().d_get() + 1, threshold);
00094
00095
00096 features.setDirty();
00097
00098 BOOST_CHECK_EQUAL(features.ftCount(),0);
00099 BOOST_CHECK_EQUAL(features.rawFeatureCount(),0);
00100
00101
00102
00103
00104
00105
00106
00107
00108 try {
00109 for(unsigned o = 0; o <nOctaves; o++)
00110 {
00111 asrl::GpuSurfOctave & octave = olist[o];
00112
00113 std::vector<cv::KeyPoint> keypoints;
00114 for(int i = 1; i < octave.intervals(); i++)
00115 {
00116 for(int r = 1; r < octave.height(); r++)
00117 {
00118 for(int c = 1; c < octave.width(); c++)
00119 {
00120 features.featureCounterMem().memset(0);
00121 hessian[c + olist[0].stride() * r + olist[0].stride() * octave.height() * i] = 1.f;
00122 hessian.pushToDevice();
00123
00124 grid.x = ( octave.width() + (threads.x-2) - 1) / (threads.x-2);
00125 grid.y = ( (octave.height() + (threads.y-2) - 1) / (threads.y-2));
00126 grid.z = 1;
00127
00128 asrl::run_surf_nonmaxonly_kernel(grid, threads, sharedBytes, hessian.d_get(), o, features.rawFeatureMem().d_get(), features.featureCounterMem().d_get() + 1, threshold);
00129 features.setDirty();
00130
00131 ASRL_ASSERT_EQ(features.ftCount(),0,"at location (" << o << "," << i << "," << r << "," << c << ")");
00132
00133 if(r == 0 || c == 0 || i == 0 ||
00134 i == octave.intervals() -1 ||
00135 r == octave.height() - 1 ||
00136 c == octave.width() - 1)
00137 {
00138 if(features.rawFeatureCount() != 0)
00139 {
00140 std::vector<cv::KeyPoint> keypoints;
00141 features.getRawKeypoints(keypoints);
00142 for(unsigned i = 0; i < keypoints.size(); i++)
00143 {
00144 cv::KeyPoint & k = keypoints[i];
00145 std::cout << "[" << i << "] (" << k.pt.x << "," << k.pt.y << ") x " << k.response << " -- " << k.octave << std::endl;
00146 }
00147 }
00148
00149 ASRL_ASSERT_EQ(features.rawFeatureCount(),0,"at location (" << o << "," << i << "," << r << "," << c << ")");
00150
00151 }
00152 else
00153 {
00154 ASRL_ASSERT_EQ(features.rawFeatureCount(),1,"at location (" << o << "," << i << "," << r << "," << c << ")");
00155 if(features.rawFeatureCount() == 1)
00156 {
00157
00158 keypoints.clear();
00159 features.getRawKeypoints(keypoints);
00160 ASRL_ASSERT_EQ(keypoints.size(),1,"at location (" << o << "," << i << "," << r << "," << c << ")");
00161 ASRL_ASSERT_EQ(keypoints[0].pt.x,c,"at location (" << o << "," << i << "," << r << "," << c << ")");
00162 ASRL_ASSERT_EQ(keypoints[0].pt.y,r,"at location (" << o << "," << i << "," << r << "," << c << ")");
00163 ASRL_ASSERT_EQ(keypoints[0].octave,o,"at location (" << o << "," << i << "," << r << "," << c << ")");
00164
00165 }
00166
00167 }
00168 features.clearFeatureCounts();
00169 hessian[c + olist[0].stride() * r + olist[0].stride() * octave.height() * i] = 0.f;
00170
00171 }
00172 }
00173 }
00174 }
00175 }
00176 catch(std::exception const & e)
00177 {
00178 BOOST_ERROR(e.what());
00179 }
00180
00181 if(features.rawFeatureCount() != 0)
00182 {
00183 std::vector<cv::KeyPoint> keypoints;
00184 features.getRawKeypoints(keypoints);
00185 for(unsigned i = 0; i < keypoints.size(); i++)
00186 {
00187 cv::KeyPoint & k = keypoints[i];
00188 std::cout << "[" << i << "] (" << k.pt.x << "," << k.pt.y << ") x " << k.response << " -- " << k.octave << std::endl;
00189 }
00190 }
00191
00192 }
00193
00194
00195 BOOST_AUTO_TEST_SUITE_END()
00196
00197 #endif // ASRL_NONMAX_TEST_HPP