fixed bug in gpu::cornerHarris and gpu::cornerMinEigenVal

This commit is contained in:
Alexey Spizhevoy 2010-12-01 10:00:47 +00:00
parent db5cce885d
commit d9489bbe0c
2 changed files with 41 additions and 23 deletions

View File

@ -478,10 +478,13 @@ namespace cv { namespace gpu { namespace imgproc
float b = 0.f;
float c = 0.f;
const unsigned int j_begin = max(x - block_size, 0);
const unsigned int i_begin = max(y - block_size, 0);
const unsigned int j_end = min(x + block_size + 1, cols);
const unsigned int i_end = min(y + block_size + 1, rows);
int offset1 = -(block_size / 2);
int offset2 = offset1 + block_size;
unsigned int j_begin = max(x + offset1, 0);
unsigned int i_begin = max(y + offset1, 0);
unsigned int j_end = min(x + offset2, cols);
unsigned int i_end = min(y + offset2, rows);
for (unsigned int i = i_begin; i < i_end; ++i)
{
@ -509,7 +512,7 @@ namespace cv { namespace gpu { namespace imgproc
dim3 threads(32, 8);
dim3 grid(divUp(cols, threads.x), divUp(rows, threads.y));
cornerHarris_kernel<<<grid, threads>>>(cols, rows, block_size / 2, k, Dx, Dy, dst);
cornerHarris_kernel<<<grid, threads>>>(cols, rows, block_size, k, Dx, Dy, dst);
cudaSafeCall(cudaThreadSynchronize());
}
@ -527,10 +530,13 @@ namespace cv { namespace gpu { namespace imgproc
float b = 0.f;
float c = 0.f;
const unsigned int j_begin = max(x - block_size, 0);
const unsigned int i_begin = max(y - block_size, 0);
const unsigned int j_end = min(x + block_size + 1, cols);
const unsigned int i_end = min(y + block_size + 1, rows);
int offset1 = -(block_size / 2);
int offset2 = offset1 + block_size;
unsigned int j_begin = max(x + offset1, 0);
unsigned int i_begin = max(y + offset1, 0);
unsigned int j_end = min(x + offset2, cols);
unsigned int i_end = min(y + offset2, rows);
for (unsigned int i = i_begin; i < i_end; ++i)
{
@ -560,7 +566,7 @@ namespace cv { namespace gpu { namespace imgproc
dim3 threads(32, 8);
dim3 grid(divUp(cols, threads.x), divUp(rows, threads.y));
cornerMinEigenVal_kernel<<<grid, threads>>>(cols, rows, block_size / 2, Dx, Dy, dst);
cornerMinEigenVal_kernel<<<grid, threads>>>(cols, rows, block_size, Dx, Dy, dst);
cudaSafeCall(cudaThreadSynchronize());
}
}}}

View File

@ -614,12 +614,11 @@ struct CV_GpuCornerHarrisTest: CvTest
{
try
{
int rows = 1 + rand() % 300, cols = 1 + rand() % 300;
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, -1)) return;
for (int i = 0; i < 3; ++i)
for (int i = 0; i < 5; ++i)
{
rows = 1 + rand() % 300; cols = 1 + rand() % 300;
int rows = 1 + rand() % 300, cols = 1 + rand() % 300;
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, 1 + 2 * (rand() % 4))) return;
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, -1)) return;
}
}
catch (const Exception& e)
@ -645,14 +644,21 @@ struct CV_GpuCornerHarrisTest: CvTest
cv::gpu::GpuMat dst;
cv::gpu::cornerHarris(cv::gpu::GpuMat(src), dst, blockSize, apertureSize, k);
int asize = apertureSize > 0 ? apertureSize : 3;
cv::Mat dsth = dst;
for (int i = apertureSize + 2; i < dst.rows - apertureSize - 2; ++i)
for (int i = max(blockSize, asize) + 2; i < dst.rows - max(blockSize, asize) - 2; ++i)
{
for (int j = apertureSize + 2; j < dst.cols - apertureSize - 2; ++j)
for (int j = max(blockSize, asize) + 2; j < dst.cols - max(blockSize, asize) - 2; ++j)
{
float a = dst_gold.at<float>(i, j);
float b = dsth.at<float>(i, j);
if (fabs(a - b) > 1e-3f) return false;
if (fabs(a - b) > 1e-3f)
{
ts->printf(CvTS::CONSOLE, "%d %d %f %f %d\n", i, j, a, b, apertureSize);
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
return false;
};
}
}
return true;
@ -670,11 +676,10 @@ struct CV_GpuCornerMinEigenValTest: CvTest
{
try
{
int rows = 1 + rand() % 300, cols = 1 + rand() % 300;
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, -1)) return;
for (int i = 0; i < 3; ++i)
{
rows = 1 + rand() % 300; cols = 1 + rand() % 300;
int rows = 1 + rand() % 300, cols = 1 + rand() % 300;
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, -1)) return;
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, 1 + 2 * (rand() % 4))) return;
}
}
@ -700,14 +705,21 @@ struct CV_GpuCornerMinEigenValTest: CvTest
cv::gpu::GpuMat dst;
cv::gpu::cornerMinEigenVal(cv::gpu::GpuMat(src), dst, blockSize, apertureSize);
int asize = apertureSize > 0 ? apertureSize : 3;
cv::Mat dsth = dst;
for (int i = apertureSize + 2; i < dst.rows - apertureSize - 2; ++i)
for (int i = max(blockSize, asize) + 2; i < dst.rows - max(blockSize, asize) - 2; ++i)
{
for (int j = apertureSize + 2; j < dst.cols - apertureSize - 2; ++j)
for (int j = max(blockSize, asize) + 2; j < dst.cols - max(blockSize, asize) - 2; ++j)
{
float a = dst_gold.at<float>(i, j);
float b = dsth.at<float>(i, j);
if (fabs(a - b) > 1e-3f) return false;
if (fabs(a - b) > 1e-3f)
{
ts->printf(CvTS::CONSOLE, "%d %d %f %f %d %d\n", i, j, a, b, apertureSize, blockSize);
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
return false;
};
}
}
return true;