added GPU implementation of morphology functions (using NPP) and tests for it.
added npp_error function added check_and_treat_gpu_exception function for tests_gpu
This commit is contained in:
@@ -59,6 +59,7 @@ namespace cv
|
||||
namespace gpu
|
||||
{
|
||||
extern "C" void error( const char *error_string, const char *file, const int line, const char *func = "");
|
||||
extern "C" void npp_error( int error, const char *file, const int line, const char *func = "");
|
||||
|
||||
static inline void ___cudaSafeCall(cudaError_t err, const char *file, const int line, const char *func = "")
|
||||
{
|
||||
@@ -69,7 +70,7 @@ namespace cv
|
||||
static inline void ___nppSafeCall(NppStatus err, const char *file, const int line, const char *func = "")
|
||||
{
|
||||
if (err < 0)
|
||||
cv::gpu::error("NPP Error", file, line, func);
|
||||
cv::gpu::npp_error(err, file, line, func);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
143
modules/gpu/src/filtering_npp.cpp
Normal file
143
modules/gpu/src/filtering_npp.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
|
||||
#if !defined (HAVE_CUDA)
|
||||
|
||||
void cv::gpu::erode( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor, int iterations) { throw_nogpu(); }
|
||||
void cv::gpu::dilate( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor, int iterations) { throw_nogpu(); }
|
||||
void morphologyEx( const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, Point anchor, int iterations) { throw_nogpu(); }
|
||||
|
||||
#else
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef NppStatus (*npp_morf_func)(const Npp8u*, Npp32s, Npp8u*, Npp32s, NppiSize, const Npp8u*, NppiSize, NppiPoint);
|
||||
|
||||
|
||||
void morphoogy_caller(npp_morf_func func, const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor, int iterations)
|
||||
{
|
||||
CV_Assert(src.type() == CV_8U || src.type() == CV_8UC4);
|
||||
CV_Assert(kernel.isContinuous() && kernel.type() == CV_8U && (kernel.cols & 1) != 0 && (kernel.rows & 1) != 0);
|
||||
|
||||
// in NPP for Cuda 3.1 only such anchor is supported.
|
||||
CV_Assert(anchor.x == kernel.cols/2 && anchor.y == kernel.rows/2);
|
||||
|
||||
NppiSize sz;
|
||||
sz.width = src.cols;
|
||||
sz.height = dst.rows;
|
||||
|
||||
NppiSize mask_sz;
|
||||
mask_sz.width = kernel.cols;
|
||||
mask_sz.height = kernel.rows;
|
||||
|
||||
NppiPoint anc;
|
||||
anc.x = anchor.x;
|
||||
anc.y = anchor.y;
|
||||
|
||||
dst.create(src.size(), src.type());
|
||||
|
||||
for(int i = 0; i < iterations; ++i)
|
||||
nppSafeCall( func(src.ptr<Npp8u>(), src.step, dst.ptr<Npp8u>(), dst.step, sz, kernel.ptr<Npp8u>(), mask_sz, anc) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cv::gpu::erode( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor, int iterations)
|
||||
{
|
||||
static npp_morf_func funcs[] = {0, nppiErode_8u_C1R, 0, 0, nppiErode_8u_C4R };
|
||||
|
||||
morphoogy_caller(funcs[src.channels()], src, dst, kernel, anchor, iterations);
|
||||
}
|
||||
|
||||
void cv::gpu::dilate( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor, int iterations)
|
||||
{
|
||||
static npp_morf_func funcs[] = {0, nppiDilate_8u_C1R, 0, 0, nppiDilate_8u_C4R };
|
||||
morphoogy_caller(funcs[src.channels()], src, dst, kernel, anchor, iterations);
|
||||
}
|
||||
|
||||
void cv::gpu::morphologyEx( const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, Point anchor, int iterations)
|
||||
{
|
||||
GpuMat temp;
|
||||
switch( op )
|
||||
{
|
||||
case MORPH_ERODE: erode( src, dst, kernel, anchor, iterations); break;
|
||||
case MORPH_DILATE: dilate( src, dst, kernel, anchor, iterations); break;
|
||||
case MORPH_OPEN:
|
||||
erode( src, dst, kernel, anchor, iterations);
|
||||
dilate( dst, dst, kernel, anchor, iterations);
|
||||
break;
|
||||
case CV_MOP_CLOSE:
|
||||
dilate( src, dst, kernel, anchor, iterations);
|
||||
erode( dst, dst, kernel, anchor, iterations);
|
||||
break;
|
||||
case CV_MOP_GRADIENT:
|
||||
erode( src, temp, kernel, anchor, iterations);
|
||||
dilate( src, dst, kernel, anchor, iterations);
|
||||
subtract(dst, temp, dst);
|
||||
break;
|
||||
case CV_MOP_TOPHAT:
|
||||
if( src.data != dst.data )
|
||||
temp = dst;
|
||||
erode( src, temp, kernel, anchor, iterations);
|
||||
dilate( temp, temp, kernel, anchor, iterations);
|
||||
subtract(src, temp, dst);
|
||||
break;
|
||||
case CV_MOP_BLACKHAT:
|
||||
if( src.data != dst.data )
|
||||
temp = dst;
|
||||
dilate( src, temp, kernel, anchor, iterations);
|
||||
erode( temp, temp, kernel, anchor, iterations);
|
||||
dst = temp - src;
|
||||
subtract(temp, src, dst);
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "unknown morphological operation" );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
133
modules/gpu/src/npp_error.cpp
Normal file
133
modules/gpu/src/npp_error.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
|
||||
#if !defined (HAVE_CUDA)
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
struct NppError
|
||||
{
|
||||
int error;
|
||||
const char* str;
|
||||
}
|
||||
npp_errors [] =
|
||||
{
|
||||
{ NPP_NOT_SUPPORTED_MODE_ERROR, "NPP_NOT_SUPPORTED_MODE_ERROR" },
|
||||
{ NPP_ROUND_MODE_NOT_SUPPORTED_ERROR, "NPP_ROUND_MODE_NOT_SUPPORTED_ERROR" },
|
||||
{ NPP_RESIZE_NO_OPERATION_ERROR, "NPP_RESIZE_NO_OPERATION_ERROR" },
|
||||
{ NPP_BAD_ARG_ERROR, "NPP_BAD_ARG_ERROR" },
|
||||
{ NPP_LUT_NUMBER_OF_LEVELS_ERROR, "NPP_LUT_NUMBER_OF_LEVELS_ERROR" },
|
||||
{ NPP_TEXTURE_BIND_ERROR, "NPP_TEXTURE_BIND_ERROR" },
|
||||
{ NPP_COEFF_ERROR, "NPP_COEFF_ERROR" },
|
||||
{ NPP_RECT_ERROR, "NPP_RECT_ERROR" },
|
||||
{ NPP_QUAD_ERROR, "NPP_QUAD_ERROR" },
|
||||
{ NPP_WRONG_INTERSECTION_ROI_ERROR, "NPP_WRONG_INTERSECTION_ROI_ERROR" },
|
||||
{ NPP_NOT_EVEN_STEP_ERROR, "NPP_NOT_EVEN_STEP_ERROR" },
|
||||
{ NPP_INTERPOLATION_ERROR, "NPP_INTERPOLATION_ERROR" },
|
||||
{ NPP_RESIZE_FACTOR_ERROR, "NPP_RESIZE_FACTOR_ERROR" },
|
||||
{ NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR, "NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR" },
|
||||
{ NPP_MEMFREE_ERR, "NPP_MEMFREE_ERR" },
|
||||
{ NPP_MEMSET_ERR, "NPP_MEMSET_ERR" },
|
||||
{ NPP_MEMCPY_ERROR, "NPP_MEMCPY_ERROR" },
|
||||
{ NPP_MEM_ALLOC_ERR, "NPP_MEM_ALLOC_ERR" },
|
||||
{ NPP_HISTO_NUMBER_OF_LEVELS_ERROR, "NPP_HISTO_NUMBER_OF_LEVELS_ERROR" },
|
||||
{ NPP_MIRROR_FLIP_ERR, "NPP_MIRROR_FLIP_ERR" },
|
||||
{ NPP_INVALID_INPUT, "NPP_INVALID_INPUT" },
|
||||
{ NPP_ALIGNMENT_ERROR, "NPP_ALIGNMENT_ERROR" },
|
||||
{ NPP_STEP_ERROR, "NPP_STEP_ERROR" },
|
||||
{ NPP_SIZE_ERROR, "NPP_SIZE_ERROR" },
|
||||
{ NPP_POINTER_ERROR, "NPP_POINTER_ERROR" },
|
||||
{ NPP_NULL_POINTER_ERROR, "NPP_NULL_POINTER_ERROR" },
|
||||
{ NPP_CUDA_KERNEL_EXECUTION_ERROR, "NPP_CUDA_KERNEL_EXECUTION_ERROR" },
|
||||
{ NPP_NOT_IMPLEMENTED_ERROR, "NPP_NOT_IMPLEMENTED_ERROR" },
|
||||
{ NPP_ERROR, "NPP_ERROR" },
|
||||
{ NPP_NO_ERROR, "NPP_NO_ERROR" },
|
||||
{ NPP_SUCCESS, "NPP_SUCCESS" },
|
||||
{ NPP_WARNING, "NPP_WARNING" },
|
||||
{ NPP_WRONG_INTERSECTION_QUAD_WARNING, "NPP_WRONG_INTERSECTION_QUAD_WARNING" },
|
||||
{ NPP_MISALIGNED_DST_ROI_WARNING, "NPP_MISALIGNED_DST_ROI_WARNING" },
|
||||
{ NPP_AFFINE_QUAD_INCORRECT_WARNING, "NPP_AFFINE_QUAD_INCORRECT_WARNING" },
|
||||
{ NPP_AFFINE_QUAD_CHANGED_WARNING, "NPP_AFFINE_QUAD_CHANGED_WARNING" },
|
||||
{ NPP_ADJUSTED_ROI_SIZE_WARNING, "NPP_ADJUSTED_ROI_SIZE_WARNING" },
|
||||
{ NPP_DOUBLE_SIZE_WARNING, "NPP_DOUBLE_SIZE_WARNING" },
|
||||
{ NPP_ODD_ROI_WARNING, "NPP_ODD_ROI_WARNING" }
|
||||
};
|
||||
|
||||
int error_num = sizeof(npp_errors)/sizeof(npp_errors[0]);
|
||||
|
||||
struct Searcher
|
||||
{
|
||||
int err;
|
||||
Searcher(int err_) : err(err_) {};
|
||||
bool operator()(const NppError& e) const { return e.error == err; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace gpu
|
||||
{
|
||||
extern "C" const char* getNppErrorString( int err )
|
||||
{
|
||||
int idx = std::find_if(npp_errors, npp_errors + error_num, Searcher(err)) - npp_errors;
|
||||
|
||||
return (idx != error_num) ? npp_errors[idx].str : "";
|
||||
}
|
||||
|
||||
extern "C" void npp_error( int err, const char *file, const int line, const char *func)
|
||||
{
|
||||
cv::error( cv::Exception(CV_GpuNppCallError, getNppErrorString(err), func, file, line) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -53,6 +53,7 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
@@ -62,7 +63,7 @@
|
||||
#include "cuda_shared.hpp"
|
||||
#include "cuda_runtime_api.h"
|
||||
#include "opencv2/gpu/stream_accessor.hpp"
|
||||
#include "npp.h"
|
||||
#include "npp.h"
|
||||
|
||||
#else /* defined(HAVE_CUDA) */
|
||||
|
||||
|
Reference in New Issue
Block a user