diff --git a/modules/gpu/src/border_interpolate.cpp b/modules/gpu/src/border_interpolate.cpp new file mode 100644 index 000000000..dbd839451 --- /dev/null +++ b/modules/gpu/src/border_interpolate.cpp @@ -0,0 +1,63 @@ +/*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 "internal_common.hpp" +#include "border_interpolate.hpp" +#include "opencv2/gpu/gpu.hpp" + + +bool cv::gpu::tryConvertToGpuBorderType(int cpuBorderType, int& gpuBorderType) +{ + if (cpuBorderType == cv::BORDER_REFLECT101) + { + gpuBorderType = cv::gpu::BORDER_REFLECT101; + return true; + } + + if (cpuBorderType == cv::BORDER_REPLICATE) + { + gpuBorderType = cv::gpu::BORDER_REPLICATE; + return true; + } + + return false; +} \ No newline at end of file diff --git a/modules/gpu/src/border_interpolate.hpp b/modules/gpu/src/border_interpolate.hpp new file mode 100644 index 000000000..64a9fcd3d --- /dev/null +++ b/modules/gpu/src/border_interpolate.hpp @@ -0,0 +1,56 @@ +/*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*/ + +#ifndef __OPENCV_GPU_BORDER_INTERPOLATE_HPP__ +#define __OPENCV_GPU_BORDER_INTERPOLATE_HPP__ + +#include "border_interpolate.hpp" + +namespace cv { namespace gpu { + + // Converts CPU border extrapolation mode into GPU internal analogue. + // Returns true if the GPU analogue exists, false otherwise. + bool tryConvertToGpuBorderType(int cpuBorderType, int& gpuBorderType); + +}} + +#endif \ No newline at end of file diff --git a/modules/gpu/src/cuda/border_interpolate.hpp b/modules/gpu/src/cuda/border_interpolate.hpp index ec8f474ef..3dad03eb4 100644 --- a/modules/gpu/src/cuda/border_interpolate.hpp +++ b/modules/gpu/src/cuda/border_interpolate.hpp @@ -28,7 +28,7 @@ // 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 bpied warranties, including, but not limited to, the bpied +// 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 @@ -40,6 +40,11 @@ // //M*/ +#ifndef __OPENCV_GPU_BORDER_INTERPOLATE_HPP__ +#define __OPENCV_GPU_BORDER_INTERPOLATE_HPP__ + +#include "../internal_common.hpp" + namespace cv { namespace gpu { struct BrdReflect101 @@ -169,4 +174,6 @@ namespace cv { namespace gpu { int step; }; -}} \ No newline at end of file +}} + +#endif \ No newline at end of file diff --git a/modules/gpu/src/cuda/cuda_shared.hpp b/modules/gpu/src/cuda/cuda_shared.hpp index 0b82f8bc7..600fb08ca 100644 --- a/modules/gpu/src/cuda/cuda_shared.hpp +++ b/modules/gpu/src/cuda/cuda_shared.hpp @@ -95,13 +95,6 @@ namespace cv cudaSafeCall( cudaUnbindTexture(tex) ); } - // Available GPU border interpolation modes (named as CPU - // border interpolation modes) - enum - { - BORDER_REFLECT101 = 0, - BORDER_REPLICATE - }; } } diff --git a/modules/gpu/src/cuda/imgproc.cu b/modules/gpu/src/cuda/imgproc.cu index 8d43ac6a1..f85e03fdc 100644 --- a/modules/gpu/src/cuda/imgproc.cu +++ b/modules/gpu/src/cuda/imgproc.cu @@ -42,7 +42,6 @@ #include "cuda_shared.hpp" #include "border_interpolate.hpp" -#include using namespace cv::gpu; diff --git a/modules/gpu/src/imgproc_gpu.cpp b/modules/gpu/src/imgproc_gpu.cpp index 712956a63..2118c4d3b 100644 --- a/modules/gpu/src/imgproc_gpu.cpp +++ b/modules/gpu/src/imgproc_gpu.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "border_interpolate.hpp" using namespace cv; using namespace cv::gpu; @@ -940,18 +941,11 @@ namespace void cv::gpu::cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType) { + CV_Assert(borderType == cv::BORDER_REFLECT101 || + borderType == cv::BORDER_REPLICATE); + int gpuBorderType; - switch (borderType) - { - case cv::BORDER_REFLECT101: - gpuBorderType = cv::gpu::BORDER_REFLECT101; - break; - case cv::BORDER_REPLICATE: - gpuBorderType = cv::gpu::BORDER_REPLICATE; - break; - default: - CV_Error(CV_StsBadArg, "cornerHarris: unsupported border extrapolation mode"); - } + CV_Assert(tryConvertToGpuBorderType(borderType, gpuBorderType)); GpuMat Dx, Dy; extractCovData(src, Dx, Dy, blockSize, ksize, gpuBorderType); @@ -961,18 +955,11 @@ void cv::gpu::cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ks void cv::gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType) { + CV_Assert(borderType == cv::BORDER_REFLECT101 || + borderType == cv::BORDER_REPLICATE); + int gpuBorderType; - switch (borderType) - { - case cv::BORDER_REFLECT101: - gpuBorderType = cv::gpu::BORDER_REFLECT101; - break; - case cv::BORDER_REPLICATE: - gpuBorderType = cv::gpu::BORDER_REPLICATE; - break; - default: - CV_Error(CV_StsBadArg, "cornerMinEigenVal: unsupported border extrapolation mode"); - } + CV_Assert(tryConvertToGpuBorderType(borderType, gpuBorderType)); GpuMat Dx, Dy; extractCovData(src, Dx, Dy, blockSize, ksize, gpuBorderType); diff --git a/modules/gpu/src/internal_common.hpp b/modules/gpu/src/internal_common.hpp new file mode 100644 index 000000000..c9af36395 --- /dev/null +++ b/modules/gpu/src/internal_common.hpp @@ -0,0 +1,57 @@ +/*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*/ + +#ifndef __OPENCV_GPU_INTERNAL_COMMON_HPP__ +#define __OPENCV_GPU_INTERNAL_COMMON_HPP__ + +namespace cv { namespace gpu { + + // Internal GPU anlagues of CPU border extrapolation types + enum + { + BORDER_REFLECT101 = 0, + BORDER_REPLICATE + }; + +}} + +#endif \ No newline at end of file