fixed overflow bugs, updated perf tests
authorVladislav Vinogradov <vlad.vinogradov@itseez.com>
Tue, 14 Aug 2012 08:33:47 +0000 (12:33 +0400)
committerVladislav Vinogradov <vlad.vinogradov@itseez.com>
Tue, 14 Aug 2012 08:33:47 +0000 (12:33 +0400)
modules/gpu/perf/perf_imgproc.cpp
modules/gpu/perf_cpu/perf_imgproc.cpp
modules/gpu/src/cuda/hough.cu
modules/gpu/src/hough.cpp

index 77f6074..3baca6c 100644 (file)
@@ -1334,42 +1334,47 @@ INSTANTIATE_TEST_CASE_P(ImgProc, ImagePyramid_getLayer, testing::Combine(
 //////////////////////////////////////////////////////////////////////\r
 // HoughLines\r
 \r
-GPU_PERF_TEST(HoughLines, cv::gpu::DeviceInfo, std::string)\r
+IMPLEMENT_PARAM_CLASS(DoSort, bool)\r
+\r
+GPU_PERF_TEST(HoughLines, cv::gpu::DeviceInfo, cv::Size, DoSort)\r
 {\r
+    declare.time(30.0);\r
+\r
     const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);\r
     cv::gpu::setDevice(devInfo.deviceID());\r
-    const std::string fileName = GET_PARAM(1);\r
+    const cv::Size size = GET_PARAM(1);\r
+    const bool doSort = GET_PARAM(2);\r
 \r
     const float rho = 1.0f;\r
     const float theta = CV_PI / 180.0f;\r
     const int threshold = 300;\r
 \r
-    cv::Mat img_base = readImage(fileName, cv::IMREAD_GRAYSCALE);\r
-    ASSERT_FALSE(img_base.empty());\r
+    cv::RNG rng(123456789);\r
 \r
-    cv::Mat img;\r
-    cv::resize(img_base, img, cv::Size(1920, 1080));\r
+    cv::Mat src(size, CV_8UC1, cv::Scalar::all(0));\r
 \r
-    cv::Mat edges;\r
-    cv::Canny(img, edges, 50, 200);\r
+    const int numLines = rng.uniform(500, 2000);\r
+    for (int i = 0; i < numLines; ++i)\r
+    {\r
+        cv::Point p1(rng.uniform(0, src.cols), rng.uniform(0, src.rows));\r
+        cv::Point p2(rng.uniform(0, src.cols), rng.uniform(0, src.rows));\r
+        cv::line(src, p1, p2, cv::Scalar::all(255), 2);\r
+    }\r
 \r
-    cv::gpu::GpuMat d_edges(edges);\r
+    cv::gpu::GpuMat d_src(src);\r
     cv::gpu::GpuMat d_lines;\r
     cv::gpu::GpuMat d_accum;\r
-    cv::gpu::HoughLines(d_edges, d_lines, d_accum, rho, theta, threshold);\r
+    cv::gpu::HoughLines(d_src, d_lines, d_accum, rho, theta, threshold, doSort);\r
 \r
     TEST_CYCLE()\r
     {\r
-        cv::gpu::HoughLines(d_edges, d_lines, d_accum, rho, theta, threshold);\r
+        cv::gpu::HoughLines(d_src, d_lines, d_accum, rho, theta, threshold, doSort);\r
     }\r
 }\r
 \r
 INSTANTIATE_TEST_CASE_P(ImgProc, HoughLines, testing::Combine(\r
     ALL_DEVICES,\r
-    testing::Values(std::string("cv/shared/pic1.png"),\r
-                    std::string("cv/shared/pic3.png"),\r
-                    std::string("cv/shared/pic4.png"),\r
-                    std::string("cv/shared/pic5.png"),\r
-                    std::string("cv/shared/pic6.png"))));\r
+    GPU_TYPICAL_MAT_SIZES,\r
+    testing::Values(DoSort(false), DoSort(true))));\r
 \r
 #endif\r
index bc77646..1b3c095 100644 (file)
@@ -730,38 +730,42 @@ INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor, testing::Combine(
 //////////////////////////////////////////////////////////////////////\r
 // HoughLines\r
 \r
-GPU_PERF_TEST(HoughLines, cv::gpu::DeviceInfo, std::string)\r
+IMPLEMENT_PARAM_CLASS(DoSort, bool)\r
+\r
+GPU_PERF_TEST(HoughLines, cv::gpu::DeviceInfo, cv::Size, DoSort)\r
 {\r
-    const std::string fileName = GET_PARAM(1);\r
+    declare.time(30.0);\r
+\r
+    const cv::Size size = GET_PARAM(1);\r
 \r
     const float rho = 1.0f;\r
     const float theta = CV_PI / 180.0f;\r
     const int threshold = 300;\r
 \r
-    cv::Mat img_base = readImage(fileName, cv::IMREAD_GRAYSCALE);\r
-    ASSERT_FALSE(img_base.empty());\r
+    cv::RNG rng(123456789);\r
 \r
-    cv::Mat img;\r
-    cv::resize(img_base, img, cv::Size(1920, 1080));\r
+    cv::Mat src(size, CV_8UC1, cv::Scalar::all(0));\r
 \r
-    cv::Mat edges;\r
-    cv::Canny(img, edges, 50, 200);\r
+    const int numLines = rng.uniform(500, 2000);\r
+    for (int i = 0; i < numLines; ++i)\r
+    {\r
+        cv::Point p1(rng.uniform(0, src.cols), rng.uniform(0, src.rows));\r
+        cv::Point p2(rng.uniform(0, src.cols), rng.uniform(0, src.rows));\r
+        cv::line(src, p1, p2, cv::Scalar::all(255), 2);\r
+    }\r
 \r
     std::vector<cv::Vec2f> lines;\r
-    cv::HoughLines(edges, lines, rho, theta, threshold);\r
+    cv::HoughLines(src, lines, rho, theta, threshold);\r
 \r
     TEST_CYCLE()\r
     {\r
-        cv::HoughLines(edges, lines, rho, theta, threshold);\r
+        cv::HoughLines(src, lines, rho, theta, threshold);\r
     }\r
 }\r
 \r
 INSTANTIATE_TEST_CASE_P(ImgProc, HoughLines, testing::Combine(\r
     ALL_DEVICES,\r
-    testing::Values(std::string("cv/shared/pic1.png"),\r
-                    std::string("cv/shared/pic3.png"),\r
-                    std::string("cv/shared/pic4.png"),\r
-                    std::string("cv/shared/pic5.png"),\r
-                    std::string("cv/shared/pic6.png"))));\r
+    GPU_TYPICAL_MAT_SIZES,\r
+    testing::Values(DoSort(false), DoSort(true))));\r
 \r
 #endif\r
