Commit 60769f54 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

possibly repaired FAST test (however, FAST<7/12> and <5/8> could still do…

possibly repaired FAST test (however, FAST<7/12> and <5/8> could still do something different than described in the paper)
parent 6308be2c
...@@ -89,7 +89,7 @@ void FAST_t(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bo ...@@ -89,7 +89,7 @@ void FAST_t(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bo
if( i < img.rows - 3 ) if( i < img.rows - 3 )
{ {
j = 3; j = 3;
#if CV_SSE2 #if 0 //CV_SSE2
for(; j < img.cols - 16 - 3; j += 16, ptr += 16) for(; j < img.cols - 16 - 3; j += 16, ptr += 16)
{ {
__m128i m0, m1; __m128i m0, m1;
......
...@@ -46,58 +46,39 @@ The references are: ...@@ -46,58 +46,39 @@ The references are:
namespace cv namespace cv
{ {
void makeOffsets(int pixel[25], int row_stride, int patternSize) void makeOffsets(int pixel[25], int rowStride, int patternSize)
{ {
CV_Assert(pixel != 0); static const int offsets16[][2] =
switch(patternSize) { {
case 16: {0, 3}, { 1, 3}, { 2, 2}, { 3, 1}, { 3, 0}, { 3, -1}, { 2, -2}, { 1, -3},
pixel[0] = 0 + row_stride * 3; {0, -3}, {-1, -3}, {-2, -2}, {-3, -1}, {-3, 0}, {-3, 1}, {-2, 2}, {-1, 3}
pixel[1] = 1 + row_stride * 3; };
pixel[2] = 2 + row_stride * 2;
pixel[3] = 3 + row_stride * 1; static const int offsets12[][2] =
pixel[4] = 3 + row_stride * 0; {
pixel[5] = 3 + row_stride * -1; {0, 2}, { 1, 2}, { 2, 1}, { 2, 0}, { 2, -1}, { 1, -2},
pixel[6] = 2 + row_stride * -2; {0, -2}, {-1, -2}, {-2, -1}, {-2, 0}, {-2, 1}, {-1, 2}
pixel[7] = 1 + row_stride * -3; };
pixel[8] = 0 + row_stride * -3;
pixel[9] = -1 + row_stride * -3; static const int offsets8[][2] =
pixel[10] = -2 + row_stride * -2; {
pixel[11] = -3 + row_stride * -1; {0, 1}, { 1, 1}, { 1, 0}, { 1, -1},
pixel[12] = -3 + row_stride * 0; {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}
pixel[13] = -3 + row_stride * 1; };
pixel[14] = -2 + row_stride * 2;
pixel[15] = -1 + row_stride * 3; const int (*offsets)[2] = patternSize == 16 ? offsets16 :
break; patternSize == 12 ? offsets12 : patternSize == 8 ? offsets8 : 0;
case 12:
pixel[0] = 0 + row_stride * 2; CV_Assert(pixel != 0 && offsets);
pixel[1] = 1 + row_stride * 2;
pixel[2] = 2 + row_stride * 1; int k = 0;
pixel[3] = 2 + row_stride * 0; for( ; k < patternSize; k++ )
pixel[4] = 2 + row_stride * -1; pixel[k] = offsets[k][0] + offsets[k][1]*rowStride;
pixel[5] = 1 + row_stride * -2; for( ; k < 25; k++ )
pixel[6] = 0 + row_stride * -2; pixel[k] = pixel[k - patternSize];
pixel[7] = -1 + row_stride * -2;
pixel[8] = -2 + row_stride * -1;
pixel[9] = -2 + row_stride * 0;
pixel[10] = -2 + row_stride * 1;
pixel[11] = -1 + row_stride * 2;
break;
case 8:
pixel[0] = 0 + row_stride * 1;
pixel[1] = 1 + row_stride * 1;
pixel[2] = 1 + row_stride * 0;
pixel[3] = 1 + row_stride * -1;
pixel[4] = 0 + row_stride * -1;
pixel[5] = -1 + row_stride * -1;
pixel[6] = 0 + row_stride * 0;
pixel[7] = 1 + row_stride * 1;
break;
}
for(int k = patternSize; k < 25; k++)
pixel[k] = pixel[k - patternSize];
} }
/*static void testCorner(const uchar* ptr, const int pixel[], int K, int N, int threshold) { static void testCorner(const uchar* ptr, const int pixel[], int K, int N, int threshold) {
// check that with the computed "threshold" the pixel is still a corner // check that with the computed "threshold" the pixel is still a corner
// and that with the increased-by-1 "threshold" the pixel is not a corner anymore // and that with the increased-by-1 "threshold" the pixel is not a corner anymore
for( int delta = 0; delta <= 1; delta++ ) for( int delta = 0; delta <= 1; delta++ )
...@@ -129,12 +110,12 @@ void makeOffsets(int pixel[25], int row_stride, int patternSize) ...@@ -129,12 +110,12 @@ void makeOffsets(int pixel[25], int row_stride, int patternSize)
CV_Assert( (delta == 0 && std::max(c0, c1) > K) || CV_Assert( (delta == 0 && std::max(c0, c1) > K) ||
(delta == 1 && std::max(c0, c1) <= K) ); (delta == 1 && std::max(c0, c1) <= K) );
} }
}*/ }
template<> template<>
int cornerScore<16>(const uchar* ptr, const int pixel[], int threshold) int cornerScore<16>(const uchar* ptr, const int pixel[], int threshold)
{ {
const int K = 8, N = 16 + K + 1; const int K = 8, N = K*3 + 1;
int k, v = ptr[0]; int k, v = ptr[0];
short d[N]; short d[N];
for( k = 0; k < N; k++ ) for( k = 0; k < N; k++ )
...@@ -224,7 +205,7 @@ int cornerScore<16>(const uchar* ptr, const int pixel[], int threshold) ...@@ -224,7 +205,7 @@ int cornerScore<16>(const uchar* ptr, const int pixel[], int threshold)
template<> template<>
int cornerScore<12>(const uchar* ptr, const int pixel[], int threshold) int cornerScore<12>(const uchar* ptr, const int pixel[], int threshold)
{ {
const int K = 6, N = 12 + K + 1; const int K = 6, N = K*3 + 1;
int k, v = ptr[0]; int k, v = ptr[0];
short d[N]; short d[N];
for( k = 0; k < N; k++ ) for( k = 0; k < N; k++ )
...@@ -304,7 +285,7 @@ int cornerScore<12>(const uchar* ptr, const int pixel[], int threshold) ...@@ -304,7 +285,7 @@ int cornerScore<12>(const uchar* ptr, const int pixel[], int threshold)
template<> template<>
int cornerScore<8>(const uchar* ptr, const int pixel[], int threshold) int cornerScore<8>(const uchar* ptr, const int pixel[], int threshold)
{ {
const int K = 4, N = 8 + K + 1; const int K = 4, N = K*3 + 1;
int k, v = ptr[0]; int k, v = ptr[0];
short d[N]; short d[N];
for( k = 0; k < N; k++ ) for( k = 0; k < N; k++ )
......
...@@ -61,7 +61,7 @@ void CV_FastTest::run( int ) ...@@ -61,7 +61,7 @@ void CV_FastTest::run( int )
for(int type=0; type <= 2; ++type) { for(int type=0; type <= 2; ++type) {
Mat image1 = imread(string(ts->get_data_path()) + "inpaint/orig.jpg"); Mat image1 = imread(string(ts->get_data_path()) + "inpaint/orig.jpg");
Mat image2 = imread(string(ts->get_data_path()) + "cameracalibration/chess9.jpg"); Mat image2 = imread(string(ts->get_data_path()) + "cameracalibration/chess9.jpg");
string xml = string(ts->get_data_path()) + "fast/result.xml"; string xml = string(ts->get_data_path()) + format("fast/result%d.xml", type);
if (image1.empty() || image2.empty()) if (image1.empty() || image2.empty())
{ {
...@@ -76,7 +76,7 @@ void CV_FastTest::run( int ) ...@@ -76,7 +76,7 @@ void CV_FastTest::run( int )
vector<KeyPoint> keypoints1; vector<KeyPoint> keypoints1;
vector<KeyPoint> keypoints2; vector<KeyPoint> keypoints2;
FAST(gray1, keypoints1, 30, true, type); FAST(gray1, keypoints1, 30, true, type);
FAST(gray2, keypoints2, 30, true, type); FAST(gray2, keypoints2, (type > 0 ? 30 : 20), true, type);
for(size_t i = 0; i < keypoints1.size(); ++i) for(size_t i = 0; i < keypoints1.size(); ++i)
{ {
...@@ -97,27 +97,32 @@ void CV_FastTest::run( int ) ...@@ -97,27 +97,32 @@ void CV_FastTest::run( int )
if (!fs.isOpened()) if (!fs.isOpened())
{ {
fs.open(xml, FileStorage::WRITE); fs.open(xml, FileStorage::WRITE);
if (!fs.isOpened())
{
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
return;
}
fs << "exp_kps1" << kps1; fs << "exp_kps1" << kps1;
fs << "exp_kps2" << kps2; fs << "exp_kps2" << kps2;
fs.release(); fs.release();
}
if (!fs.isOpened())
fs.open(xml, FileStorage::READ); fs.open(xml, FileStorage::READ);
if (!fs.isOpened())
{
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
return;
}
}
Mat exp_kps1, exp_kps2; Mat exp_kps1, exp_kps2;
read( fs["exp_kps1"], exp_kps1, Mat() ); read( fs["exp_kps1"], exp_kps1, Mat() );
read( fs["exp_kps2"], exp_kps2, Mat() ); read( fs["exp_kps2"], exp_kps2, Mat() );
fs.release(); fs.release();
// We only have testing data for 9_16 but it actually works equally well for 7_12 if ( exp_kps1.size != kps1.size || 0 != norm(exp_kps1, kps1, NORM_L2) ||
if ((type==1) || (type==2)){ exp_kps2.size != kps2.size || 0 != norm(exp_kps2, kps2, NORM_L2))
if ( exp_kps1.size != kps1.size || 0 != norm(exp_kps1, kps1, NORM_L2) || {
exp_kps2.size != kps2.size || 0 != norm(exp_kps2, kps2, NORM_L2)) ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
{ return;
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
return;
}
} }
/*cv::namedWindow("Img1"); cv::imshow("Img1", image1); /*cv::namedWindow("Img1"); cv::imshow("Img1", image1);
......
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