index 0a439f4..9f5cd65 100644 (file)
@@ -75,12 +75,12 @@ namespace cv { namespace gpu { namespace device
             }
         }
 
-        void linesAccum_gpu(DevMem2Db src, PtrStep_<uint> accum, float theta, int numangle, int numrho, float irho)
+        void linesAccum_gpu(DevMem2Db src, DevMem2D_<uint> accum, float rho, float theta)
         {
             const dim3 block(32, 8);
             const dim3 grid(divUp(src.cols, block.x), divUp(src.rows, block.y));
 
-            linesAccum<<<grid, block>>>(src, accum, theta, numangle, numrho, irho);
+            linesAccum<<<grid, block>>>(src, accum, theta, accum.rows - 2, accum.cols - 2, 1.0f / rho);
             cudaSafeCall( cudaGetLastError() );
 
             cudaSafeCall( cudaDeviceSynchronize() );
@@ -125,7 +125,7 @@ namespace cv { namespace gpu { namespace device
             }
         }
 
-        int linesGetResult_gpu(DevMem2D_<uint> accum, float2* out, int* voices, int maxSize, float threshold, float theta, float rho, bool doSort)
+        unsigned int linesGetResult_gpu(DevMem2D_<uint> accum, float2* out, int* voices, unsigned int maxSize, float rho, float theta, float threshold, bool doSort)
         {
             void* counter_ptr;
             cudaSafeCall( cudaGetSymbolAddress(&counter_ptr, g_counter) );
@@ -143,7 +143,9 @@ namespace cv { namespace gpu { namespace device
             uint total_count;
             cudaSafeCall( cudaMemcpy(&total_count, counter_ptr, sizeof(uint), cudaMemcpyDeviceToHost) );
 
-            if (doSort)
+            total_count = ::min(total_count, maxSize);
+
+            if (doSort && total_count > 0)
             {
                 thrust::device_ptr<float2> out_ptr(out);
                 thrust::device_ptr<int> voices_ptr(voices);
index 721e680..b577ca5 100644 (file)
@@ -46,8 +46,8 @@ namespace cv { namespace gpu { namespace device
 {
     namespace hough
     {
-        void linesAccum_gpu(DevMem2Db src, PtrStep_<uint> accum, float theta, int numangle, int numrho, float irho);
-        int linesGetResult_gpu(DevMem2D_<uint> accum, float2* out, int* voices, int maxSize, float threshold, float theta, float rho, bool doSort);
+        void linesAccum_gpu(DevMem2Db src, DevMem2D_<uint> accum, float rho, float theta);
+        unsigned int linesGetResult_gpu(DevMem2D_<uint> accum, float2* out, int* voices, unsigned int maxSize, float rho, float theta, float threshold, bool doSort);
     }
 }}}
 
@@ -59,12 +59,11 @@ void cv::gpu::HoughLinesTransform(const GpuMat& src, GpuMat& accum, float rho, f
 
     const int numangle = cvRound(CV_PI / theta);
     const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho);
-    const float irho = 1.0f / rho;
 
-    accum.create(numangle + 2, numrho + 2, CV_32SC1);
+    ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, accum);
     accum.setTo(cv::Scalar::all(0));
 
-    hough::linesAccum_gpu(src, accum, theta, numangle, numrho, irho);
+    hough::linesAccum_gpu(src, accum, rho, theta);
 }
 
 void cv::gpu::HoughLinesGet(const GpuMat& accum, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines)
@@ -73,11 +72,11 @@ void cv::gpu::HoughLinesGet(const GpuMat& accum, GpuMat& lines, float rho, float
 
     CV_Assert(accum.type() == CV_32SC1);
 
-    lines.create(2, maxLines, CV_32FC2);
-    int count = hough::linesGetResult_gpu(accum, lines.ptr<float2>(0), lines.ptr<int>(1), maxLines, threshold, theta, rho, doSort);
+    ensureSizeIsEnough(2, maxLines, CV_32FC2, lines);
+    unsigned int count = hough::linesGetResult_gpu(accum, lines.ptr<float2>(0), lines.ptr<int>(1), maxLines, rho, theta, threshold, doSort);
 
     if (count > 0)
-        lines.cols = std::min(count, maxLines);
+        lines.cols = count;
     else
         lines.release();
 }