diff --git a/3rdparty/bin/OcrLiteOnnx.dll b/3rdparty/bin/OcrLiteOnnx.dll index 3daaaaee87..dd1de0c9a5 100644 Binary files a/3rdparty/bin/OcrLiteOnnx.dll and b/3rdparty/bin/OcrLiteOnnx.dll differ diff --git a/3rdparty/bin/opencv_world3413.dll b/3rdparty/bin/opencv_world3413.dll deleted file mode 100644 index 971061760d..0000000000 Binary files a/3rdparty/bin/opencv_world3413.dll and /dev/null differ diff --git a/3rdparty/bin/opencv_world453.dll b/3rdparty/bin/opencv_world453.dll new file mode 100644 index 0000000000..079c2f90da Binary files /dev/null and b/3rdparty/bin/opencv_world453.dll differ diff --git a/3rdparty/bin/penguin-stats-recognize.dll b/3rdparty/bin/penguin-stats-recognize.dll new file mode 100644 index 0000000000..a46684b91f Binary files /dev/null and b/3rdparty/bin/penguin-stats-recognize.dll differ diff --git a/3rdparty/include/OcrLiteOnnx/AngleNet.h b/3rdparty/include/OcrLiteOnnx/AngleNet.h index a1b72911ce..283b3fb213 100644 --- a/3rdparty/include/OcrLiteOnnx/AngleNet.h +++ b/3rdparty/include/OcrLiteOnnx/AngleNet.h @@ -3,7 +3,7 @@ #include "OcrStruct.h" #include "onnxruntime_cxx_api.h" -#include +#include class AngleNet { public: diff --git a/3rdparty/include/OcrLiteOnnx/CrnnNet.h b/3rdparty/include/OcrLiteOnnx/CrnnNet.h index 57110d9ca2..288e8d58ec 100644 --- a/3rdparty/include/OcrLiteOnnx/CrnnNet.h +++ b/3rdparty/include/OcrLiteOnnx/CrnnNet.h @@ -3,7 +3,7 @@ #include "OcrStruct.h" #include "onnxruntime_cxx_api.h" -#include +#include class CrnnNet { public: diff --git a/3rdparty/include/OcrLiteOnnx/DbNet.h b/3rdparty/include/OcrLiteOnnx/DbNet.h index 548e0d8acf..4d070c30a6 100644 --- a/3rdparty/include/OcrLiteOnnx/DbNet.h +++ b/3rdparty/include/OcrLiteOnnx/DbNet.h @@ -3,7 +3,7 @@ #include "OcrStruct.h" #include "onnxruntime_cxx_api.h" -#include +#include class DbNet { public: diff --git a/3rdparty/include/OcrLiteOnnx/OcrLiteCaller.h b/3rdparty/include/OcrLiteOnnx/OcrLiteCaller.h index a473bd2101..8e8236d7bd 100644 --- a/3rdparty/include/OcrLiteOnnx/OcrLiteCaller.h +++ b/3rdparty/include/OcrLiteOnnx/OcrLiteCaller.h @@ -16,20 +16,24 @@ class OCRLITE_PORT OcrLiteCaller { public: OcrLiteCaller(); - ~OcrLiteCaller() = default; + ~OcrLiteCaller(); OcrLiteCaller(const OcrLite&) = delete; OcrLiteCaller(OcrLite&&) = delete; void setNumThread(int numOfThread); - void initModels(const std::string& detPath, const std::string& clsPath, + bool initModels(const std::string& detPath, const std::string& clsPath, const std::string& recPath, const std::string& keysPath); OcrResult detect(const cv::Mat& mat, int padding, int maxSideLen, float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); + OcrResult detect(const std::string& dir, const std::string& file, + int padding, int maxSideLen, + float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); + OcrLiteCaller& operator=(const OcrLiteCaller&) = delete; OcrLiteCaller& operator=(OcrLiteCaller&&) = delete; private: - std::shared_ptr m_ocrlite_ptr; + std::unique_ptr m_ocrlite_ptr; }; \ No newline at end of file diff --git a/3rdparty/include/OcrLiteOnnx/OcrLitePort.h b/3rdparty/include/OcrLiteOnnx/OcrLitePort.h index d65557bcc8..e21b6999d4 100644 --- a/3rdparty/include/OcrLiteOnnx/OcrLitePort.h +++ b/3rdparty/include/OcrLiteOnnx/OcrLitePort.h @@ -1,6 +1,6 @@ #pragma once -#pragma once +#if !defined(__JNI__) && !defined(__EXEC__) // The way how the function is called #if !defined(OCRLITE_CALL) @@ -9,7 +9,7 @@ #else #define OCRLITE_CALL #endif /* _WIN32 */ -#endif /* ISSCALL */ +#endif /* OCRLITE_CALL */ #if defined _WIN32 || defined __CYGWIN__ #define OCRLITE_EXPORT __declspec(dllexport) @@ -34,4 +34,12 @@ #define OCR_API OCRLITE_PORT OCRLITE_CALL -#define OCR_LOCAL OCRLITE_LOCAL OCRLITE_CALL \ No newline at end of file +#define OCR_LOCAL OCRLITE_LOCAL OCRLITE_CALL + +#else // __JNI__ || __EXEC__ + +#define OCRLITE_PORT +#define OCR_API +#define OCR_LOCAL + +#endif // __JNI__ || __EXEC__ diff --git a/3rdparty/include/OcrLiteOnnx/getopt.h b/3rdparty/include/OcrLiteOnnx/getopt.h index 4d6f296c4f..d606dfe90d 100644 --- a/3rdparty/include/OcrLiteOnnx/getopt.h +++ b/3rdparty/include/OcrLiteOnnx/getopt.h @@ -9,8 +9,6 @@ #ifndef _GETOPT_H_ #define _GETOPT_H_ -#ifndef __CLIB__ - #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -42,6 +40,5 @@ int getopt_long(int argc, char *const argv[], ****************************************************************************/ #ifdef __cplusplus } -#endif #endif // __cplusplus #endif // _GETOPT_H_ diff --git a/3rdparty/include/OcrLiteOnnx/main.h b/3rdparty/include/OcrLiteOnnx/main.h index 6996262b9b..4949e1e977 100644 --- a/3rdparty/include/OcrLiteOnnx/main.h +++ b/3rdparty/include/OcrLiteOnnx/main.h @@ -1,6 +1,5 @@ #ifndef __MAIN_H__ #define __MAIN_H__ -#ifndef __CLIB__ #include "getopt.h" @@ -52,5 +51,4 @@ const char *otherMsg = "-v --version: show version\n" \ const char *example1Msg = "Example1: %s --models models --det det.onnx --cls cls.onnx --rec rec.onnx --keys keys.txt --image 1.jpg\n"; const char *example2Msg = "Example2: %s -d models -1 det.onnx -2 cls.onnx -3 rec.onnx -4 keys.txt -i 1.jpg -t 4 -p 50 -s 0 -b 0.6 -o 0.3 -u 2.0 -a 1 -A 1\n"; -#endif -#endif //__MAIN_H__ \ No newline at end of file +#endif //__MAIN_H__ diff --git a/3rdparty/include/opencv/cv.h b/3rdparty/include/opencv/cv.h deleted file mode 100644 index 19a74e297c..0000000000 --- a/3rdparty/include/opencv/cv.h +++ /dev/null @@ -1,73 +0,0 @@ -/*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_OLD_CV_H -#define OPENCV_OLD_CV_H - -#if defined(_MSC_VER) - #define CV_DO_PRAGMA(x) __pragma(x) - #define __CVSTR2__(x) #x - #define __CVSTR1__(x) __CVSTR2__(x) - #define __CVMSVCLOC__ __FILE__ "("__CVSTR1__(__LINE__)") : " - #define CV_MSG_PRAGMA(_msg) CV_DO_PRAGMA(message (__CVMSVCLOC__ _msg)) -#elif defined(__GNUC__) - #define CV_DO_PRAGMA(x) _Pragma (#x) - #define CV_MSG_PRAGMA(_msg) CV_DO_PRAGMA(message (_msg)) -#else - #define CV_DO_PRAGMA(x) - #define CV_MSG_PRAGMA(_msg) -#endif -#define CV_WARNING(x) CV_MSG_PRAGMA("Warning: " #x) - -//CV_WARNING("This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module") - -#include "opencv2/core/core_c.h" -#include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/photo/photo_c.h" -#include "opencv2/video/tracking_c.h" -#include "opencv2/objdetect/objdetect_c.h" - -#if !defined(CV_IMPL) -#define CV_IMPL extern "C" -#endif //CV_IMPL - -#endif // __OPENCV_OLD_CV_H_ diff --git a/3rdparty/include/opencv/cv.hpp b/3rdparty/include/opencv/cv.hpp deleted file mode 100644 index 867395644b..0000000000 --- a/3rdparty/include/opencv/cv.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/*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_OLD_CV_HPP -#define OPENCV_OLD_CV_HPP - -//#if defined(__GNUC__) -//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" -//#endif - -#include "cv.h" -#include "opencv2/core.hpp" -#include "opencv2/imgproc.hpp" -#include "opencv2/photo.hpp" -#include "opencv2/video.hpp" -#include "opencv2/highgui.hpp" -#include "opencv2/features2d.hpp" -#include "opencv2/calib3d.hpp" -#include "opencv2/objdetect.hpp" - -#endif diff --git a/3rdparty/include/opencv/cvaux.h b/3rdparty/include/opencv/cvaux.h deleted file mode 100644 index c0367cc25b..0000000000 --- a/3rdparty/include/opencv/cvaux.h +++ /dev/null @@ -1,57 +0,0 @@ -/*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. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_OLD_AUX_H -#define OPENCV_OLD_AUX_H - -//#if defined(__GNUC__) -//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" -//#endif - -#include "opencv2/core/core_c.h" -#include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/photo/photo_c.h" -#include "opencv2/video/tracking_c.h" -#include "opencv2/objdetect/objdetect_c.h" - -#endif - -/* End of file. */ diff --git a/3rdparty/include/opencv/cvaux.hpp b/3rdparty/include/opencv/cvaux.hpp deleted file mode 100644 index 4888eef282..0000000000 --- a/3rdparty/include/opencv/cvaux.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/*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. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_OLD_AUX_HPP -#define OPENCV_OLD_AUX_HPP - -//#if defined(__GNUC__) -//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" -//#endif - -#include "cvaux.h" -#include "opencv2/core/utility.hpp" - -#endif diff --git a/3rdparty/include/opencv/cvwimage.h b/3rdparty/include/opencv/cvwimage.h deleted file mode 100644 index ec0ab141d9..0000000000 --- a/3rdparty/include/opencv/cvwimage.h +++ /dev/null @@ -1,46 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// 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) 2008, Google, 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 Intel Corporation or contributors 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. - - -#ifndef OPENCV_OLD_WIMAGE_HPP -#define OPENCV_OLD_WIMAGE_HPP - -#include "opencv2/core/wimage.hpp" - -#endif diff --git a/3rdparty/include/opencv/cxcore.h b/3rdparty/include/opencv/cxcore.h deleted file mode 100644 index dc070c77d2..0000000000 --- a/3rdparty/include/opencv/cxcore.h +++ /dev/null @@ -1,52 +0,0 @@ -/*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_OLD_CXCORE_H -#define OPENCV_OLD_CXCORE_H - -//#if defined(__GNUC__) -//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" -//#endif - -#include "opencv2/core/core_c.h" - -#endif diff --git a/3rdparty/include/opencv/cxcore.hpp b/3rdparty/include/opencv/cxcore.hpp deleted file mode 100644 index c371677c93..0000000000 --- a/3rdparty/include/opencv/cxcore.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/*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_OLD_CXCORE_HPP -#define OPENCV_OLD_CXCORE_HPP - -//#if defined(__GNUC__) -//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" -//#endif - -#include "cxcore.h" -#include "opencv2/core.hpp" - -#endif diff --git a/3rdparty/include/opencv/cxeigen.hpp b/3rdparty/include/opencv/cxeigen.hpp deleted file mode 100644 index 1d3df914ac..0000000000 --- a/3rdparty/include/opencv/cxeigen.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/*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_OLD_EIGEN_HPP -#define OPENCV_OLD_EIGEN_HPP - -#include "opencv2/core/eigen.hpp" - -#endif diff --git a/3rdparty/include/opencv/cxmisc.h b/3rdparty/include/opencv/cxmisc.h deleted file mode 100644 index 9b9bc8204b..0000000000 --- a/3rdparty/include/opencv/cxmisc.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef OPENCV_OLD_CXMISC_H -#define OPENCV_OLD_CXMISC_H - -#ifdef __cplusplus -# include "opencv2/core/utility.hpp" -#endif - -#endif diff --git a/3rdparty/include/opencv/highgui.h b/3rdparty/include/opencv/highgui.h deleted file mode 100644 index 69b394e08a..0000000000 --- a/3rdparty/include/opencv/highgui.h +++ /dev/null @@ -1,48 +0,0 @@ -/*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. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_OLD_HIGHGUI_H -#define OPENCV_OLD_HIGHGUI_H - -#include "opencv2/core/core_c.h" -#include "opencv2/highgui/highgui_c.h" - -#endif diff --git a/3rdparty/include/opencv/ml.h b/3rdparty/include/opencv/ml.h deleted file mode 100644 index 0c376bacb9..0000000000 --- a/3rdparty/include/opencv/ml.h +++ /dev/null @@ -1,47 +0,0 @@ -/*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. -// -// -// Intel License Agreement -// -// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_OLD_ML_H -#define OPENCV_OLD_ML_H - -#include "opencv2/core/core_c.h" -#include "opencv2/ml.hpp" - -#endif diff --git a/3rdparty/include/opencv2/aruco.hpp b/3rdparty/include/opencv2/aruco.hpp deleted file mode 100644 index 65a19dff9b..0000000000 --- a/3rdparty/include/opencv2/aruco.hpp +++ /dev/null @@ -1,604 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2013, OpenCV Foundation, 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -#ifndef __OPENCV_ARUCO_HPP__ -#define __OPENCV_ARUCO_HPP__ - -#include -#include -#include "opencv2/aruco/dictionary.hpp" - -/** - * @defgroup aruco ArUco Marker Detection - * This module is dedicated to square fiducial markers (also known as Augmented Reality Markers) - * These markers are useful for easy, fast and robust camera pose estimation.ç - * - * The main functionalities are: - * - Detection of markers in an image - * - Pose estimation from a single marker or from a board/set of markers - * - Detection of ChArUco board for high subpixel accuracy - * - Camera calibration from both, ArUco boards and ChArUco boards. - * - Detection of ChArUco diamond markers - * The samples directory includes easy examples of how to use the module. - * - * The implementation is based on the ArUco Library by R. Muñoz-Salinas and S. Garrido-Jurado @cite Aruco2014. - * - * Markers can also be detected based on the AprilTag 2 @cite wang2016iros fiducial detection method. - * - * @sa S. Garrido-Jurado, R. Muñoz-Salinas, F. J. Madrid-Cuevas, and M. J. Marín-Jiménez. 2014. - * "Automatic generation and detection of highly reliable fiducial markers under occlusion". - * Pattern Recogn. 47, 6 (June 2014), 2280-2292. DOI=10.1016/j.patcog.2014.01.005 - * - * @sa http://www.uco.es/investiga/grupos/ava/node/26 - * - * This module has been originally developed by Sergio Garrido-Jurado as a project - * for Google Summer of Code 2015 (GSoC 15). - * - * -*/ - -namespace cv { -namespace aruco { - -//! @addtogroup aruco -//! @{ - -enum CornerRefineMethod{ - CORNER_REFINE_NONE, ///< Tag and corners detection based on the ArUco approach - CORNER_REFINE_SUBPIX, ///< ArUco approach and refine the corners locations using corner subpixel accuracy - CORNER_REFINE_CONTOUR, ///< ArUco approach and refine the corners locations using the contour-points line fitting - CORNER_REFINE_APRILTAG, ///< Tag and corners detection based on the AprilTag 2 approach @cite wang2016iros -}; - -/** - * @brief Parameters for the detectMarker process: - * - adaptiveThreshWinSizeMin: minimum window size for adaptive thresholding before finding - * contours (default 3). - * - adaptiveThreshWinSizeMax: maximum window size for adaptive thresholding before finding - * contours (default 23). - * - adaptiveThreshWinSizeStep: increments from adaptiveThreshWinSizeMin to adaptiveThreshWinSizeMax - * during the thresholding (default 10). - * - adaptiveThreshConstant: constant for adaptive thresholding before finding contours (default 7) - * - minMarkerPerimeterRate: determine minimum perimeter for marker contour to be detected. This - * is defined as a rate respect to the maximum dimension of the input image (default 0.03). - * - maxMarkerPerimeterRate: determine maximum perimeter for marker contour to be detected. This - * is defined as a rate respect to the maximum dimension of the input image (default 4.0). - * - polygonalApproxAccuracyRate: minimum accuracy during the polygonal approximation process to - * determine which contours are squares. (default 0.03) - * - minCornerDistanceRate: minimum distance between corners for detected markers relative to its - * perimeter (default 0.05) - * - minDistanceToBorder: minimum distance of any corner to the image border for detected markers - * (in pixels) (default 3) - * - minMarkerDistanceRate: minimum mean distance beetween two marker corners to be considered - * similar, so that the smaller one is removed. The rate is relative to the smaller perimeter - * of the two markers (default 0.05). - * - cornerRefinementMethod: corner refinement method. (CORNER_REFINE_NONE, no refinement. - * CORNER_REFINE_SUBPIX, do subpixel refinement. CORNER_REFINE_CONTOUR use contour-Points, - * CORNER_REFINE_APRILTAG use the AprilTag2 approach). (default CORNER_REFINE_NONE) - * - cornerRefinementWinSize: window size for the corner refinement process (in pixels) (default 5). - * - cornerRefinementMaxIterations: maximum number of iterations for stop criteria of the corner - * refinement process (default 30). - * - cornerRefinementMinAccuracy: minimum error for the stop cristeria of the corner refinement - * process (default: 0.1) - * - markerBorderBits: number of bits of the marker border, i.e. marker border width (default 1). - * - perspectiveRemovePixelPerCell: number of bits (per dimension) for each cell of the marker - * when removing the perspective (default 4). - * - perspectiveRemoveIgnoredMarginPerCell: width of the margin of pixels on each cell not - * considered for the determination of the cell bit. Represents the rate respect to the total - * size of the cell, i.e. perspectiveRemovePixelPerCell (default 0.13) - * - maxErroneousBitsInBorderRate: maximum number of accepted erroneous bits in the border (i.e. - * number of allowed white bits in the border). Represented as a rate respect to the total - * number of bits per marker (default 0.35). - * - minOtsuStdDev: minimun standard deviation in pixels values during the decodification step to - * apply Otsu thresholding (otherwise, all the bits are set to 0 or 1 depending on mean higher - * than 128 or not) (default 5.0) - * - errorCorrectionRate error correction rate respect to the maximun error correction capability - * for each dictionary. (default 0.6). - * - aprilTagMinClusterPixels: reject quads containing too few pixels. (default 5) - * - aprilTagMaxNmaxima: how many corner candidates to consider when segmenting a group of pixels into a quad. (default 10) - * - aprilTagCriticalRad: Reject quads where pairs of edges have angles that are close to straight or close to - * 180 degrees. Zero means that no quads are rejected. (In radians) (default 10*PI/180) - * - aprilTagMaxLineFitMse: When fitting lines to the contours, what is the maximum mean squared error - * allowed? This is useful in rejecting contours that are far from being quad shaped; rejecting - * these quads "early" saves expensive decoding processing. (default 10.0) - * - aprilTagMinWhiteBlackDiff: When we build our model of black & white pixels, we add an extra check that - * the white model must be (overall) brighter than the black model. How much brighter? (in pixel values, [0,255]). (default 5) - * - aprilTagDeglitch: should the thresholded image be deglitched? Only useful for very noisy images. (default 0) - * - aprilTagQuadDecimate: Detection of quads can be done on a lower-resolution image, improving speed at a - * cost of pose accuracy and a slight decrease in detection rate. Decoding the binary payload is still - * done at full resolution. (default 0.0) - * - aprilTagQuadSigma: What Gaussian blur should be applied to the segmented image (used for quad detection?) - * Parameter is the standard deviation in pixels. Very noisy images benefit from non-zero values (e.g. 0.8). (default 0.0) - * - detectInvertedMarker: to check if there is a white marker. In order to generate a "white" marker just - * invert a normal marker by using a tilde, ~markerImage. (default false) - */ -struct CV_EXPORTS_W DetectorParameters { - - DetectorParameters(); - - CV_WRAP static Ptr create(); - - CV_PROP_RW int adaptiveThreshWinSizeMin; - CV_PROP_RW int adaptiveThreshWinSizeMax; - CV_PROP_RW int adaptiveThreshWinSizeStep; - CV_PROP_RW double adaptiveThreshConstant; - CV_PROP_RW double minMarkerPerimeterRate; - CV_PROP_RW double maxMarkerPerimeterRate; - CV_PROP_RW double polygonalApproxAccuracyRate; - CV_PROP_RW double minCornerDistanceRate; - CV_PROP_RW int minDistanceToBorder; - CV_PROP_RW double minMarkerDistanceRate; - CV_PROP_RW int cornerRefinementMethod; - CV_PROP_RW int cornerRefinementWinSize; - CV_PROP_RW int cornerRefinementMaxIterations; - CV_PROP_RW double cornerRefinementMinAccuracy; - CV_PROP_RW int markerBorderBits; - CV_PROP_RW int perspectiveRemovePixelPerCell; - CV_PROP_RW double perspectiveRemoveIgnoredMarginPerCell; - CV_PROP_RW double maxErroneousBitsInBorderRate; - CV_PROP_RW double minOtsuStdDev; - CV_PROP_RW double errorCorrectionRate; - - // April :: User-configurable parameters. - CV_PROP_RW float aprilTagQuadDecimate; - CV_PROP_RW float aprilTagQuadSigma; - - // April :: Internal variables - CV_PROP_RW int aprilTagMinClusterPixels; - CV_PROP_RW int aprilTagMaxNmaxima; - CV_PROP_RW float aprilTagCriticalRad; - CV_PROP_RW float aprilTagMaxLineFitMse; - CV_PROP_RW int aprilTagMinWhiteBlackDiff; - CV_PROP_RW int aprilTagDeglitch; - - // to detect white (inverted) markers - CV_PROP_RW bool detectInvertedMarker; -}; - - - -/** - * @brief Basic marker detection - * - * @param image input image - * @param dictionary indicates the type of markers that will be searched - * @param corners vector of detected marker corners. For each marker, its four corners - * are provided, (e.g std::vector > ). For N detected markers, - * the dimensions of this array is Nx4. The order of the corners is clockwise. - * @param ids vector of identifiers of the detected markers. The identifier is of type int - * (e.g. std::vector). For N detected markers, the size of ids is also N. - * The identifiers have the same order than the markers in the imgPoints array. - * @param parameters marker detection parameters - * @param rejectedImgPoints contains the imgPoints of those squares whose inner code has not a - * correct codification. Useful for debugging purposes. - * @param cameraMatrix optional input 3x3 floating-point camera matrix - * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ - * @param distCoeff optional vector of distortion coefficients - * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements - * - * Performs marker detection in the input image. Only markers included in the specific dictionary - * are searched. For each detected marker, it returns the 2D position of its corner in the image - * and its corresponding identifier. - * Note that this function does not perform pose estimation. - * @sa estimatePoseSingleMarkers, estimatePoseBoard - * - */ -CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr &dictionary, OutputArrayOfArrays corners, - OutputArray ids, const Ptr ¶meters = DetectorParameters::create(), - OutputArrayOfArrays rejectedImgPoints = noArray(), InputArray cameraMatrix= noArray(), InputArray distCoeff= noArray()); - - - -/** - * @brief Pose estimation for single markers - * - * @param corners vector of already detected markers corners. For each marker, its four corners - * are provided, (e.g std::vector > ). For N detected markers, - * the dimensions of this array should be Nx4. The order of the corners should be clockwise. - * @sa detectMarkers - * @param markerLength the length of the markers' side. The returning translation vectors will - * be in the same unit. Normally, unit is meters. - * @param cameraMatrix input 3x3 floating-point camera matrix - * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ - * @param distCoeffs vector of distortion coefficients - * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements - * @param rvecs array of output rotation vectors (@sa Rodrigues) (e.g. std::vector). - * Each element in rvecs corresponds to the specific marker in imgPoints. - * @param tvecs array of output translation vectors (e.g. std::vector). - * Each element in tvecs corresponds to the specific marker in imgPoints. - * @param _objPoints array of object points of all the marker corners - * - * This function receives the detected markers and returns their pose estimation respect to - * the camera individually. So for each marker, one rotation and translation vector is returned. - * The returned transformation is the one that transforms points from each marker coordinate system - * to the camera coordinate system. - * The marker corrdinate system is centered on the middle of the marker, with the Z axis - * perpendicular to the marker plane. - * The coordinates of the four corners of the marker in its own coordinate system are: - * (-markerLength/2, markerLength/2, 0), (markerLength/2, markerLength/2, 0), - * (markerLength/2, -markerLength/2, 0), (-markerLength/2, -markerLength/2, 0) - */ -CV_EXPORTS_W void estimatePoseSingleMarkers(InputArrayOfArrays corners, float markerLength, - InputArray cameraMatrix, InputArray distCoeffs, - OutputArray rvecs, OutputArray tvecs, OutputArray _objPoints = noArray()); - - - -/** - * @brief Board of markers - * - * A board is a set of markers in the 3D space with a common coordinate system. - * The common form of a board of marker is a planar (2D) board, however any 3D layout can be used. - * A Board object is composed by: - * - The object points of the marker corners, i.e. their coordinates respect to the board system. - * - The dictionary which indicates the type of markers of the board - * - The identifier of all the markers in the board. - */ -class CV_EXPORTS_W Board { - - public: - /** - * @brief Provide way to create Board by passing necessary data. Specially needed in Python. - * - * @param objPoints array of object points of all the marker corners in the board - * @param dictionary the dictionary of markers employed for this board - * @param ids vector of the identifiers of the markers in the board - * - */ - CV_WRAP static Ptr create(InputArrayOfArrays objPoints, const Ptr &dictionary, InputArray ids); - /// array of object points of all the marker corners in the board - /// each marker include its 4 corners in CCW order. For M markers, the size is Mx4. - CV_PROP std::vector< std::vector< Point3f > > objPoints; - - /// the dictionary of markers employed for this board - CV_PROP Ptr dictionary; - - /// vector of the identifiers of the markers in the board (same size than objPoints) - /// The identifiers refers to the board dictionary - CV_PROP std::vector< int > ids; -}; - - - -/** - * @brief Planar board with grid arrangement of markers - * More common type of board. All markers are placed in the same plane in a grid arrangement. - * The board can be drawn using drawPlanarBoard() function (@sa drawPlanarBoard) - */ -class CV_EXPORTS_W GridBoard : public Board { - - public: - /** - * @brief Draw a GridBoard - * - * @param outSize size of the output image in pixels. - * @param img output image with the board. The size of this image will be outSize - * and the board will be on the center, keeping the board proportions. - * @param marginSize minimum margins (in pixels) of the board in the output image - * @param borderBits width of the marker borders. - * - * This function return the image of the GridBoard, ready to be printed. - */ - CV_WRAP void draw(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1); - - - /** - * @brief Create a GridBoard object - * - * @param markersX number of markers in X direction - * @param markersY number of markers in Y direction - * @param markerLength marker side length (normally in meters) - * @param markerSeparation separation between two markers (same unit as markerLength) - * @param dictionary dictionary of markers indicating the type of markers - * @param firstMarker id of first marker in dictionary to use on board. - * @return the output GridBoard object - * - * This functions creates a GridBoard object given the number of markers in each direction and - * the marker size and marker separation. - */ - CV_WRAP static Ptr create(int markersX, int markersY, float markerLength, - float markerSeparation, const Ptr &dictionary, int firstMarker = 0); - - /** - * - */ - CV_WRAP Size getGridSize() const { return Size(_markersX, _markersY); } - - /** - * - */ - CV_WRAP float getMarkerLength() const { return _markerLength; } - - /** - * - */ - CV_WRAP float getMarkerSeparation() const { return _markerSeparation; } - - - private: - // number of markers in X and Y directions - int _markersX, _markersY; - - // marker side length (normally in meters) - float _markerLength; - - // separation between markers in the grid - float _markerSeparation; -}; - - - -/** - * @brief Pose estimation for a board of markers - * - * @param corners vector of already detected markers corners. For each marker, its four corners - * are provided, (e.g std::vector > ). For N detected markers, the - * dimensions of this array should be Nx4. The order of the corners should be clockwise. - * @param ids list of identifiers for each marker in corners - * @param board layout of markers in the board. The layout is composed by the marker identifiers - * and the positions of each marker corner in the board reference system. - * @param cameraMatrix input 3x3 floating-point camera matrix - * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ - * @param distCoeffs vector of distortion coefficients - * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements - * @param rvec Output vector (e.g. cv::Mat) corresponding to the rotation vector of the board - * (see cv::Rodrigues). Used as initial guess if not empty. - * @param tvec Output vector (e.g. cv::Mat) corresponding to the translation vector of the board. - * @param useExtrinsicGuess defines whether initial guess for \b rvec and \b tvec will be used or not. - * Used as initial guess if not empty. - * - * This function receives the detected markers and returns the pose of a marker board composed - * by those markers. - * A Board of marker has a single world coordinate system which is defined by the board layout. - * The returned transformation is the one that transforms points from the board coordinate system - * to the camera coordinate system. - * Input markers that are not included in the board layout are ignored. - * The function returns the number of markers from the input employed for the board pose estimation. - * Note that returning a 0 means the pose has not been estimated. - */ -CV_EXPORTS_W int estimatePoseBoard(InputArrayOfArrays corners, InputArray ids, const Ptr &board, - InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, - OutputArray tvec, bool useExtrinsicGuess = false); - - - - -/** - * @brief Refind not detected markers based on the already detected and the board layout - * - * @param image input image - * @param board layout of markers in the board. - * @param detectedCorners vector of already detected marker corners. - * @param detectedIds vector of already detected marker identifiers. - * @param rejectedCorners vector of rejected candidates during the marker detection process. - * @param cameraMatrix optional input 3x3 floating-point camera matrix - * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ - * @param distCoeffs optional vector of distortion coefficients - * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements - * @param minRepDistance minimum distance between the corners of the rejected candidate and the - * reprojected marker in order to consider it as a correspondence. - * @param errorCorrectionRate rate of allowed erroneous bits respect to the error correction - * capability of the used dictionary. -1 ignores the error correction step. - * @param checkAllOrders Consider the four posible corner orders in the rejectedCorners array. - * If it set to false, only the provided corner order is considered (default true). - * @param recoveredIdxs Optional array to returns the indexes of the recovered candidates in the - * original rejectedCorners array. - * @param parameters marker detection parameters - * - * This function tries to find markers that were not detected in the basic detecMarkers function. - * First, based on the current detected marker and the board layout, the function interpolates - * the position of the missing markers. Then it tries to find correspondence between the reprojected - * markers and the rejected candidates based on the minRepDistance and errorCorrectionRate - * parameters. - * If camera parameters and distortion coefficients are provided, missing markers are reprojected - * using projectPoint function. If not, missing marker projections are interpolated using global - * homography, and all the marker corners in the board must have the same Z coordinate. - */ -CV_EXPORTS_W void refineDetectedMarkers( - InputArray image,const Ptr &board, InputOutputArrayOfArrays detectedCorners, - InputOutputArray detectedIds, InputOutputArrayOfArrays rejectedCorners, - InputArray cameraMatrix = noArray(), InputArray distCoeffs = noArray(), - float minRepDistance = 10.f, float errorCorrectionRate = 3.f, bool checkAllOrders = true, - OutputArray recoveredIdxs = noArray(), const Ptr ¶meters = DetectorParameters::create()); - - - -/** - * @brief Draw detected markers in image - * - * @param image input/output image. It must have 1 or 3 channels. The number of channels is not - * altered. - * @param corners positions of marker corners on input image. - * (e.g std::vector > ). For N detected markers, the dimensions of - * this array should be Nx4. The order of the corners should be clockwise. - * @param ids vector of identifiers for markers in markersCorners . - * Optional, if not provided, ids are not painted. - * @param borderColor color of marker borders. Rest of colors (text color and first corner color) - * are calculated based on this one to improve visualization. - * - * Given an array of detected marker corners and its corresponding ids, this functions draws - * the markers in the image. The marker borders are painted and the markers identifiers if provided. - * Useful for debugging purposes. - */ -CV_EXPORTS_W void drawDetectedMarkers(InputOutputArray image, InputArrayOfArrays corners, - InputArray ids = noArray(), - Scalar borderColor = Scalar(0, 255, 0)); - - - -/** - * @brief Draw coordinate system axis from pose estimation - * - * @param image input/output image. It must have 1 or 3 channels. The number of channels is not - * altered. - * @param cameraMatrix input 3x3 floating-point camera matrix - * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ - * @param distCoeffs vector of distortion coefficients - * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements - * @param rvec rotation vector of the coordinate system that will be drawn. (@sa Rodrigues). - * @param tvec translation vector of the coordinate system that will be drawn. - * @param length length of the painted axis in the same unit than tvec (usually in meters) - * - * Given the pose estimation of a marker or board, this function draws the axis of the world - * coordinate system, i.e. the system centered on the marker/board. Useful for debugging purposes. - * - * @deprecated use cv::drawFrameAxes - */ -CV_EXPORTS_W void drawAxis(InputOutputArray image, InputArray cameraMatrix, InputArray distCoeffs, - InputArray rvec, InputArray tvec, float length); - - - -/** - * @brief Draw a canonical marker image - * - * @param dictionary dictionary of markers indicating the type of markers - * @param id identifier of the marker that will be returned. It has to be a valid id - * in the specified dictionary. - * @param sidePixels size of the image in pixels - * @param img output image with the marker - * @param borderBits width of the marker border. - * - * This function returns a marker image in its canonical form (i.e. ready to be printed) - */ -CV_EXPORTS_W void drawMarker(const Ptr &dictionary, int id, int sidePixels, OutputArray img, - int borderBits = 1); - - - -/** - * @brief Draw a planar board - * @sa _drawPlanarBoardImpl - * - * @param board layout of the board that will be drawn. The board should be planar, - * z coordinate is ignored - * @param outSize size of the output image in pixels. - * @param img output image with the board. The size of this image will be outSize - * and the board will be on the center, keeping the board proportions. - * @param marginSize minimum margins (in pixels) of the board in the output image - * @param borderBits width of the marker borders. - * - * This function return the image of a planar board, ready to be printed. It assumes - * the Board layout specified is planar by ignoring the z coordinates of the object points. - */ -CV_EXPORTS_W void drawPlanarBoard(const Ptr &board, Size outSize, OutputArray img, - int marginSize = 0, int borderBits = 1); - - - -/** - * @brief Implementation of drawPlanarBoard that accepts a raw Board pointer. - */ -void _drawPlanarBoardImpl(Board *board, Size outSize, OutputArray img, - int marginSize = 0, int borderBits = 1); - - - -/** - * @brief Calibrate a camera using aruco markers - * - * @param corners vector of detected marker corners in all frames. - * The corners should have the same format returned by detectMarkers (see #detectMarkers). - * @param ids list of identifiers for each marker in corners - * @param counter number of markers in each frame so that corners and ids can be split - * @param board Marker Board layout - * @param imageSize Size of the image used only to initialize the intrinsic camera matrix. - * @param cameraMatrix Output 3x3 floating-point camera matrix - * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS - * and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be - * initialized before calling the function. - * @param distCoeffs Output vector of distortion coefficients - * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements - * @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each board view - * (e.g. std::vector>). That is, each k-th rotation vector together with the corresponding - * k-th translation vector (see the next output parameter description) brings the board pattern - * from the model coordinate space (in which object points are specified) to the world coordinate - * space, that is, a real position of the board pattern in the k-th pattern view (k=0.. *M* -1). - * @param tvecs Output vector of translation vectors estimated for each pattern view. - * @param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. - * Order of deviations values: - * \f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, - * s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. - * @param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. - * Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, - * \f$R_i, T_i\f$ are concatenated 1x3 vectors. - * @param perViewErrors Output vector of average re-projection errors estimated for each pattern view. - * @param flags flags Different flags for the calibration process (see #calibrateCamera for details). - * @param criteria Termination criteria for the iterative optimization algorithm. - * - * This function calibrates a camera using an Aruco Board. The function receives a list of - * detected markers from several views of the Board. The process is similar to the chessboard - * calibration in calibrateCamera(). The function returns the final re-projection error. - */ -CV_EXPORTS_AS(calibrateCameraArucoExtended) double calibrateCameraAruco( - InputArrayOfArrays corners, InputArray ids, InputArray counter, const Ptr &board, - Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, - OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, - OutputArray stdDeviationsIntrinsics, OutputArray stdDeviationsExtrinsics, - OutputArray perViewErrors, int flags = 0, - TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); - - -/** @brief It's the same function as #calibrateCameraAruco but without calibration error estimation. - */ -CV_EXPORTS_W double calibrateCameraAruco( - InputArrayOfArrays corners, InputArray ids, InputArray counter, const Ptr &board, - Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, - OutputArrayOfArrays rvecs = noArray(), OutputArrayOfArrays tvecs = noArray(), int flags = 0, - TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); - - -/** - * @brief Given a board configuration and a set of detected markers, returns the corresponding - * image points and object points to call solvePnP - * - * @param board Marker board layout. - * @param detectedCorners List of detected marker corners of the board. - * @param detectedIds List of identifiers for each marker. - * @param objPoints Vector of vectors of board marker points in the board coordinate space. - * @param imgPoints Vector of vectors of the projections of board marker corner points. -*/ -CV_EXPORTS_W void getBoardObjectAndImagePoints(const Ptr &board, InputArrayOfArrays detectedCorners, - InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints); - - -//! @} -} -} - -#endif diff --git a/3rdparty/include/opencv2/aruco/charuco.hpp b/3rdparty/include/opencv2/aruco/charuco.hpp deleted file mode 100644 index d7a3b27788..0000000000 --- a/3rdparty/include/opencv2/aruco/charuco.hpp +++ /dev/null @@ -1,354 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2013, OpenCV Foundation, 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -#ifndef __OPENCV_CHARUCO_HPP__ -#define __OPENCV_CHARUCO_HPP__ - -#include -#include -#include - - -namespace cv { -namespace aruco { - -//! @addtogroup aruco -//! @{ - - -/** - * @brief ChArUco board - * Specific class for ChArUco boards. A ChArUco board is a planar board where the markers are placed - * inside the white squares of a chessboard. The benefits of ChArUco boards is that they provide - * both, ArUco markers versatility and chessboard corner precision, which is important for - * calibration and pose estimation. - * This class also allows the easy creation and drawing of ChArUco boards. - */ -class CV_EXPORTS_W CharucoBoard : public Board { - - public: - // vector of chessboard 3D corners precalculated - CV_PROP std::vector< Point3f > chessboardCorners; - - // for each charuco corner, nearest marker id and nearest marker corner id of each marker - CV_PROP std::vector< std::vector< int > > nearestMarkerIdx; - CV_PROP std::vector< std::vector< int > > nearestMarkerCorners; - - /** - * @brief Draw a ChArUco board - * - * @param outSize size of the output image in pixels. - * @param img output image with the board. The size of this image will be outSize - * and the board will be on the center, keeping the board proportions. - * @param marginSize minimum margins (in pixels) of the board in the output image - * @param borderBits width of the marker borders. - * - * This function return the image of the ChArUco board, ready to be printed. - */ - CV_WRAP void draw(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1); - - - /** - * @brief Create a CharucoBoard object - * - * @param squaresX number of chessboard squares in X direction - * @param squaresY number of chessboard squares in Y direction - * @param squareLength chessboard square side length (normally in meters) - * @param markerLength marker side length (same unit than squareLength) - * @param dictionary dictionary of markers indicating the type of markers. - * The first markers in the dictionary are used to fill the white chessboard squares. - * @return the output CharucoBoard object - * - * This functions creates a CharucoBoard object given the number of squares in each direction - * and the size of the markers and chessboard squares. - */ - CV_WRAP static Ptr create(int squaresX, int squaresY, float squareLength, - float markerLength, const Ptr &dictionary); - - /** - * - */ - CV_WRAP Size getChessboardSize() const { return Size(_squaresX, _squaresY); } - - /** - * - */ - CV_WRAP float getSquareLength() const { return _squareLength; } - - /** - * - */ - CV_WRAP float getMarkerLength() const { return _markerLength; } - - private: - void _getNearestMarkerCorners(); - - // number of markers in X and Y directions - int _squaresX, _squaresY; - - // size of chessboard squares side (normally in meters) - float _squareLength; - - // marker side length (normally in meters) - float _markerLength; -}; - - - - -/** - * @brief Interpolate position of ChArUco board corners - * @param markerCorners vector of already detected markers corners. For each marker, its four - * corners are provided, (e.g std::vector > ). For N detected markers, the - * dimensions of this array should be Nx4. The order of the corners should be clockwise. - * @param markerIds list of identifiers for each marker in corners - * @param image input image necesary for corner refinement. Note that markers are not detected and - * should be sent in corners and ids parameters. - * @param board layout of ChArUco board. - * @param charucoCorners interpolated chessboard corners - * @param charucoIds interpolated chessboard corners identifiers - * @param cameraMatrix optional 3x3 floating-point camera matrix - * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ - * @param distCoeffs optional vector of distortion coefficients - * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements - * @param minMarkers number of adjacent markers that must be detected to return a charuco corner - * - * This function receives the detected markers and returns the 2D position of the chessboard corners - * from a ChArUco board using the detected Aruco markers. If camera parameters are provided, - * the process is based in an approximated pose estimation, else it is based on local homography. - * Only visible corners are returned. For each corner, its corresponding identifier is - * also returned in charucoIds. - * The function returns the number of interpolated corners. - */ -CV_EXPORTS_W int interpolateCornersCharuco(InputArrayOfArrays markerCorners, InputArray markerIds, - InputArray image, const Ptr &board, - OutputArray charucoCorners, OutputArray charucoIds, - InputArray cameraMatrix = noArray(), - InputArray distCoeffs = noArray(), int minMarkers = 2); - - - - -/** - * @brief Pose estimation for a ChArUco board given some of their corners - * @param charucoCorners vector of detected charuco corners - * @param charucoIds list of identifiers for each corner in charucoCorners - * @param board layout of ChArUco board. - * @param cameraMatrix input 3x3 floating-point camera matrix - * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ - * @param distCoeffs vector of distortion coefficients - * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements - * @param rvec Output vector (e.g. cv::Mat) corresponding to the rotation vector of the board - * (see cv::Rodrigues). - * @param tvec Output vector (e.g. cv::Mat) corresponding to the translation vector of the board. - * @param useExtrinsicGuess defines whether initial guess for \b rvec and \b tvec will be used or not. - * - * This function estimates a Charuco board pose from some detected corners. - * The function checks if the input corners are enough and valid to perform pose estimation. - * If pose estimation is valid, returns true, else returns false. - */ -CV_EXPORTS_W bool estimatePoseCharucoBoard(InputArray charucoCorners, InputArray charucoIds, - const Ptr &board, InputArray cameraMatrix, - InputArray distCoeffs, OutputArray rvec, OutputArray tvec, - bool useExtrinsicGuess = false); - - - - -/** - * @brief Draws a set of Charuco corners - * @param image input/output image. It must have 1 or 3 channels. The number of channels is not - * altered. - * @param charucoCorners vector of detected charuco corners - * @param charucoIds list of identifiers for each corner in charucoCorners - * @param cornerColor color of the square surrounding each corner - * - * This function draws a set of detected Charuco corners. If identifiers vector is provided, it also - * draws the id of each corner. - */ -CV_EXPORTS_W void drawDetectedCornersCharuco(InputOutputArray image, InputArray charucoCorners, - InputArray charucoIds = noArray(), - Scalar cornerColor = Scalar(255, 0, 0)); - - - -/** - * @brief Calibrate a camera using Charuco corners - * - * @param charucoCorners vector of detected charuco corners per frame - * @param charucoIds list of identifiers for each corner in charucoCorners per frame - * @param board Marker Board layout - * @param imageSize input image size - * @param cameraMatrix Output 3x3 floating-point camera matrix - * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS - * and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be - * initialized before calling the function. - * @param distCoeffs Output vector of distortion coefficients - * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements - * @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each board view - * (e.g. std::vector>). That is, each k-th rotation vector together with the corresponding - * k-th translation vector (see the next output parameter description) brings the board pattern - * from the model coordinate space (in which object points are specified) to the world coordinate - * space, that is, a real position of the board pattern in the k-th pattern view (k=0.. *M* -1). - * @param tvecs Output vector of translation vectors estimated for each pattern view. - * @param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. - * Order of deviations values: - * \f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, - * s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. - * @param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. - * Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, - * \f$R_i, T_i\f$ are concatenated 1x3 vectors. - * @param perViewErrors Output vector of average re-projection errors estimated for each pattern view. - * @param flags flags Different flags for the calibration process (see #calibrateCamera for details). - * @param criteria Termination criteria for the iterative optimization algorithm. - * - * This function calibrates a camera using a set of corners of a Charuco Board. The function - * receives a list of detected corners and its identifiers from several views of the Board. - * The function returns the final re-projection error. - */ -CV_EXPORTS_AS(calibrateCameraCharucoExtended) double calibrateCameraCharuco( - InputArrayOfArrays charucoCorners, InputArrayOfArrays charucoIds, const Ptr &board, - Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, - OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, - OutputArray stdDeviationsIntrinsics, OutputArray stdDeviationsExtrinsics, - OutputArray perViewErrors, int flags = 0, - TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); - -/** @brief It's the same function as #calibrateCameraCharuco but without calibration error estimation. -*/ -CV_EXPORTS_W double calibrateCameraCharuco( - InputArrayOfArrays charucoCorners, InputArrayOfArrays charucoIds, const Ptr &board, - Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, - OutputArrayOfArrays rvecs = noArray(), OutputArrayOfArrays tvecs = noArray(), int flags = 0, - TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); - - - -/** - * @brief Detect ChArUco Diamond markers - * - * @param image input image necessary for corner subpixel. - * @param markerCorners list of detected marker corners from detectMarkers function. - * @param markerIds list of marker ids in markerCorners. - * @param squareMarkerLengthRate rate between square and marker length: - * squareMarkerLengthRate = squareLength/markerLength. The real units are not necessary. - * @param diamondCorners output list of detected diamond corners (4 corners per diamond). The order - * is the same than in marker corners: top left, top right, bottom right and bottom left. Similar - * format than the corners returned by detectMarkers (e.g std::vector > ). - * @param diamondIds ids of the diamonds in diamondCorners. The id of each diamond is in fact of - * type Vec4i, so each diamond has 4 ids, which are the ids of the aruco markers composing the - * diamond. - * @param cameraMatrix Optional camera calibration matrix. - * @param distCoeffs Optional camera distortion coefficients. - * - * This function detects Diamond markers from the previous detected ArUco markers. The diamonds - * are returned in the diamondCorners and diamondIds parameters. If camera calibration parameters - * are provided, the diamond search is based on reprojection. If not, diamond search is based on - * homography. Homography is faster than reprojection but can slightly reduce the detection rate. - */ -CV_EXPORTS_W void detectCharucoDiamond(InputArray image, InputArrayOfArrays markerCorners, - InputArray markerIds, float squareMarkerLengthRate, - OutputArrayOfArrays diamondCorners, OutputArray diamondIds, - InputArray cameraMatrix = noArray(), - InputArray distCoeffs = noArray()); - - - -/** - * @brief Draw a set of detected ChArUco Diamond markers - * - * @param image input/output image. It must have 1 or 3 channels. The number of channels is not - * altered. - * @param diamondCorners positions of diamond corners in the same format returned by - * detectCharucoDiamond(). (e.g std::vector > ). For N detected markers, - * the dimensions of this array should be Nx4. The order of the corners should be clockwise. - * @param diamondIds vector of identifiers for diamonds in diamondCorners, in the same format - * returned by detectCharucoDiamond() (e.g. std::vector). - * Optional, if not provided, ids are not painted. - * @param borderColor color of marker borders. Rest of colors (text color and first corner color) - * are calculated based on this one. - * - * Given an array of detected diamonds, this functions draws them in the image. The marker borders - * are painted and the markers identifiers if provided. - * Useful for debugging purposes. - */ -CV_EXPORTS_W void drawDetectedDiamonds(InputOutputArray image, InputArrayOfArrays diamondCorners, - InputArray diamondIds = noArray(), - Scalar borderColor = Scalar(0, 0, 255)); - - - - -/** - * @brief Draw a ChArUco Diamond marker - * - * @param dictionary dictionary of markers indicating the type of markers. - * @param ids list of 4 ids for each ArUco marker in the ChArUco marker. - * @param squareLength size of the chessboard squares in pixels. - * @param markerLength size of the markers in pixels. - * @param img output image with the marker. The size of this image will be - * 3*squareLength + 2*marginSize,. - * @param marginSize minimum margins (in pixels) of the marker in the output image - * @param borderBits width of the marker borders. - * - * This function return the image of a ChArUco marker, ready to be printed. - */ -// TODO cannot be exported yet; conversion from/to Vec4i is not wrapped in core -CV_EXPORTS void drawCharucoDiamond(const Ptr &dictionary, Vec4i ids, int squareLength, - int markerLength, OutputArray img, int marginSize = 0, - int borderBits = 1); - - -/** - * @brief test whether the ChArUco markers are collinear - * - * @param _board layout of ChArUco board. - * @param _charucoIds list of identifiers for each corner in charucoCorners per frame. - * @return bool value, 1 (true) if detected corners form a line, 0 (false) if they do not. - solvePnP, calibration functions will fail if the corners are collinear (true). - * - * The number of ids in charucoIDs should be <= the number of chessboard corners in the board. This functions checks whether the charuco corners are on a straight line (returns true, if so), or not (false). Axis parallel, as well as diagonal and other straight lines detected. Degenerate cases: for number of charucoIDs <= 2, the function returns true. - */ -CV_EXPORTS_W bool testCharucoCornersCollinear(const Ptr &_board, - InputArray _charucoIds); - -//! @} -} -} - -#endif diff --git a/3rdparty/include/opencv2/aruco/dictionary.hpp b/3rdparty/include/opencv2/aruco/dictionary.hpp deleted file mode 100644 index 27c7e5dd73..0000000000 --- a/3rdparty/include/opencv2/aruco/dictionary.hpp +++ /dev/null @@ -1,212 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2013, OpenCV Foundation, 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -#ifndef __OPENCV_DICTIONARY_HPP__ -#define __OPENCV_DICTIONARY_HPP__ - -#include - -namespace cv { -namespace aruco { - -//! @addtogroup aruco -//! @{ - - -/** - * @brief Dictionary/Set of markers. It contains the inner codification - * - * bytesList contains the marker codewords where - * - bytesList.rows is the dictionary size - * - each marker is encoded using `nbytes = ceil(markerSize*markerSize/8.)` - * - each row contains all 4 rotations of the marker, so its length is `4*nbytes` - * - * `bytesList.ptr(i)[k*nbytes + j]` is then the j-th byte of i-th marker, in its k-th rotation. - */ -class CV_EXPORTS_W Dictionary { - - public: - CV_PROP_RW Mat bytesList; // marker code information - CV_PROP_RW int markerSize; // number of bits per dimension - CV_PROP_RW int maxCorrectionBits; // maximum number of bits that can be corrected - - - /** - */ - Dictionary(const Mat &_bytesList = Mat(), int _markerSize = 0, int _maxcorr = 0); - - - /** - Dictionary(const Dictionary &_dictionary); - */ - - - /** - */ - Dictionary(const Ptr &_dictionary); - - - /** - * @see generateCustomDictionary - */ - CV_WRAP_AS(create) static Ptr create(int nMarkers, int markerSize, int randomSeed=0); - - - /** - * @see generateCustomDictionary - */ - CV_WRAP_AS(create_from) static Ptr create(int nMarkers, int markerSize, - const Ptr &baseDictionary, int randomSeed=0); - - /** - * @see getPredefinedDictionary - */ - CV_WRAP static Ptr get(int dict); - - /** - * @brief Given a matrix of bits. Returns whether if marker is identified or not. - * It returns by reference the correct id (if any) and the correct rotation - */ - bool identify(const Mat &onlyBits, int &idx, int &rotation, double maxCorrectionRate) const; - - /** - * @brief Returns the distance of the input bits to the specific id. If allRotations is true, - * the four posible bits rotation are considered - */ - int getDistanceToId(InputArray bits, int id, bool allRotations = true) const; - - - /** - * @brief Draw a canonical marker image - */ - CV_WRAP void drawMarker(int id, int sidePixels, OutputArray _img, int borderBits = 1) const; - - - /** - * @brief Transform matrix of bits to list of bytes in the 4 rotations - */ - CV_WRAP static Mat getByteListFromBits(const Mat &bits); - - - /** - * @brief Transform list of bytes to matrix of bits - */ - CV_WRAP static Mat getBitsFromByteList(const Mat &byteList, int markerSize); -}; - - - - -/** - * @brief Predefined markers dictionaries/sets - * Each dictionary indicates the number of bits and the number of markers contained - * - DICT_ARUCO_ORIGINAL: standard ArUco Library Markers. 1024 markers, 5x5 bits, 0 minimum - distance - */ -enum PREDEFINED_DICTIONARY_NAME { - DICT_4X4_50 = 0, - DICT_4X4_100, - DICT_4X4_250, - DICT_4X4_1000, - DICT_5X5_50, - DICT_5X5_100, - DICT_5X5_250, - DICT_5X5_1000, - DICT_6X6_50, - DICT_6X6_100, - DICT_6X6_250, - DICT_6X6_1000, - DICT_7X7_50, - DICT_7X7_100, - DICT_7X7_250, - DICT_7X7_1000, - DICT_ARUCO_ORIGINAL, - DICT_APRILTAG_16h5, ///< 4x4 bits, minimum hamming distance between any two codes = 5, 30 codes - DICT_APRILTAG_25h9, ///< 5x5 bits, minimum hamming distance between any two codes = 9, 35 codes - DICT_APRILTAG_36h10, ///< 6x6 bits, minimum hamming distance between any two codes = 10, 2320 codes - DICT_APRILTAG_36h11 ///< 6x6 bits, minimum hamming distance between any two codes = 11, 587 codes -}; - - -/** - * @brief Returns one of the predefined dictionaries defined in PREDEFINED_DICTIONARY_NAME - */ -CV_EXPORTS Ptr getPredefinedDictionary(PREDEFINED_DICTIONARY_NAME name); - - -/** - * @brief Returns one of the predefined dictionaries referenced by DICT_*. - */ -CV_EXPORTS_W Ptr getPredefinedDictionary(int dict); - - -/** - * @see generateCustomDictionary - */ -CV_EXPORTS_AS(custom_dictionary) Ptr generateCustomDictionary( - int nMarkers, - int markerSize, - int randomSeed=0); - - -/** - * @brief Generates a new customizable marker dictionary - * - * @param nMarkers number of markers in the dictionary - * @param markerSize number of bits per dimension of each markers - * @param baseDictionary Include the markers in this dictionary at the beginning (optional) - * @param randomSeed a user supplied seed for theRNG() - * - * This function creates a new dictionary composed by nMarkers markers and each markers composed - * by markerSize x markerSize bits. If baseDictionary is provided, its markers are directly - * included and the rest are generated based on them. If the size of baseDictionary is higher - * than nMarkers, only the first nMarkers in baseDictionary are taken and no new marker is added. - */ -CV_EXPORTS_AS(custom_dictionary_from) Ptr generateCustomDictionary( - int nMarkers, - int markerSize, - const Ptr &baseDictionary, - int randomSeed=0); - - - -//! @} -} -} - -#endif diff --git a/3rdparty/include/opencv2/bgsegm.hpp b/3rdparty/include/opencv2/bgsegm.hpp deleted file mode 100644 index 8ace5d9a5e..0000000000 --- a/3rdparty/include/opencv2/bgsegm.hpp +++ /dev/null @@ -1,380 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2013, OpenCV Foundation, 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -#ifndef __OPENCV_BGSEGM_HPP__ -#define __OPENCV_BGSEGM_HPP__ - -#include "opencv2/video.hpp" - -#ifdef __cplusplus - -/** @defgroup bgsegm Improved Background-Foreground Segmentation Methods -*/ - -namespace cv -{ -namespace bgsegm -{ - -//! @addtogroup bgsegm -//! @{ - -/** @brief Gaussian Mixture-based Background/Foreground Segmentation Algorithm. - -The class implements the algorithm described in @cite KB2001 . - */ -class CV_EXPORTS_W BackgroundSubtractorMOG : public BackgroundSubtractor -{ -public: - CV_WRAP virtual int getHistory() const = 0; - CV_WRAP virtual void setHistory(int nframes) = 0; - - CV_WRAP virtual int getNMixtures() const = 0; - CV_WRAP virtual void setNMixtures(int nmix) = 0; - - CV_WRAP virtual double getBackgroundRatio() const = 0; - CV_WRAP virtual void setBackgroundRatio(double backgroundRatio) = 0; - - CV_WRAP virtual double getNoiseSigma() const = 0; - CV_WRAP virtual void setNoiseSigma(double noiseSigma) = 0; -}; - -/** @brief Creates mixture-of-gaussian background subtractor - -@param history Length of the history. -@param nmixtures Number of Gaussian mixtures. -@param backgroundRatio Background ratio. -@param noiseSigma Noise strength (standard deviation of the brightness or each color channel). 0 -means some automatic value. - */ -CV_EXPORTS_W Ptr - createBackgroundSubtractorMOG(int history=200, int nmixtures=5, - double backgroundRatio=0.7, double noiseSigma=0); - - -/** @brief Background Subtractor module based on the algorithm given in @cite Gold2012 . - - Takes a series of images and returns a sequence of mask (8UC1) - images of the same size, where 255 indicates Foreground and 0 represents Background. - This class implements an algorithm described in "Visual Tracking of Human Visitors under - Variable-Lighting Conditions for a Responsive Audio Art Installation," A. Godbehere, - A. Matsukawa, K. Goldberg, American Control Conference, Montreal, June 2012. - */ -class CV_EXPORTS_W BackgroundSubtractorGMG : public BackgroundSubtractor -{ -public: - /** @brief Returns total number of distinct colors to maintain in histogram. - */ - CV_WRAP virtual int getMaxFeatures() const = 0; - /** @brief Sets total number of distinct colors to maintain in histogram. - */ - CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; - - /** @brief Returns the learning rate of the algorithm. - - It lies between 0.0 and 1.0. It determines how quickly features are "forgotten" from - histograms. - */ - CV_WRAP virtual double getDefaultLearningRate() const = 0; - /** @brief Sets the learning rate of the algorithm. - */ - CV_WRAP virtual void setDefaultLearningRate(double lr) = 0; - - /** @brief Returns the number of frames used to initialize background model. - */ - CV_WRAP virtual int getNumFrames() const = 0; - /** @brief Sets the number of frames used to initialize background model. - */ - CV_WRAP virtual void setNumFrames(int nframes) = 0; - - /** @brief Returns the parameter used for quantization of color-space. - - It is the number of discrete levels in each channel to be used in histograms. - */ - CV_WRAP virtual int getQuantizationLevels() const = 0; - /** @brief Sets the parameter used for quantization of color-space - */ - CV_WRAP virtual void setQuantizationLevels(int nlevels) = 0; - - /** @brief Returns the prior probability that each individual pixel is a background pixel. - */ - CV_WRAP virtual double getBackgroundPrior() const = 0; - /** @brief Sets the prior probability that each individual pixel is a background pixel. - */ - CV_WRAP virtual void setBackgroundPrior(double bgprior) = 0; - - /** @brief Returns the kernel radius used for morphological operations - */ - CV_WRAP virtual int getSmoothingRadius() const = 0; - /** @brief Sets the kernel radius used for morphological operations - */ - CV_WRAP virtual void setSmoothingRadius(int radius) = 0; - - /** @brief Returns the value of decision threshold. - - Decision value is the value above which pixel is determined to be FG. - */ - CV_WRAP virtual double getDecisionThreshold() const = 0; - /** @brief Sets the value of decision threshold. - */ - CV_WRAP virtual void setDecisionThreshold(double thresh) = 0; - - /** @brief Returns the status of background model update - */ - CV_WRAP virtual bool getUpdateBackgroundModel() const = 0; - /** @brief Sets the status of background model update - */ - CV_WRAP virtual void setUpdateBackgroundModel(bool update) = 0; - - /** @brief Returns the minimum value taken on by pixels in image sequence. Usually 0. - */ - CV_WRAP virtual double getMinVal() const = 0; - /** @brief Sets the minimum value taken on by pixels in image sequence. - */ - CV_WRAP virtual void setMinVal(double val) = 0; - - /** @brief Returns the maximum value taken on by pixels in image sequence. e.g. 1.0 or 255. - */ - CV_WRAP virtual double getMaxVal() const = 0; - /** @brief Sets the maximum value taken on by pixels in image sequence. - */ - CV_WRAP virtual void setMaxVal(double val) = 0; -}; - -/** @brief Creates a GMG Background Subtractor - -@param initializationFrames number of frames used to initialize the background models. -@param decisionThreshold Threshold value, above which it is marked foreground, else background. - */ -CV_EXPORTS_W Ptr createBackgroundSubtractorGMG(int initializationFrames=120, - double decisionThreshold=0.8); - -/** @brief Background subtraction based on counting. - - About as fast as MOG2 on a high end system. - More than twice faster than MOG2 on cheap hardware (benchmarked on Raspberry Pi3). - - %Algorithm by Sagi Zeevi ( https://github.com/sagi-z/BackgroundSubtractorCNT ) -*/ -class CV_EXPORTS_W BackgroundSubtractorCNT : public BackgroundSubtractor -{ -public: - // BackgroundSubtractor interface - CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; - CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const CV_OVERRIDE = 0; - - /** @brief Returns number of frames with same pixel color to consider stable. - */ - CV_WRAP virtual int getMinPixelStability() const = 0; - /** @brief Sets the number of frames with same pixel color to consider stable. - */ - CV_WRAP virtual void setMinPixelStability(int value) = 0; - - /** @brief Returns maximum allowed credit for a pixel in history. - */ - CV_WRAP virtual int getMaxPixelStability() const = 0; - /** @brief Sets the maximum allowed credit for a pixel in history. - */ - CV_WRAP virtual void setMaxPixelStability(int value) = 0; - - /** @brief Returns if we're giving a pixel credit for being stable for a long time. - */ - CV_WRAP virtual bool getUseHistory() const = 0; - /** @brief Sets if we're giving a pixel credit for being stable for a long time. - */ - CV_WRAP virtual void setUseHistory(bool value) = 0; - - /** @brief Returns if we're parallelizing the algorithm. - */ - CV_WRAP virtual bool getIsParallel() const = 0; - /** @brief Sets if we're parallelizing the algorithm. - */ - CV_WRAP virtual void setIsParallel(bool value) = 0; -}; - -/** @brief Creates a CNT Background Subtractor - -@param minPixelStability number of frames with same pixel color to consider stable -@param useHistory determines if we're giving a pixel credit for being stable for a long time -@param maxPixelStability maximum allowed credit for a pixel in history -@param isParallel determines if we're parallelizing the algorithm - */ - -CV_EXPORTS_W Ptr -createBackgroundSubtractorCNT(int minPixelStability = 15, - bool useHistory = true, - int maxPixelStability = 15*60, - bool isParallel = true); - -enum LSBPCameraMotionCompensation { - LSBP_CAMERA_MOTION_COMPENSATION_NONE = 0, - LSBP_CAMERA_MOTION_COMPENSATION_LK -}; - -/** @brief Implementation of the different yet better algorithm which is called GSOC, as it was implemented during GSOC and was not originated from any paper. - -This algorithm demonstrates better performance on CDNET 2014 dataset compared to other algorithms in OpenCV. - */ -class CV_EXPORTS_W BackgroundSubtractorGSOC : public BackgroundSubtractor -{ -public: - // BackgroundSubtractor interface - CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; - - CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const CV_OVERRIDE = 0; -}; - -/** @brief Background Subtraction using Local SVD Binary Pattern. More details about the algorithm can be found at @cite LGuo2016 - */ -class CV_EXPORTS_W BackgroundSubtractorLSBP : public BackgroundSubtractor -{ -public: - // BackgroundSubtractor interface - CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; - - CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const CV_OVERRIDE = 0; -}; - -/** @brief This is for calculation of the LSBP descriptors. - */ -class CV_EXPORTS_W BackgroundSubtractorLSBPDesc -{ -public: - static void calcLocalSVDValues(OutputArray localSVDValues, const Mat& frame); - - static void computeFromLocalSVDValues(OutputArray desc, const Mat& localSVDValues, const Point2i* LSBPSamplePoints); - - static void compute(OutputArray desc, const Mat& frame, const Point2i* LSBPSamplePoints); -}; - -/** @brief Creates an instance of BackgroundSubtractorGSOC algorithm. - -Implementation of the different yet better algorithm which is called GSOC, as it was implemented during GSOC and was not originated from any paper. - -@param mc Whether to use camera motion compensation. -@param nSamples Number of samples to maintain at each point of the frame. -@param replaceRate Probability of replacing the old sample - how fast the model will update itself. -@param propagationRate Probability of propagating to neighbors. -@param hitsThreshold How many positives the sample must get before it will be considered as a possible replacement. -@param alpha Scale coefficient for threshold. -@param beta Bias coefficient for threshold. -@param blinkingSupressionDecay Blinking supression decay factor. -@param blinkingSupressionMultiplier Blinking supression multiplier. -@param noiseRemovalThresholdFacBG Strength of the noise removal for background points. -@param noiseRemovalThresholdFacFG Strength of the noise removal for foreground points. - */ -CV_EXPORTS_W Ptr createBackgroundSubtractorGSOC(int mc = LSBP_CAMERA_MOTION_COMPENSATION_NONE, int nSamples = 20, float replaceRate = 0.003f, float propagationRate = 0.01f, int hitsThreshold = 32, float alpha = 0.01f, float beta = 0.0022f, float blinkingSupressionDecay = 0.1f, float blinkingSupressionMultiplier = 0.1f, float noiseRemovalThresholdFacBG = 0.0004f, float noiseRemovalThresholdFacFG = 0.0008f); - -/** @brief Creates an instance of BackgroundSubtractorLSBP algorithm. - -Background Subtraction using Local SVD Binary Pattern. More details about the algorithm can be found at @cite LGuo2016 - -@param mc Whether to use camera motion compensation. -@param nSamples Number of samples to maintain at each point of the frame. -@param LSBPRadius LSBP descriptor radius. -@param Tlower Lower bound for T-values. See @cite LGuo2016 for details. -@param Tupper Upper bound for T-values. See @cite LGuo2016 for details. -@param Tinc Increase step for T-values. See @cite LGuo2016 for details. -@param Tdec Decrease step for T-values. See @cite LGuo2016 for details. -@param Rscale Scale coefficient for threshold values. -@param Rincdec Increase/Decrease step for threshold values. -@param noiseRemovalThresholdFacBG Strength of the noise removal for background points. -@param noiseRemovalThresholdFacFG Strength of the noise removal for foreground points. -@param LSBPthreshold Threshold for LSBP binary string. -@param minCount Minimal number of matches for sample to be considered as foreground. - */ -CV_EXPORTS_W Ptr createBackgroundSubtractorLSBP(int mc = LSBP_CAMERA_MOTION_COMPENSATION_NONE, int nSamples = 20, int LSBPRadius = 16, float Tlower = 2.0f, float Tupper = 32.0f, float Tinc = 1.0f, float Tdec = 0.05f, float Rscale = 10.0f, float Rincdec = 0.005f, float noiseRemovalThresholdFacBG = 0.0004f, float noiseRemovalThresholdFacFG = 0.0008f, int LSBPthreshold = 8, int minCount = 2); - -/** @brief Synthetic frame sequence generator for testing background subtraction algorithms. - - It will generate the moving object on top of the background. - It will apply some distortion to the background to make the test more complex. - */ -class CV_EXPORTS_W SyntheticSequenceGenerator : public Algorithm -{ -private: - const double amplitude; - const double wavelength; - const double wavespeed; - const double objspeed; - unsigned timeStep; - Point2d pos; - Point2d dir; - Mat background; - Mat object; - RNG rng; - -public: - /** @brief Creates an instance of SyntheticSequenceGenerator. - - @param background Background image for object. - @param object Object image which will move slowly over the background. - @param amplitude Amplitude of wave distortion applied to background. - @param wavelength Length of waves in distortion applied to background. - @param wavespeed How fast waves will move. - @param objspeed How fast object will fly over background. - */ - CV_WRAP SyntheticSequenceGenerator(InputArray background, InputArray object, double amplitude, double wavelength, double wavespeed, double objspeed); - - /** @brief Obtain the next frame in the sequence. - - @param frame Output frame. - @param gtMask Output ground-truth (reference) segmentation mask object/background. - */ - CV_WRAP void getNextFrame(OutputArray frame, OutputArray gtMask); -}; - -/** @brief Creates an instance of SyntheticSequenceGenerator. - -@param background Background image for object. -@param object Object image which will move slowly over the background. -@param amplitude Amplitude of wave distortion applied to background. -@param wavelength Length of waves in distortion applied to background. -@param wavespeed How fast waves will move. -@param objspeed How fast object will fly over background. - */ -CV_EXPORTS_W Ptr createSyntheticSequenceGenerator(InputArray background, InputArray object, double amplitude = 2.0, double wavelength = 20.0, double wavespeed = 0.2, double objspeed = 6.0); - -//! @} - -} -} - -#endif -#endif diff --git a/3rdparty/include/opencv2/bioinspired.hpp b/3rdparty/include/opencv2/bioinspired.hpp deleted file mode 100644 index 9c7e23bd22..0000000000 --- a/3rdparty/include/opencv2/bioinspired.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/*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_BIOINSPIRED_HPP__ -#define __OPENCV_BIOINSPIRED_HPP__ - -#include "opencv2/core.hpp" -#include "opencv2/bioinspired/retina.hpp" -#include "opencv2/bioinspired/retinafasttonemapping.hpp" -#include "opencv2/bioinspired/transientareassegmentationmodule.hpp" - -/** @defgroup bioinspired Biologically inspired vision models and derivated tools - -The module provides biological visual systems models (human visual system and others). It also -provides derivated objects that take advantage of those bio-inspired models. - -@ref bioinspired_retina - -*/ - -#endif diff --git a/3rdparty/include/opencv2/bioinspired/bioinspired.hpp b/3rdparty/include/opencv2/bioinspired/bioinspired.hpp deleted file mode 100644 index 40be2854eb..0000000000 --- a/3rdparty/include/opencv2/bioinspired/bioinspired.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/*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. -// Copyright (C) 2013, OpenCV Foundation, 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*/ - -#ifdef __OPENCV_BUILD -#error this is a compatibility header which should not be used inside the OpenCV library -#endif - -#include "opencv2/bioinspired.hpp" diff --git a/3rdparty/include/opencv2/bioinspired/retina.hpp b/3rdparty/include/opencv2/bioinspired/retina.hpp deleted file mode 100644 index 91c81484ff..0000000000 --- a/3rdparty/include/opencv2/bioinspired/retina.hpp +++ /dev/null @@ -1,454 +0,0 @@ -/*#****************************************************************************** - ** 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. - ** - ** - ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab. - ** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping. - ** - ** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications) - ** - ** Creation - enhancement process 2007-2015 - ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France - ** - ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). - ** Refer to the following research paper for more information: - ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 - ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: - ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. - ** - ** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author : - ** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper: - ** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007 - ** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions. - ** ====> more informations in the above cited Jeanny Heraults's book. - ** - ** License Agreement - ** For Open Source Computer Vision Library - ** - ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. - ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. - ** - ** For Human Visual System tools (bioinspired) - ** Copyright (C) 2007-2015, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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: - ** - ** * Redistributions of source code must retain the above copyright notice, - ** this list of conditions and the following disclaimer. - ** - ** * Redistributions 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. - *******************************************************************************/ - -#ifndef __OPENCV_BIOINSPIRED_RETINA_HPP__ -#define __OPENCV_BIOINSPIRED_RETINA_HPP__ - -/** -@file -@date Jul 19, 2011 -@author Alexandre Benoit -*/ - -#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support - - -namespace cv{ -namespace bioinspired{ - -//! @addtogroup bioinspired -//! @{ - -enum { - RETINA_COLOR_RANDOM, //!< each pixel position is either R, G or B in a random choice - RETINA_COLOR_DIAGONAL,//!< color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR... - RETINA_COLOR_BAYER//!< standard bayer sampling -}; - - -/** @brief retina model parameters structure - - For better clarity, check explenations on the comments of methods : setupOPLandIPLParvoChannel and setupIPLMagnoChannel - - Here is the default configuration file of the retina module. It gives results such as the first - retina output shown on the top of this page. - - @code{xml} - - - - 1 - 1 - 7.5e-01 - 9.0e-01 - 5.3e-01 - 0.01 - 0.5 - 7. - 7.5e-01 - - 1 - 0. - 0. - 7. - 2.0e+00 - 9.5e-01 - 0. - 7. - - @endcode - - Here is the 'realistic" setup used to obtain the second retina output shown on the top of this page. - - @code{xml} - - - - 1 - 1 - 8.9e-01 - 9.0e-01 - 5.3e-01 - 0.3 - 0.5 - 7. - 8.9e-01 - - 1 - 0. - 0. - 7. - 2.0e+00 - 9.5e-01 - 0. - 7. - - @endcode - */ - struct RetinaParameters{ - //! Outer Plexiform Layer (OPL) and Inner Plexiform Layer Parvocellular (IplParvo) parameters - struct OPLandIplParvoParameters{ - OPLandIplParvoParameters():colorMode(true), - normaliseOutput(true), - photoreceptorsLocalAdaptationSensitivity(0.75f), - photoreceptorsTemporalConstant(0.9f), - photoreceptorsSpatialConstant(0.53f), - horizontalCellsGain(0.01f), - hcellsTemporalConstant(0.5f), - hcellsSpatialConstant(7.f), - ganglionCellsSensitivity(0.75f) { } // default setup - bool colorMode, normaliseOutput; - float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity; - }; - //! Inner Plexiform Layer Magnocellular channel (IplMagno) - struct IplMagnoParameters{ - IplMagnoParameters(): - normaliseOutput(true), - parasolCells_beta(0.f), - parasolCells_tau(0.f), - parasolCells_k(7.f), - amacrinCellsTemporalCutFrequency(2.0f), - V0CompressionParameter(0.95f), - localAdaptintegration_tau(0.f), - localAdaptintegration_k(7.f) { } // default setup - bool normaliseOutput; - float parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k; - }; - OPLandIplParvoParameters OPLandIplParvo; - IplMagnoParameters IplMagno; - }; - - - -/** @brief class which allows the Gipsa/Listic Labs model to be used with OpenCV. - -This retina model allows spatio-temporal image processing (applied on still images, video sequences). -As a summary, these are the retina model properties: -- It applies a spectral whithening (mid-frequency details enhancement) -- high frequency spatio-temporal noise reduction -- low frequency luminance to be reduced (luminance range compression) -- local logarithmic luminance compression allows details to be enhanced in low light conditions - -USE : this model can be used basically for spatio-temporal video effects but also for : - _using the getParvo method output matrix : texture analysiswith enhanced signal to noise ratio and enhanced details robust against input images luminance ranges - _using the getMagno method output matrix : motion analysis also with the previously cited properties - -for more information, reer to the following papers : -Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 -Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. - -The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author : -take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper: -B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007 -take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions. -more informations in the above cited Jeanny Heraults's book. - */ -class CV_EXPORTS_W Retina : public Algorithm { - -public: - - - /** @brief Retreive retina input buffer size - @return the retina input buffer size - */ - CV_WRAP virtual Size getInputSize()=0; - - /** @brief Retreive retina output buffer size that can be different from the input if a spatial log - transformation is applied - @return the retina output buffer size - */ - CV_WRAP virtual Size getOutputSize()=0; - - /** @brief Try to open an XML retina parameters file to adjust current retina instance setup - - - if the xml file does not exist, then default setup is applied - - warning, Exceptions are thrown if read XML file is not valid - @param retinaParameterFile the parameters filename - @param applyDefaultSetupOnFailure set to true if an error must be thrown on error - - You can retrieve the current parameters structure using the method Retina::getParameters and update - it before running method Retina::setup. - */ - CV_WRAP virtual void setup(String retinaParameterFile="", const bool applyDefaultSetupOnFailure=true)=0; - - /** @overload - @param fs the open Filestorage which contains retina parameters - @param applyDefaultSetupOnFailure set to true if an error must be thrown on error - */ - virtual void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true)=0; - - /** @overload - @param newParameters a parameters structures updated with the new target configuration. - */ - virtual void setup(RetinaParameters newParameters)=0; - - /** - @return the current parameters setup - */ - virtual RetinaParameters getParameters()=0; - - /** @brief Outputs a string showing the used parameters setup - @return a string which contains formated parameters information - */ - CV_WRAP virtual const String printSetup()=0; - - /** @brief Write xml/yml formated parameters information - @param fs the filename of the xml file that will be open and writen with formatted parameters - information - */ - CV_WRAP virtual void write( String fs ) const=0; - - /** @overload */ - virtual void write( FileStorage& fs ) const CV_OVERRIDE = 0; - - /** @brief Setup the OPL and IPL parvo channels (see biologocal model) - - OPL is referred as Outer Plexiform Layer of the retina, it allows the spatio-temporal filtering - which withens the spectrum and reduces spatio-temporal noise while attenuating global luminance - (low frequency energy) IPL parvo is the OPL next processing stage, it refers to a part of the - Inner Plexiform layer of the retina, it allows high contours sensitivity in foveal vision. See - reference papers for more informations. - for more informations, please have a look at the paper Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 - @param colorMode specifies if (true) color is processed of not (false) to then processing gray - level image - @param normaliseOutput specifies if (true) output is rescaled between 0 and 255 of not (false) - @param photoreceptorsLocalAdaptationSensitivity the photoreceptors sensitivity renage is 0-1 - (more log compression effect when value increases) - @param photoreceptorsTemporalConstant the time constant of the first order low pass filter of - the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is - frames, typical value is 1 frame - @param photoreceptorsSpatialConstant the spatial constant of the first order low pass filter of - the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is - pixels, typical value is 1 pixel - @param horizontalCellsGain gain of the horizontal cells network, if 0, then the mean value of - the output is zero, if the parameter is near 1, then, the luminance is not filtered and is - still reachable at the output, typicall value is 0 - @param HcellsTemporalConstant the time constant of the first order low pass filter of the - horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is - frames, typical value is 1 frame, as the photoreceptors - @param HcellsSpatialConstant the spatial constant of the first order low pass filter of the - horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, - typical value is 5 pixel, this value is also used for local contrast computing when computing - the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular - channel model) - @param ganglionCellsSensitivity the compression strengh of the ganglion cells local adaptation - output, set a value between 0.6 and 1 for best results, a high value increases more the low - value sensitivity... and the output saturates faster, recommended value: 0.7 - */ - CV_WRAP virtual void setupOPLandIPLParvoChannel(const bool colorMode=true, const bool normaliseOutput = true, const float photoreceptorsLocalAdaptationSensitivity=0.7f, const float photoreceptorsTemporalConstant=0.5f, const float photoreceptorsSpatialConstant=0.53f, const float horizontalCellsGain=0.f, const float HcellsTemporalConstant=1.f, const float HcellsSpatialConstant=7.f, const float ganglionCellsSensitivity=0.7f)=0; - - /** @brief Set parameters values for the Inner Plexiform Layer (IPL) magnocellular channel - - this channel processes signals output from OPL processing stage in peripheral vision, it allows - motion information enhancement. It is decorrelated from the details channel. See reference - papers for more details. - - @param normaliseOutput specifies if (true) output is rescaled between 0 and 255 of not (false) - @param parasolCells_beta the low pass filter gain used for local contrast adaptation at the - IPL level of the retina (for ganglion cells local adaptation), typical value is 0 - @param parasolCells_tau the low pass filter time constant used for local contrast adaptation - at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical - value is 0 (immediate response) - @param parasolCells_k the low pass filter spatial constant used for local contrast adaptation - at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical - value is 5 - @param amacrinCellsTemporalCutFrequency the time constant of the first order high pass fiter of - the magnocellular way (motion information channel), unit is frames, typical value is 1.2 - @param V0CompressionParameter the compression strengh of the ganglion cells local adaptation - output, set a value between 0.6 and 1 for best results, a high value increases more the low - value sensitivity... and the output saturates faster, recommended value: 0.95 - @param localAdaptintegration_tau specifies the temporal constant of the low pas filter - involved in the computation of the local "motion mean" for the local adaptation computation - @param localAdaptintegration_k specifies the spatial constant of the low pas filter involved - in the computation of the local "motion mean" for the local adaptation computation - */ - CV_WRAP virtual void setupIPLMagnoChannel(const bool normaliseOutput = true, const float parasolCells_beta=0.f, const float parasolCells_tau=0.f, const float parasolCells_k=7.f, const float amacrinCellsTemporalCutFrequency=1.2f, const float V0CompressionParameter=0.95f, const float localAdaptintegration_tau=0.f, const float localAdaptintegration_k=7.f)=0; - - /** @brief Method which allows retina to be applied on an input image, - - after run, encapsulated retina module is ready to deliver its outputs using dedicated - acccessors, see getParvo and getMagno methods - @param inputImage the input Mat image to be processed, can be gray level or BGR coded in any - format (from 8bit to 16bits) - */ - CV_WRAP virtual void run(InputArray inputImage)=0; - - /** @brief Method which processes an image in the aim to correct its luminance correct - backlight problems, enhance details in shadows. - - This method is designed to perform High Dynamic Range image tone mapping (compress \>8bit/pixel - images to 8bit/pixel). This is a simplified version of the Retina Parvocellular model - (simplified version of the run/getParvo methods call) since it does not include the - spatio-temporal filter modelling the Outer Plexiform Layer of the retina that performs spectral - whitening and many other stuff. However, it works great for tone mapping and in a faster way. - - Check the demos and experiments section to see examples and the way to perform tone mapping - using the original retina model and the method. - - @param inputImage the input image to process (should be coded in float format : CV_32F, - CV_32FC1, CV_32F_C3, CV_32F_C4, the 4th channel won't be considered). - @param outputToneMappedImage the output 8bit/channel tone mapped image (CV_8U or CV_8UC3 format). - */ - CV_WRAP virtual void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)=0; - - /** @brief Accessor of the details channel of the retina (models foveal vision). - - Warning, getParvoRAW methods return buffers that are not rescaled within range [0;255] while - the non RAW method allows a normalized matrix to be retrieved. - - @param retinaOutput_parvo the output buffer (reallocated if necessary), format can be : - - a Mat, this output is rescaled for standard 8bits image processing use in OpenCV - - RAW methods actually return a 1D matrix (encoding is R1, R2, ... Rn, G1, G2, ..., Gn, B1, - B2, ...Bn), this output is the original retina filter model output, without any - quantification or rescaling. - @see getParvoRAW - */ - CV_WRAP virtual void getParvo(OutputArray retinaOutput_parvo)=0; - - /** @brief Accessor of the details channel of the retina (models foveal vision). - @see getParvo - */ - CV_WRAP virtual void getParvoRAW(OutputArray retinaOutput_parvo)=0; - - /** @brief Accessor of the motion channel of the retina (models peripheral vision). - - Warning, getMagnoRAW methods return buffers that are not rescaled within range [0;255] while - the non RAW method allows a normalized matrix to be retrieved. - @param retinaOutput_magno the output buffer (reallocated if necessary), format can be : - - a Mat, this output is rescaled for standard 8bits image processing use in OpenCV - - RAW methods actually return a 1D matrix (encoding is M1, M2,... Mn), this output is the - original retina filter model output, without any quantification or rescaling. - @see getMagnoRAW - */ - CV_WRAP virtual void getMagno(OutputArray retinaOutput_magno)=0; - - /** @brief Accessor of the motion channel of the retina (models peripheral vision). - @see getMagno - */ - CV_WRAP virtual void getMagnoRAW(OutputArray retinaOutput_magno)=0; - - /** @overload */ - CV_WRAP virtual const Mat getMagnoRAW() const=0; - /** @overload */ - CV_WRAP virtual const Mat getParvoRAW() const=0; - - /** @brief Activate color saturation as the final step of the color demultiplexing process -\> this - saturation is a sigmoide function applied to each channel of the demultiplexed image. - @param saturateColors boolean that activates color saturation (if true) or desactivate (if false) - @param colorSaturationValue the saturation factor : a simple factor applied on the chrominance - buffers - */ - CV_WRAP virtual void setColorSaturation(const bool saturateColors=true, const float colorSaturationValue=4.0f)=0; - - /** @brief Clears all retina buffers - - (equivalent to opening the eyes after a long period of eye close ;o) whatchout the temporal - transition occuring just after this method call. - */ - CV_WRAP virtual void clearBuffers()=0; - - /** @brief Activate/desactivate the Magnocellular pathway processing (motion information extraction), by - default, it is activated - @param activate true if Magnocellular output should be activated, false if not... if activated, - the Magnocellular output can be retrieved using the **getMagno** methods - */ - CV_WRAP virtual void activateMovingContoursProcessing(const bool activate)=0; - - /** @brief Activate/desactivate the Parvocellular pathway processing (contours information extraction), by - default, it is activated - @param activate true if Parvocellular (contours information extraction) output should be - activated, false if not... if activated, the Parvocellular output can be retrieved using the - Retina::getParvo methods - */ - CV_WRAP virtual void activateContoursProcessing(const bool activate)=0; - - /** @overload */ - CV_WRAP static Ptr create(Size inputSize); - /** @brief Constructors from standardized interfaces : retreive a smart pointer to a Retina instance - - @param inputSize the input frame size - @param colorMode the chosen processing mode : with or without color processing - @param colorSamplingMethod specifies which kind of color sampling will be used : - - cv::bioinspired::RETINA_COLOR_RANDOM: each pixel position is either R, G or B in a random choice - - cv::bioinspired::RETINA_COLOR_DIAGONAL: color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR... - - cv::bioinspired::RETINA_COLOR_BAYER: standard bayer sampling - @param useRetinaLogSampling activate retina log sampling, if true, the 2 following parameters can - be used - @param reductionFactor only usefull if param useRetinaLogSampling=true, specifies the reduction - factor of the output frame (as the center (fovea) is high resolution and corners can be - underscaled, then a reduction of the output is allowed without precision leak - @param samplingStrength only usefull if param useRetinaLogSampling=true, specifies the strength of - the log scale that is applied - */ - CV_WRAP static Ptr create(Size inputSize, const bool colorMode, - int colorSamplingMethod=RETINA_COLOR_BAYER, - const bool useRetinaLogSampling=false, - const float reductionFactor=1.0f, const float samplingStrength=10.0f); -}; - -//! @} - -} -} -#endif /* __OPENCV_BIOINSPIRED_RETINA_HPP__ */ diff --git a/3rdparty/include/opencv2/bioinspired/retinafasttonemapping.hpp b/3rdparty/include/opencv2/bioinspired/retinafasttonemapping.hpp deleted file mode 100644 index ba1a87292e..0000000000 --- a/3rdparty/include/opencv2/bioinspired/retinafasttonemapping.hpp +++ /dev/null @@ -1,138 +0,0 @@ - -/*#****************************************************************************** - ** 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. - ** - ** - ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab. - ** - ** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications) - ** - ** Creation - enhancement process 2007-2013 - ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France - ** - ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). - ** Refer to the following research paper for more information: - ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 - ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: - ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. - ** - ** - ** - ** - ** - ** This class is based on image processing tools of the author and already used within the Retina class (this is the same code as method retina::applyFastToneMapping, but in an independent class, it is ligth from a memory requirement point of view). It implements an adaptation of the efficient tone mapping algorithm propose by David Alleyson, Sabine Susstruck and Laurence Meylan's work, please cite: - ** -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816 - ** - ** - ** License Agreement - ** For Open Source Computer Vision Library - ** - ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. - ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. - ** - ** For Human Visual System tools (bioinspired) - ** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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: - ** - ** * Redistributions of source code must retain the above copyright notice, - ** this list of conditions and the following disclaimer. - ** - ** * Redistributions 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. - *******************************************************************************/ - -#ifndef __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ -#define __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ - -/** -@file -@date May 26, 2013 -@author Alexandre Benoit - */ - -#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support - -namespace cv{ -namespace bioinspired{ - -//! @addtogroup bioinspired -//! @{ - -/** @brief a wrapper class which allows the tone mapping algorithm of Meylan&al(2007) to be used with OpenCV. - -This algorithm is already implemented in thre Retina class (retina::applyFastToneMapping) but used it does not require all the retina model to be allocated. This allows a light memory use for low memory devices (smartphones, etc. -As a summary, these are the model properties: -- 2 stages of local luminance adaptation with a different local neighborhood for each. -- first stage models the retina photorecetors local luminance adaptation -- second stage models th ganglion cells local information adaptation -- compared to the initial publication, this class uses spatio-temporal low pass filters instead of spatial only filters. - this can help noise robustness and temporal stability for video sequence use cases. - -for more information, read to the following papers : -Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 -regarding spatio-temporal filter and the bigger retina model : -Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. -*/ -class CV_EXPORTS_W RetinaFastToneMapping : public Algorithm -{ -public: - - /** @brief applies a luminance correction (initially High Dynamic Range (HDR) tone mapping) - - using only the 2 local adaptation stages of the retina parvocellular channel : photoreceptors - level and ganlion cells level. Spatio temporal filtering is applied but limited to temporal - smoothing and eventually high frequencies attenuation. This is a lighter method than the one - available using the regular retina::run method. It is then faster but it does not include - complete temporal filtering nor retina spectral whitening. Then, it can have a more limited - effect on images with a very high dynamic range. This is an adptation of the original still - image HDR tone mapping algorithm of David Alleyson, Sabine Susstruck and Laurence Meylan's - work, please cite: -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local - Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of - America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816 - - @param inputImage the input image to process RGB or gray levels - @param outputToneMappedImage the output tone mapped image - */ - CV_WRAP virtual void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)=0; - - /** @brief updates tone mapping behaviors by adjusing the local luminance computation area - - @param photoreceptorsNeighborhoodRadius the first stage local adaptation area - @param ganglioncellsNeighborhoodRadius the second stage local adaptation area - @param meanLuminanceModulatorK the factor applied to modulate the meanLuminance information - (default is 1, see reference paper) - */ - CV_WRAP virtual void setup(const float photoreceptorsNeighborhoodRadius=3.f, const float ganglioncellsNeighborhoodRadius=1.f, const float meanLuminanceModulatorK=1.f)=0; - - CV_WRAP static Ptr create(Size inputSize); -}; - - -//! @} - -} -} -#endif /* __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ */ diff --git a/3rdparty/include/opencv2/bioinspired/transientareassegmentationmodule.hpp b/3rdparty/include/opencv2/bioinspired/transientareassegmentationmodule.hpp deleted file mode 100644 index d5f5b2fd1e..0000000000 --- a/3rdparty/include/opencv2/bioinspired/transientareassegmentationmodule.hpp +++ /dev/null @@ -1,204 +0,0 @@ -/*#****************************************************************************** - ** 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. - ** - ** - ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. - ** TransientAreasSegmentationModule Use: extract areas that present spatio-temporal changes. - ** => It should be used at the output of the cv::bioinspired::Retina::getMagnoRAW() output that enhances spatio-temporal changes - ** - ** Maintainers : Listic lab (code author current affiliation & applications) - ** - ** Creation - enhancement process 2007-2015 - ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France - ** - ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). - ** Refer to the following research paper for more information: - ** Strat, S.T.; Benoit, A.; Lambert, P., "Retina enhanced bag of words descriptors for video classification," Signal Processing Conference (EUSIPCO), 2014 Proceedings of the 22nd European , vol., no., pp.1307,1311, 1-5 Sept. 2014 (http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6952461&isnumber=6951911) - ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 - ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: - ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. - ** - ** - ** License Agreement - ** For Open Source Computer Vision Library - ** - ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. - ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. - ** - ** For Human Visual System tools (bioinspired) - ** Copyright (C) 2007-2015, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, 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: - ** - ** * Redistributions of source code must retain the above copyright notice, - ** this list of conditions and the following disclaimer. - ** - ** * Redistributions 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. - *******************************************************************************/ - -#ifndef SEGMENTATIONMODULE_HPP_ -#define SEGMENTATIONMODULE_HPP_ - -/** -@file -@date 2007-2013 -@author Alexandre BENOIT, benoit.alexandre.vision@gmail.com -*/ - -#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support - -namespace cv -{ -namespace bioinspired -{ -//! @addtogroup bioinspired -//! @{ - -/** @brief parameter structure that stores the transient events detector setup parameters -*/ -struct SegmentationParameters{ // CV_EXPORTS_W_MAP to export to python native dictionnaries - // default structure instance construction with default values - SegmentationParameters(): - thresholdON(100), - thresholdOFF(100), - localEnergy_temporalConstant(0.5), - localEnergy_spatialConstant(5), - neighborhoodEnergy_temporalConstant(1), - neighborhoodEnergy_spatialConstant(15), - contextEnergy_temporalConstant(1), - contextEnergy_spatialConstant(75){}; - // all properties list - float thresholdON; - float thresholdOFF; - //! the time constant of the first order low pass filter, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 0.5 frame - float localEnergy_temporalConstant; - //! the spatial constant of the first order low pass filter, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 5 pixel - float localEnergy_spatialConstant; - //! local neighborhood energy filtering parameters : the aim is to get information about the energy neighborhood to perform a center surround energy analysis - float neighborhoodEnergy_temporalConstant; - float neighborhoodEnergy_spatialConstant; - //! context neighborhood energy filtering parameters : the aim is to get information about the energy on a wide neighborhood area to filtered out local effects - float contextEnergy_temporalConstant; - float contextEnergy_spatialConstant; -}; - -/** @brief class which provides a transient/moving areas segmentation module - -perform a locally adapted segmentation by using the retina magno input data Based on Alexandre -BENOIT thesis: "Le système visuel humain au secours de la vision par ordinateur" - -3 spatio temporal filters are used: -- a first one which filters the noise and local variations of the input motion energy -- a second (more powerfull low pass spatial filter) which gives the neighborhood motion energy the -segmentation consists in the comparison of these both outputs, if the local motion energy is higher -to the neighborhood otion energy, then the area is considered as moving and is segmented -- a stronger third low pass filter helps decision by providing a smooth information about the -"motion context" in a wider area - */ - -class CV_EXPORTS_W TransientAreasSegmentationModule: public Algorithm -{ -public: - - - /** @brief return the sze of the manage input and output images - */ - CV_WRAP virtual Size getSize()=0; - - /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup - - - if the xml file does not exist, then default setup is applied - - warning, Exceptions are thrown if read XML file is not valid - @param segmentationParameterFile : the parameters filename - @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error - */ - CV_WRAP virtual void setup(String segmentationParameterFile="", const bool applyDefaultSetupOnFailure=true)=0; - - /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup - - - if the xml file does not exist, then default setup is applied - - warning, Exceptions are thrown if read XML file is not valid - @param fs : the open Filestorage which contains segmentation parameters - @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error - */ - virtual void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true)=0; - - /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup - - - if the xml file does not exist, then default setup is applied - - warning, Exceptions are thrown if read XML file is not valid - @param newParameters : a parameters structures updated with the new target configuration - */ - virtual void setup(SegmentationParameters newParameters)=0; - - /** @brief return the current parameters setup - */ - virtual SegmentationParameters getParameters()=0; - - /** @brief parameters setup display method - @return a string which contains formatted parameters information - */ - CV_WRAP virtual const String printSetup()=0; - - /** @brief write xml/yml formated parameters information - @param fs : the filename of the xml file that will be open and writen with formatted parameters information - */ - CV_WRAP virtual void write( String fs ) const=0; - - /** @brief write xml/yml formated parameters information - @param fs : a cv::Filestorage object ready to be filled - */ - virtual void write( cv::FileStorage& fs ) const CV_OVERRIDE = 0; - - /** @brief main processing method, get result using methods getSegmentationPicture() - @param inputToSegment : the image to process, it must match the instance buffer size ! - @param channelIndex : the channel to process in case of multichannel images - */ - CV_WRAP virtual void run(InputArray inputToSegment, const int channelIndex=0)=0; - - /** @brief access function - return the last segmentation result: a boolean picture which is resampled between 0 and 255 for a display purpose - */ - CV_WRAP virtual void getSegmentationPicture(OutputArray transientAreas)=0; - - /** @brief cleans all the buffers of the instance - */ - CV_WRAP virtual void clearAllBuffers()=0; - - /** @brief allocator - @param inputSize : size of the images input to segment (output will be the same size) - */ - CV_WRAP static Ptr create(Size inputSize); -}; - -//! @} - -}} // namespaces end : cv and bioinspired - - -#endif - - diff --git a/3rdparty/include/opencv2/calib3d.hpp b/3rdparty/include/opencv2/calib3d.hpp index b48c928d82..4928df65d1 100644 --- a/3rdparty/include/opencv2/calib3d.hpp +++ b/3rdparty/include/opencv2/calib3d.hpp @@ -441,9 +441,16 @@ namespace cv //! @{ //! type of the robust estimation algorithm -enum { LMEDS = 4, //!< least-median of squares algorithm - RANSAC = 8, //!< RANSAC algorithm - RHO = 16 //!< RHO algorithm +enum { LMEDS = 4, //!< least-median of squares algorithm + RANSAC = 8, //!< RANSAC algorithm + RHO = 16, //!< RHO algorithm + USAC_DEFAULT = 32, //!< USAC algorithm, default settings + USAC_PARALLEL = 33, //!< USAC, parallel version + USAC_FM_8PTS = 34, //!< USAC, fundamental matrix 8 points + USAC_FAST = 35, //!< USAC, fast settings + USAC_ACCURATE = 36, //!< USAC, accurate settings + USAC_PROSAC = 37, //!< USAC, sorted points, runs PROSAC + USAC_MAGSAC = 38 //!< USAC, runs MAGSAC++ }; enum SolvePnPMethod { @@ -473,7 +480,11 @@ enum SolvePnPMethod { enum { CALIB_CB_ADAPTIVE_THRESH = 1, CALIB_CB_NORMALIZE_IMAGE = 2, CALIB_CB_FILTER_QUADS = 4, - CALIB_CB_FAST_CHECK = 8 + CALIB_CB_FAST_CHECK = 8, + CALIB_CB_EXHAUSTIVE = 16, + CALIB_CB_ACCURACY = 32, + CALIB_CB_LARGER = 64, + CALIB_CB_MARKER = 128 }; enum { CALIB_CB_SYMMETRIC_GRID = 1, @@ -481,7 +492,8 @@ enum { CALIB_CB_SYMMETRIC_GRID = 1, CALIB_CB_CLUSTERING = 4 }; -enum { CALIB_USE_INTRINSIC_GUESS = 0x00001, +enum { CALIB_NINTRINSIC = 18, + CALIB_USE_INTRINSIC_GUESS = 0x00001, CALIB_FIX_ASPECT_RATIO = 0x00002, CALIB_FIX_PRINCIPAL_POINT = 0x00004, CALIB_ZERO_TANGENT_DIST = 0x00008, @@ -524,6 +536,34 @@ enum HandEyeCalibrationMethod CALIB_HAND_EYE_DANIILIDIS = 4 //!< Hand-Eye Calibration Using Dual Quaternions @cite Daniilidis98 }; +enum RobotWorldHandEyeCalibrationMethod +{ + CALIB_ROBOT_WORLD_HAND_EYE_SHAH = 0, //!< Solving the robot-world/hand-eye calibration problem using the kronecker product @cite Shah2013SolvingTR + CALIB_ROBOT_WORLD_HAND_EYE_LI = 1 //!< Simultaneous robot-world and hand-eye calibration using dual-quaternions and kronecker product @cite Li2010SimultaneousRA +}; + +enum SamplingMethod { SAMPLING_UNIFORM, SAMPLING_PROGRESSIVE_NAPSAC, SAMPLING_NAPSAC, + SAMPLING_PROSAC }; +enum LocalOptimMethod {LOCAL_OPTIM_NULL, LOCAL_OPTIM_INNER_LO, LOCAL_OPTIM_INNER_AND_ITER_LO, + LOCAL_OPTIM_GC, LOCAL_OPTIM_SIGMA}; +enum ScoreMethod {SCORE_METHOD_RANSAC, SCORE_METHOD_MSAC, SCORE_METHOD_MAGSAC, SCORE_METHOD_LMEDS}; +enum NeighborSearchMethod { NEIGH_FLANN_KNN, NEIGH_GRID, NEIGH_FLANN_RADIUS }; + +struct CV_EXPORTS_W_SIMPLE UsacParams +{ // in alphabetical order + CV_WRAP UsacParams(); + CV_PROP_RW double confidence; + CV_PROP_RW bool isParallel; + CV_PROP_RW int loIterations; + CV_PROP_RW LocalOptimMethod loMethod; + CV_PROP_RW int loSampleSize; + CV_PROP_RW int maxIterations; + CV_PROP_RW NeighborSearchMethod neighborsSearch; + CV_PROP_RW int randomGeneratorState; + CV_PROP_RW SamplingMethod sampler; + CV_PROP_RW ScoreMethod score; + CV_PROP_RW double threshold; +}; /** @brief Converts a rotation matrix to a rotation vector or vice versa. @@ -553,6 +593,73 @@ can be found in: */ CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() ); + + +/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it + optimizes the target vector criteria "err" + (finds local minima of each target vector component absolute value). + + When needed, it calls user-provided callback. +*/ +class CV_EXPORTS LMSolver : public Algorithm +{ +public: + class CV_EXPORTS Callback + { + public: + virtual ~Callback() {} + /** + computes error and Jacobian for the specified vector of parameters + + @param param the current vector of parameters + @param err output vector of errors: err_i = actual_f_i - ideal_f_i + @param J output Jacobian: J_ij = d(err_i)/d(param_j) + + when J=noArray(), it means that it does not need to be computed. + Dimensionality of error vector and param vector can be different. + The callback should explicitly allocate (with "create" method) each output array + (unless it's noArray()). + */ + virtual bool compute(InputArray param, OutputArray err, OutputArray J) const = 0; + }; + + /** + Runs Levenberg-Marquardt algorithm using the passed vector of parameters as the start point. + The final vector of parameters (whether the algorithm converged or not) is stored at the same + vector. The method returns the number of iterations used. If it's equal to the previously specified + maxIters, there is a big chance the algorithm did not converge. + + @param param initial/final vector of parameters. + + Note that the dimensionality of parameter space is defined by the size of param vector, + and the dimensionality of optimized criteria is defined by the size of err vector + computed by the callback. + */ + virtual int run(InputOutputArray param) const = 0; + + /** + Sets the maximum number of iterations + @param maxIters the number of iterations + */ + virtual void setMaxIters(int maxIters) = 0; + /** + Retrieves the current maximum number of iterations + */ + virtual int getMaxIters() const = 0; + + /** + Creates Levenberg-Marquard solver + + @param cb callback + @param maxIters maximum number of iterations that can be further + modified using setMaxIters() method. + */ + static Ptr create(const Ptr& cb, int maxIters); + static Ptr create(const Ptr& cb, int maxIters, double eps); +}; + + + /** @example samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp An example program about pose estimation from coplanar points @@ -627,6 +734,10 @@ CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints, CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints, OutputArray mask, int method = 0, double ransacReprojThreshold = 3 ); + +CV_EXPORTS_W Mat findHomography(InputArray srcPoints, InputArray dstPoints, OutputArray mask, + const UsacParams ¶ms); + /** @brief Computes an RQ decomposition of 3x3 matrices. @param src 3x3 input matrix. @@ -637,7 +748,7 @@ CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints, @param Qz Optional output 3x3 rotation matrix around z-axis. The function computes a RQ decomposition using the given rotations. This function is used in -decomposeProjectionMatrix to decompose the left 3x3 submatrix of a projection matrix into a camera +#decomposeProjectionMatrix to decompose the left 3x3 submatrix of a projection matrix into a camera and a rotation matrix. It optionally returns three rotation matrices, one for each axis, and the three Euler angles in @@ -691,7 +802,7 @@ CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray The function computes partial derivatives of the elements of the matrix product \f$A*B\f$ with regard to the elements of each of the two input matrices. The function is used to compute the Jacobian -matrices in stereoCalibrate but can also be used in any other similar optimization function. +matrices in #stereoCalibrate but can also be used in any other similar optimization function. */ CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB ); @@ -720,7 +831,7 @@ where \f$\mathrm{rodrigues}\f$ denotes a rotation vector to a rotation matrix tr \f$\mathrm{rodrigues}^{-1}\f$ denotes the inverse transformation. See Rodrigues for details. Also, the functions can compute the derivatives of the output vectors with regards to the input -vectors (see matMulDeriv ). The functions are used inside stereoCalibrate but can also be used in +vectors (see matMulDeriv ). The functions are used inside #stereoCalibrate but can also be used in your own code where Levenberg-Marquardt or another gradient-based solver is used to optimize a function that contains a matrix multiplication. */ @@ -941,7 +1052,7 @@ a 3D point expressed in the world frame into the camera frame: arrays (enforced by the assertion using cv::Mat::checkVector() around line 55 of modules/calib3d/src/solvepnp.cpp version 2.4.9) - The P3P algorithm requires image points to be in an array of shape (N,1,2) due - to its calling of cv::undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9) + to its calling of #undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9) which requires 2-channel information. - Thus, given some data D = np.array(...) where D.shape = (N,M), in order to use a subset of it as, e.g., imagePoints, one must effectively copy it into a new array: imagePoints = @@ -1017,6 +1128,16 @@ CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoint float reprojectionError = 8.0, double confidence = 0.99, OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE ); + +/* +Finds rotation and translation vector. +If cameraMatrix is given then run P3P. Otherwise run linear P6P and output cameraMatrix too. +*/ +CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints, + InputOutputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, OutputArray inliers, + const UsacParams ¶ms=UsacParams()); + /** @brief Finds an object pose from 3 3D-2D point correspondences. @param objectPoints Array of object points in the object coordinate space, 3x3 1-channel or @@ -1136,7 +1257,7 @@ vectors, respectively, and further optimizes them. - @ref SOLVEPNP_ITERATIVE Iterative method is based on a Levenberg-Marquardt optimization. In this case the function finds such a pose that minimizes reprojection error, that is the sum of squared distances between the observed projections imagePoints and the projected (using -projectPoints ) objectPoints . + #projectPoints ) objectPoints . - @ref SOLVEPNP_P3P Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang "Complete Solution Classification for the Perspective-Three-Point Problem" (@cite gao2003complete). In this case the function requires exactly four object and image points. @@ -1272,7 +1393,7 @@ a 3D point expressed in the world frame into the camera frame: arrays (enforced by the assertion using cv::Mat::checkVector() around line 55 of modules/calib3d/src/solvepnp.cpp version 2.4.9) - The P3P algorithm requires image points to be in an array of shape (N,1,2) due - to its calling of cv::undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9) + to its calling of #undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9) which requires 2-channel information. - Thus, given some data D = np.array(...) where D.shape = (N,M), in order to use a subset of it as, e.g., imagePoints, one must effectively copy it into a new array: imagePoints = @@ -1305,7 +1426,7 @@ CV_EXPORTS_W int solvePnPGeneric( InputArray objectPoints, InputArray imagePoint @param objectPoints Vector of vectors of the calibration pattern points in the calibration pattern coordinate space. In the old interface all the per-view vectors are concatenated. See -calibrateCamera for details. +#calibrateCamera for details. @param imagePoints Vector of vectors of the projections of the calibration pattern points. In the old interface all the per-view vectors are concatenated. @param imageSize Image size in pixels used to initialize the principal point. @@ -1324,7 +1445,7 @@ CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, @param image Source chessboard view. It must be an 8-bit grayscale or color image. @param patternSize Number of inner corners per a chessboard row and column -( patternSize = cvSize(points_per_row,points_per_colum) = cvSize(columns,rows) ). +( patternSize = cv::Size(points_per_row,points_per_colum) = cv::Size(columns,rows) ). @param corners Output array of detected corners. @param flags Various operation flags that can be zero or a combination of the following values: - @ref CALIB_CB_ADAPTIVE_THRESH Use adaptive thresholding to convert the image to black @@ -1372,6 +1493,103 @@ square grouping and ordering algorithm fails. CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners, int flags = CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE ); +/* + Checks whether the image contains chessboard of the specific size or not. + If yes, nonzero value is returned. +*/ +CV_EXPORTS_W bool checkChessboard(InputArray img, Size size); + +/** @brief Finds the positions of internal corners of the chessboard using a sector based approach. + +@param image Source chessboard view. It must be an 8-bit grayscale or color image. +@param patternSize Number of inner corners per a chessboard row and column +( patternSize = cv::Size(points_per_row,points_per_colum) = cv::Size(columns,rows) ). +@param corners Output array of detected corners. +@param flags Various operation flags that can be zero or a combination of the following values: +- @ref CALIB_CB_NORMALIZE_IMAGE Normalize the image gamma with equalizeHist before detection. +- @ref CALIB_CB_EXHAUSTIVE Run an exhaustive search to improve detection rate. +- @ref CALIB_CB_ACCURACY Up sample input image to improve sub-pixel accuracy due to aliasing effects. +- @ref CALIB_CB_LARGER The detected pattern is allowed to be larger than patternSize (see description). +- @ref CALIB_CB_MARKER The detected pattern must have a marker (see description). +This should be used if an accurate camera calibration is required. +@param meta Optional output arrray of detected corners (CV_8UC1 and size = cv::Size(columns,rows)). +Each entry stands for one corner of the pattern and can have one of the following values: +- 0 = no meta data attached +- 1 = left-top corner of a black cell +- 2 = left-top corner of a white cell +- 3 = left-top corner of a black cell with a white marker dot +- 4 = left-top corner of a white cell with a black marker dot (pattern origin in case of markers otherwise first corner) + +The function is analog to #findChessboardCorners but uses a localized radon +transformation approximated by box filters being more robust to all sort of +noise, faster on larger images and is able to directly return the sub-pixel +position of the internal chessboard corners. The Method is based on the paper +@cite duda2018 "Accurate Detection and Localization of Checkerboard Corners for +Calibration" demonstrating that the returned sub-pixel positions are more +accurate than the one returned by cornerSubPix allowing a precise camera +calibration for demanding applications. + +In the case, the flags @ref CALIB_CB_LARGER or @ref CALIB_CB_MARKER are given, +the result can be recovered from the optional meta array. Both flags are +helpful to use calibration patterns exceeding the field of view of the camera. +These oversized patterns allow more accurate calibrations as corners can be +utilized, which are as close as possible to the image borders. For a +consistent coordinate system across all images, the optional marker (see image +below) can be used to move the origin of the board to the location where the +black circle is located. + +@note The function requires a white boarder with roughly the same width as one +of the checkerboard fields around the whole board to improve the detection in +various environments. In addition, because of the localized radon +transformation it is beneficial to use round corners for the field corners +which are located on the outside of the board. The following figure illustrates +a sample checkerboard optimized for the detection. However, any other checkerboard +can be used as well. +![Checkerboard](pics/checkerboard_radon.png) + */ +CV_EXPORTS_AS(findChessboardCornersSBWithMeta) +bool findChessboardCornersSB(InputArray image,Size patternSize, OutputArray corners, + int flags,OutputArray meta); +/** @overload */ +CV_EXPORTS_W inline +bool findChessboardCornersSB(InputArray image, Size patternSize, OutputArray corners, + int flags = 0) +{ + return findChessboardCornersSB(image, patternSize, corners, flags, noArray()); +} + +/** @brief Estimates the sharpness of a detected chessboard. + +Image sharpness, as well as brightness, are a critical parameter for accuracte +camera calibration. For accessing these parameters for filtering out +problematic calibraiton images, this method calculates edge profiles by traveling from +black to white chessboard cell centers. Based on this, the number of pixels is +calculated required to transit from black to white. This width of the +transition area is a good indication of how sharp the chessboard is imaged +and should be below ~3.0 pixels. + +@param image Gray image used to find chessboard corners +@param patternSize Size of a found chessboard pattern +@param corners Corners found by #findChessboardCornersSB +@param rise_distance Rise distance 0.8 means 10% ... 90% of the final signal strength +@param vertical By default edge responses for horizontal lines are calculated +@param sharpness Optional output array with a sharpness value for calculated edge responses (see description) + +The optional sharpness array is of type CV_32FC1 and has for each calculated +profile one row with the following five entries: +* 0 = x coordinate of the underlying edge in the image +* 1 = y coordinate of the underlying edge in the image +* 2 = width of the transition area (sharpness) +* 3 = signal strength in the black cell (min brightness) +* 4 = signal strength in the white cell (max brightness) + +@return Scalar(average sharpness, average min brightness, average max brightness,0) +*/ +CV_EXPORTS_W Scalar estimateChessboardSharpness(InputArray image, Size patternSize, InputArray corners, + float rise_distance=0.8F,bool vertical=false, + OutputArray sharpness=noArray()); + + //! finds subpixel-accurate positions of the chessboard corners CV_EXPORTS_W bool find4QuadCornerSubpix( InputArray img, InputOutputArray corners, Size region_size ); @@ -1380,9 +1598,9 @@ CV_EXPORTS_W bool find4QuadCornerSubpix( InputArray img, InputOutputArray corner @param image Destination image. It must be an 8-bit color image. @param patternSize Number of inner corners per a chessboard row and column (patternSize = cv::Size(points_per_row,points_per_column)). -@param corners Array of detected corners, the output of findChessboardCorners. +@param corners Array of detected corners, the output of #findChessboardCorners. @param patternWasFound Parameter indicating whether the complete board was found or not. The -return value of findChessboardCorners should be passed here. +return value of #findChessboardCorners should be passed here. The function draws individual chessboard corners detected either as red circles if the board was not found, or as colored corners connected with lines if the board was found. @@ -1431,16 +1649,15 @@ struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters SYMMETRIC_GRID, ASYMMETRIC_GRID }; GridType gridType; -}; - -struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters2 : public CirclesGridFinderParameters -{ - CV_WRAP CirclesGridFinderParameters2(); CV_PROP_RW float squareSize; //!< Distance between two adjacent points. Used by CALIB_CB_CLUSTERING. CV_PROP_RW float maxRectifiedDistance; //!< Max deviation from prediction. Used by CALIB_CB_CLUSTERING. }; +#ifndef DISABLE_OPENCV_3_COMPATIBILITY +typedef CirclesGridFinderParameters CirclesGridFinderParameters2; +#endif + /** @brief Finds centers in the grid of circles. @param image grid view of input circles; it must be an 8-bit grayscale or color image. @@ -1477,13 +1694,7 @@ the board to make the detection more robust in various environments. CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, OutputArray centers, int flags, const Ptr &blobDetector, - CirclesGridFinderParameters parameters); - -/** @overload */ -CV_EXPORTS_W bool findCirclesGrid2( InputArray image, Size patternSize, - OutputArray centers, int flags, - const Ptr &blobDetector, - CirclesGridFinderParameters2 parameters); + const CirclesGridFinderParameters& parameters); /** @overload */ CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, @@ -1510,8 +1721,8 @@ concatenated together. @param imageSize Size of the image used only to initialize the camera intrinsic matrix. @param cameraMatrix Input/output 3x3 floating-point camera intrinsic matrix \f$\cameramatrix{A}\f$ . If @ref CALIB_USE_INTRINSIC_GUESS -and/or @ref CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be -initialized before calling the function. +and/or @ref CALIB_FIX_ASPECT_RATIO, @ref CALIB_FIX_PRINCIPAL_POINT or @ref CALIB_FIX_FOCAL_LENGTH +are specified, some or all of fx, fy, cx, cy must be initialized before calling the function. @param distCoeffs Input/output vector of distortion coefficients \f$\distcoeffs\f$. @param rvecs Output vector of rotation vectors (@ref Rodrigues ) estimated for each pattern view @@ -1537,7 +1748,7 @@ the number of pattern views. \f$R_i, T_i\f$ are concatenated 1x3 vectors. fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image center ( imageSize is used), and focal distances are computed in a least-squares fashion. Note, that if intrinsic parameters are known, there is no need to use this function just to -estimate extrinsic parameters. Use solvePnP instead. +estimate extrinsic parameters. Use @ref solvePnP instead. - @ref CALIB_FIX_PRINCIPAL_POINT The principal point is not changed during the global optimization. It stays at the center or at a different location specified when @ref CALIB_USE_INTRINSIC_GUESS is set too. @@ -1547,24 +1758,23 @@ ratio fx/fy stays the same as in the input cameraMatrix . When ignored, only their ratio is computed and used further. - @ref CALIB_ZERO_TANGENT_DIST Tangential distortion coefficients \f$(p_1, p_2)\f$ are set to zeros and stay zero. +- @ref CALIB_FIX_FOCAL_LENGTH The focal length is not changed during the global optimization if + @ref CALIB_USE_INTRINSIC_GUESS is set. - @ref CALIB_FIX_K1,..., @ref CALIB_FIX_K6 The corresponding radial distortion coefficient is not changed during the optimization. If @ref CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. - @ref CALIB_RATIONAL_MODEL Coefficients k4, k5, and k6 are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the -calibration function use the rational model and return 8 coefficients. If the flag is not -set, the function computes and returns only 5 distortion coefficients. +calibration function use the rational model and return 8 coefficients or more. - @ref CALIB_THIN_PRISM_MODEL Coefficients s1, s2, s3 and s4 are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the -calibration function use the thin prism model and return 12 coefficients. If the flag is not -set, the function computes and returns only 5 distortion coefficients. +calibration function use the thin prism model and return 12 coefficients or more. - @ref CALIB_FIX_S1_S2_S3_S4 The thin prism distortion coefficients are not changed during the optimization. If @ref CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. - @ref CALIB_TILTED_MODEL Coefficients tauX and tauY are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the -calibration function use the tilted sensor model and return 14 coefficients. If the flag is not -set, the function computes and returns only 5 distortion coefficients. +calibration function use the tilted sensor model and return 14 coefficients. - @ref CALIB_FIX_TAUX_TAUY The coefficients of the tilted sensor model are not changed during the optimization. If @ref CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. @@ -1589,12 +1799,12 @@ The algorithm performs the following steps: zeros initially unless some of CALIB_FIX_K? are specified. - Estimate the initial camera pose as if the intrinsic parameters have been already known. This is - done using solvePnP . + done using @ref solvePnP . - Run the global Levenberg-Marquardt optimization algorithm to minimize the reprojection error, that is, the total sum of squared distances between the observed feature points imagePoints and the projected (using the current estimates for camera parameters and the poses) object points - objectPoints. See projectPoints for details. + objectPoints. See @ref projectPoints for details. @note If you use a non-square (i.e. non-N-by-N) grid and @ref findChessboardCorners for calibration, @@ -1604,7 +1814,8 @@ The algorithm performs the following steps: instead of using patternSize=cvSize(cols,rows) in @ref findChessboardCorners. @sa - findChessboardCorners, solvePnP, initCameraMatrix2D, stereoCalibrate, undistort + calibrateCameraRO, findChessboardCorners, solvePnP, initCameraMatrix2D, stereoCalibrate, + undistort */ CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, @@ -1616,14 +1827,7 @@ CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera( InputArrayOfArray int flags = 0, TermCriteria criteria = TermCriteria( TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); -/** @overload double calibrateCamera( InputArrayOfArrays objectPoints, - InputArrayOfArrays imagePoints, Size imageSize, - InputOutputArray cameraMatrix, InputOutputArray distCoeffs, - OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, - OutputArray stdDeviations, OutputArray perViewErrors, - int flags = 0, TermCriteria criteria = TermCriteria( - TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ) - */ +/** @overload */ CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, @@ -1631,10 +1835,88 @@ CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints, int flags = 0, TermCriteria criteria = TermCriteria( TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); +/** @brief Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. + +This function is an extension of #calibrateCamera with the method of releasing object which was +proposed in @cite strobl2011iccv. In many common cases with inaccurate, unmeasured, roughly planar +targets (calibration plates), this method can dramatically improve the precision of the estimated +camera parameters. Both the object-releasing method and standard method are supported by this +function. Use the parameter **iFixedPoint** for method selection. In the internal implementation, +#calibrateCamera is a wrapper for this function. + +@param objectPoints Vector of vectors of calibration pattern points in the calibration pattern +coordinate space. See #calibrateCamera for details. If the method of releasing object to be used, +the identical calibration board must be used in each view and it must be fully visible, and all +objectPoints[i] must be the same and all points should be roughly close to a plane. **The calibration +target has to be rigid, or at least static if the camera (rather than the calibration target) is +shifted for grabbing images.** +@param imagePoints Vector of vectors of the projections of calibration pattern points. See +#calibrateCamera for details. +@param imageSize Size of the image used only to initialize the intrinsic camera matrix. +@param iFixedPoint The index of the 3D object point in objectPoints[0] to be fixed. It also acts as +a switch for calibration method selection. If object-releasing method to be used, pass in the +parameter in the range of [1, objectPoints[0].size()-2], otherwise a value out of this range will +make standard calibration method selected. Usually the top-right corner point of the calibration +board grid is recommended to be fixed when object-releasing method being utilized. According to +\cite strobl2011iccv, two other points are also fixed. In this implementation, objectPoints[0].front +and objectPoints[0].back.z are used. With object-releasing method, accurate rvecs, tvecs and +newObjPoints are only possible if coordinates of these three fixed points are accurate enough. +@param cameraMatrix Output 3x3 floating-point camera matrix. See #calibrateCamera for details. +@param distCoeffs Output vector of distortion coefficients. See #calibrateCamera for details. +@param rvecs Output vector of rotation vectors estimated for each pattern view. See #calibrateCamera +for details. +@param tvecs Output vector of translation vectors estimated for each pattern view. +@param newObjPoints The updated output vector of calibration pattern points. The coordinates might +be scaled based on three fixed points. The returned coordinates are accurate only if the above +mentioned three fixed points are accurate. If not needed, noArray() can be passed in. This parameter +is ignored with standard calibration method. +@param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. +See #calibrateCamera for details. +@param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. +See #calibrateCamera for details. +@param stdDeviationsObjPoints Output vector of standard deviations estimated for refined coordinates +of calibration pattern points. It has the same size and order as objectPoints[0] vector. This +parameter is ignored with standard calibration method. + @param perViewErrors Output vector of the RMS re-projection error estimated for each pattern view. +@param flags Different flags that may be zero or a combination of some predefined values. See +#calibrateCamera for details. If the method of releasing object is used, the calibration time may +be much longer. CALIB_USE_QR or CALIB_USE_LU could be used for faster calibration with potentially +less precise and less stable in some rare cases. +@param criteria Termination criteria for the iterative optimization algorithm. + +@return the overall RMS re-projection error. + +The function estimates the intrinsic camera parameters and extrinsic parameters for each of the +views. The algorithm is based on @cite Zhang2000, @cite BouguetMCT and @cite strobl2011iccv. See +#calibrateCamera for other detailed explanations. +@sa + calibrateCamera, findChessboardCorners, solvePnP, initCameraMatrix2D, stereoCalibrate, undistort + */ +CV_EXPORTS_AS(calibrateCameraROExtended) double calibrateCameraRO( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, int iFixedPoint, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray newObjPoints, + OutputArray stdDeviationsIntrinsics, + OutputArray stdDeviationsExtrinsics, + OutputArray stdDeviationsObjPoints, + OutputArray perViewErrors, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); + +/** @overload */ +CV_EXPORTS_W double calibrateCameraRO( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, int iFixedPoint, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray newObjPoints, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); + /** @brief Computes useful camera characteristics from the camera intrinsic matrix. -@param cameraMatrix Input camera intrinsic matrix that can be estimated by calibrateCamera or -stereoCalibrate . +@param cameraMatrix Input camera intrinsic matrix that can be estimated by #calibrateCamera or +#stereoCalibrate . @param imageSize Input image size in pixels. @param apertureWidth Physical width in mm of the sensor. @param apertureHeight Physical height in mm of the sensor. @@ -1769,13 +2051,13 @@ Besides the stereo-related information, the function can also perform a full cal the two cameras. However, due to the high dimensionality of the parameter space and noise in the input data, the function can diverge from the correct solution. If the intrinsic parameters can be estimated with high accuracy for each of the cameras individually (for example, using -calibrateCamera ), you are recommended to do so and then pass @ref CALIB_FIX_INTRINSIC flag to the +#calibrateCamera ), you are recommended to do so and then pass @ref CALIB_FIX_INTRINSIC flag to the function along with the computed intrinsic parameters. Otherwise, if all the parameters are estimated at once, it makes sense to restrict some parameters, for example, pass @ref CALIB_SAME_FOCAL_LENGTH and @ref CALIB_ZERO_TANGENT_DIST flags, which is usually a reasonable assumption. -Similarly to calibrateCamera, the function minimizes the total re-projection error for all the +Similarly to #calibrateCamera, the function minimizes the total re-projection error for all the points in all the available views from both cameras. The function returns the final value of the re-projection error. */ @@ -1835,7 +2117,7 @@ pixels from the original images from the cameras are retained in the rectified i image pixels are lost). Any intermediate value yields an intermediate result between those two extreme cases. @param newImageSize New image resolution after rectification. The same size should be passed to -initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) +#initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) is passed (default), it is set to the original imageSize . Setting it to a larger value can help you preserve details in the original image, especially when there is a big radial distortion. @param validPixROI1 Optional output rectangles inside the rectified images where all the pixels @@ -1847,7 +2129,7 @@ are valid. If alpha=0 , the ROIs cover the whole images. Otherwise, they are lik The function computes the rotation matrices for each camera that (virtually) make both camera image planes the same plane. Consequently, this makes all the epipolar lines parallel and thus simplifies -the dense stereo correspondence problem. The function takes the matrices computed by stereoCalibrate +the dense stereo correspondence problem. The function takes the matrices computed by #stereoCalibrate as input. As output, it provides two rotation matrices and also two projection matrices in the new coordinates. The function distinguishes the following two cases: @@ -1891,7 +2173,7 @@ coordinates. The function distinguishes the following two cases: @ref CALIB_ZERO_DISPARITY is set. As you can see, the first three columns of P1 and P2 will effectively be the new "rectified" camera -matrices. The matrices, together with R1 and R2 , can then be passed to initUndistortRectifyMap to +matrices. The matrices, together with R1 and R2 , can then be passed to #initUndistortRectifyMap to initialize the rectification map for each camera. See below the screenshot from the stereo_calib.cpp sample. Some red horizontal lines pass through @@ -1914,9 +2196,9 @@ CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs @param points1 Array of feature points in the first image. @param points2 The corresponding points in the second image. The same formats as in -findFundamentalMat are supported. +#findFundamentalMat are supported. @param F Input fundamental matrix. It can be computed from the same set of point pairs using -findFundamentalMat . +#findFundamentalMat . @param imgSize Size of the image. @param H1 Output rectification homography matrix for the first image. @param H2 Output rectification homography matrix for the second image. @@ -1927,7 +2209,7 @@ rejected prior to computing the homographies. Otherwise, all the points are cons The function computes the rectification transformations without knowing intrinsic parameters of the cameras and their relative position in the space, which explains the suffix "uncalibrated". Another -related difference from stereoRectify is that the function outputs not the rectification +related difference from #stereoRectify is that the function outputs not the rectification transformations in the object (3D) space, but the planar perspective transformations encoded by the homography matrices H1 and H2 . The function implements the algorithm @cite Hartley99 . @@ -1936,8 +2218,8 @@ homography matrices H1 and H2 . The function implements the algorithm @cite Hart depends on the epipolar geometry. Therefore, if the camera lenses have a significant distortion, it would be better to correct it before computing the fundamental matrix and calling this function. For example, distortion coefficients can be estimated for each head of stereo camera - separately by using calibrateCamera . Then, the images can be corrected using undistort , or - just the point coordinates can be corrected with undistortPoints . + separately by using #calibrateCamera . Then, the images can be corrected using #undistort , or + just the point coordinates can be corrected with #undistortPoints . */ CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2, InputArray F, Size imgSize, @@ -1965,10 +2247,10 @@ assumed. @param imageSize Original image size. @param alpha Free scaling parameter between 0 (when all the pixels in the undistorted image are valid) and 1 (when all the source image pixels are retained in the undistorted image). See -stereoRectify for details. +#stereoRectify for details. @param newImgSize Image size after rectification. By default, it is set to imageSize . @param validPixROI Optional output rectangle that outlines all-good-pixels region in the -undistorted image. See roi1, roi2 description in stereoRectify . +undistorted image. See roi1, roi2 description in #stereoRectify . @param centerPrincipalPoint Optional flag that indicates whether in the new camera intrinsic matrix the principal point should be at the image center or not. By default, the principal point is chosen to best fit a subset of the source image (determined by alpha) to the corrected image. @@ -1980,7 +2262,7 @@ image pixels if there is valuable information in the corners alpha=1 , or get so When alpha\>0 , the undistorted result is likely to have some black pixels corresponding to "virtual" pixels outside of the captured distorted image. The original camera intrinsic matrix, distortion coefficients, the computed new camera intrinsic matrix, and newImageSize should be passed to -initUndistortRectifyMap to produce the maps for remap . +#initUndistortRectifyMap to produce the maps for #remap . */ CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs, Size imageSize, double alpha, Size newImgSize = Size(), @@ -2018,12 +2300,16 @@ rotation then the translation (separable solutions) and the following methods ar - R. Horaud, F. Dornaika Hand-Eye Calibration \cite Horaud95 Another approach consists in estimating simultaneously the rotation and the translation (simultaneous solutions), -with the following implemented method: +with the following implemented methods: - N. Andreff, R. Horaud, B. Espiau On-line Hand-Eye Calibration \cite Andreff99 - K. Daniilidis Hand-Eye Calibration Using Dual Quaternions \cite Daniilidis98 The following picture describes the Hand-Eye calibration problem where the transformation between a camera ("eye") -mounted on a robot gripper ("hand") has to be estimated. +mounted on a robot gripper ("hand") has to be estimated. This configuration is called eye-in-hand. + +The eye-to-hand configuration consists in a static camera observing a calibration pattern mounted on the robot +end-effector. The transformation from the camera to the robot base frame can then be estimated by inputting +the suitable transformations to the function, see below. ![](pics/hand-eye_figure.png) @@ -2096,6 +2382,7 @@ The Hand-Eye calibration procedure returns the following homogeneous transformat \f] This problem is also known as solving the \f$\mathbf{A}\mathbf{X}=\mathbf{X}\mathbf{B}\f$ equation: + - for an eye-in-hand configuration \f[ \begin{align*} ^{b}{\textrm{T}_g}^{(1)} \hspace{0.2em} ^{g}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(1)} &= @@ -2108,6 +2395,19 @@ This problem is also known as solving the \f$\mathbf{A}\mathbf{X}=\mathbf{X}\mat \end{align*} \f] + - for an eye-to-hand configuration +\f[ + \begin{align*} + ^{g}{\textrm{T}_b}^{(1)} \hspace{0.2em} ^{b}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(1)} &= + \hspace{0.1em} ^{g}{\textrm{T}_b}^{(2)} \hspace{0.2em} ^{b}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(2)} \\ + + (^{g}{\textrm{T}_b}^{(2)})^{-1} \hspace{0.2em} ^{g}{\textrm{T}_b}^{(1)} \hspace{0.2em} ^{b}\textrm{T}_c &= + \hspace{0.1em} ^{b}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(2)} (^{c}{\textrm{T}_t}^{(1)})^{-1} \\ + + \textrm{A}_i \textrm{X} &= \textrm{X} \textrm{B}_i \\ + \end{align*} +\f] + \note Additional information can be found on this [website](http://campar.in.tum.de/Chair/HandEyeCalibration). \note @@ -2120,6 +2420,150 @@ CV_EXPORTS_W void calibrateHandEye( InputArrayOfArrays R_gripper2base, InputArra OutputArray R_cam2gripper, OutputArray t_cam2gripper, HandEyeCalibrationMethod method=CALIB_HAND_EYE_TSAI ); +/** @brief Computes Robot-World/Hand-Eye calibration: \f$_{}^{w}\textrm{T}_b\f$ and \f$_{}^{c}\textrm{T}_g\f$ + +@param[in] R_world2cam Rotation part extracted from the homogeneous matrix that transforms a point +expressed in the world frame to the camera frame (\f$_{}^{c}\textrm{T}_w\f$). +This is a vector (`vector`) that contains the rotation, `(3x3)` rotation matrices or `(3x1)` rotation vectors, +for all the transformations from world frame to the camera frame. +@param[in] t_world2cam Translation part extracted from the homogeneous matrix that transforms a point +expressed in the world frame to the camera frame (\f$_{}^{c}\textrm{T}_w\f$). +This is a vector (`vector`) that contains the `(3x1)` translation vectors for all the transformations +from world frame to the camera frame. +@param[in] R_base2gripper Rotation part extracted from the homogeneous matrix that transforms a point +expressed in the robot base frame to the gripper frame (\f$_{}^{g}\textrm{T}_b\f$). +This is a vector (`vector`) that contains the rotation, `(3x3)` rotation matrices or `(3x1)` rotation vectors, +for all the transformations from robot base frame to the gripper frame. +@param[in] t_base2gripper Rotation part extracted from the homogeneous matrix that transforms a point +expressed in the robot base frame to the gripper frame (\f$_{}^{g}\textrm{T}_b\f$). +This is a vector (`vector`) that contains the `(3x1)` translation vectors for all the transformations +from robot base frame to the gripper frame. +@param[out] R_base2world Estimated `(3x3)` rotation part extracted from the homogeneous matrix that transforms a point +expressed in the robot base frame to the world frame (\f$_{}^{w}\textrm{T}_b\f$). +@param[out] t_base2world Estimated `(3x1)` translation part extracted from the homogeneous matrix that transforms a point +expressed in the robot base frame to the world frame (\f$_{}^{w}\textrm{T}_b\f$). +@param[out] R_gripper2cam Estimated `(3x3)` rotation part extracted from the homogeneous matrix that transforms a point +expressed in the gripper frame to the camera frame (\f$_{}^{c}\textrm{T}_g\f$). +@param[out] t_gripper2cam Estimated `(3x1)` translation part extracted from the homogeneous matrix that transforms a point +expressed in the gripper frame to the camera frame (\f$_{}^{c}\textrm{T}_g\f$). +@param[in] method One of the implemented Robot-World/Hand-Eye calibration method, see cv::RobotWorldHandEyeCalibrationMethod + +The function performs the Robot-World/Hand-Eye calibration using various methods. One approach consists in estimating the +rotation then the translation (separable solutions): + - M. Shah, Solving the robot-world/hand-eye calibration problem using the kronecker product \cite Shah2013SolvingTR + +Another approach consists in estimating simultaneously the rotation and the translation (simultaneous solutions), +with the following implemented method: + - A. Li, L. Wang, and D. Wu, Simultaneous robot-world and hand-eye calibration using dual-quaternions and kronecker product \cite Li2010SimultaneousRA + +The following picture describes the Robot-World/Hand-Eye calibration problem where the transformations between a robot and a world frame +and between a robot gripper ("hand") and a camera ("eye") mounted at the robot end-effector have to be estimated. + +![](pics/robot-world_hand-eye_figure.png) + +The calibration procedure is the following: + - a static calibration pattern is used to estimate the transformation between the target frame + and the camera frame + - the robot gripper is moved in order to acquire several poses + - for each pose, the homogeneous transformation between the gripper frame and the robot base frame is recorded using for + instance the robot kinematics +\f[ + \begin{bmatrix} + X_g\\ + Y_g\\ + Z_g\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{g}\textrm{R}_b & _{}^{g}\textrm{t}_b \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_b\\ + Y_b\\ + Z_b\\ + 1 + \end{bmatrix} +\f] + - for each pose, the homogeneous transformation between the calibration target frame (the world frame) and the camera frame is recorded using + for instance a pose estimation method (PnP) from 2D-3D point correspondences +\f[ + \begin{bmatrix} + X_c\\ + Y_c\\ + Z_c\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{c}\textrm{R}_w & _{}^{c}\textrm{t}_w \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_w\\ + Y_w\\ + Z_w\\ + 1 + \end{bmatrix} +\f] + +The Robot-World/Hand-Eye calibration procedure returns the following homogeneous transformations +\f[ + \begin{bmatrix} + X_w\\ + Y_w\\ + Z_w\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{w}\textrm{R}_b & _{}^{w}\textrm{t}_b \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_b\\ + Y_b\\ + Z_b\\ + 1 + \end{bmatrix} +\f] +\f[ + \begin{bmatrix} + X_c\\ + Y_c\\ + Z_c\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{c}\textrm{R}_g & _{}^{c}\textrm{t}_g \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_g\\ + Y_g\\ + Z_g\\ + 1 + \end{bmatrix} +\f] + +This problem is also known as solving the \f$\mathbf{A}\mathbf{X}=\mathbf{Z}\mathbf{B}\f$ equation, with: + - \f$\mathbf{A} \Leftrightarrow \hspace{0.1em} _{}^{c}\textrm{T}_w\f$ + - \f$\mathbf{X} \Leftrightarrow \hspace{0.1em} _{}^{w}\textrm{T}_b\f$ + - \f$\mathbf{Z} \Leftrightarrow \hspace{0.1em} _{}^{c}\textrm{T}_g\f$ + - \f$\mathbf{B} \Leftrightarrow \hspace{0.1em} _{}^{g}\textrm{T}_b\f$ + +\note +At least 3 measurements are required (input vectors size must be greater or equal to 3). + + */ +CV_EXPORTS_W void calibrateRobotWorldHandEye( InputArrayOfArrays R_world2cam, InputArrayOfArrays t_world2cam, + InputArrayOfArrays R_base2gripper, InputArrayOfArrays t_base2gripper, + OutputArray R_base2world, OutputArray t_base2world, + OutputArray R_gripper2cam, OutputArray t_gripper2cam, + RobotWorldHandEyeCalibrationMethod method=CALIB_ROBOT_WORLD_HAND_EYE_SHAH ); + /** @brief Converts points from Euclidean to homogeneous space. @param src Input vector of N-dimensional points. @@ -2147,7 +2591,7 @@ CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst @param dst Output vector of 2D, 3D, or 4D points. The function converts 2D or 3D points from/to homogeneous coordinates by calling either -convertPointsToHomogeneous or convertPointsFromHomogeneous. +#convertPointsToHomogeneous or #convertPointsFromHomogeneous. @note The function is obsolete. Use one of the previous two functions instead. */ @@ -2186,7 +2630,7 @@ matrices sequentially). The calculated fundamental matrix may be passed further to computeCorrespondEpilines that finds the epipolar lines corresponding to the specified points. It can also be passed to -stereoRectifyUncalibrated to compute the rectification transformation. : +#stereoRectifyUncalibrated to compute the rectification transformation. : @code // Example. Estimation of fundamental matrix using the RANSAC algorithm int point_count = 100; @@ -2219,6 +2663,10 @@ CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2, OutputArray mask, int method = FM_RANSAC, double ransacReprojThreshold = 3., double confidence = 0.99 ); + +CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2, + OutputArray mask, const UsacParams ¶ms); + /** @brief Calculates an essential matrix from the corresponding points in two images. @param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should @@ -2227,7 +2675,7 @@ be floating-point (single or double precision). @param cameraMatrix Camera intrinsic matrix \f$\cameramatrix{A}\f$ . Note that this function assumes that points1 and points2 are feature points from cameras with the same camera intrinsic matrix. If this assumption does not hold for your use case, use -`undistortPoints()` with `P = cv::NoArray()` for both cameras to transform image points +#undistortPoints with `P = cv::NoArray()` for both cameras to transform image points to normalized image coordinates, which are valid for the identity camera intrinsic matrix. When passing these coordinates, pass the identity matrix for this parameter. @param method Method for computing an essential matrix. @@ -2241,6 +2689,7 @@ final fundamental matrix. It can be set to something like 1-3, depending on the point localization, image resolution, and the image noise. @param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in the RANSAC and LMedS methods. +@param maxIters The maximum number of robust method iterations. This function estimates essential matrix based on the five-point algorithm solver in @cite Nister03 . @cite SteweniusCFS is also a related. The epipolar geometry is described by the following equation: @@ -2249,12 +2698,24 @@ This function estimates essential matrix based on the five-point algorithm solve where \f$E\f$ is an essential matrix, \f$p_1\f$ and \f$p_2\f$ are corresponding points in the first and the second images, respectively. The result of this function may be passed further to -decomposeEssentialMat or recoverPose to recover the relative pose between cameras. +#decomposeEssentialMat or #recoverPose to recover the relative pose between cameras. */ -CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, - InputArray cameraMatrix, int method = RANSAC, - double prob = 0.999, double threshold = 1.0, - OutputArray mask = noArray() ); +CV_EXPORTS_W +Mat findEssentialMat( + InputArray points1, InputArray points2, + InputArray cameraMatrix, int method = RANSAC, + double prob = 0.999, double threshold = 1.0, + int maxIters = 1000, OutputArray mask = noArray() +); + +/** @overload */ +CV_EXPORTS +Mat findEssentialMat( + InputArray points1, InputArray points2, + InputArray cameraMatrix, int method, + double prob, double threshold, + OutputArray mask +); // TODO remove from OpenCV 5.0 /** @overload @param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should @@ -2274,6 +2735,7 @@ point localization, image resolution, and the image noise. confidence (probability) that the estimated matrix is correct. @param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in the RANSAC and LMedS methods. +@param maxIters The maximum number of robust method iterations. This function differs from the one above that it computes camera intrinsic matrix from focal length and principal point: @@ -2285,10 +2747,80 @@ f & 0 & x_{pp} \\ 0 & 0 & 1 \end{bmatrix}\f] */ +CV_EXPORTS_W +Mat findEssentialMat( + InputArray points1, InputArray points2, + double focal = 1.0, Point2d pp = Point2d(0, 0), + int method = RANSAC, double prob = 0.999, + double threshold = 1.0, int maxIters = 1000, + OutputArray mask = noArray() +); + +/** @overload */ +CV_EXPORTS +Mat findEssentialMat( + InputArray points1, InputArray points2, + double focal, Point2d pp, + int method, double prob, + double threshold, OutputArray mask +); // TODO remove from OpenCV 5.0 + +/** @brief Calculates an essential matrix from the corresponding points in two images from potentially two different cameras. + +@param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should +be floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param cameraMatrix1 Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +Note that this function assumes that points1 and points2 are feature points from cameras with the +same camera matrix. If this assumption does not hold for your use case, use +#undistortPoints with `P = cv::NoArray()` for both cameras to transform image points +to normalized image coordinates, which are valid for the identity camera matrix. When +passing these coordinates, pass the identity matrix for this parameter. +@param cameraMatrix2 Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +Note that this function assumes that points1 and points2 are feature points from cameras with the +same camera matrix. If this assumption does not hold for your use case, use +#undistortPoints with `P = cv::NoArray()` for both cameras to transform image points +to normalized image coordinates, which are valid for the identity camera matrix. When +passing these coordinates, pass the identity matrix for this parameter. +@param distCoeffs1 Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param distCoeffs2 Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param method Method for computing an essential matrix. +- @ref RANSAC for the RANSAC algorithm. +- @ref LMEDS for the LMedS algorithm. +@param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of +confidence (probability) that the estimated matrix is correct. +@param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar +line in pixels, beyond which the point is considered an outlier and is not used for computing the +final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the +point localization, image resolution, and the image noise. +@param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 +for the other points. The array is computed only in the RANSAC and LMedS methods. + +This function estimates essential matrix based on the five-point algorithm solver in @cite Nister03 . +@cite SteweniusCFS is also a related. The epipolar geometry is described by the following equation: + +\f[[p_2; 1]^T K^{-T} E K^{-1} [p_1; 1] = 0\f] + +where \f$E\f$ is an essential matrix, \f$p_1\f$ and \f$p_2\f$ are corresponding points in the first and the +second images, respectively. The result of this function may be passed further to +#decomposeEssentialMat or #recoverPose to recover the relative pose between cameras. + */ CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, - double focal = 1.0, Point2d pp = Point2d(0, 0), - int method = RANSAC, double prob = 0.999, - double threshold = 1.0, OutputArray mask = noArray() ); + InputArray cameraMatrix1, InputArray distCoeffs1, + InputArray cameraMatrix2, InputArray distCoeffs2, + int method = RANSAC, + double prob = 0.999, double threshold = 1.0, + OutputArray mask = noArray() ); + + +CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, + InputArray cameraMatrix1, InputArray cameraMatrix2, + InputArray dist_coeff1, InputArray dist_coeff2, OutputArray mask, + const UsacParams ¶ms); /** @brief Decompose an essential matrix to possible rotations and translation. @@ -2337,7 +2869,7 @@ possible pose hypotheses by doing cheirality check. The cheirality check means t triangulated 3D points should have positive depth. Some details can be found in @cite Nister03. This function can be used to process the output E and mask from @ref findEssentialMat. In this -scenario, points1 and points2 are the same input for findEssentialMat.: +scenario, points1 and points2 are the same input for #findEssentialMat : @code // Example. Estimation of fundamental matrix using the RANSAC algorithm int point_count = 100; @@ -2432,14 +2964,14 @@ CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray point @param points Input points. \f$N \times 1\f$ or \f$1 \times N\f$ matrix of type CV_32FC2 or vector\ . @param whichImage Index of the image (1 or 2) that contains the points . -@param F Fundamental matrix that can be estimated using findFundamentalMat or stereoRectify . +@param F Fundamental matrix that can be estimated using #findFundamentalMat or #stereoRectify . @param lines Output vector of the epipolar lines corresponding to the points in the other image. Each line \f$ax + by + c=0\f$ is encoded by 3 numbers \f$(a, b, c)\f$ . For every point in one of the two images of a stereo pair, the function finds the equation of the corresponding epipolar line in the other image. -From the fundamental matrix definition (see findFundamentalMat ), line \f$l^{(2)}_i\f$ in the second +From the fundamental matrix definition (see #findFundamentalMat ), line \f$l^{(2)}_i\f$ in the second image for the point \f$p^{(1)}_i\f$ in the first image (when whichImage=1 ) is computed as: \f[l^{(2)}_i = F p^{(1)}_i\f] @@ -2515,7 +3047,7 @@ CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, int maxSpeckleSize, double maxDiff, InputOutputArray buf = noArray() ); -//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify()) +//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by #stereoRectify) CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2, int minDisparity, int numberOfDisparities, int blockSize ); @@ -2580,7 +3112,7 @@ sd( \texttt{pt1} , \texttt{pt2} )= ((\texttt{F}^t \cdot \texttt{pt2})(0))^2 + ((\texttt{F}^t \cdot \texttt{pt2})(1))^2} \f] -The fundamental matrix may be calculated using the cv::findFundamentalMat function. See @cite HartleyZ00 11.4.3 for details. +The fundamental matrix may be calculated using the #findFundamentalMat function. See @cite HartleyZ00 11.4.3 for details. @param pt1 first homogeneous 2d point @param pt2 second homogeneous 2d point @param F fundamental matrix @@ -2640,6 +3172,80 @@ CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst, OutputArray out, OutputArray inliers, double ransacThreshold = 3, double confidence = 0.99); +/** @brief Computes an optimal affine transformation between two 3D point sets. + +It computes \f$R,s,t\f$ minimizing \f$\sum{i} dst_i - c \cdot R \cdot src_i \f$ +where \f$R\f$ is a 3x3 rotation matrix, \f$t\f$ is a 3x1 translation vector and \f$s\f$ is a +scalar size value. This is an implementation of the algorithm by Umeyama \cite umeyama1991least . +The estimated affine transform has a homogeneous scale which is a subclass of affine +transformations with 7 degrees of freedom. The paired point sets need to comprise at least 3 +points each. + +@param src First input 3D point set. +@param dst Second input 3D point set. +@param scale If null is passed, the scale parameter c will be assumed to be 1.0. +Else the pointed-to variable will be set to the optimal scale. +@param force_rotation If true, the returned rotation will never be a reflection. +This might be unwanted, e.g. when optimizing a transform between a right- and a +left-handed coordinate system. +@return 3D affine transformation matrix \f$3 \times 4\f$ of the form +\f[T = +\begin{bmatrix} +R & t\\ +\end{bmatrix} +\f] + + */ +CV_EXPORTS_W cv::Mat estimateAffine3D(InputArray src, InputArray dst, + CV_OUT double* scale = nullptr, bool force_rotation = true); + +/** @brief Computes an optimal translation between two 3D point sets. + * + * It computes + * \f[ + * \begin{bmatrix} + * x\\ + * y\\ + * z\\ + * \end{bmatrix} + * = + * \begin{bmatrix} + * X\\ + * Y\\ + * Z\\ + * \end{bmatrix} + * + + * \begin{bmatrix} + * b_1\\ + * b_2\\ + * b_3\\ + * \end{bmatrix} + * \f] + * + * @param src First input 3D point set containing \f$(X,Y,Z)\f$. + * @param dst Second input 3D point set containing \f$(x,y,z)\f$. + * @param out Output 3D translation vector \f$3 \times 1\f$ of the form + * \f[ + * \begin{bmatrix} + * b_1 \\ + * b_2 \\ + * b_3 \\ + * \end{bmatrix} + * \f] + * @param inliers Output vector indicating which points are inliers (1-inlier, 0-outlier). + * @param ransacThreshold Maximum reprojection error in the RANSAC algorithm to consider a point as + * an inlier. + * @param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything + * between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation + * significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. + * + * The function estimates an optimal 3D translation between two 3D point sets using the + * RANSAC algorithm. + * */ +CV_EXPORTS_W int estimateTranslation3D(InputArray src, InputArray dst, + OutputArray out, OutputArray inliers, + double ransacThreshold = 3, double confidence = 0.99); + /** @brief Computes an optimal affine transformation between two 2D point sets. It computes @@ -2707,6 +3313,10 @@ CV_EXPORTS_W cv::Mat estimateAffine2D(InputArray from, InputArray to, OutputArra size_t maxIters = 2000, double confidence = 0.99, size_t refineIters = 10); + +CV_EXPORTS_W cv::Mat estimateAffine2D(InputArray pts1, InputArray pts2, OutputArray inliers, + const UsacParams ¶ms); + /** @brief Computes an optimal limited affine transformation with 4 degrees of freedom between two 2D point sets. @@ -2796,10 +3406,10 @@ CV_EXPORTS_W int decomposeHomographyMat(InputArray H, @param beforePoints Vector of (rectified) visible reference points before the homography is applied @param afterPoints Vector of (rectified) visible reference points after the homography is applied @param possibleSolutions Vector of int indices representing the viable solution set after filtering -@param pointsMask optional Mat/Vector of 8u type representing the mask for the inliers as given by the findHomography function +@param pointsMask optional Mat/Vector of 8u type representing the mask for the inliers as given by the #findHomography function -This function is intended to filter the output of the decomposeHomographyMat based on additional -information as described in @cite Malis . The summary of the method: the decomposeHomographyMat function +This function is intended to filter the output of the #decomposeHomographyMat based on additional +information as described in @cite Malis . The summary of the method: the #decomposeHomographyMat function returns 2 unique solutions and their "opposites" for a total of 4 solutions. If we have access to the sets of points visible in the camera frame before and after the homography transformation is applied, we can determine which are the true potential solutions and which are the opposites by verifying which @@ -2992,6 +3602,280 @@ public: int mode = StereoSGBM::MODE_SGBM); }; + +//! cv::undistort mode +enum UndistortTypes +{ + PROJ_SPHERICAL_ORTHO = 0, + PROJ_SPHERICAL_EQRECT = 1 +}; + +/** @brief Transforms an image to compensate for lens distortion. + +The function transforms an image to compensate radial and tangential lens distortion. + +The function is simply a combination of #initUndistortRectifyMap (with unity R ) and #remap +(with bilinear interpolation). See the former function for details of the transformation being +performed. + +Those pixels in the destination image, for which there is no correspondent pixels in the source +image, are filled with zeros (black color). + +A particular subset of the source image that will be visible in the corrected image can be regulated +by newCameraMatrix. You can use #getOptimalNewCameraMatrix to compute the appropriate +newCameraMatrix depending on your requirements. + +The camera matrix and the distortion parameters can be determined using #calibrateCamera. If +the resolution of images is different from the resolution used at the calibration stage, \f$f_x, +f_y, c_x\f$ and \f$c_y\f$ need to be scaled accordingly, while the distortion coefficients remain +the same. + +@param src Input (distorted) image. +@param dst Output (corrected) image that has the same size and type as src . +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param newCameraMatrix Camera matrix of the distorted image. By default, it is the same as +cameraMatrix but you may additionally scale and shift the result by using a different matrix. + */ +CV_EXPORTS_W void undistort( InputArray src, OutputArray dst, + InputArray cameraMatrix, + InputArray distCoeffs, + InputArray newCameraMatrix = noArray() ); + +/** @brief Computes the undistortion and rectification transformation map. + +The function computes the joint undistortion and rectification transformation and represents the +result in the form of maps for #remap. The undistorted image looks like original, as if it is +captured with a camera using the camera matrix =newCameraMatrix and zero distortion. In case of a +monocular camera, newCameraMatrix is usually equal to cameraMatrix, or it can be computed by +#getOptimalNewCameraMatrix for a better control over scaling. In case of a stereo camera, +newCameraMatrix is normally set to P1 or P2 computed by #stereoRectify . + +Also, this new camera is oriented differently in the coordinate space, according to R. That, for +example, helps to align two heads of a stereo camera so that the epipolar lines on both images +become horizontal and have the same y- coordinate (in case of a horizontally aligned stereo camera). + +The function actually builds the maps for the inverse mapping algorithm that is used by #remap. That +is, for each pixel \f$(u, v)\f$ in the destination (corrected and rectified) image, the function +computes the corresponding coordinates in the source image (that is, in the original image from +camera). The following process is applied: +\f[ +\begin{array}{l} +x \leftarrow (u - {c'}_x)/{f'}_x \\ +y \leftarrow (v - {c'}_y)/{f'}_y \\ +{[X\,Y\,W]} ^T \leftarrow R^{-1}*[x \, y \, 1]^T \\ +x' \leftarrow X/W \\ +y' \leftarrow Y/W \\ +r^2 \leftarrow x'^2 + y'^2 \\ +x'' \leftarrow x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} ++ 2p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4\\ +y'' \leftarrow y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} ++ p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\ +s\vecthree{x'''}{y'''}{1} = +\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)} +{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} +{0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\ +map_x(u,v) \leftarrow x''' f_x + c_x \\ +map_y(u,v) \leftarrow y''' f_y + c_y +\end{array} +\f] +where \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +are the distortion coefficients. + +In case of a stereo camera, this function is called twice: once for each camera head, after +#stereoRectify, which in its turn is called after #stereoCalibrate. But if the stereo camera +was not calibrated, it is still possible to compute the rectification transformations directly from +the fundamental matrix using #stereoRectifyUncalibrated. For each camera, the function computes +homography H as the rectification transformation in a pixel domain, not a rotation matrix R in 3D +space. R can be computed from H as +\f[\texttt{R} = \texttt{cameraMatrix} ^{-1} \cdot \texttt{H} \cdot \texttt{cameraMatrix}\f] +where cameraMatrix can be chosen arbitrarily. + +@param cameraMatrix Input camera matrix \f$A=\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param R Optional rectification transformation in the object space (3x3 matrix). R1 or R2 , +computed by #stereoRectify can be passed here. If the matrix is empty, the identity transformation +is assumed. In cvInitUndistortMap R assumed to be an identity matrix. +@param newCameraMatrix New camera matrix \f$A'=\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}\f$. +@param size Undistorted image size. +@param m1type Type of the first output map that can be CV_32FC1, CV_32FC2 or CV_16SC2, see #convertMaps +@param map1 The first output map. +@param map2 The second output map. + */ +CV_EXPORTS_W +void initUndistortRectifyMap(InputArray cameraMatrix, InputArray distCoeffs, + InputArray R, InputArray newCameraMatrix, + Size size, int m1type, OutputArray map1, OutputArray map2); + +/** @brief Computes the projection and inverse-rectification transformation map. In essense, this is the inverse of +#initUndistortRectifyMap to accomodate stereo-rectification of projectors ('inverse-cameras') in projector-camera pairs. + +The function computes the joint projection and inverse rectification transformation and represents the +result in the form of maps for #remap. The projected image looks like a distorted version of the original which, +once projected by a projector, should visually match the original. In case of a monocular camera, newCameraMatrix +is usually equal to cameraMatrix, or it can be computed by +#getOptimalNewCameraMatrix for a better control over scaling. In case of a projector-camera pair, +newCameraMatrix is normally set to P1 or P2 computed by #stereoRectify . + +The projector is oriented differently in the coordinate space, according to R. In case of projector-camera pairs, +this helps align the projector (in the same manner as #initUndistortRectifyMap for the camera) to create a stereo-rectified pair. This +allows epipolar lines on both images to become horizontal and have the same y-coordinate (in case of a horizontally aligned projector-camera pair). + +The function builds the maps for the inverse mapping algorithm that is used by #remap. That +is, for each pixel \f$(u, v)\f$ in the destination (projected and inverse-rectified) image, the function +computes the corresponding coordinates in the source image (that is, in the original digital image). The following process is applied: + +\f[ +\begin{array}{l} +\text{newCameraMatrix}\\ +x \leftarrow (u - {c'}_x)/{f'}_x \\ +y \leftarrow (v - {c'}_y)/{f'}_y \\ + +\\\text{Undistortion} +\\\scriptsize{\textit{though equation shown is for radial undistortion, function implements cv::undistortPoints()}}\\ +r^2 \leftarrow x^2 + y^2 \\ +\theta \leftarrow \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6}\\ +x' \leftarrow \frac{x}{\theta} \\ +y' \leftarrow \frac{y}{\theta} \\ + +\\\text{Rectification}\\ +{[X\,Y\,W]} ^T \leftarrow R*[x' \, y' \, 1]^T \\ +x'' \leftarrow X/W \\ +y'' \leftarrow Y/W \\ + +\\\text{cameraMatrix}\\ +map_x(u,v) \leftarrow x'' f_x + c_x \\ +map_y(u,v) \leftarrow y'' f_y + c_y +\end{array} +\f] +where \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +are the distortion coefficients vector distCoeffs. + +In case of a stereo-rectified projector-camera pair, this function is called for the projector while #initUndistortRectifyMap is called for the camera head. +This is done after #stereoRectify, which in turn is called after #stereoCalibrate. If the projector-camera pair +is not calibrated, it is still possible to compute the rectification transformations directly from +the fundamental matrix using #stereoRectifyUncalibrated. For the projector and camera, the function computes +homography H as the rectification transformation in a pixel domain, not a rotation matrix R in 3D +space. R can be computed from H as +\f[\texttt{R} = \texttt{cameraMatrix} ^{-1} \cdot \texttt{H} \cdot \texttt{cameraMatrix}\f] +where cameraMatrix can be chosen arbitrarily. + +@param cameraMatrix Input camera matrix \f$A=\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param R Optional rectification transformation in the object space (3x3 matrix). R1 or R2, +computed by #stereoRectify can be passed here. If the matrix is empty, the identity transformation +is assumed. +@param newCameraMatrix New camera matrix \f$A'=\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}\f$. +@param size Distorted image size. +@param m1type Type of the first output map. Can be CV_32FC1, CV_32FC2 or CV_16SC2, see #convertMaps +@param map1 The first output map for #remap. +@param map2 The second output map for #remap. + */ +CV_EXPORTS_W +void initInverseRectificationMap( InputArray cameraMatrix, InputArray distCoeffs, + InputArray R, InputArray newCameraMatrix, + const Size& size, int m1type, OutputArray map1, OutputArray map2 ); + +//! initializes maps for #remap for wide-angle +CV_EXPORTS +float initWideAngleProjMap(InputArray cameraMatrix, InputArray distCoeffs, + Size imageSize, int destImageWidth, + int m1type, OutputArray map1, OutputArray map2, + enum UndistortTypes projType = PROJ_SPHERICAL_EQRECT, double alpha = 0); +static inline +float initWideAngleProjMap(InputArray cameraMatrix, InputArray distCoeffs, + Size imageSize, int destImageWidth, + int m1type, OutputArray map1, OutputArray map2, + int projType, double alpha = 0) +{ + return initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize, destImageWidth, + m1type, map1, map2, (UndistortTypes)projType, alpha); +} + +/** @brief Returns the default new camera matrix. + +The function returns the camera matrix that is either an exact copy of the input cameraMatrix (when +centerPrinicipalPoint=false ), or the modified one (when centerPrincipalPoint=true). + +In the latter case, the new camera matrix will be: + +\f[\begin{bmatrix} f_x && 0 && ( \texttt{imgSize.width} -1)*0.5 \\ 0 && f_y && ( \texttt{imgSize.height} -1)*0.5 \\ 0 && 0 && 1 \end{bmatrix} ,\f] + +where \f$f_x\f$ and \f$f_y\f$ are \f$(0,0)\f$ and \f$(1,1)\f$ elements of cameraMatrix, respectively. + +By default, the undistortion functions in OpenCV (see #initUndistortRectifyMap, #undistort) do not +move the principal point. However, when you work with stereo, it is important to move the principal +points in both views to the same y-coordinate (which is required by most of stereo correspondence +algorithms), and may be to the same x-coordinate too. So, you can form the new camera matrix for +each view where the principal points are located at the center. + +@param cameraMatrix Input camera matrix. +@param imgsize Camera view image size in pixels. +@param centerPrincipalPoint Location of the principal point in the new camera matrix. The +parameter indicates whether this location should be at the image center or not. + */ +CV_EXPORTS_W +Mat getDefaultNewCameraMatrix(InputArray cameraMatrix, Size imgsize = Size(), + bool centerPrincipalPoint = false); + +/** @brief Computes the ideal point coordinates from the observed point coordinates. + +The function is similar to #undistort and #initUndistortRectifyMap but it operates on a +sparse set of points instead of a raster image. Also the function performs a reverse transformation +to #projectPoints. In case of a 3D object, it does not reconstruct its 3D coordinates, but for a +planar object, it does, up to a translation vector, if the proper R is specified. + +For each observed point coordinate \f$(u, v)\f$ the function computes: +\f[ +\begin{array}{l} +x^{"} \leftarrow (u - c_x)/f_x \\ +y^{"} \leftarrow (v - c_y)/f_y \\ +(x',y') = undistort(x^{"},y^{"}, \texttt{distCoeffs}) \\ +{[X\,Y\,W]} ^T \leftarrow R*[x' \, y' \, 1]^T \\ +x \leftarrow X/W \\ +y \leftarrow Y/W \\ +\text{only performed if P is specified:} \\ +u' \leftarrow x {f'}_x + {c'}_x \\ +v' \leftarrow y {f'}_y + {c'}_y +\end{array} +\f] + +where *undistort* is an approximate iterative algorithm that estimates the normalized original +point coordinates out of the normalized distorted point coordinates ("normalized" means that the +coordinates do not depend on the camera matrix). + +The function can be used for both a stereo camera head or a monocular camera (when R is empty). +@param src Observed point coordinates, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel (CV_32FC2 or CV_64FC2) (or +vector\ ). +@param dst Output ideal point coordinates (1xN/Nx1 2-channel or vector\ ) after undistortion and reverse perspective +transformation. If matrix P is identity or omitted, dst will contain normalized point coordinates. +@param cameraMatrix Camera matrix \f$\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param R Rectification transformation in the object space (3x3 matrix). R1 or R2 computed by +#stereoRectify can be passed here. If the matrix is empty, the identity transformation is used. +@param P New camera matrix (3x3) or new projection matrix (3x4) \f$\begin{bmatrix} {f'}_x & 0 & {c'}_x & t_x \\ 0 & {f'}_y & {c'}_y & t_y \\ 0 & 0 & 1 & t_z \end{bmatrix}\f$. P1 or P2 computed by +#stereoRectify can be passed here. If the matrix is empty, the identity new camera matrix is used. + */ +CV_EXPORTS_W +void undistortPoints(InputArray src, OutputArray dst, + InputArray cameraMatrix, InputArray distCoeffs, + InputArray R = noArray(), InputArray P = noArray()); +/** @overload + @note Default version of #undistortPoints does 5 iterations to compute undistorted points. + */ +CV_EXPORTS_AS(undistortPointsIter) +void undistortPoints(InputArray src, OutputArray dst, + InputArray cameraMatrix, InputArray distCoeffs, + InputArray R, InputArray P, TermCriteria criteria); + //! @} calib3d /** @brief The methods in this namespace use a so-called fisheye camera model. @@ -3013,7 +3897,8 @@ namespace fisheye CALIB_FIX_K4 = 1 << 7, CALIB_FIX_INTRINSIC = 1 << 8, CALIB_FIX_PRINCIPAL_POINT = 1 << 9, - CALIB_ZERO_DISPARITY = 1 << 10 + CALIB_ZERO_DISPARITY = 1 << 10, + CALIB_FIX_FOCAL_LENGTH = 1 << 11 }; /** @brief Projects points using fisheye model @@ -3053,7 +3938,7 @@ namespace fisheye @param distorted Output array of image points, 1xN/Nx1 2-channel, or vector\ . Note that the function assumes the camera intrinsic matrix of the undistorted points to be identity. - This means if you want to transform back points undistorted with undistortPoints() you have to + This means if you want to transform back points undistorted with #fisheye::undistortPoints you have to multiply them with \f$P^{-1}\f$. */ CV_EXPORTS_W void distortPoints(InputArray undistorted, OutputArray distorted, InputArray K, InputArray D, double alpha = 0); @@ -3072,7 +3957,7 @@ namespace fisheye CV_EXPORTS_W void undistortPoints(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray R = noArray(), InputArray P = noArray()); - /** @brief Computes undistortion and rectification maps for image transform by cv::remap(). If D is empty zero + /** @brief Computes undistortion and rectification maps for image transform by #remap. If D is empty zero distortion is used, if R or P is empty identity matrixes are used. @param K Camera intrinsic matrix \f$cameramatrix{K}\f$. @@ -3081,7 +3966,7 @@ namespace fisheye 1-channel or 1x1 3-channel @param P New camera intrinsic matrix (3x3) or new projection matrix (3x4) @param size Undistorted image size. - @param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2 . See convertMaps() + @param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2 . See #convertMaps for details. @param map1 The first output map. @param map2 The second output map. @@ -3101,14 +3986,14 @@ namespace fisheye The function transforms an image to compensate radial and tangential lens distortion. - The function is simply a combination of fisheye::initUndistortRectifyMap (with unity R ) and remap + The function is simply a combination of #fisheye::initUndistortRectifyMap (with unity R ) and #remap (with bilinear interpolation). See the former function for details of the transformation being performed. See below the results of undistortImage. - a\) result of undistort of perspective camera model (all possible coefficients (k_1, k_2, k_3, k_4, k_5, k_6) of distortion were optimized under calibration) - - b\) result of fisheye::undistortImage of fisheye camera model (all possible coefficients (k_1, k_2, + - b\) result of #fisheye::undistortImage of fisheye camera model (all possible coefficients (k_1, k_2, k_3, k_4) of fisheye distortion were optimized under calibration) - c\) original image was captured with fisheye lens @@ -3167,6 +4052,8 @@ namespace fisheye are set to zeros and stay zero. - @ref fisheye::CALIB_FIX_PRINCIPAL_POINT The principal point is not changed during the global optimization. It stays at the center or at a different location specified when @ref fisheye::CALIB_USE_INTRINSIC_GUESS is set too. + - @ref fisheye::CALIB_FIX_FOCAL_LENGTH The focal length is not changed during the global +optimization. It is the \f$max(width,height)/\pi\f$ or the provided \f$f_x\f$, \f$f_y\f$ when @ref fisheye::CALIB_USE_INTRINSIC_GUESS is set too. @param criteria Termination criteria for the iterative optimization algorithm. */ CV_EXPORTS_W double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, const Size& image_size, @@ -3196,7 +4083,7 @@ optimization. It stays at the center or at a different location specified when @ horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the useful image area. @param newImageSize New image resolution after rectification. The same size should be passed to - initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) + #initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) is passed (default), it is set to the original imageSize . Setting it to larger value can help you preserve details in the original image, especially when there is a big radial distortion. @param balance Sets the new focal length in range between the min focal length and the max focal @@ -3249,8 +4136,44 @@ optimization. It stays at the center or at a different location specified when @ } //end namespace cv -#ifndef DISABLE_OPENCV_24_COMPATIBILITY -#include "opencv2/calib3d/calib3d_c.h" +#if 0 //def __cplusplus +////////////////////////////////////////////////////////////////////////////////////////// +class CV_EXPORTS CvLevMarq +{ +public: + CvLevMarq(); + CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + ~CvLevMarq(); + void init( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + bool update( const CvMat*& param, CvMat*& J, CvMat*& err ); + bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm ); + + void clear(); + void step(); + enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 }; + + cv::Ptr mask; + cv::Ptr prevParam; + cv::Ptr param; + cv::Ptr J; + cv::Ptr err; + cv::Ptr JtJ; + cv::Ptr JtJN; + cv::Ptr JtErr; + cv::Ptr JtJV; + cv::Ptr JtJW; + double prevErrNorm, errNorm; + int lambdaLg10; + CvTermCriteria criteria; + int state; + int iters; + bool completeSymmFlag; + int solveMethod; +}; #endif #endif diff --git a/3rdparty/include/opencv2/calib3d/calib3d_c.h b/3rdparty/include/opencv2/calib3d/calib3d_c.h index 8ec6390d70..e2af07b2e2 100644 --- a/3rdparty/include/opencv2/calib3d/calib3d_c.h +++ b/3rdparty/include/opencv2/calib3d/calib3d_c.h @@ -44,41 +44,12 @@ #ifndef OPENCV_CALIB3D_C_H #define OPENCV_CALIB3D_C_H -#include "opencv2/core/core_c.h" +#include "opencv2/core/types_c.h" #ifdef __cplusplus extern "C" { #endif -/** @addtogroup calib3d_c - @{ - */ - -/****************************************************************************************\ -* Camera Calibration, Pose Estimation and Stereo * -\****************************************************************************************/ - -typedef struct CvPOSITObject CvPOSITObject; - -/* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */ -CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count ); - - -/* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of - an object given its model and projection in a weak-perspective case */ -CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points, - double focal_length, CvTermCriteria criteria, - float* rotation_matrix, float* translation_vector); - -/* Releases CvPOSITObject structure */ -CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object ); - -/* updates the number of RANSAC iterations */ -CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob, - int model_points, int max_iters ); - -CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst ); - /* Calculates fundamental matrix given a set of corresponding points */ #define CV_FM_7POINT 1 #define CV_FM_8POINT 2 @@ -99,136 +70,11 @@ enum CV_DLS = 3 // Joel A. Hesch and Stergios I. Roumeliotis. "A Direct Least-Squares (DLS) Method for PnP" }; -CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2, - CvMat* fundamental_matrix, - int method CV_DEFAULT(CV_FM_RANSAC), - double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99), - CvMat* status CV_DEFAULT(NULL) ); - -/* For each input point on one of images - computes parameters of the corresponding - epipolar line on the other image */ -CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points, - int which_image, - const CvMat* fundamental_matrix, - CvMat* correspondent_lines ); - -/* Triangulation functions */ - -CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2, - CvMat* projPoints1, CvMat* projPoints2, - CvMat* points4D); - -CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2, - CvMat* new_points1, CvMat* new_points2); - - -/* Computes the optimal new camera matrix according to the free scaling parameter alpha: - alpha=0 - only valid pixels will be retained in the undistorted image - alpha=1 - all the source image pixels will be retained in the undistorted image -*/ -CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix, - const CvMat* dist_coeffs, - CvSize image_size, double alpha, - CvMat* new_camera_matrix, - CvSize new_imag_size CV_DEFAULT(cvSize(0,0)), - CvRect* valid_pixel_ROI CV_DEFAULT(0), - int center_principal_point CV_DEFAULT(0)); - -/* Converts rotation vector to rotation matrix or vice versa */ -CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst, - CvMat* jacobian CV_DEFAULT(0) ); - -/* Finds perspective transformation between the object plane and image (view) plane */ -CVAPI(int) cvFindHomography( const CvMat* src_points, - const CvMat* dst_points, - CvMat* homography, - int method CV_DEFAULT(0), - double ransacReprojThreshold CV_DEFAULT(3), - CvMat* mask CV_DEFAULT(0), - int maxIters CV_DEFAULT(2000), - double confidence CV_DEFAULT(0.995)); - -/* Computes RQ decomposition for 3x3 matrices */ -CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ, - CvMat *matrixQx CV_DEFAULT(NULL), - CvMat *matrixQy CV_DEFAULT(NULL), - CvMat *matrixQz CV_DEFAULT(NULL), - CvPoint3D64f *eulerAngles CV_DEFAULT(NULL)); - -/* Computes projection matrix decomposition */ -CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr, - CvMat *rotMatr, CvMat *posVect, - CvMat *rotMatrX CV_DEFAULT(NULL), - CvMat *rotMatrY CV_DEFAULT(NULL), - CvMat *rotMatrZ CV_DEFAULT(NULL), - CvPoint3D64f *eulerAngles CV_DEFAULT(NULL)); - -/* Computes d(AB)/dA and d(AB)/dB */ -CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB ); - -/* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)), - t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */ -CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1, - const CvMat* _rvec2, const CvMat* _tvec2, - CvMat* _rvec3, CvMat* _tvec3, - CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0), - CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0), - CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0), - CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) ); - -/* Projects object points to the view plane using - the specified extrinsic and intrinsic camera parameters */ -CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector, - const CvMat* translation_vector, const CvMat* camera_matrix, - const CvMat* distortion_coeffs, CvMat* image_points, - CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL), - CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL), - CvMat* dpddist CV_DEFAULT(NULL), - double aspect_ratio CV_DEFAULT(0)); - -/* Finds extrinsic camera parameters from - a few known corresponding point pairs and intrinsic parameters */ -CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points, - const CvMat* image_points, - const CvMat* camera_matrix, - const CvMat* distortion_coeffs, - CvMat* rotation_vector, - CvMat* translation_vector, - int use_extrinsic_guess CV_DEFAULT(0) ); - -/* Computes initial estimate of the intrinsic camera parameters - in case of planar calibration target (e.g. chessboard) */ -CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points, - const CvMat* image_points, - const CvMat* npoints, CvSize image_size, - CvMat* camera_matrix, - double aspect_ratio CV_DEFAULT(1.) ); - #define CV_CALIB_CB_ADAPTIVE_THRESH 1 #define CV_CALIB_CB_NORMALIZE_IMAGE 2 #define CV_CALIB_CB_FILTER_QUADS 4 #define CV_CALIB_CB_FAST_CHECK 8 -// Performs a fast check if a chessboard is in the input image. This is a workaround to -// a problem of cvFindChessboardCorners being slow on images with no chessboard -// - src: input image -// - size: chessboard size -// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called, -// 0 if there is no chessboard, -1 in case of error -CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size); - - /* Detects corners on a chessboard calibration pattern */ -CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size, - CvPoint2D32f* corners, - int* corner_count CV_DEFAULT(NULL), - int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) ); - -/* Draws individual chessboard corners or the whole chessboard detected */ -CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size, - CvPoint2D32f* corners, - int count, int pattern_was_found ); - #define CV_CALIB_USE_INTRINSIC_GUESS 1 #define CV_CALIB_FIX_ASPECT_RATIO 2 #define CV_CALIB_FIX_PRINCIPAL_POINT 4 @@ -249,138 +95,15 @@ CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size, #define CV_CALIB_NINTRINSIC 18 -/* Finds intrinsic and extrinsic camera parameters - from a few views of known calibration pattern */ -CVAPI(double) cvCalibrateCamera2( const CvMat* object_points, - const CvMat* image_points, - const CvMat* point_counts, - CvSize image_size, - CvMat* camera_matrix, - CvMat* distortion_coeffs, - CvMat* rotation_vectors CV_DEFAULT(NULL), - CvMat* translation_vectors CV_DEFAULT(NULL), - int flags CV_DEFAULT(0), - CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria( - CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) ); - -/* Computes various useful characteristics of the camera from the data computed by - cvCalibrateCamera2 */ -CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix, - CvSize image_size, - double aperture_width CV_DEFAULT(0), - double aperture_height CV_DEFAULT(0), - double *fovx CV_DEFAULT(NULL), - double *fovy CV_DEFAULT(NULL), - double *focal_length CV_DEFAULT(NULL), - CvPoint2D64f *principal_point CV_DEFAULT(NULL), - double *pixel_aspect_ratio CV_DEFAULT(NULL)); - #define CV_CALIB_FIX_INTRINSIC 256 #define CV_CALIB_SAME_FOCAL_LENGTH 512 -/* Computes the transformation from one camera coordinate system to another one - from a few correspondent views of the same calibration target. Optionally, calibrates - both cameras */ -CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1, - const CvMat* image_points2, const CvMat* npoints, - CvMat* camera_matrix1, CvMat* dist_coeffs1, - CvMat* camera_matrix2, CvMat* dist_coeffs2, - CvSize image_size, CvMat* R, CvMat* T, - CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0), - int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC), - CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria( - CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)) ); - #define CV_CALIB_ZERO_DISPARITY 1024 -/* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both - views parallel (=> to make all the epipolar lines horizontal or vertical) */ -CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2, - const CvMat* dist_coeffs1, const CvMat* dist_coeffs2, - CvSize image_size, const CvMat* R, const CvMat* T, - CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2, - CvMat* Q CV_DEFAULT(0), - int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY), - double alpha CV_DEFAULT(-1), - CvSize new_image_size CV_DEFAULT(cvSize(0,0)), - CvRect* valid_pix_ROI1 CV_DEFAULT(0), - CvRect* valid_pix_ROI2 CV_DEFAULT(0)); - -/* Computes rectification transformations for uncalibrated pair of images using a set - of point correspondences */ -CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2, - const CvMat* F, CvSize img_size, - CvMat* H1, CvMat* H2, - double threshold CV_DEFAULT(5)); - - - /* stereo correspondence parameters and functions */ - #define CV_STEREO_BM_NORMALIZED_RESPONSE 0 #define CV_STEREO_BM_XSOBEL 1 -/* Block matching algorithm structure */ -typedef struct CvStereoBMState -{ - // pre-filtering (normalization of input images) - int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now - int preFilterSize; // averaging window size: ~5x5..21x21 - int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap] - - // correspondence using Sum of Absolute Difference (SAD) - int SADWindowSize; // ~5x5..21x21 - int minDisparity; // minimum disparity (can be negative) - int numberOfDisparities; // maximum disparity - minimum disparity (> 0) - - // post-filtering - int textureThreshold; // the disparity is only computed for pixels - // with textured enough neighborhood - int uniquenessRatio; // accept the computed disparity d* only if - // SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.) - // for any d != d*+/-1 within the search range. - int speckleWindowSize; // disparity variation window - int speckleRange; // acceptable range of variation in window - - int trySmallerWindows; // if 1, the results may be more accurate, - // at the expense of slower processing - CvRect roi1, roi2; - int disp12MaxDiff; - - // temporary buffers - CvMat* preFilteredImg0; - CvMat* preFilteredImg1; - CvMat* slidingSumBuf; - CvMat* cost; - CvMat* disp; -} CvStereoBMState; - -#define CV_STEREO_BM_BASIC 0 -#define CV_STEREO_BM_FISH_EYE 1 -#define CV_STEREO_BM_NARROW 2 - -CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC), - int numberOfDisparities CV_DEFAULT(0)); - -CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state ); - -CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right, - CvArr* disparity, CvStereoBMState* state ); - -CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity, - int numberOfDisparities, int SADWindowSize ); - -CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost, - int minDisparity, int numberOfDisparities, - int disp12MaxDiff CV_DEFAULT(1) ); - -/* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */ -CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage, - CvArr* _3dImage, const CvMat* Q, - int handleMissingValues CV_DEFAULT(0) ); - -/** @} calib3d_c */ - #ifdef __cplusplus } // extern "C" diff --git a/3rdparty/include/opencv2/ccalib.hpp b/3rdparty/include/opencv2/ccalib.hpp deleted file mode 100644 index c9b9391cb4..0000000000 --- a/3rdparty/include/opencv2/ccalib.hpp +++ /dev/null @@ -1,157 +0,0 @@ -/*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) 2014, OpenCV Foundation, 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_CCALIB_HPP__ -#define __OPENCV_CCALIB_HPP__ - -#include -#include -#include -#include - -#include - -/** @defgroup ccalib Custom Calibration Pattern for 3D reconstruction -*/ - -namespace cv{ namespace ccalib{ - -//! @addtogroup ccalib -//! @{ - -class CV_EXPORTS CustomPattern : public Algorithm -{ -public: - CustomPattern(); - virtual ~CustomPattern(); - - bool create(InputArray pattern, const Size2f boardSize, OutputArray output = noArray()); - - bool findPattern(InputArray image, OutputArray matched_features, OutputArray pattern_points, const double ratio = 0.7, - const double proj_error = 8.0, const bool refine_position = false, OutputArray out = noArray(), - OutputArray H = noArray(), OutputArray pattern_corners = noArray()); - - bool isInitialized(); - - void getPatternPoints(std::vector& original_points); - /**< - Returns a vector of the original points. - */ - double getPixelSize(); - /**< - Get the pixel size of the pattern - */ - - bool setFeatureDetector(Ptr featureDetector); - bool setDescriptorExtractor(Ptr extractor); - bool setDescriptorMatcher(Ptr matcher); - - Ptr getFeatureDetector(); - Ptr getDescriptorExtractor(); - Ptr getDescriptorMatcher(); - - double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, - Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, - OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags = 0, - TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); - /**< - Calls the calirateCamera function with the same inputs. - */ - - bool findRt(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, - OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE); - bool findRt(InputArray image, InputArray cameraMatrix, InputArray distCoeffs, - OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE); - /**< - Uses solvePnP to find the rotation and translation of the pattern - with respect to the camera frame. - */ - - bool findRtRANSAC(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, - OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess = false, int iterationsCount = 100, - float reprojectionError = 8.0, int minInliersCount = 100, OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE); - bool findRtRANSAC(InputArray image, InputArray cameraMatrix, InputArray distCoeffs, - OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess = false, int iterationsCount = 100, - float reprojectionError = 8.0, int minInliersCount = 100, OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE); - /**< - Uses solvePnPRansac() - */ - - void drawOrientation(InputOutputArray image, InputArray tvec, InputArray rvec, InputArray cameraMatrix, - InputArray distCoeffs, double axis_length = 3, int axis_width = 2); - /**< - pattern_corners -> projected over the image position of the edges of the pattern. - */ - -private: - - Mat img_roi; - std::vector obj_corners; - double pxSize; - - bool initialized; - - Ptr detector; - Ptr descriptorExtractor; - Ptr descriptorMatcher; - - std::vector keypoints; - std::vector points3d; - Mat descriptor; - - bool init(Mat& image, const float pixel_size, OutputArray output = noArray()); - bool findPatternPass(const Mat& image, std::vector& matched_features, std::vector& pattern_points, - Mat& H, std::vector& scene_corners, const double pratio, const double proj_error, - const bool refine_position = false, const Mat& mask = Mat(), OutputArray output = noArray()); - void scaleFoundPoints(const double squareSize, const std::vector& corners, std::vector& pts3d); - void check_matches(std::vector& matched, const std::vector& pattern, std::vector& good, std::vector& pattern_3d, const Mat& H); - - void keypoints2points(const std::vector& in, std::vector& out); - void updateKeypointsPos(std::vector& in, const std::vector& new_pos); - void refinePointsPos(const Mat& img, std::vector& p); - void refineKeypointsPos(const Mat& img, std::vector& kp); -}; - -//! @} - -}} // namespace ccalib, cv - -#endif diff --git a/3rdparty/include/opencv2/ccalib/multicalib.hpp b/3rdparty/include/opencv2/ccalib/multicalib.hpp deleted file mode 100644 index 686d7a52b0..0000000000 --- a/3rdparty/include/opencv2/ccalib/multicalib.hpp +++ /dev/null @@ -1,212 +0,0 @@ -/*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) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University, -// all rights reserved. -// -// 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_MULTICAMERACALIBRATION_HPP__ -#define __OPENCV_MULTICAMERACALIBRATION_HPP__ - -#include "opencv2/ccalib/randpattern.hpp" -#include "opencv2/ccalib/omnidir.hpp" -#include -#include - -namespace cv { namespace multicalib { - -//! @addtogroup ccalib -//! @{ - -#define HEAD -1 -#define INVALID -2 - -/** @brief Class for multiple camera calibration that supports pinhole camera and omnidirection camera. -For omnidirectional camera model, please refer to omnidir.hpp in ccalib module. -It first calibrate each camera individually, then a bundle adjustment like optimization is applied to -refine extrinsic parameters. So far, it only support "random" pattern for calibration, -see randomPattern.hpp in ccalib module for details. -Images that are used should be named by "cameraIdx-timestamp.*", several images with the same timestamp -means that they are the same pattern that are photographed. cameraIdx should start from 0. - -For more details, please refer to paper - B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System - Calibration Toolbox Using A Feature Descriptor-Based Calibration - Pattern", in IROS 2013. -*/ - -class CV_EXPORTS MultiCameraCalibration -{ -public: - enum { - PINHOLE, - OMNIDIRECTIONAL - //FISHEYE - }; - - // an edge connects a camera and pattern - struct edge - { - int cameraVertex; // vertex index for camera in this edge - int photoVertex; // vertex index for pattern in this edge - int photoIndex; // photo index among photos for this camera - Mat transform; // transform from pattern to camera - - edge(int cv, int pv, int pi, Mat trans) - { - cameraVertex = cv; - photoVertex = pv; - photoIndex = pi; - transform = trans; - } - }; - - struct vertex - { - Mat pose; // relative pose to the first camera. For camera vertex, it is the - // transform from the first camera to this camera, for pattern vertex, - // it is the transform from pattern to the first camera - int timestamp; // timestamp of photo, only available for photo vertex - - vertex(Mat po, int ts) - { - pose = po; - timestamp = ts; - } - - vertex() - { - pose = Mat::eye(4, 4, CV_32F); - timestamp = -1; - } - }; - /* @brief Constructor - @param cameraType camera type, PINHOLE or OMNIDIRECTIONAL - @param nCameras number of cameras - @fileName filename of string list that are used for calibration, the file is generated - by imagelist_creator from OpenCv samples. The first one in the list is the pattern filename. - @patternWidth the physical width of pattern, in user defined unit. - @patternHeight the physical height of pattern, in user defined unit. - @showExtration whether show extracted features and feature filtering. - @nMiniMatches minimal number of matched features for a frame. - @flags Calibration flags - @criteria optimization stopping criteria. - @detector feature detector that detect feature points in pattern and images. - @descriptor feature descriptor. - @matcher feature matcher. - */ - MultiCameraCalibration(int cameraType, int nCameras, const std::string& fileName, float patternWidth, - float patternHeight, int verbose = 0, int showExtration = 0, int nMiniMatches = 20, int flags = 0, - TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 200, 1e-7), - Ptr detector = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 0, 3, 0.006f), - Ptr descriptor = AKAZE::create(AKAZE::DESCRIPTOR_MLDB,0, 3, 0.006f), - Ptr matcher = DescriptorMatcher::create("BruteForce-L1")); - - /* @brief load images - */ - void loadImages(); - - /* @brief initialize multiple camera calibration. It calibrates each camera individually. - */ - void initialize(); - - /* @brief optimization extrinsic parameters - */ - double optimizeExtrinsics(); - - /* @brief run multi-camera camera calibration, it runs loadImage(), initialize() and optimizeExtrinsics() - */ - double run(); - - /* @brief write camera parameters to file. - */ - void writeParameters(const std::string& filename); - -private: - std::vector readStringList(); - - int getPhotoVertex(int timestamp); - - void graphTraverse(const Mat& G, int begin, std::vector& order, std::vector& pre); - - void findRowNonZero(const Mat& row, Mat& idx); - - void computeJacobianExtrinsic(const Mat& extrinsicParams, Mat& JTJ_inv, Mat& JTE); - - void computePhotoCameraJacobian(const Mat& rvecPhoto, const Mat& tvecPhoto, const Mat& rvecCamera, - const Mat& tvecCamera, Mat& rvecTran, Mat& tvecTran, const Mat& objectPoints, const Mat& imagePoints, const Mat& K, - const Mat& distort, const Mat& xi, Mat& jacobianPhoto, Mat& jacobianCamera, Mat& E); - - void compose_motion(InputArray _om1, InputArray _T1, InputArray _om2, InputArray _T2, Mat& om3, Mat& T3, Mat& dom3dom1, - Mat& dom3dT1, Mat& dom3dom2, Mat& dom3dT2, Mat& dT3dom1, Mat& dT3dT1, Mat& dT3dom2, Mat& dT3dT2); - - void JRodriguesMatlab(const Mat& src, Mat& dst); - void dAB(InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB); - - double computeProjectError(Mat& parameters); - - void vector2parameters(const Mat& parameters, std::vector& rvecVertex, std::vector& tvecVertexs); - void parameters2vector(const std::vector& rvecVertex, const std::vector& tvecVertex, Mat& parameters); - - int _camType; //PINHOLE, FISHEYE or OMNIDIRECTIONAL - int _nCamera; - int _nMiniMatches; - int _flags; - int _verbose; - double _error; - float _patternWidth, _patternHeight; - TermCriteria _criteria; - std::string _filename; - int _showExtraction; - Ptr _detector; - Ptr _descriptor; - Ptr _matcher; - - std::vector _edgeList; - std::vector _vertexList; - std::vector > _objectPointsForEachCamera; - std::vector > _imagePointsForEachCamera; - std::vector _cameraMatrix; - std::vector _distortCoeffs; - std::vector _xi; - std::vector > _omEachCamera, _tEachCamera; -}; - -//! @} - -}} // namespace multicalib, cv -#endif \ No newline at end of file diff --git a/3rdparty/include/opencv2/ccalib/omnidir.hpp b/3rdparty/include/opencv2/ccalib/omnidir.hpp deleted file mode 100644 index d3132b3fff..0000000000 --- a/3rdparty/include/opencv2/ccalib/omnidir.hpp +++ /dev/null @@ -1,315 +0,0 @@ -/*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) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University, -// all rights reserved. -// -// 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_OMNIDIR_HPP__ -#define __OPENCV_OMNIDIR_HPP__ - -#include "opencv2/core.hpp" -#include "opencv2/core/affine.hpp" -#include - -namespace cv -{ -namespace omnidir -{ - //! @addtogroup ccalib - //! @{ - - enum { - CALIB_USE_GUESS = 1, - CALIB_FIX_SKEW = 2, - CALIB_FIX_K1 = 4, - CALIB_FIX_K2 = 8, - CALIB_FIX_P1 = 16, - CALIB_FIX_P2 = 32, - CALIB_FIX_XI = 64, - CALIB_FIX_GAMMA = 128, - CALIB_FIX_CENTER = 256 - }; - - enum{ - RECTIFY_PERSPECTIVE = 1, - RECTIFY_CYLINDRICAL = 2, - RECTIFY_LONGLATI = 3, - RECTIFY_STEREOGRAPHIC = 4 - }; - - enum{ - XYZRGB = 1, - XYZ = 2 - }; -/** - * This module was accepted as a GSoC 2015 project for OpenCV, authored by - * Baisheng Lai, mentored by Bo Li. - */ - - /** @brief Projects points for omnidirectional camera using CMei's model - - @param objectPoints Object points in world coordinate, vector of vector of Vec3f or Mat of - 1xN/Nx1 3-channel of type CV_32F and N is the number of points. 64F is also acceptable. - @param imagePoints Output array of image points, vector of vector of Vec2f or - 1xN/Nx1 2-channel of type CV_32F. 64F is also acceptable. - @param rvec vector of rotation between world coordinate and camera coordinate, i.e., om - @param tvec vector of translation between pattern coordinate and camera coordinate - @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. - @param D Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$. - @param xi The parameter xi for CMei's model - @param jacobian Optional output 2Nx16 of type CV_64F jacobian matrix, contains the derivatives of - image pixel points wrt parameters including \f$om, T, f_x, f_y, s, c_x, c_y, xi, k_1, k_2, p_1, p_2\f$. - This matrix will be used in calibration by optimization. - - The function projects object 3D points of world coordinate to image pixels, parameter by intrinsic - and extrinsic parameters. Also, it optionally compute a by-product: the jacobian matrix containing - contains the derivatives of image pixel points wrt intrinsic and extrinsic parameters. - */ - CV_EXPORTS_W void projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray rvec, InputArray tvec, - InputArray K, double xi, InputArray D, OutputArray jacobian = noArray()); - - /** @overload */ - CV_EXPORTS void projectPoints(InputArray objectPoints, OutputArray imagePoints, const Affine3d& affine, - InputArray K, double xi, InputArray D, OutputArray jacobian = noArray()); - - /** @brief Undistort 2D image points for omnidirectional camera using CMei's model - - @param distorted Array of distorted image points, vector of Vec2f - or 1xN/Nx1 2-channel Mat of type CV_32F, 64F depth is also acceptable - @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. - @param D Distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$. - @param xi The parameter xi for CMei's model - @param R Rotation trainsform between the original and object space : 3x3 1-channel, or vector: 3x1/1x3 - 1-channel or 1x1 3-channel - @param undistorted array of normalized object points, vector of Vec2f/Vec2d or 1xN/Nx1 2-channel Mat with the same - depth of distorted points. - */ - CV_EXPORTS_W void undistortPoints(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray xi, InputArray R); - - /** @brief Computes undistortion and rectification maps for omnidirectional camera image transform by a rotation R. - It output two maps that are used for cv::remap(). If D is empty then zero distortion is used, - if R or P is empty then identity matrices are used. - - @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$, with depth CV_32F or CV_64F - @param D Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$, with depth CV_32F or CV_64F - @param xi The parameter xi for CMei's model - @param R Rotation transform between the original and object space : 3x3 1-channel, or vector: 3x1/1x3, with depth CV_32F or CV_64F - @param P New camera matrix (3x3) or new projection matrix (3x4) - @param size Undistorted image size. - @param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2 . See convertMaps() - for details. - @param map1 The first output map. - @param map2 The second output map. - @param flags Flags indicates the rectification type, RECTIFY_PERSPECTIVE, RECTIFY_CYLINDRICAL, RECTIFY_LONGLATI and RECTIFY_STEREOGRAPHIC - are supported. - */ - CV_EXPORTS_W void initUndistortRectifyMap(InputArray K, InputArray D, InputArray xi, InputArray R, InputArray P, const cv::Size& size, - int m1type, OutputArray map1, OutputArray map2, int flags); - - /** @brief Undistort omnidirectional images to perspective images - - @param distorted The input omnidirectional image. - @param undistorted The output undistorted image. - @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. - @param D Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$. - @param xi The parameter xi for CMei's model. - @param flags Flags indicates the rectification type, RECTIFY_PERSPECTIVE, RECTIFY_CYLINDRICAL, RECTIFY_LONGLATI and RECTIFY_STEREOGRAPHIC - @param Knew Camera matrix of the distorted image. If it is not assigned, it is just K. - @param new_size The new image size. By default, it is the size of distorted. - @param R Rotation matrix between the input and output images. By default, it is identity matrix. - */ - CV_EXPORTS_W void undistortImage(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray xi, int flags, - InputArray Knew = cv::noArray(), const Size& new_size = Size(), InputArray R = Mat::eye(3, 3, CV_64F)); - - /** @brief Perform omnidirectional camera calibration, the default depth of outputs is CV_64F. - - @param objectPoints Vector of vector of Vec3f object points in world (pattern) coordinate. - It also can be vector of Mat with size 1xN/Nx1 and type CV_32FC3. Data with depth of 64_F is also acceptable. - @param imagePoints Vector of vector of Vec2f corresponding image points of objectPoints. It must be the same - size and the same type with objectPoints. - @param size Image size of calibration images. - @param K Output calibrated camera matrix. - @param xi Output parameter xi for CMei's model - @param D Output distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ - @param rvecs Output rotations for each calibration images - @param tvecs Output translation for each calibration images - @param flags The flags that control calibrate - @param criteria Termination criteria for optimization - @param idx Indices of images that pass initialization, which are really used in calibration. So the size of rvecs is the - same as idx.total(). - */ - CV_EXPORTS_W double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size size, - InputOutputArray K, InputOutputArray xi, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, - int flags, TermCriteria criteria, OutputArray idx=noArray()); - - /** @brief Stereo calibration for omnidirectional camera model. It computes the intrinsic parameters for two - cameras and the extrinsic parameters between two cameras. The default depth of outputs is CV_64F. - - @param objectPoints Object points in world (pattern) coordinate. Its type is vector >. - It also can be vector of Mat with size 1xN/Nx1 and type CV_32FC3. Data with depth of 64_F is also acceptable. - @param imagePoints1 The corresponding image points of the first camera, with type vector >. - It must be the same size and the same type as objectPoints. - @param imagePoints2 The corresponding image points of the second camera, with type vector >. - It must be the same size and the same type as objectPoints. - @param imageSize1 Image size of calibration images of the first camera. - @param imageSize2 Image size of calibration images of the second camera. - @param K1 Output camera matrix for the first camera. - @param xi1 Output parameter xi of Mei's model for the first camera - @param D1 Output distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the first camera - @param K2 Output camera matrix for the first camera. - @param xi2 Output parameter xi of CMei's model for the second camera - @param D2 Output distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the second camera - @param rvec Output rotation between the first and second camera - @param tvec Output translation between the first and second camera - @param rvecsL Output rotation for each image of the first camera - @param tvecsL Output translation for each image of the first camera - @param flags The flags that control stereoCalibrate - @param criteria Termination criteria for optimization - @param idx Indices of image pairs that pass initialization, which are really used in calibration. So the size of rvecs is the - same as idx.total(). - @ - */ - CV_EXPORTS_W double stereoCalibrate(InputOutputArrayOfArrays objectPoints, InputOutputArrayOfArrays imagePoints1, InputOutputArrayOfArrays imagePoints2, - const Size& imageSize1, const Size& imageSize2, InputOutputArray K1, InputOutputArray xi1, InputOutputArray D1, InputOutputArray K2, InputOutputArray xi2, - InputOutputArray D2, OutputArray rvec, OutputArray tvec, OutputArrayOfArrays rvecsL, OutputArrayOfArrays tvecsL, int flags, TermCriteria criteria, OutputArray idx=noArray()); - - /** @brief Stereo rectification for omnidirectional camera model. It computes the rectification rotations for two cameras - - @param R Rotation between the first and second camera - @param T Translation between the first and second camera - @param R1 Output 3x3 rotation matrix for the first camera - @param R2 Output 3x3 rotation matrix for the second camera - */ - CV_EXPORTS_W void stereoRectify(InputArray R, InputArray T, OutputArray R1, OutputArray R2); - - /** @brief Stereo 3D reconstruction from a pair of images - - @param image1 The first input image - @param image2 The second input image - @param K1 Input camera matrix of the first camera - @param D1 Input distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the first camera - @param xi1 Input parameter xi for the first camera for CMei's model - @param K2 Input camera matrix of the second camera - @param D2 Input distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the second camera - @param xi2 Input parameter xi for the second camera for CMei's model - @param R Rotation between the first and second camera - @param T Translation between the first and second camera - @param flag Flag of rectification type, RECTIFY_PERSPECTIVE or RECTIFY_LONGLATI - @param numDisparities The parameter 'numDisparities' in StereoSGBM, see StereoSGBM for details. - @param SADWindowSize The parameter 'SADWindowSize' in StereoSGBM, see StereoSGBM for details. - @param disparity Disparity map generated by stereo matching - @param image1Rec Rectified image of the first image - @param image2Rec rectified image of the second image - @param newSize Image size of rectified image, see omnidir::undistortImage - @param Knew New camera matrix of rectified image, see omnidir::undistortImage - @param pointCloud Point cloud of 3D reconstruction, with type CV_64FC3 - @param pointType Point cloud type, it can be XYZRGB or XYZ - */ - CV_EXPORTS_W void stereoReconstruct(InputArray image1, InputArray image2, InputArray K1, InputArray D1, InputArray xi1, - InputArray K2, InputArray D2, InputArray xi2, InputArray R, InputArray T, int flag, int numDisparities, int SADWindowSize, - OutputArray disparity, OutputArray image1Rec, OutputArray image2Rec, const Size& newSize = Size(), InputArray Knew = cv::noArray(), - OutputArray pointCloud = cv::noArray(), int pointType = XYZRGB); - -namespace internal -{ - void initializeCalibration(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size size, OutputArrayOfArrays omAll, - OutputArrayOfArrays tAll, OutputArray K, double& xi, OutputArray idx = noArray()); - - void initializeStereoCalibration(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, - const Size& size1, const Size& size2, OutputArray om, OutputArray T, OutputArrayOfArrays omL, OutputArrayOfArrays tL, OutputArray K1, OutputArray D1, OutputArray K2, OutputArray D2, - double &xi1, double &xi2, int flags, OutputArray idx); - - void computeJacobian(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, InputArray parameters, Mat& JTJ_inv, Mat& JTE, int flags, - double epsilon); - - void computeJacobianStereo(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, - InputArray parameters, Mat& JTJ_inv, Mat& JTE, int flags, double epsilon); - - void encodeParameters(InputArray K, InputArrayOfArrays omAll, InputArrayOfArrays tAll, InputArray distoaration, double xi, OutputArray parameters); - - void encodeParametersStereo(InputArray K1, InputArray K2, InputArray om, InputArray T, InputArrayOfArrays omL, InputArrayOfArrays tL, - InputArray D1, InputArray D2, double xi1, double xi2, OutputArray parameters); - - void decodeParameters(InputArray paramsters, OutputArray K, OutputArrayOfArrays omAll, OutputArrayOfArrays tAll, OutputArray distoration, double& xi); - - void decodeParametersStereo(InputArray parameters, OutputArray K1, OutputArray K2, OutputArray om, OutputArray T, OutputArrayOfArrays omL, - OutputArrayOfArrays tL, OutputArray D1, OutputArray D2, double& xi1, double& xi2); - - void estimateUncertainties(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, InputArray parameters, Mat& errors, Vec2d& std_error, double& rms, int flags); - - void estimateUncertaintiesStereo(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, InputArray parameters, Mat& errors, - Vec2d& std_error, double& rms, int flags); - - double computeMeanReproErr(InputArrayOfArrays imagePoints, InputArrayOfArrays proImagePoints); - - double computeMeanReproErr(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, InputArray K, InputArray D, double xi, InputArrayOfArrays omAll, - InputArrayOfArrays tAll); - - double computeMeanReproErrStereo(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, InputArray K1, InputArray K2, - InputArray D1, InputArray D2, double xi1, double xi2, InputArray om, InputArray T, InputArrayOfArrays omL, InputArrayOfArrays TL); - - void subMatrix(const Mat& src, Mat& dst, const std::vector& cols, const std::vector& rows); - - void flags2idx(int flags, std::vector& idx, int n); - - void flags2idxStereo(int flags, std::vector& idx, int n); - - void fillFixed(Mat&G, int flags, int n); - - void fillFixedStereo(Mat& G, int flags, int n); - - double findMedian(const Mat& row); - - Vec3d findMedian3(InputArray mat); - - void getInterset(InputArray idx1, InputArray idx2, OutputArray inter1, OutputArray inter2, OutputArray inter_ori); - - void compose_motion(InputArray _om1, InputArray _T1, InputArray _om2, InputArray _T2, Mat& om3, Mat& T3, Mat& dom3dom1, - Mat& dom3dT1, Mat& dom3dom2, Mat& dom3dT2, Mat& dT3dom1, Mat& dT3dT1, Mat& dT3dom2, Mat& dT3dT2); - - //void JRodriguesMatlab(const Mat& src, Mat& dst); - - //void dAB(InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB); -} // internal - -//! @} - -} // omnidir - -} //cv -#endif diff --git a/3rdparty/include/opencv2/ccalib/randpattern.hpp b/3rdparty/include/opencv2/ccalib/randpattern.hpp deleted file mode 100644 index fb362bd530..0000000000 --- a/3rdparty/include/opencv2/ccalib/randpattern.hpp +++ /dev/null @@ -1,184 +0,0 @@ -/*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) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University, -// all rights reserved. -// -// 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_RANDOMPATTERN_HPP__ -#define __OPENCV_RANDOMPATTERN_HPP__ - -#include "opencv2/features2d.hpp" -#include "opencv2/highgui.hpp" - -namespace cv { namespace randpattern { - - -//! @addtogroup ccalib -//! @{ - -/** @brief Class for finding features points and corresponding 3D in world coordinate of -a "random" pattern, which can be to be used in calibration. It is useful when pattern is -partly occluded or only a part of pattern can be observed in multiple cameras calibration. -The pattern can be generated by RandomPatternGenerator class described in this file. - -Please refer to paper - B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System - Calibration Toolbox Using A Feature Descriptor-Based Calibration - Pattern", in IROS 2013. -*/ - -class CV_EXPORTS RandomPatternCornerFinder -{ -public: - - /* @brief Construct RandomPatternCornerFinder object - - @param patternWidth the real width of "random" pattern in a user defined unit. - @param patternHeight the real height of "random" pattern in a user defined unit. - @param nMiniMatch number of minimal matches, otherwise that image is abandoned - @depth depth of output objectPoints and imagePoints, set it to be CV_32F or CV_64F. - @showExtraction whether show feature extraction, 0 for no and 1 for yes. - @detector feature detector to detect feature points in pattern and images. - @descriptor feature descriptor. - @matcher feature matcher. - */ - RandomPatternCornerFinder(float patternWidth, float patternHeight, - int nminiMatch = 20, int depth = CV_32F, int verbose = 0, int showExtraction = 0, - Ptr detector = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 0, 3, 0.005f), - Ptr descriptor = AKAZE::create(AKAZE::DESCRIPTOR_MLDB,0, 3, 0.005f), - Ptr matcher = DescriptorMatcher::create("BruteForce-L1")); - - /* @brief Load pattern image and compute features for pattern - @param patternImage image for "random" pattern generated by RandomPatternGenerator, run it first. - */ - void loadPattern(const cv::Mat &patternImage); - - /* @brief Load pattern and features - @param patternImage image for "random" pattern generated by RandomPatternGenerator, run it first. - @param patternKeyPoints keyPoints created from a FeatureDetector. - @param patternDescriptors descriptors created from a DescriptorExtractor. - */ - void loadPattern(const cv::Mat &patternImage, const std::vector &patternKeyPoints, const cv::Mat &patternDescriptors); - - /* @brief Compute matched object points and image points which are used for calibration - The objectPoints (3D) and imagePoints (2D) are stored inside the class. Run getObjectPoints() - and getImagePoints() to get them. - - @param inputImages vector of 8-bit grayscale images containing "random" pattern - that are used for calibration. - */ - void computeObjectImagePoints(std::vector inputImages); - - //void computeObjectImagePoints2(std::vector inputImages); - - /* @brief Compute object and image points for a single image. It returns a vector that - the first element stores the imagePoints and the second one stores the objectPoints. - - @param inputImage single input image for calibration - */ - std::vector computeObjectImagePointsForSingle(cv::Mat inputImage); - - /* @brief Get object(3D) points - */ - const std::vector &getObjectPoints(); - - /* @brief and image(2D) points - */ - const std::vector &getImagePoints(); - -private: - - std::vector _objectPonits, _imagePoints; - float _patternWidth, _patternHeight; - cv::Size _patternImageSize; - int _nminiMatch; - int _depth; - int _verbose; - - Ptr _detector; - Ptr _descriptor; - Ptr _matcher; - Mat _descriptorPattern; - std::vector _keypointsPattern; - Mat _patternImage; - int _showExtraction; - - void keyPoints2MatchedLocation(const std::vector& imageKeypoints, - const std::vector& patternKeypoints, const std::vector matchces, - cv::Mat& matchedImagelocation, cv::Mat& matchedPatternLocation); - void getFilteredLocation(cv::Mat& imageKeypoints, cv::Mat& patternKeypoints, const cv::Mat mask); - void getObjectImagePoints(const cv::Mat& imageKeypoints, const cv::Mat& patternKeypoints); - void crossCheckMatching( cv::Ptr& descriptorMatcher, - const Mat& descriptors1, const Mat& descriptors2, - std::vector& filteredMatches12, int knn=1 ); - void drawCorrespondence(const Mat& image1, const std::vector keypoint1, - const Mat& image2, const std::vector keypoint2, const std::vector matchces, - const Mat& mask1, const Mat& mask2, const int step); -}; - -/* @brief Class to generate "random" pattern image that are used for RandomPatternCornerFinder -Please refer to paper -B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System -Calibration Toolbox Using A Feature Descriptor-Based Calibration -Pattern", in IROS 2013. -*/ -class CV_EXPORTS RandomPatternGenerator -{ -public: - /* @brief Construct RandomPatternGenerator - - @param imageWidth image width of the generated pattern image - @param imageHeight image height of the generated pattern image - */ - RandomPatternGenerator(int imageWidth, int imageHeight); - - /* @brief Generate pattern - */ - void generatePattern(); - /* @brief Get pattern - */ - cv::Mat getPattern(); -private: - cv::Mat _pattern; - int _imageWidth, _imageHeight; -}; - -//! @} - -}} //namespace randpattern, cv -#endif \ No newline at end of file diff --git a/3rdparty/include/opencv2/core.hpp b/3rdparty/include/opencv2/core.hpp index fc2432dcdf..48023844a9 100644 --- a/3rdparty/include/opencv2/core.hpp +++ b/3rdparty/include/opencv2/core.hpp @@ -50,7 +50,6 @@ #endif #include "opencv2/core/cvdef.h" -#include "opencv2/core/version.hpp" #include "opencv2/core/base.hpp" #include "opencv2/core/cvstd.hpp" #include "opencv2/core/traits.hpp" @@ -95,6 +94,11 @@ @{ @defgroup core_hal_intrin_impl Private implementation helpers @} + @defgroup core_lowlevel_api Low-level API for external libraries / plugins + @} + @defgroup core_parallel Parallel Processing + @{ + @defgroup core_parallel_backend Parallel backends API @} @} */ @@ -148,7 +152,7 @@ It is possible to alternate error processing by using #redirectError(). @param exc the exception raisen. @deprecated drop this version */ -CV_EXPORTS void error( const Exception& exc ); +CV_EXPORTS CV_NORETURN void error(const Exception& exc); enum SortFlags { SORT_EVERY_ROW = 0, //!< each matrix row is sorted independently SORT_EVERY_COLUMN = 1, //!< each matrix column is sorted @@ -220,27 +224,6 @@ enum KmeansFlags { //! @} core_cluster -//! type of line -enum LineTypes { - FILLED = -1, - LINE_4 = 4, //!< 4-connected line - LINE_8 = 8, //!< 8-connected line - LINE_AA = 16 //!< antialiased line -}; - -//! Only a subset of Hershey fonts are supported -enum HersheyFonts { - FONT_HERSHEY_SIMPLEX = 0, //!< normal size sans-serif font - FONT_HERSHEY_PLAIN = 1, //!< small size sans-serif font - FONT_HERSHEY_DUPLEX = 2, //!< normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX) - FONT_HERSHEY_COMPLEX = 3, //!< normal size serif font - FONT_HERSHEY_TRIPLEX = 4, //!< normal size serif font (more complex than FONT_HERSHEY_COMPLEX) - FONT_HERSHEY_COMPLEX_SMALL = 5, //!< smaller version of FONT_HERSHEY_COMPLEX - FONT_HERSHEY_SCRIPT_SIMPLEX = 6, //!< hand-writing style font - FONT_HERSHEY_SCRIPT_COMPLEX = 7, //!< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX - FONT_ITALIC = 16 //!< flag for italic font -}; - //! @addtogroup core_array //! @{ @@ -449,8 +432,13 @@ The function cv::divide divides one array by another: or a scalar by an array when there is no src1 : \f[\texttt{dst(I) = saturate(scale/src2(I))}\f] -When src2(I) is zero, dst(I) will also be zero. Different channels of -multi-channel arrays are processed independently. +Different channels of multi-channel arrays are processed independently. + +For integer types when src2(I) is zero, dst(I) will also be zero. + +@note In case of floating point data there is no special defined behavior for zero src2(I) values. +Regular floating-point division is used. +Expect correct IEEE-754 behaviour for floating-point data (with NaN, Inf result values). @note Saturation is not applied when the output array has the depth CV_32S. You may even get result of an incorrect sign in the case of overflow. @@ -615,7 +603,7 @@ or // access pixel coordinates Point pnt = locations[i]; @endcode -@param src single-channel array (type CV_8UC1) +@param src single-channel array @param idx the output array, type of cv::Mat or std::vector, corresponding to non-zero indices in the input */ CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx ); @@ -715,7 +703,8 @@ CV_EXPORTS double norm( const SparseMat& src, int normType ); /** @brief Computes the Peak Signal-to-Noise Ratio (PSNR) image quality metric. -This function calculates the Peak Signal-to-Noise Ratio (PSNR) image quality metric in decibels (dB), between two input arrays src1 and src2. Arrays must have depth CV_8U. +This function calculates the Peak Signal-to-Noise Ratio (PSNR) image quality metric in decibels (dB), +between two input arrays src1 and src2. The arrays must have the same type. The PSNR is calculated as follows: @@ -723,13 +712,15 @@ The PSNR is calculated as follows: \texttt{PSNR} = 10 \cdot \log_{10}{\left( \frac{R^2}{MSE} \right) } \f] -where R is the maximum integer value of depth CV_8U (255) and MSE is the mean squared error between the two arrays. +where R is the maximum integer value of depth (e.g. 255 in the case of CV_8U data) +and MSE is the mean squared error between the two arrays. @param src1 first input array. @param src2 second input array of the same size as src1. +@param R the maximum pixel value (255 by default) */ -CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2); +CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2, double R=255.); /** @brief naive nearest neighbor finder @@ -1372,6 +1363,17 @@ You may even get a negative value in the case of overflow. */ CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst); +/** @brief This is an overloaded member function, provided for convenience (python) +Copies the matrix to another one. +When the operation mask is specified, if the Mat::create call shown above reallocates the matrix, the newly allocated matrix is initialized with all zeros before copying the data. +@param src source matrix. +@param dst Destination matrix. If it does not have a proper size or type before the operation, it is +reallocated. +@param mask Operation mask of the same size as \*this. Its non-zero elements indicate which matrix +elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels. +*/ + +void CV_EXPORTS_W copyTo(InputArray src, OutputArray dst, InputArray mask); /** @brief Checks if array elements lie between the elements of two other arrays. The function checks the range as follows: @@ -2618,7 +2620,6 @@ public: static Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src); protected: - bool _dataAsRow; // unused, but needed for 3.0 ABI compatibility. int _num_components; Mat _eigenvectors; Mat _eigenvalues; @@ -3031,7 +3032,8 @@ public: class CV_EXPORTS Formatter { public: - enum { FMT_DEFAULT = 0, + enum FormatType { + FMT_DEFAULT = 0, FMT_MATLAB = 1, FMT_CSV = 2, FMT_PYTHON = 3, @@ -3043,11 +3045,12 @@ public: virtual Ptr format(const Mat& mtx) const = 0; + virtual void set16fPrecision(int p = 4) = 0; virtual void set32fPrecision(int p = 8) = 0; virtual void set64fPrecision(int p = 16) = 0; virtual void setMultiline(bool ml = true) = 0; - static Ptr get(int fmt = FMT_DEFAULT); + static Ptr get(Formatter::FormatType fmt = FMT_DEFAULT); }; @@ -3070,7 +3073,7 @@ String& operator << (String& out, const Mat& mtx) class CV_EXPORTS Algorithm; -template struct ParamType {}; +template struct ParamType {}; /** @brief This is a base class for all more or less complex algorithms in OpenCV @@ -3183,9 +3186,9 @@ protected: void writeFormat(FileStorage& fs) const; }; -struct Param { - enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, - UNSIGNED_INT=8, UINT64=9, UCHAR=11, SCALAR=12 }; +enum struct Param { + INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, + UNSIGNED_INT=8, UINT64=9, UCHAR=11, SCALAR=12 }; @@ -3195,7 +3198,7 @@ template<> struct ParamType typedef bool const_param_type; typedef bool member_type; - enum { type = Param::BOOLEAN }; + static const Param type = Param::BOOLEAN; }; template<> struct ParamType @@ -3203,7 +3206,7 @@ template<> struct ParamType typedef int const_param_type; typedef int member_type; - enum { type = Param::INT }; + static const Param type = Param::INT; }; template<> struct ParamType @@ -3211,7 +3214,7 @@ template<> struct ParamType typedef double const_param_type; typedef double member_type; - enum { type = Param::REAL }; + static const Param type = Param::REAL; }; template<> struct ParamType @@ -3219,7 +3222,7 @@ template<> struct ParamType typedef const String& const_param_type; typedef String member_type; - enum { type = Param::STRING }; + static const Param type = Param::STRING; }; template<> struct ParamType @@ -3227,7 +3230,7 @@ template<> struct ParamType typedef const Mat& const_param_type; typedef Mat member_type; - enum { type = Param::MAT }; + static const Param type = Param::MAT; }; template<> struct ParamType > @@ -3235,7 +3238,7 @@ template<> struct ParamType > typedef const std::vector& const_param_type; typedef std::vector member_type; - enum { type = Param::MAT_VECTOR }; + static const Param type = Param::MAT_VECTOR; }; template<> struct ParamType @@ -3243,7 +3246,7 @@ template<> struct ParamType typedef const Ptr& const_param_type; typedef Ptr member_type; - enum { type = Param::ALGORITHM }; + static const Param type = Param::ALGORITHM; }; template<> struct ParamType @@ -3251,7 +3254,7 @@ template<> struct ParamType typedef float const_param_type; typedef float member_type; - enum { type = Param::FLOAT }; + static const Param type = Param::FLOAT; }; template<> struct ParamType @@ -3259,7 +3262,7 @@ template<> struct ParamType typedef unsigned const_param_type; typedef unsigned member_type; - enum { type = Param::UNSIGNED_INT }; + static const Param type = Param::UNSIGNED_INT; }; template<> struct ParamType @@ -3267,7 +3270,7 @@ template<> struct ParamType typedef uint64 const_param_type; typedef uint64 member_type; - enum { type = Param::UINT64 }; + static const Param type = Param::UINT64; }; template<> struct ParamType @@ -3275,7 +3278,7 @@ template<> struct ParamType typedef uchar const_param_type; typedef uchar member_type; - enum { type = Param::UCHAR }; + static const Param type = Param::UCHAR; }; template<> struct ParamType @@ -3283,7 +3286,16 @@ template<> struct ParamType typedef const Scalar& const_param_type; typedef Scalar member_type; - enum { type = Param::SCALAR }; + static const Param type = Param::SCALAR; +}; + +template +struct ParamType<_Tp, typename std::enable_if< std::is_enum<_Tp>::value >::type> +{ + typedef typename std::underlying_type<_Tp>::type const_param_type; + typedef typename std::underlying_type<_Tp>::type member_type; + + static const Param type = Param::INT; }; //! @} core_basic diff --git a/3rdparty/include/opencv2/core/affine.hpp b/3rdparty/include/opencv2/core/affine.hpp index 7e2ed30785..1806382e99 100644 --- a/3rdparty/include/opencv2/core/affine.hpp +++ b/3rdparty/include/opencv2/core/affine.hpp @@ -499,7 +499,7 @@ typename cv::Affine3::Vec3 cv::Affine3::rvec() const double s = std::sqrt((rx*rx + ry*ry + rz*rz)*0.25); double c = (R.val[0] + R.val[4] + R.val[8] - 1) * 0.5; c = c > 1.0 ? 1.0 : c < -1.0 ? -1.0 : c; - double theta = acos(c); + double theta = std::acos(c); if( s < 1e-5 ) { diff --git a/3rdparty/include/opencv2/core/base.hpp b/3rdparty/include/opencv2/core/base.hpp index 546140e9f1..21a61a4e53 100644 --- a/3rdparty/include/opencv2/core/base.hpp +++ b/3rdparty/include/opencv2/core/base.hpp @@ -295,32 +295,7 @@ It is possible to alternate error processing by using redirectError(). @param _line - line number in the source file where the error has occurred @see CV_Error, CV_Error_, CV_Assert, CV_DbgAssert */ -CV_EXPORTS void error(int _code, const String& _err, const char* _func, const char* _file, int _line); - -#ifdef __GNUC__ -# if defined __clang__ || defined __APPLE__ -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Winvalid-noreturn" -# endif -#endif - -/** same as cv::error, but does not return */ -CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const char* _func, const char* _file, int _line) -{ - error(_code, _err, _func, _file, _line); -#ifdef __GNUC__ -# if !defined __clang__ && !defined __APPLE__ - // this suppresses this warning: "noreturn" function does return [enabled by default] - __builtin_trap(); - // or use infinite loop: for (;;) {} -# endif -#endif -} -#ifdef __GNUC__ -# if defined __clang__ || defined __APPLE__ -# pragma GCC diagnostic pop -# endif -#endif +CV_EXPORTS CV_NORETURN void error(int _code, const String& _err, const char* _func, const char* _file, int _line); #ifdef CV_STATIC_ANALYSIS @@ -329,8 +304,6 @@ CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const ch #define CV_Error(code, msg) do { (void)(code); (void)(msg); abort(); } while (0) #define CV_Error_(code, args) do { (void)(code); (void)(cv::format args); abort(); } while (0) #define CV_Assert( expr ) do { if (!(expr)) abort(); } while (0) -#define CV_ErrorNoReturn CV_Error -#define CV_ErrorNoReturn_ CV_Error_ #else // CV_STATIC_ANALYSIS @@ -368,53 +341,31 @@ configurations while CV_DbgAssert is only retained in the Debug configuration. */ #define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0) -//! @cond IGNORED -#define CV__ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ ) -#define CV__ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ ) -#ifdef __OPENCV_BUILD -#undef CV_Error -#define CV_Error CV__ErrorNoReturn -#undef CV_Error_ -#define CV_Error_ CV__ErrorNoReturn_ -#undef CV_Assert -#define CV_Assert( expr ) do { if(!!(expr)) ; else cv::errorNoReturn( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0) -#else -// backward compatibility -#define CV_ErrorNoReturn CV__ErrorNoReturn -#define CV_ErrorNoReturn_ CV__ErrorNoReturn_ -#endif -//! @endcond - #endif // CV_STATIC_ANALYSIS //! @cond IGNORED - -#if defined OPENCV_FORCE_MULTIARG_ASSERT_CHECK && defined CV_STATIC_ANALYSIS -#warning "OPENCV_FORCE_MULTIARG_ASSERT_CHECK can't be used with CV_STATIC_ANALYSIS" -#undef OPENCV_FORCE_MULTIARG_ASSERT_CHECK +#if !defined(__OPENCV_BUILD) // TODO: backward compatibility only +#ifndef CV_ErrorNoReturn +#define CV_ErrorNoReturn CV_Error +#endif +#ifndef CV_ErrorNoReturn_ +#define CV_ErrorNoReturn_ CV_Error_ +#endif #endif -#ifdef OPENCV_FORCE_MULTIARG_ASSERT_CHECK -#define CV_Assert_1( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0) -#else #define CV_Assert_1 CV_Assert -#endif -#define CV_Assert_2( expr1, expr2 ) CV_Assert_1(expr1); CV_Assert_1(expr2) -#define CV_Assert_3( expr1, expr2, expr3 ) CV_Assert_2(expr1, expr2); CV_Assert_1(expr3) -#define CV_Assert_4( expr1, expr2, expr3, expr4 ) CV_Assert_3(expr1, expr2, expr3); CV_Assert_1(expr4) -#define CV_Assert_5( expr1, expr2, expr3, expr4, expr5 ) CV_Assert_4(expr1, expr2, expr3, expr4); CV_Assert_1(expr5) -#define CV_Assert_6( expr1, expr2, expr3, expr4, expr5, expr6 ) CV_Assert_5(expr1, expr2, expr3, expr4, expr5); CV_Assert_1(expr6) -#define CV_Assert_7( expr1, expr2, expr3, expr4, expr5, expr6, expr7 ) CV_Assert_6(expr1, expr2, expr3, expr4, expr5, expr6 ); CV_Assert_1(expr7) -#define CV_Assert_8( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8 ) CV_Assert_7(expr1, expr2, expr3, expr4, expr5, expr6, expr7 ); CV_Assert_1(expr8) -#define CV_Assert_9( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9 ) CV_Assert_8(expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8 ); CV_Assert_1(expr9) -#define CV_Assert_10( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9, expr10 ) CV_Assert_9(expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9 ); CV_Assert_1(expr10) +#define CV_Assert_2( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_1( __VA_ARGS__ )) +#define CV_Assert_3( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_2( __VA_ARGS__ )) +#define CV_Assert_4( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_3( __VA_ARGS__ )) +#define CV_Assert_5( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_4( __VA_ARGS__ )) +#define CV_Assert_6( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_5( __VA_ARGS__ )) +#define CV_Assert_7( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_6( __VA_ARGS__ )) +#define CV_Assert_8( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_7( __VA_ARGS__ )) +#define CV_Assert_9( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_8( __VA_ARGS__ )) +#define CV_Assert_10( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_9( __VA_ARGS__ )) -#define CV_Assert_N(...) do { __CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__); } while(0) +#define CV_Assert_N(...) do { __CV_EXPAND(__CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__)); } while(0) -#ifdef OPENCV_FORCE_MULTIARG_ASSERT_CHECK -#undef CV_Assert -#define CV_Assert CV_Assert_N -#endif //! @endcond #if defined _DEBUG || defined CV_STATIC_ANALYSIS @@ -430,7 +381,7 @@ configurations while CV_DbgAssert is only retained in the Debug configuration. */ struct CV_EXPORTS Hamming { - enum { normType = NORM_HAMMING }; + static const NormTypes normType = NORM_HAMMING; typedef unsigned char ValueType; typedef int ResultType; @@ -587,6 +538,16 @@ _AccTp normInf(const _Tp* a, const _Tp* b, int n) */ CV_EXPORTS_W float cubeRoot(float val); +/** @overload + +cubeRoot with argument of `double` type calls `std::cbrt(double)` +*/ +static inline +double cubeRoot(double val) +{ + return std::cbrt(val); +} + /** @brief Calculates the angle of a 2D vector in degrees. The function fastAtan2 calculates the full-range angle of an input 2D vector. The angle is measured @@ -667,11 +628,7 @@ namespace cudev namespace ipp { -#if OPENCV_ABI_COMPATIBILITY > 300 CV_EXPORTS unsigned long long getIppFeatures(); -#else -CV_EXPORTS int getIppFeatures(); -#endif CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL, int line = 0); CV_EXPORTS int getIppStatus(); @@ -684,9 +641,9 @@ CV_EXPORTS_W String getIppVersion(); // but have internal accuracy differences which have too much direct or indirect impact on accuracy tests. CV_EXPORTS_W bool useIPP_NotExact(); CV_EXPORTS_W void setUseIPP_NotExact(bool flag); -#if OPENCV_ABI_COMPATIBILITY < 400 -CV_EXPORTS_W bool useIPP_NE(); -CV_EXPORTS_W void setUseIPP_NE(bool flag); +#ifndef DISABLE_OPENCV_3_COMPATIBILITY +static inline bool useIPP_NE() { return useIPP_NotExact(); } +static inline void setUseIPP_NE(bool flag) { setUseIPP_NotExact(flag); } #endif } // ipp diff --git a/3rdparty/include/opencv2/core/bindings_utils.hpp b/3rdparty/include/opencv2/core/bindings_utils.hpp index 92f27f0e87..cf8bcdd622 100644 --- a/3rdparty/include/opencv2/core/bindings_utils.hpp +++ b/3rdparty/include/opencv2/core/bindings_utils.hpp @@ -7,6 +7,9 @@ #include #include +#include + +#include namespace cv { namespace utils { //! @addtogroup core_utils @@ -64,6 +67,61 @@ String dumpString(const String& argument) return cv::format("String: %s", argument.c_str()); } +CV_WRAP static inline +String testOverloadResolution(int value, const Point& point = Point(42, 24)) +{ + return format("overload (int=%d, point=(x=%d, y=%d))", value, point.x, + point.y); +} + +CV_WRAP static inline +String testOverloadResolution(const Rect& rect) +{ + return format("overload (rect=(x=%d, y=%d, w=%d, h=%d))", rect.x, rect.y, + rect.width, rect.height); +} + +CV_WRAP static inline +String dumpRect(const Rect& argument) +{ + return format("rect: (x=%d, y=%d, w=%d, h=%d)", argument.x, argument.y, + argument.width, argument.height); +} + +CV_WRAP static inline +String dumpTermCriteria(const TermCriteria& argument) +{ + return format("term_criteria: (type=%d, max_count=%d, epsilon=%lf", + argument.type, argument.maxCount, argument.epsilon); +} + +CV_WRAP static inline +String dumpRotatedRect(const RotatedRect& argument) +{ + return format("rotated_rect: (c_x=%f, c_y=%f, w=%f, h=%f, a=%f)", + argument.center.x, argument.center.y, argument.size.width, + argument.size.height, argument.angle); +} + +CV_WRAP static inline +String dumpRange(const Range& argument) +{ + if (argument == Range::all()) + { + return "range: all"; + } + else + { + return format("range: (s=%d, e=%d)", argument.start, argument.end); + } +} + +CV_WRAP static inline +void testRaiseGeneralException() +{ + throw std::runtime_error("exception text"); +} + CV_WRAP static inline AsyncArray testAsyncArray(InputArray argument) { @@ -87,7 +145,30 @@ AsyncArray testAsyncException() return p.getArrayResult(); } -//! @} -}} // namespace +namespace fs { + CV_EXPORTS_W cv::String getCacheDirectoryForDownloads(); +} // namespace fs + +//! @} // core_utils +} // namespace cv::utils + +//! @cond IGNORED + +CV_WRAP static inline +int setLogLevel(int level) +{ + // NB: Binding generators doesn't work with enums properly yet, so we define separate overload here + return cv::utils::logging::setLogLevel((cv::utils::logging::LogLevel)level); +} + +CV_WRAP static inline +int getLogLevel() +{ + return cv::utils::logging::getLogLevel(); +} + +//! @endcond IGNORED + +} // namespaces cv / utils #endif // OPENCV_CORE_BINDINGS_UTILS_HPP diff --git a/3rdparty/include/opencv2/core/core_c.h b/3rdparty/include/opencv2/core/core_c.h index 95a98cfcd0..09ac1e789a 100644 --- a/3rdparty/include/opencv2/core/core_c.h +++ b/3rdparty/include/opencv2/core/core_c.h @@ -1576,8 +1576,8 @@ CVAPI(void) cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos CVAPI(void*) cvMemStorageAlloc( CvMemStorage* storage, size_t size ); /** Allocates string in memory storage */ -CVAPI(CvString) cvMemStorageAllocString( CvMemStorage* storage, const char* ptr, - int len CV_DEFAULT(-1) ); +//CVAPI(CvString) cvMemStorageAllocString( CvMemStorage* storage, const char* ptr, +// int len CV_DEFAULT(-1) ); /** Creates new empty sequence that will reside in the specified storage */ CVAPI(CvSeq*) cvCreateSeq( int seq_flags, size_t header_size, @@ -1970,6 +1970,7 @@ CVAPI(void) cvSetIPLAllocators( Cv_iplCreateImageHeader create_header, * Data Persistence * \****************************************************************************************/ +#if 0 /********************************** High-level functions ********************************/ /** @brief Opens file storage for reading or writing data. @@ -2556,10 +2557,12 @@ returns NULL. */ CVAPI(CvTypeInfo*) cvTypeOf( const void* struct_ptr ); +#endif + /** @brief Releases an object. -The function finds the type of a given object and calls release with the double pointer. -@param struct_ptr Double pointer to the object + The function finds the type of a given object and calls release with the double pointer. + @param struct_ptr Double pointer to the object */ CVAPI(void) cvRelease( void** struct_ptr ); @@ -2572,41 +2575,6 @@ function, like cvCloneMat. */ CVAPI(void*) cvClone( const void* struct_ptr ); -/** @brief Saves an object to a file. - -The function saves an object to a file. It provides a simple interface to cvWrite . -@param filename File name -@param struct_ptr Object to save -@param name Optional object name. If it is NULL, the name will be formed from filename . -@param comment Optional comment to put in the beginning of the file -@param attributes Optional attributes passed to cvWrite - */ -CVAPI(void) cvSave( const char* filename, const void* struct_ptr, - const char* name CV_DEFAULT(NULL), - const char* comment CV_DEFAULT(NULL), - CvAttrList attributes CV_DEFAULT(cvAttrList())); - -/** @brief Loads an object from a file. - -The function loads an object from a file. It basically reads the specified file, find the first -top-level node and calls cvRead for that node. If the file node does not have type information or -the type information can not be found by the type name, the function returns NULL. After the object -is loaded, the file storage is closed and all the temporary buffers are deleted. Thus, to load a -dynamic structure, such as a sequence, contour, or graph, one should pass a valid memory storage -destination to the function. -@param filename File name -@param memstorage Memory storage for dynamic structures, such as CvSeq or CvGraph . It is not used -for matrices or images. -@param name Optional object name. If it is NULL, the first top-level object in the storage will be -loaded. -@param real_name Optional output parameter that will contain the name of the loaded object -(useful if name=NULL ) - */ -CVAPI(void*) cvLoad( const char* filename, - CvMemStorage* memstorage CV_DEFAULT(NULL), - const char* name CV_DEFAULT(NULL), - const char** real_name CV_DEFAULT(NULL) ); - /*********************************** Measuring Execution Time ***************************/ /** helper functions for RNG initialization and accurate time measurement: @@ -2757,24 +2725,6 @@ static char cvFuncName[] = Name #ifdef __cplusplus -//! @addtogroup core_c_glue -//! @{ - -//! class for automatic module/RTTI data registration/unregistration -struct CV_EXPORTS CvType -{ - CvType( const char* type_name, - CvIsInstanceFunc is_instance, CvReleaseFunc release=0, - CvReadFunc read=0, CvWriteFunc write=0, CvCloneFunc clone=0 ); - ~CvType(); - CvTypeInfo* info; - - static CvTypeInfo* first; - static CvTypeInfo* last; -}; - -//! @} - #include "opencv2/core/utility.hpp" namespace cv @@ -2805,11 +2755,11 @@ CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1); ////// specialized implementations of DefaultDeleter::operator() for classic OpenCV types ////// -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvMat* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(IplImage* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvMatND* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvSparseMat* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvMemStorage* obj) const; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvMat* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(IplImage* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvMatND* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvSparseMat* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvMemStorage* obj) const; }; ////////////// convenient wrappers for operating old-style dynamic structures ////////////// diff --git a/3rdparty/include/opencv2/core/cuda.hpp b/3rdparty/include/opencv2/core/cuda.hpp index 7d7bb62e16..716b8bf2a8 100644 --- a/3rdparty/include/opencv2/core/cuda.hpp +++ b/3rdparty/include/opencv2/core/cuda.hpp @@ -102,10 +102,10 @@ streams. @sa Mat */ -class CV_EXPORTS GpuMat +class CV_EXPORTS_W GpuMat { public: - class CV_EXPORTS Allocator + class CV_EXPORTS_W Allocator { public: virtual ~Allocator() {} @@ -116,33 +116,33 @@ public: }; //! default allocator - static Allocator* defaultAllocator(); - static void setDefaultAllocator(Allocator* allocator); + CV_WRAP static GpuMat::Allocator* defaultAllocator(); + CV_WRAP static void setDefaultAllocator(GpuMat::Allocator* allocator); //! default constructor - explicit GpuMat(Allocator* allocator = defaultAllocator()); + CV_WRAP explicit GpuMat(GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); //! constructs GpuMat of the specified size and type - GpuMat(int rows, int cols, int type, Allocator* allocator = defaultAllocator()); - GpuMat(Size size, int type, Allocator* allocator = defaultAllocator()); + CV_WRAP GpuMat(int rows, int cols, int type, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); + CV_WRAP GpuMat(Size size, int type, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); //! constructs GpuMat and fills it with the specified value _s - GpuMat(int rows, int cols, int type, Scalar s, Allocator* allocator = defaultAllocator()); - GpuMat(Size size, int type, Scalar s, Allocator* allocator = defaultAllocator()); + CV_WRAP GpuMat(int rows, int cols, int type, Scalar s, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); + CV_WRAP GpuMat(Size size, int type, Scalar s, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); //! copy constructor - GpuMat(const GpuMat& m); + CV_WRAP GpuMat(const GpuMat& m); //! constructor for GpuMat headers pointing to user-allocated data GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP); GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP); //! creates a GpuMat header for a part of the bigger matrix - GpuMat(const GpuMat& m, Range rowRange, Range colRange); - GpuMat(const GpuMat& m, Rect roi); + CV_WRAP GpuMat(const GpuMat& m, Range rowRange, Range colRange); + CV_WRAP GpuMat(const GpuMat& m, Rect roi); //! builds GpuMat from host memory (Blocking call) - explicit GpuMat(InputArray arr, Allocator* allocator = defaultAllocator()); + CV_WRAP explicit GpuMat(InputArray arr, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); //! destructor - calls release() ~GpuMat(); @@ -151,21 +151,21 @@ public: GpuMat& operator =(const GpuMat& m); //! allocates new GpuMat data unless the GpuMat already has specified size and type - void create(int rows, int cols, int type); - void create(Size size, int type); + CV_WRAP void create(int rows, int cols, int type); + CV_WRAP void create(Size size, int type); //! decreases reference counter, deallocate the data when reference counter reaches 0 void release(); //! swaps with other smart pointer - void swap(GpuMat& mat); + CV_WRAP void swap(GpuMat& mat); /** @brief Performs data upload to GpuMat (Blocking call) This function copies data from host memory to device memory. As being a blocking call, it is guaranteed that the copy operation is finished when this function returns. */ - void upload(InputArray arr); + CV_WRAP void upload(InputArray arr); /** @brief Performs data upload to GpuMat (Non-Blocking call) @@ -175,14 +175,14 @@ public: The copy operation may be overlapped with operations in other non-default streams if \p stream is not the default stream and \p dst is HostMem allocated with HostMem::PAGE_LOCKED option. */ - void upload(InputArray arr, Stream& stream); + CV_WRAP void upload(InputArray arr, Stream& stream); /** @brief Performs data download from GpuMat (Blocking call) This function copies data from device memory to host memory. As being a blocking call, it is guaranteed that the copy operation is finished when this function returns. */ - void download(OutputArray dst) const; + CV_WRAP void download(OutputArray dst) const; /** @brief Performs data download from GpuMat (Non-Blocking call) @@ -192,51 +192,51 @@ public: The copy operation may be overlapped with operations in other non-default streams if \p stream is not the default stream and \p dst is HostMem allocated with HostMem::PAGE_LOCKED option. */ - void download(OutputArray dst, Stream& stream) const; + CV_WRAP void download(OutputArray dst, Stream& stream) const; //! returns deep copy of the GpuMat, i.e. the data is copied - GpuMat clone() const; + CV_WRAP GpuMat clone() const; //! copies the GpuMat content to device memory (Blocking call) - void copyTo(OutputArray dst) const; + CV_WRAP void copyTo(OutputArray dst) const; //! copies the GpuMat content to device memory (Non-Blocking call) - void copyTo(OutputArray dst, Stream& stream) const; + CV_WRAP void copyTo(OutputArray dst, Stream& stream) const; //! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Blocking call) - void copyTo(OutputArray dst, InputArray mask) const; + CV_WRAP void copyTo(OutputArray dst, InputArray mask) const; //! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Non-Blocking call) - void copyTo(OutputArray dst, InputArray mask, Stream& stream) const; + CV_WRAP void copyTo(OutputArray dst, InputArray mask, Stream& stream) const; //! sets some of the GpuMat elements to s (Blocking call) - GpuMat& setTo(Scalar s); + CV_WRAP GpuMat& setTo(Scalar s); //! sets some of the GpuMat elements to s (Non-Blocking call) - GpuMat& setTo(Scalar s, Stream& stream); + CV_WRAP GpuMat& setTo(Scalar s, Stream& stream); //! sets some of the GpuMat elements to s, according to the mask (Blocking call) - GpuMat& setTo(Scalar s, InputArray mask); + CV_WRAP GpuMat& setTo(Scalar s, InputArray mask); //! sets some of the GpuMat elements to s, according to the mask (Non-Blocking call) - GpuMat& setTo(Scalar s, InputArray mask, Stream& stream); + CV_WRAP GpuMat& setTo(Scalar s, InputArray mask, Stream& stream); //! converts GpuMat to another datatype (Blocking call) - void convertTo(OutputArray dst, int rtype) const; + CV_WRAP void convertTo(OutputArray dst, int rtype) const; //! converts GpuMat to another datatype (Non-Blocking call) - void convertTo(OutputArray dst, int rtype, Stream& stream) const; + CV_WRAP void convertTo(OutputArray dst, int rtype, Stream& stream) const; //! converts GpuMat to another datatype with scaling (Blocking call) - void convertTo(OutputArray dst, int rtype, double alpha, double beta = 0.0) const; + CV_WRAP void convertTo(OutputArray dst, int rtype, double alpha, double beta = 0.0) const; //! converts GpuMat to another datatype with scaling (Non-Blocking call) - void convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const; + CV_WRAP void convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const; //! converts GpuMat to another datatype with scaling (Non-Blocking call) - void convertTo(OutputArray dst, int rtype, double alpha, double beta, Stream& stream) const; + CV_WRAP void convertTo(OutputArray dst, int rtype, double alpha, double beta, Stream& stream) const; - void assignTo(GpuMat& m, int type=-1) const; + CV_WRAP void assignTo(GpuMat& m, int type = -1) const; //! returns pointer to y-th row uchar* ptr(int y = 0); @@ -250,18 +250,18 @@ public: template operator PtrStep<_Tp>() const; //! returns a new GpuMat header for the specified row - GpuMat row(int y) const; + CV_WRAP GpuMat row(int y) const; //! returns a new GpuMat header for the specified column - GpuMat col(int x) const; + CV_WRAP GpuMat col(int x) const; //! ... for the specified row span - GpuMat rowRange(int startrow, int endrow) const; - GpuMat rowRange(Range r) const; + CV_WRAP GpuMat rowRange(int startrow, int endrow) const; + CV_WRAP GpuMat rowRange(Range r) const; //! ... for the specified column span - GpuMat colRange(int startcol, int endcol) const; - GpuMat colRange(Range r) const; + CV_WRAP GpuMat colRange(int startcol, int endcol) const; + CV_WRAP GpuMat colRange(Range r) const; //! extracts a rectangular sub-GpuMat (this is a generalized form of row, rowRange etc.) GpuMat operator ()(Range rowRange, Range colRange) const; @@ -269,44 +269,47 @@ public: //! creates alternative GpuMat header for the same data, with different //! number of channels and/or different number of rows - GpuMat reshape(int cn, int rows = 0) const; + CV_WRAP GpuMat reshape(int cn, int rows = 0) const; //! locates GpuMat header within a parent GpuMat - void locateROI(Size& wholeSize, Point& ofs) const; + CV_WRAP void locateROI(Size& wholeSize, Point& ofs) const; //! moves/resizes the current GpuMat ROI inside the parent GpuMat - GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright); + CV_WRAP GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright); //! returns true iff the GpuMat data is continuous //! (i.e. when there are no gaps between successive rows) - bool isContinuous() const; + CV_WRAP bool isContinuous() const; //! returns element size in bytes - size_t elemSize() const; + CV_WRAP size_t elemSize() const; //! returns the size of element channel in bytes - size_t elemSize1() const; + CV_WRAP size_t elemSize1() const; //! returns element type - int type() const; + CV_WRAP int type() const; //! returns element type - int depth() const; + CV_WRAP int depth() const; //! returns number of channels - int channels() const; + CV_WRAP int channels() const; //! returns step/elemSize1() - size_t step1() const; + CV_WRAP size_t step1() const; //! returns GpuMat size : width == number of columns, height == number of rows - Size size() const; + CV_WRAP Size size() const; //! returns true if GpuMat data is NULL - bool empty() const; + CV_WRAP bool empty() const; + + // returns pointer to cuda memory + CV_WRAP void* cudaPtr() const; //! internal use method: updates the continuity flag - void updateContinuityFlag(); + CV_WRAP void updateContinuityFlag(); /*! includes several bit-fields: - the magic signature @@ -320,7 +323,7 @@ public: int rows, cols; //! a distance between successive rows in bytes; includes the gap if any - size_t step; + CV_PROP size_t step; //! pointer to the data uchar* data; @@ -337,6 +340,209 @@ public: Allocator* allocator; }; +struct CV_EXPORTS_W GpuData +{ + explicit GpuData(size_t _size); + ~GpuData(); + + GpuData(const GpuData&) = delete; + GpuData& operator=(const GpuData&) = delete; + + GpuData(GpuData&&) = delete; + GpuData& operator=(GpuData&&) = delete; + + uchar* data; + size_t size; +}; + +class CV_EXPORTS_W GpuMatND +{ +public: + using SizeArray = std::vector; + using StepArray = std::vector; + using IndexArray = std::vector; + + //! destructor + ~GpuMatND(); + + //! default constructor + GpuMatND(); + + /** @overload + @param size Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_16FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + GpuMatND(SizeArray size, int type); + + /** @overload + @param size Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_16FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param step Array of _size.size()-1 steps in case of a multi-dimensional array (the last step is always + set to the element size). If not specified, the matrix is assumed to be continuous. + */ + GpuMatND(SizeArray size, int type, void* data, StepArray step = StepArray()); + + /** @brief Allocates GPU memory. + Suppose there is some GPU memory already allocated. In that case, this method may choose to reuse that + GPU memory under the specific condition: it must be of the same size and type, not externally allocated, + the GPU memory is continuous(i.e., isContinuous() is true), and is not a sub-matrix of another GpuMatND + (i.e., isSubmatrix() is false). In other words, this method guarantees that the GPU memory allocated by + this method is always continuous and is not a sub-region of another GpuMatND. + */ + void create(SizeArray size, int type); + + void release(); + + void swap(GpuMatND& m) noexcept; + + /** @brief Creates a full copy of the array and the underlying data. + The method creates a full copy of the array. It mimics the behavior of Mat::clone(), i.e. + the original step is not taken into account. So, the array copy is a continuous array + occupying total()\*elemSize() bytes. + */ + GpuMatND clone() const; + + /** @overload + This overload is non-blocking, so it may return even if the copy operation is not finished. + */ + GpuMatND clone(Stream& stream) const; + + /** @brief Extracts a sub-matrix. + The operator makes a new header for the specified sub-array of \*this. + The operator is an O(1) operation, that is, no matrix data is copied. + @param ranges Array of selected ranges along each dimension. + */ + GpuMatND operator()(const std::vector& ranges) const; + + /** @brief Creates a GpuMat header for a 2D plane part of an n-dim matrix. + @note The returned GpuMat is constructed with the constructor for user-allocated data. + That is, It does not perform reference counting. + @note This function does not increment this GpuMatND's reference counter. + */ + GpuMat createGpuMatHeader(IndexArray idx, Range rowRange, Range colRange) const; + + /** @overload + Creates a GpuMat header if this GpuMatND is effectively 2D. + @note The returned GpuMat is constructed with the constructor for user-allocated data. + That is, It does not perform reference counting. + @note This function does not increment this GpuMatND's reference counter. + */ + GpuMat createGpuMatHeader() const; + + /** @brief Extracts a 2D plane part of an n-dim matrix. + It differs from createGpuMatHeader(IndexArray, Range, Range) in that it clones a part of this + GpuMatND to the returned GpuMat. + @note This operator does not increment this GpuMatND's reference counter; + */ + GpuMat operator()(IndexArray idx, Range rowRange, Range colRange) const; + + /** @brief Extracts a 2D plane part of an n-dim matrix if this GpuMatND is effectively 2D. + It differs from createGpuMatHeader() in that it clones a part of this GpuMatND. + @note This operator does not increment this GpuMatND's reference counter; + */ + operator GpuMat() const; + + GpuMatND(const GpuMatND&) = default; + GpuMatND& operator=(const GpuMatND&) = default; + +#if defined(__GNUC__) && __GNUC__ < 5 + // error: function '...' defaulted on its first declaration with an exception-specification + // that differs from the implicit declaration '...' + + GpuMatND(GpuMatND&&) = default; + GpuMatND& operator=(GpuMatND&&) = default; +#else + GpuMatND(GpuMatND&&) noexcept = default; + GpuMatND& operator=(GpuMatND&&) noexcept = default; +#endif + + void upload(InputArray src); + void upload(InputArray src, Stream& stream); + void download(OutputArray dst) const; + void download(OutputArray dst, Stream& stream) const; + + //! returns true iff the GpuMatND data is continuous + //! (i.e. when there are no gaps between successive rows) + bool isContinuous() const; + + //! returns true if the matrix is a sub-matrix of another matrix + bool isSubmatrix() const; + + //! returns element size in bytes + size_t elemSize() const; + + //! returns the size of element channel in bytes + size_t elemSize1() const; + + //! returns true if data is null + bool empty() const; + + //! returns true if not empty and points to external(user-allocated) gpu memory + bool external() const; + + //! returns pointer to the first byte of the GPU memory + uchar* getDevicePtr() const; + + //! returns the total number of array elements + size_t total() const; + + //! returns the size of underlying memory in bytes + size_t totalMemSize() const; + + //! returns element type + int type() const; + +private: + //! internal use + void setFields(SizeArray size, int type, StepArray step = StepArray()); + +public: + /*! includes several bit-fields: + - the magic signature + - continuity flag + - depth + - number of channels + */ + int flags; + + //! matrix dimensionality + int dims; + + //! shape of this array + SizeArray size; + + /*! step values + Their semantics is identical to the semantics of step for Mat. + */ + StepArray step; + +private: + /*! internal use + If this GpuMatND holds external memory, this is empty. + */ + std::shared_ptr data_; + + /*! internal use + If this GpuMatND manages memory with reference counting, this value is + always equal to data_->data. If this GpuMatND holds external memory, + data_ is empty and data points to the external memory. + */ + uchar* data; + + /*! internal use + If this GpuMatND is a sub-matrix of a larger matrix, this value is the + difference of the first byte between the sub-matrix and the whole matrix. + */ + size_t offset; +}; + /** @brief Creates a continuous matrix. @param rows Row count. @@ -348,7 +554,7 @@ public: Matrix is called continuous if its elements are stored continuously, that is, without gaps at the end of each row. */ -CV_EXPORTS void createContinuous(int rows, int cols, int type, OutputArray arr); +CV_EXPORTS_W void createContinuous(int rows, int cols, int type, OutputArray arr); /** @brief Ensures that the size of a matrix is big enough and the matrix has a proper type. @@ -359,7 +565,7 @@ CV_EXPORTS void createContinuous(int rows, int cols, int type, OutputArray arr); The function does not reallocate memory if the matrix has proper attributes already. */ -CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr); +CV_EXPORTS_W void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr); /** @brief BufferPool for use with CUDA streams @@ -478,7 +684,7 @@ and the corresponding memory is automatically returned to the pool for later usa } @endcode */ -class CV_EXPORTS BufferPool +class CV_EXPORTS_W BufferPool { public: @@ -486,21 +692,21 @@ public: explicit BufferPool(Stream& stream); //! Allocates a new GpuMat of given size and type. - GpuMat getBuffer(int rows, int cols, int type); + CV_WRAP GpuMat getBuffer(int rows, int cols, int type); //! Allocates a new GpuMat of given size and type. - GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); } + CV_WRAP GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); } //! Returns the allocator associated with the stream. - Ptr getAllocator() const { return allocator_; } + CV_WRAP Ptr getAllocator() const { return allocator_; } private: Ptr allocator_; }; //! BufferPool management (must be called before Stream creation) -CV_EXPORTS void setBufferPoolUsage(bool on); -CV_EXPORTS void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount); +CV_EXPORTS_W void setBufferPoolUsage(bool on); +CV_EXPORTS_W void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount); //=================================================================================== // HostMem @@ -521,46 +727,46 @@ Its interface is also Mat-like but with additional memory type parameters. @note Allocation size of such memory types is usually limited. For more details, see *CUDA 2.2 Pinned Memory APIs* document or *CUDA C Programming Guide*. */ -class CV_EXPORTS HostMem +class CV_EXPORTS_W HostMem { public: enum AllocType { PAGE_LOCKED = 1, SHARED = 2, WRITE_COMBINED = 4 }; - static MatAllocator* getAllocator(AllocType alloc_type = PAGE_LOCKED); + static MatAllocator* getAllocator(HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); - explicit HostMem(AllocType alloc_type = PAGE_LOCKED); + CV_WRAP explicit HostMem(HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); HostMem(const HostMem& m); - HostMem(int rows, int cols, int type, AllocType alloc_type = PAGE_LOCKED); - HostMem(Size size, int type, AllocType alloc_type = PAGE_LOCKED); + CV_WRAP HostMem(int rows, int cols, int type, HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); + CV_WRAP HostMem(Size size, int type, HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); //! creates from host memory with coping data - explicit HostMem(InputArray arr, AllocType alloc_type = PAGE_LOCKED); + CV_WRAP explicit HostMem(InputArray arr, HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); ~HostMem(); HostMem& operator =(const HostMem& m); //! swaps with other smart pointer - void swap(HostMem& b); + CV_WRAP void swap(HostMem& b); //! returns deep copy of the matrix, i.e. the data is copied - HostMem clone() const; + CV_WRAP HostMem clone() const; //! allocates new matrix data unless the matrix already has specified size and type. - void create(int rows, int cols, int type); + CV_WRAP void create(int rows, int cols, int type); void create(Size size, int type); //! creates alternative HostMem header for the same data, with different //! number of channels and/or different number of rows - HostMem reshape(int cn, int rows = 0) const; + CV_WRAP HostMem reshape(int cn, int rows = 0) const; //! decrements reference counter and released memory if needed. void release(); //! returns matrix header with disabled reference counting for HostMem data. - Mat createMatHeader() const; + CV_WRAP Mat createMatHeader() const; /** @brief Maps CPU memory to GPU address space and creates the cuda::GpuMat header without reference counting for it. @@ -572,20 +778,20 @@ public: GpuMat createGpuMatHeader() const; // Please see cv::Mat for descriptions - bool isContinuous() const; - size_t elemSize() const; - size_t elemSize1() const; - int type() const; - int depth() const; - int channels() const; - size_t step1() const; - Size size() const; - bool empty() const; + CV_WRAP bool isContinuous() const; + CV_WRAP size_t elemSize() const; + CV_WRAP size_t elemSize1() const; + CV_WRAP int type() const; + CV_WRAP int depth() const; + CV_WRAP int channels() const; + CV_WRAP size_t step1() const; + CV_WRAP Size size() const; + CV_WRAP bool empty() const; // Please see cv::Mat for descriptions int flags; int rows, cols; - size_t step; + CV_PROP size_t step; uchar* data; int* refcount; @@ -600,13 +806,13 @@ public: @param m Input matrix. */ -CV_EXPORTS void registerPageLocked(Mat& m); +CV_EXPORTS_W void registerPageLocked(Mat& m); /** @brief Unmaps the memory of matrix and makes it pageable again. @param m Input matrix. */ -CV_EXPORTS void unregisterPageLocked(Mat& m); +CV_EXPORTS_W void unregisterPageLocked(Mat& m); //=================================================================================== // Stream @@ -639,7 +845,7 @@ void thread2() @note By default all CUDA routines are launched in Stream::Null() object, if the stream is not specified by user. In multi-threading environment the stream objects must be passed explicitly (see previous note). */ -class CV_EXPORTS Stream +class CV_EXPORTS_W Stream { typedef void (Stream::*bool_type)() const; void this_type_does_not_support_comparisons() const {} @@ -648,22 +854,34 @@ public: typedef void (*StreamCallback)(int status, void* userData); //! creates a new asynchronous stream - Stream(); + CV_WRAP Stream(); //! creates a new asynchronous stream with custom allocator - Stream(const Ptr& allocator); + CV_WRAP Stream(const Ptr& allocator); + + /** @brief creates a new Stream using the cudaFlags argument to determine the behaviors of the stream + + @note The cudaFlags parameter is passed to the underlying api cudaStreamCreateWithFlags() and + supports the same parameter values. + @code + // creates an OpenCV cuda::Stream that manages an asynchronous, non-blocking, + // non-default CUDA stream + cv::cuda::Stream cvStream(cudaStreamNonBlocking); + @endcode + */ + CV_WRAP Stream(const size_t cudaFlags); /** @brief Returns true if the current stream queue is finished. Otherwise, it returns false. */ - bool queryIfComplete() const; + CV_WRAP bool queryIfComplete() const; /** @brief Blocks the current CPU thread until all operations in the stream are complete. */ - void waitForCompletion(); + CV_WRAP void waitForCompletion(); /** @brief Makes a compute stream wait on an event. */ - void waitEvent(const Event& event); + CV_WRAP void waitEvent(const Event& event); /** @brief Adds a callback to be called on the host after all currently enqueued items in the stream have completed. @@ -676,11 +894,14 @@ public: void enqueueHostCallback(StreamCallback callback, void* userData); //! return Stream object for default CUDA stream - static Stream& Null(); + CV_WRAP static Stream& Null(); //! returns true if stream object is not default (!= 0) operator bool_type() const; + //! return Pointer to CUDA stream + CV_WRAP void* cudaPtr() const; + class Impl; private: @@ -692,7 +913,7 @@ private: friend class DefaultDeviceInitializer; }; -class CV_EXPORTS Event +class CV_EXPORTS_W Event { public: enum CreateFlags @@ -703,19 +924,19 @@ public: INTERPROCESS = 0x04 /**< Event is suitable for interprocess use. DisableTiming must be set */ }; - explicit Event(CreateFlags flags = DEFAULT); + CV_WRAP explicit Event(Event::CreateFlags flags = Event::CreateFlags::DEFAULT); //! records an event - void record(Stream& stream = Stream::Null()); + CV_WRAP void record(Stream& stream = Stream::Null()); //! queries an event's status - bool queryIfComplete() const; + CV_WRAP bool queryIfComplete() const; //! waits for an event to complete - void waitForCompletion(); + CV_WRAP void waitForCompletion(); //! computes the elapsed time between events - static float elapsedTime(const Event& start, const Event& end); + CV_WRAP static float elapsedTime(const Event& start, const Event& end); class Impl; @@ -741,7 +962,7 @@ Use this function before any other CUDA functions calls. If OpenCV is compiled w this function returns 0. If the CUDA driver is not installed, or is incompatible, this function returns -1. */ -CV_EXPORTS int getCudaEnabledDeviceCount(); +CV_EXPORTS_W int getCudaEnabledDeviceCount(); /** @brief Sets a device and initializes it for the current thread. @@ -749,18 +970,18 @@ CV_EXPORTS int getCudaEnabledDeviceCount(); If the call of this function is omitted, a default device is initialized at the fist CUDA usage. */ -CV_EXPORTS void setDevice(int device); +CV_EXPORTS_W void setDevice(int device); /** @brief Returns the current device index set by cuda::setDevice or initialized by default. */ -CV_EXPORTS int getDevice(); +CV_EXPORTS_W int getDevice(); /** @brief Explicitly destroys and cleans up all resources associated with the current device in the current process. Any subsequent API call to this device will reinitialize the device. */ -CV_EXPORTS void resetDevice(); +CV_EXPORTS_W void resetDevice(); /** @brief Enumeration providing CUDA computing features. */ @@ -793,7 +1014,7 @@ built for. According to the CUDA C Programming Guide Version 3.2: "PTX code produced for some specific compute capability can always be compiled to binary code of greater or equal compute capability". */ -class CV_EXPORTS TargetArchs +class CV_EXPORTS_W TargetArchs { public: /** @brief The following method checks whether the module was built with the support of the given feature: @@ -808,23 +1029,23 @@ public: @param major Major compute capability version. @param minor Minor compute capability version. */ - static bool has(int major, int minor); - static bool hasPtx(int major, int minor); - static bool hasBin(int major, int minor); + CV_WRAP static bool has(int major, int minor); + CV_WRAP static bool hasPtx(int major, int minor); + CV_WRAP static bool hasBin(int major, int minor); - static bool hasEqualOrLessPtx(int major, int minor); - static bool hasEqualOrGreater(int major, int minor); - static bool hasEqualOrGreaterPtx(int major, int minor); - static bool hasEqualOrGreaterBin(int major, int minor); + CV_WRAP static bool hasEqualOrLessPtx(int major, int minor); + CV_WRAP static bool hasEqualOrGreater(int major, int minor); + CV_WRAP static bool hasEqualOrGreaterPtx(int major, int minor); + CV_WRAP static bool hasEqualOrGreaterBin(int major, int minor); }; /** @brief Class providing functionality for querying the specified GPU properties. */ -class CV_EXPORTS DeviceInfo +class CV_EXPORTS_W DeviceInfo { public: //! creates DeviceInfo object for the current GPU - DeviceInfo(); + CV_WRAP DeviceInfo(); /** @brief The constructors. @@ -833,68 +1054,68 @@ public: Constructs the DeviceInfo object for the specified device. If device_id parameter is missed, it constructs an object for the current device. */ - DeviceInfo(int device_id); + CV_WRAP DeviceInfo(int device_id); /** @brief Returns system index of the CUDA device starting with 0. */ - int deviceID() const; + CV_WRAP int deviceID() const; //! ASCII string identifying device const char* name() const; //! global memory available on device in bytes - size_t totalGlobalMem() const; + CV_WRAP size_t totalGlobalMem() const; //! shared memory available per block in bytes - size_t sharedMemPerBlock() const; + CV_WRAP size_t sharedMemPerBlock() const; //! 32-bit registers available per block - int regsPerBlock() const; + CV_WRAP int regsPerBlock() const; //! warp size in threads - int warpSize() const; + CV_WRAP int warpSize() const; //! maximum pitch in bytes allowed by memory copies - size_t memPitch() const; + CV_WRAP size_t memPitch() const; //! maximum number of threads per block - int maxThreadsPerBlock() const; + CV_WRAP int maxThreadsPerBlock() const; //! maximum size of each dimension of a block - Vec3i maxThreadsDim() const; + CV_WRAP Vec3i maxThreadsDim() const; //! maximum size of each dimension of a grid - Vec3i maxGridSize() const; + CV_WRAP Vec3i maxGridSize() const; //! clock frequency in kilohertz - int clockRate() const; + CV_WRAP int clockRate() const; //! constant memory available on device in bytes - size_t totalConstMem() const; + CV_WRAP size_t totalConstMem() const; //! major compute capability - int majorVersion() const; + CV_WRAP int majorVersion() const; //! minor compute capability - int minorVersion() const; + CV_WRAP int minorVersion() const; //! alignment requirement for textures - size_t textureAlignment() const; + CV_WRAP size_t textureAlignment() const; //! pitch alignment requirement for texture references bound to pitched memory - size_t texturePitchAlignment() const; + CV_WRAP size_t texturePitchAlignment() const; //! number of multiprocessors on device - int multiProcessorCount() const; + CV_WRAP int multiProcessorCount() const; //! specified whether there is a run time limit on kernels - bool kernelExecTimeoutEnabled() const; + CV_WRAP bool kernelExecTimeoutEnabled() const; //! device is integrated as opposed to discrete - bool integrated() const; + CV_WRAP bool integrated() const; //! device can map host memory with cudaHostAlloc/cudaHostGetDevicePointer - bool canMapHostMemory() const; + CV_WRAP bool canMapHostMemory() const; enum ComputeMode { @@ -905,108 +1126,108 @@ public: }; //! compute mode - ComputeMode computeMode() const; + CV_WRAP DeviceInfo::ComputeMode computeMode() const; //! maximum 1D texture size - int maxTexture1D() const; + CV_WRAP int maxTexture1D() const; //! maximum 1D mipmapped texture size - int maxTexture1DMipmap() const; + CV_WRAP int maxTexture1DMipmap() const; //! maximum size for 1D textures bound to linear memory - int maxTexture1DLinear() const; + CV_WRAP int maxTexture1DLinear() const; //! maximum 2D texture dimensions - Vec2i maxTexture2D() const; + CV_WRAP Vec2i maxTexture2D() const; //! maximum 2D mipmapped texture dimensions - Vec2i maxTexture2DMipmap() const; + CV_WRAP Vec2i maxTexture2DMipmap() const; //! maximum dimensions (width, height, pitch) for 2D textures bound to pitched memory - Vec3i maxTexture2DLinear() const; + CV_WRAP Vec3i maxTexture2DLinear() const; //! maximum 2D texture dimensions if texture gather operations have to be performed - Vec2i maxTexture2DGather() const; + CV_WRAP Vec2i maxTexture2DGather() const; //! maximum 3D texture dimensions - Vec3i maxTexture3D() const; + CV_WRAP Vec3i maxTexture3D() const; //! maximum Cubemap texture dimensions - int maxTextureCubemap() const; + CV_WRAP int maxTextureCubemap() const; //! maximum 1D layered texture dimensions - Vec2i maxTexture1DLayered() const; + CV_WRAP Vec2i maxTexture1DLayered() const; //! maximum 2D layered texture dimensions - Vec3i maxTexture2DLayered() const; + CV_WRAP Vec3i maxTexture2DLayered() const; //! maximum Cubemap layered texture dimensions - Vec2i maxTextureCubemapLayered() const; + CV_WRAP Vec2i maxTextureCubemapLayered() const; //! maximum 1D surface size - int maxSurface1D() const; + CV_WRAP int maxSurface1D() const; //! maximum 2D surface dimensions - Vec2i maxSurface2D() const; + CV_WRAP Vec2i maxSurface2D() const; //! maximum 3D surface dimensions - Vec3i maxSurface3D() const; + CV_WRAP Vec3i maxSurface3D() const; //! maximum 1D layered surface dimensions - Vec2i maxSurface1DLayered() const; + CV_WRAP Vec2i maxSurface1DLayered() const; //! maximum 2D layered surface dimensions - Vec3i maxSurface2DLayered() const; + CV_WRAP Vec3i maxSurface2DLayered() const; //! maximum Cubemap surface dimensions - int maxSurfaceCubemap() const; + CV_WRAP int maxSurfaceCubemap() const; //! maximum Cubemap layered surface dimensions - Vec2i maxSurfaceCubemapLayered() const; + CV_WRAP Vec2i maxSurfaceCubemapLayered() const; //! alignment requirements for surfaces - size_t surfaceAlignment() const; + CV_WRAP size_t surfaceAlignment() const; //! device can possibly execute multiple kernels concurrently - bool concurrentKernels() const; + CV_WRAP bool concurrentKernels() const; //! device has ECC support enabled - bool ECCEnabled() const; + CV_WRAP bool ECCEnabled() const; //! PCI bus ID of the device - int pciBusID() const; + CV_WRAP int pciBusID() const; //! PCI device ID of the device - int pciDeviceID() const; + CV_WRAP int pciDeviceID() const; //! PCI domain ID of the device - int pciDomainID() const; + CV_WRAP int pciDomainID() const; //! true if device is a Tesla device using TCC driver, false otherwise - bool tccDriver() const; + CV_WRAP bool tccDriver() const; //! number of asynchronous engines - int asyncEngineCount() const; + CV_WRAP int asyncEngineCount() const; //! device shares a unified address space with the host - bool unifiedAddressing() const; + CV_WRAP bool unifiedAddressing() const; //! peak memory clock frequency in kilohertz - int memoryClockRate() const; + CV_WRAP int memoryClockRate() const; //! global memory bus width in bits - int memoryBusWidth() const; + CV_WRAP int memoryBusWidth() const; //! size of L2 cache in bytes - int l2CacheSize() const; + CV_WRAP int l2CacheSize() const; //! maximum resident threads per multiprocessor - int maxThreadsPerMultiProcessor() const; + CV_WRAP int maxThreadsPerMultiProcessor() const; //! gets free and total device memory - void queryMemory(size_t& totalMemory, size_t& freeMemory) const; - size_t freeMemory() const; - size_t totalMemory() const; + CV_WRAP void queryMemory(size_t& totalMemory, size_t& freeMemory) const; + CV_WRAP size_t freeMemory() const; + CV_WRAP size_t totalMemory() const; /** @brief Provides information on CUDA feature support. @@ -1021,14 +1242,14 @@ public: This function returns true if the CUDA module can be run on the specified device. Otherwise, it returns false . */ - bool isCompatible() const; + CV_WRAP bool isCompatible() const; private: int device_id_; }; -CV_EXPORTS void printCudaDeviceInfo(int device); -CV_EXPORTS void printShortCudaDeviceInfo(int device); +CV_EXPORTS_W void printCudaDeviceInfo(int device); +CV_EXPORTS_W void printShortCudaDeviceInfo(int device); /** @brief Converts an array to half precision floating number. diff --git a/3rdparty/include/opencv2/core/cuda.inl.hpp b/3rdparty/include/opencv2/core/cuda.inl.hpp index 35ae2e49d7..3f2a0c7240 100644 --- a/3rdparty/include/opencv2/core/cuda.inl.hpp +++ b/3rdparty/include/opencv2/core/cuda.inl.hpp @@ -343,6 +343,12 @@ bool GpuMat::empty() const return data == 0; } +inline +void* GpuMat::cudaPtr() const +{ + return data; +} + static inline GpuMat createContinuous(int rows, int cols, int type) { @@ -377,6 +383,92 @@ void swap(GpuMat& a, GpuMat& b) a.swap(b); } +//=================================================================================== +// GpuMatND +//=================================================================================== + +inline +GpuMatND::GpuMatND() : + flags(0), dims(0), data(nullptr), offset(0) +{ +} + +inline +GpuMatND::GpuMatND(SizeArray _size, int _type) : + flags(0), dims(0), data(nullptr), offset(0) +{ + create(std::move(_size), _type); +} + +inline +void GpuMatND::swap(GpuMatND& m) noexcept +{ + std::swap(*this, m); +} + +inline +bool GpuMatND::isContinuous() const +{ + return (flags & Mat::CONTINUOUS_FLAG) != 0; +} + +inline +bool GpuMatND::isSubmatrix() const +{ + return (flags & Mat::SUBMATRIX_FLAG) != 0; +} + +inline +size_t GpuMatND::elemSize() const +{ + return CV_ELEM_SIZE(flags); +} + +inline +size_t GpuMatND::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +bool GpuMatND::empty() const +{ + return data == nullptr; +} + +inline +bool GpuMatND::external() const +{ + return !empty() && data_.use_count() == 0; +} + +inline +uchar* GpuMatND::getDevicePtr() const +{ + return data + offset; +} + +inline +size_t GpuMatND::total() const +{ + size_t p = 1; + for(auto s : size) + p *= s; + return p; +} + +inline +size_t GpuMatND::totalMemSize() const +{ + return size[0] * step[0]; +} + +inline +int GpuMatND::type() const +{ + return CV_MAT_TYPE(flags); +} + //=================================================================================== // HostMem //=================================================================================== diff --git a/3rdparty/include/opencv2/core/cuda/detail/color_detail.hpp b/3rdparty/include/opencv2/core/cuda/detail/color_detail.hpp index bfb40550dc..f4b4796571 100644 --- a/3rdparty/include/opencv2/core/cuda/detail/color_detail.hpp +++ b/3rdparty/include/opencv2/core/cuda/detail/color_detail.hpp @@ -92,13 +92,51 @@ namespace cv { namespace cuda { namespace device return vec.w; } + //constants for conversion from/to RGB and Gray, YUV, YCrCb according to BT.601 + constexpr float B2YF = 0.114f; + constexpr float G2YF = 0.587f; + constexpr float R2YF = 0.299f; + + //to YCbCr + constexpr float YCBF = 0.564f; // == 1/2/(1-B2YF) + constexpr float YCRF = 0.713f; // == 1/2/(1-R2YF) + const int YCBI = 9241; // == YCBF*16384 + const int YCRI = 11682; // == YCRF*16384 + //to YUV + constexpr float B2UF = 0.492f; + constexpr float R2VF = 0.877f; + const int B2UI = 8061; // == B2UF*16384 + const int R2VI = 14369; // == R2VF*16384 + //from YUV + constexpr float U2BF = 2.032f; + constexpr float U2GF = -0.395f; + constexpr float V2GF = -0.581f; + constexpr float V2RF = 1.140f; + const int U2BI = 33292; + const int U2GI = -6472; + const int V2GI = -9519; + const int V2RI = 18678; + //from YCrCb + constexpr float CB2BF = 1.773f; + constexpr float CB2GF = -0.344f; + constexpr float CR2GF = -0.714f; + constexpr float CR2RF = 1.403f; + const int CB2BI = 29049; + const int CB2GI = -5636; + const int CR2GI = -11698; + const int CR2RI = 22987; + enum { yuv_shift = 14, xyz_shift = 12, + gray_shift = 15, R2Y = 4899, G2Y = 9617, B2Y = 1868, + RY15 = 9798, // == R2YF*32768 + 0.5 + GY15 = 19235, // == G2YF*32768 + 0.5 + BY15 = 3735, // == B2YF*32768 + 0.5 BLOCK_SIZE = 256 }; } @@ -406,7 +444,7 @@ namespace cv { namespace cuda { namespace device { static __device__ __forceinline__ uchar cvt(uint t) { - return (uchar)CV_DESCALE(((t << 3) & 0xf8) * B2Y + ((t >> 3) & 0xfc) * G2Y + ((t >> 8) & 0xf8) * R2Y, yuv_shift); + return (uchar)CV_DESCALE(((t << 3) & 0xf8) * BY15 + ((t >> 3) & 0xfc) * GY15 + ((t >> 8) & 0xf8) * RY15, gray_shift); } }; @@ -414,7 +452,7 @@ namespace cv { namespace cuda { namespace device { static __device__ __forceinline__ uchar cvt(uint t) { - return (uchar)CV_DESCALE(((t << 3) & 0xf8) * B2Y + ((t >> 2) & 0xf8) * G2Y + ((t >> 7) & 0xf8) * R2Y, yuv_shift); + return (uchar)CV_DESCALE(((t << 3) & 0xf8) * BY15 + ((t >> 2) & 0xf8) * GY15 + ((t >> 7) & 0xf8) * RY15, gray_shift); } }; @@ -443,7 +481,7 @@ namespace cv { namespace cuda { namespace device { template static __device__ __forceinline__ T RGB2GrayConvert(const T* src) { - return (T)CV_DESCALE((unsigned)(src[bidx] * B2Y + src[1] * G2Y + src[bidx^2] * R2Y), yuv_shift); + return (T)CV_DESCALE((unsigned)(src[bidx] * BY15 + src[1] * GY15 + src[bidx^2] * RY15), gray_shift); } template static __device__ __forceinline__ uchar RGB2GrayConvert(uint src) @@ -451,12 +489,12 @@ namespace cv { namespace cuda { namespace device uint b = 0xffu & (src >> (bidx * 8)); uint g = 0xffu & (src >> 8); uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); - return CV_DESCALE((uint)(b * B2Y + g * G2Y + r * R2Y), yuv_shift); + return CV_DESCALE((uint)(b * BY15 + g * GY15 + r * RY15), gray_shift); } template static __device__ __forceinline__ float RGB2GrayConvert(const float* src) { - return src[bidx] * 0.114f + src[1] * 0.587f + src[bidx^2] * 0.299f; + return src[bidx] * B2YF + src[1] * G2YF + src[bidx^2] * R2YF; } template struct RGB2Gray : unary_function::vec_type, T> @@ -494,8 +532,8 @@ namespace cv { namespace cuda { namespace device namespace color_detail { - __constant__ float c_RGB2YUVCoeffs_f[5] = { 0.114f, 0.587f, 0.299f, 0.492f, 0.877f }; - __constant__ int c_RGB2YUVCoeffs_i[5] = { B2Y, G2Y, R2Y, 8061, 14369 }; + __constant__ float c_RGB2YUVCoeffs_f[5] = { B2YF, G2YF, R2YF, B2UF, R2VF }; + __constant__ int c_RGB2YUVCoeffs_i[5] = { B2Y, G2Y, R2Y, B2UI, R2VI }; template static __device__ void RGB2YUVConvert(const T* src, D& dst) { @@ -543,8 +581,8 @@ namespace cv { namespace cuda { namespace device namespace color_detail { - __constant__ float c_YUV2RGBCoeffs_f[5] = { 2.032f, -0.395f, -0.581f, 1.140f }; - __constant__ int c_YUV2RGBCoeffs_i[5] = { 33292, -6472, -9519, 18678 }; + __constant__ float c_YUV2RGBCoeffs_f[5] = { U2BF, U2GF, V2GF, V2RF }; + __constant__ int c_YUV2RGBCoeffs_i[5] = { U2BI, U2GI, V2GI, V2RI }; template static __device__ void YUV2RGBConvert(const T& src, D* dst) { @@ -633,8 +671,8 @@ namespace cv { namespace cuda { namespace device namespace color_detail { - __constant__ float c_RGB2YCrCbCoeffs_f[5] = {0.299f, 0.587f, 0.114f, 0.713f, 0.564f}; - __constant__ int c_RGB2YCrCbCoeffs_i[5] = {R2Y, G2Y, B2Y, 11682, 9241}; + __constant__ float c_RGB2YCrCbCoeffs_f[5] = {R2YF, G2YF, B2YF, YCRF, YCBF}; + __constant__ int c_RGB2YCrCbCoeffs_i[5] = {R2Y, G2Y, B2Y, YCRI, YCBI}; template static __device__ void RGB2YCrCbConvert(const T* src, D& dst) { @@ -710,8 +748,8 @@ namespace cv { namespace cuda { namespace device namespace color_detail { - __constant__ float c_YCrCb2RGBCoeffs_f[5] = {1.403f, -0.714f, -0.344f, 1.773f}; - __constant__ int c_YCrCb2RGBCoeffs_i[5] = {22987, -11698, -5636, 29049}; + __constant__ float c_YCrCb2RGBCoeffs_f[5] = {CR2RF, CR2GF, CB2GF, CB2BF}; + __constant__ int c_YCrCb2RGBCoeffs_i[5] = {CR2RI, CR2GI, CB2GI, CB2BI}; template static __device__ void YCrCb2RGBConvert(const T& src, D* dst) { diff --git a/3rdparty/include/opencv2/core/cuda/functional.hpp b/3rdparty/include/opencv2/core/cuda/functional.hpp index 3b531a13ed..9f53d87527 100644 --- a/3rdparty/include/opencv2/core/cuda/functional.hpp +++ b/3rdparty/include/opencv2/core/cuda/functional.hpp @@ -57,7 +57,6 @@ namespace cv { namespace cuda { namespace device { // Function Objects -#ifdef CV_CXX11 template struct unary_function { typedef Argument argument_type; @@ -69,10 +68,6 @@ namespace cv { namespace cuda { namespace device typedef Argument2 second_argument_type; typedef Result result_type; }; -#else - template struct unary_function : public std::unary_function {}; - template struct binary_function : public std::binary_function {}; -#endif // Arithmetic Operations template struct plus : binary_function diff --git a/3rdparty/include/opencv2/core/cuda/vec_math.hpp b/3rdparty/include/opencv2/core/cuda/vec_math.hpp index 9085b92397..80b1303681 100644 --- a/3rdparty/include/opencv2/core/cuda/vec_math.hpp +++ b/3rdparty/include/opencv2/core/cuda/vec_math.hpp @@ -199,14 +199,7 @@ CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, uint, uint) return VecTraits::make(func (a.x), func (a.y), func (a.z), func (a.w)); \ } -CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, /*::abs*/, uchar, uchar) -CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::abs, char, char) -CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, /*::abs*/, ushort, ushort) -CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::abs, short, short) -CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::abs, int, int) -CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, /*::abs*/, uint, uint) CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::fabsf, float, float) -CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::fabs, double, double) CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, uchar, float) CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, char, float) diff --git a/3rdparty/include/opencv2/core/cv_cpu_dispatch.h b/3rdparty/include/opencv2/core/cv_cpu_dispatch.h index 540fbb605c..8365b10ba9 100644 --- a/3rdparty/include/opencv2/core/cv_cpu_dispatch.h +++ b/3rdparty/include/opencv2/core/cv_cpu_dispatch.h @@ -142,6 +142,11 @@ # define CV_NEON 1 #endif +#if defined(__riscv) && defined(__riscv_vector) && defined(__riscv_vector_071) +# include +# define CV_RVV071 1 +#endif + #if defined(__ARM_NEON__) || defined(__aarch64__) # include #endif @@ -168,6 +173,11 @@ # include #endif +#if defined CV_CPU_COMPILE_RVV +# define CV_RVV 1 +# include +#endif + #endif // CV_ENABLE_INTRINSICS && !CV_DISABLE_OPTIMIZATION && !__CUDACC__ #if defined CV_CPU_COMPILE_AVX && !defined CV_CPU_BASELINE_COMPILE_AVX @@ -333,6 +343,10 @@ struct VZeroUpperGuard { # define CV_NEON 0 #endif +#ifndef CV_RVV071 +# define CV_RVV071 0 +#endif + #ifndef CV_VSX # define CV_VSX 0 #endif @@ -348,3 +362,7 @@ struct VZeroUpperGuard { #ifndef CV_WASM_SIMD # define CV_WASM_SIMD 0 #endif + +#ifndef CV_RVV +# define CV_RVV 0 +#endif diff --git a/3rdparty/include/opencv2/core/cv_cpu_helper.h b/3rdparty/include/opencv2/core/cv_cpu_helper.h index aaa89ed415..39ae0b91f7 100644 --- a/3rdparty/include/opencv2/core/cv_cpu_helper.h +++ b/3rdparty/include/opencv2/core/cv_cpu_helper.h @@ -483,5 +483,26 @@ #endif #define __CV_CPU_DISPATCH_CHAIN_VSX3(fn, args, mode, ...) CV_CPU_CALL_VSX3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_RVV +# define CV_TRY_RVV 1 +# define CV_CPU_FORCE_RVV 1 +# define CV_CPU_HAS_SUPPORT_RVV 1 +# define CV_CPU_CALL_RVV(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_RVV_(fn, args) return (opt_RVV::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_RVV +# define CV_TRY_RVV 1 +# define CV_CPU_FORCE_RVV 0 +# define CV_CPU_HAS_SUPPORT_RVV (cv::checkHardwareSupport(CV_CPU_RVV)) +# define CV_CPU_CALL_RVV(fn, args) if (CV_CPU_HAS_SUPPORT_RVV) return (opt_RVV::fn args) +# define CV_CPU_CALL_RVV_(fn, args) if (CV_CPU_HAS_SUPPORT_RVV) return (opt_RVV::fn args) +#else +# define CV_TRY_RVV 0 +# define CV_CPU_FORCE_RVV 0 +# define CV_CPU_HAS_SUPPORT_RVV 0 +# define CV_CPU_CALL_RVV(fn, args) +# define CV_CPU_CALL_RVV_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_RVV(fn, args, mode, ...) CV_CPU_CALL_RVV(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + #define CV_CPU_CALL_BASELINE(fn, args) return (cpu_baseline::fn args) #define __CV_CPU_DISPATCH_CHAIN_BASELINE(fn, args, mode, ...) CV_CPU_CALL_BASELINE(fn, args) /* last in sequence */ diff --git a/3rdparty/include/opencv2/core/cvdef.h b/3rdparty/include/opencv2/core/cvdef.h index 6488b8bd4f..7f510748af 100644 --- a/3rdparty/include/opencv2/core/cvdef.h +++ b/3rdparty/include/opencv2/core/cvdef.h @@ -45,6 +45,8 @@ #ifndef OPENCV_CORE_CVDEF_H #define OPENCV_CORE_CVDEF_H +#include "opencv2/core/version.hpp" + //! @addtogroup core_utils //! @{ @@ -84,7 +86,7 @@ namespace cv { namespace debug_build_guard { } using namespace debug_build_guard #endif #define __CV_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N -#define __CV_VA_NUM_ARGS(...) __CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) +#define __CV_VA_NUM_ARGS(...) __CV_EXPAND(__CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) #ifdef CV_Func // keep current value (through OpenCV port file) @@ -170,20 +172,6 @@ namespace cv { #define CV_UNUSED(name) (void)name -#if defined __GNUC__ && !defined __EXCEPTIONS -#define CV_TRY -#define CV_CATCH(A, B) for (A B; false; ) -#define CV_CATCH_ALL if (false) -#define CV_THROW(A) abort() -#define CV_RETHROW() abort() -#else -#define CV_TRY try -#define CV_CATCH(A, B) catch(const A & B) -#define CV_CATCH_ALL catch(...) -#define CV_THROW(A) throw A -#define CV_RETHROW() throw -#endif - //! @endcond // undef problematic defines sometimes defined by system headers (windows.h in particular) @@ -283,9 +271,13 @@ namespace cv { #define CV_CPU_MSA 150 +#define CV_CPU_RISCVV 170 + #define CV_CPU_VSX 200 #define CV_CPU_VSX3 201 +#define CV_CPU_RVV 210 + // CPU features groups #define CV_CPU_AVX512_SKX 256 #define CV_CPU_AVX512_COMMON 257 @@ -335,9 +327,13 @@ enum CpuFeatures { CPU_MSA = 150, + CPU_RISCVV = 170, + CPU_VSX = 200, CPU_VSX3 = 201, + CPU_RVV = 210, + CPU_AVX512_SKX = 256, //!< Skylake-X with AVX-512F/CD/BW/DQ/VL CPU_AVX512_COMMON = 257, //!< Common instructions AVX-512F/CD for all CPUs that support AVX-512 CPU_AVX512_KNL = 258, //!< Knights Landing with AVX-512F/CD/ER/PF @@ -398,10 +394,12 @@ typedef union Cv64suf } Cv64suf; -#define OPENCV_ABI_COMPATIBILITY 300 +#ifndef OPENCV_ABI_COMPATIBILITY +#define OPENCV_ABI_COMPATIBILITY 400 +#endif #ifdef __OPENCV_BUILD -# define DISABLE_OPENCV_24_COMPATIBILITY +# define DISABLE_OPENCV_3_COMPATIBILITY # define OPENCV_DISABLE_DEPRECATED_COMPATIBILITY #endif @@ -461,6 +459,9 @@ Cv64suf; #define CV_PROP_RW #define CV_WRAP #define CV_WRAP_AS(synonym) +#define CV_WRAP_MAPPABLE(mappable) +#define CV_WRAP_PHANTOM(phantom_header) +#define CV_WRAP_DEFAULT(val) /****************************************************************************************\ * Matrix type (Mat) * @@ -479,13 +480,10 @@ Cv64suf; #define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG) /** Size of each channel item, - 0x8442211 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ -#define CV_ELEM_SIZE1(type) \ - ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15) + 0x28442211 = 0010 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ +#define CV_ELEM_SIZE1(type) ((0x28442211 >> CV_MAT_DEPTH(type)*4) & 15) -/** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */ -#define CV_ELEM_SIZE(type) \ - (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3)) +#define CV_ELEM_SIZE(type) (CV_MAT_CN(type)*CV_ELEM_SIZE1(type)) #ifndef MIN # define MIN(a,b) ((a) > (b) ? (b) : (a)) @@ -495,6 +493,142 @@ Cv64suf; # define MAX(a,b) ((a) < (b) ? (b) : (a)) #endif +///////////////////////////////////////// Enum operators /////////////////////////////////////// + +/** + +Provides compatibility operators for both classical and C++11 enum classes, +as well as exposing the C++11 enum class members for backwards compatibility + +@code + // Provides operators required for flag enums + CV_ENUM_FLAGS(AccessFlag) + + // Exposes the listed members of the enum class AccessFlag to the current namespace + CV_ENUM_CLASS_EXPOSE(AccessFlag, ACCESS_READ [, ACCESS_WRITE [, ...] ]); +@endcode +*/ + +#define __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST) \ +static const EnumType MEMBER_CONST = EnumType::MEMBER_CONST; \ + +#define __CV_ENUM_CLASS_EXPOSE_2(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_1(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_3(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_2(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_4(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_3(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_5(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_4(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_6(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_5(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_7(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_6(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_8(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_7(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_9(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_8(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_FLAGS_LOGICAL_NOT(EnumType) \ +static inline bool operator!(const EnumType& val) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return !static_cast(val); \ +} \ + +#define __CV_ENUM_FLAGS_LOGICAL_NOT_EQ(Arg1Type, Arg2Type) \ +static inline bool operator!=(const Arg1Type& a, const Arg2Type& b) \ +{ \ + return static_cast(a) != static_cast(b); \ +} \ + +#define __CV_ENUM_FLAGS_LOGICAL_EQ(Arg1Type, Arg2Type) \ +static inline bool operator==(const Arg1Type& a, const Arg2Type& b) \ +{ \ + return static_cast(a) == static_cast(b); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_NOT(EnumType) \ +static inline EnumType operator~(const EnumType& val) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(~static_cast(val)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_OR(EnumType, Arg1Type, Arg2Type) \ +static inline EnumType operator|(const Arg1Type& a, const Arg2Type& b) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(static_cast(a) | static_cast(b)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_AND(EnumType, Arg1Type, Arg2Type) \ +static inline EnumType operator&(const Arg1Type& a, const Arg2Type& b) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(static_cast(a) & static_cast(b)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_XOR(EnumType, Arg1Type, Arg2Type) \ +static inline EnumType operator^(const Arg1Type& a, const Arg2Type& b) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(static_cast(a) ^ static_cast(b)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_OR_EQ(EnumType, Arg1Type) \ +static inline EnumType& operator|=(EnumType& _this, const Arg1Type& val) \ +{ \ + _this = static_cast(static_cast(_this) | static_cast(val)); \ + return _this; \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_AND_EQ(EnumType, Arg1Type) \ +static inline EnumType& operator&=(EnumType& _this, const Arg1Type& val) \ +{ \ + _this = static_cast(static_cast(_this) & static_cast(val)); \ + return _this; \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_XOR_EQ(EnumType, Arg1Type) \ +static inline EnumType& operator^=(EnumType& _this, const Arg1Type& val) \ +{ \ + _this = static_cast(static_cast(_this) ^ static_cast(val)); \ + return _this; \ +} \ + +#define CV_ENUM_CLASS_EXPOSE(EnumType, ...) \ +__CV_EXPAND(__CV_CAT(__CV_ENUM_CLASS_EXPOSE_, __CV_VA_NUM_ARGS(__VA_ARGS__))(EnumType, __VA_ARGS__)); \ + +#define CV_ENUM_FLAGS(EnumType) \ +__CV_ENUM_FLAGS_LOGICAL_NOT (EnumType) \ +__CV_ENUM_FLAGS_LOGICAL_EQ (EnumType, int) \ +__CV_ENUM_FLAGS_LOGICAL_NOT_EQ (EnumType, int) \ + \ +__CV_ENUM_FLAGS_BITWISE_NOT (EnumType) \ +__CV_ENUM_FLAGS_BITWISE_OR (EnumType, EnumType, EnumType) \ +__CV_ENUM_FLAGS_BITWISE_AND (EnumType, EnumType, EnumType) \ +__CV_ENUM_FLAGS_BITWISE_XOR (EnumType, EnumType, EnumType) \ + \ +__CV_ENUM_FLAGS_BITWISE_OR_EQ (EnumType, EnumType) \ +__CV_ENUM_FLAGS_BITWISE_AND_EQ (EnumType, EnumType) \ +__CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType) \ + /****************************************************************************************\ * static analysys * \****************************************************************************************/ @@ -550,7 +684,7 @@ Cv64suf; # define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta) #else #ifdef OPENCV_FORCE_UNSAFE_XADD - CV_INLINE CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; } + CV_INLINE int CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; } #else #error "OpenCV: can't define safe CV_XADD macro for current platform (unsupported). Define CV_XADD macro through custom port header (see OPENCV_INCLUDE_PORT_FILE)" #endif @@ -602,75 +736,21 @@ Cv64suf; # undef CV_CXX11 # endif #endif - - -/****************************************************************************************\ -* C++ Move semantics * -\****************************************************************************************/ - -#ifndef CV_CXX_MOVE_SEMANTICS -# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && _MSC_VER >= 1600) -# define CV_CXX_MOVE_SEMANTICS 1 -# elif defined(__clang) -# if __has_feature(cxx_rvalue_references) -# define CV_CXX_MOVE_SEMANTICS 1 -# endif -# endif -#else -# if CV_CXX_MOVE_SEMANTICS == 0 -# undef CV_CXX_MOVE_SEMANTICS -# endif +#ifndef CV_CXX11 +# error "OpenCV 4.x+ requires enabled C++11 support" #endif -#ifdef CV_CXX_MOVE_SEMANTICS +#define CV_CXX_MOVE_SEMANTICS 1 #define CV_CXX_MOVE(x) std::move(x) -#else -#define CV_CXX_MOVE(x) (x) -#endif - - -/****************************************************************************************\ -* C++11 std::array * -\****************************************************************************************/ - -#ifndef CV_CXX_STD_ARRAY -# if __cplusplus >= 201103L || (defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) -# define CV_CXX_STD_ARRAY 1 -# include -# endif -#else -# if CV_CXX_STD_ARRAY == 0 -# undef CV_CXX_STD_ARRAY -# endif -#endif - - -/****************************************************************************************\ -* C++11 override / final * -\****************************************************************************************/ - +#define CV_CXX_STD_ARRAY 1 +#include #ifndef CV_OVERRIDE -# ifdef CV_CXX11 -# define CV_OVERRIDE override -# endif -#endif -#ifndef CV_OVERRIDE -# define CV_OVERRIDE -#endif - -#ifndef CV_FINAL -# ifdef CV_CXX11 -# define CV_FINAL final -# endif +# define CV_OVERRIDE override #endif #ifndef CV_FINAL -# define CV_FINAL +# define CV_FINAL final #endif -/****************************************************************************************\ -* C++11 noexcept * -\****************************************************************************************/ - #ifndef CV_NOEXCEPT # if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) # define CV_NOEXCEPT noexcept @@ -680,7 +760,14 @@ Cv64suf; # define CV_NOEXCEPT #endif - +#ifndef CV_CONSTEXPR +# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) +# define CV_CONSTEXPR constexpr +# endif +#endif +#ifndef CV_CONSTEXPR +# define CV_CONSTEXPR +#endif // Integer types portatibility #ifdef OPENCV_STDINT_HEADER @@ -735,7 +822,7 @@ class float16_t public: #if CV_FP16_TYPE - float16_t() {} + float16_t() : h(0) {} explicit float16_t(float x) { h = (__fp16)x; } operator float() const { return (float)h; } static float16_t fromBits(ushort w) @@ -762,7 +849,7 @@ protected: __fp16 h; #else - float16_t() {} + float16_t() : w(0) {} explicit float16_t(float x) { #if CV_FP16 @@ -809,7 +896,7 @@ protected: out.u = t + (1 << 23); out.u = (e >= 0x7c00 ? t + 0x38000000 : - e == 0 ? (out.f -= 6.103515625e-05f, out.u) : t) | sign; + e == 0 ? (static_cast(out.f -= 6.103515625e-05f), out.u) : t) | sign; return out.f; #endif } diff --git a/3rdparty/include/opencv2/core/cvstd.hpp b/3rdparty/include/opencv2/core/cvstd.hpp index fbf6d317e1..6ce9e4b060 100644 --- a/3rdparty/include/opencv2/core/cvstd.hpp +++ b/3rdparty/include/opencv2/core/cvstd.hpp @@ -78,6 +78,8 @@ namespace cv using std::log; } +#include "cvstd_wrapper.hpp" + namespace cv { //! @addtogroup core_utils @@ -138,894 +140,16 @@ public: //! @} core_utils -//! @cond IGNORED - -namespace detail -{ - -// Metafunction to avoid taking a reference to void. -template -struct RefOrVoid { typedef T& type; }; - -template<> -struct RefOrVoid{ typedef void type; }; - -template<> -struct RefOrVoid{ typedef const void type; }; - -template<> -struct RefOrVoid{ typedef volatile void type; }; - -template<> -struct RefOrVoid{ typedef const volatile void type; }; - -// This class would be private to Ptr, if it didn't have to be a non-template. -struct PtrOwner; - -} - -template -struct DefaultDeleter -{ - void operator () (Y* p) const; -}; - //! @endcond //! @addtogroup core_basic //! @{ -/** @brief Template class for smart pointers with shared ownership - -A Ptr\ pretends to be a pointer to an object of type T. Unlike an ordinary pointer, however, the -object will be automatically cleaned up once all Ptr instances pointing to it are destroyed. - -Ptr is similar to boost::shared_ptr that is part of the Boost library -() and std::shared_ptr from -the [C++11](http://en.wikipedia.org/wiki/C++11) standard. - -This class provides the following advantages: -- Default constructor, copy constructor, and assignment operator for an arbitrary C++ class or C - structure. For some objects, like files, windows, mutexes, sockets, and others, a copy - constructor or an assignment operator are difficult to define. For some other objects, like - complex classifiers in OpenCV, copy constructors are absent and not easy to implement. Finally, - some of complex OpenCV and your own data structures may be written in C. However, copy - constructors and default constructors can simplify programming a lot. Besides, they are often - required (for example, by STL containers). By using a Ptr to such an object instead of the - object itself, you automatically get all of the necessary constructors and the assignment - operator. -- *O(1)* complexity of the above-mentioned operations. While some structures, like std::vector, - provide a copy constructor and an assignment operator, the operations may take a considerable - amount of time if the data structures are large. But if the structures are put into a Ptr, the - overhead is small and independent of the data size. -- Automatic and customizable cleanup, even for C structures. See the example below with FILE\*. -- Heterogeneous collections of objects. The standard STL and most other C++ and OpenCV containers - can store only objects of the same type and the same size. The classical solution to store - objects of different types in the same container is to store pointers to the base class (Base\*) - instead but then you lose the automatic memory management. Again, by using Ptr\ instead - of raw pointers, you can solve the problem. - -A Ptr is said to *own* a pointer - that is, for each Ptr there is a pointer that will be deleted -once all Ptr instances that own it are destroyed. The owned pointer may be null, in which case -nothing is deleted. Each Ptr also *stores* a pointer. The stored pointer is the pointer the Ptr -pretends to be; that is, the one you get when you use Ptr::get or the conversion to T\*. It's -usually the same as the owned pointer, but if you use casts or the general shared-ownership -constructor, the two may diverge: the Ptr will still own the original pointer, but will itself point -to something else. - -The owned pointer is treated as a black box. The only thing Ptr needs to know about it is how to -delete it. This knowledge is encapsulated in the *deleter* - an auxiliary object that is associated -with the owned pointer and shared between all Ptr instances that own it. The default deleter is an -instance of DefaultDeleter, which uses the standard C++ delete operator; as such it will work with -any pointer allocated with the standard new operator. - -However, if the pointer must be deleted in a different way, you must specify a custom deleter upon -Ptr construction. A deleter is simply a callable object that accepts the pointer as its sole -argument. For example, if you want to wrap FILE, you may do so as follows: -@code - Ptr f(fopen("myfile.txt", "w"), fclose); - if(!f) throw ...; - fprintf(f, ....); - ... - // the file will be closed automatically by f's destructor. -@endcode -Alternatively, if you want all pointers of a particular type to be deleted the same way, you can -specialize DefaultDeleter::operator() for that type, like this: -@code - namespace cv { - template<> void DefaultDeleter::operator ()(FILE * obj) const - { - fclose(obj); - } - } -@endcode -For convenience, the following types from the OpenCV C API already have such a specialization that -calls the appropriate release function: -- CvCapture -- CvFileStorage -- CvHaarClassifierCascade -- CvMat -- CvMatND -- CvMemStorage -- CvSparseMat -- CvVideoWriter -- IplImage -@note The shared ownership mechanism is implemented with reference counting. As such, cyclic -ownership (e.g. when object a contains a Ptr to object b, which contains a Ptr to object a) will -lead to all involved objects never being cleaned up. Avoid such situations. -@note It is safe to concurrently read (but not write) a Ptr instance from multiple threads and -therefore it is normally safe to use it in multi-threaded applications. The same is true for Mat and -other C++ OpenCV classes that use internal reference counts. -*/ -template -struct Ptr -{ - /** Generic programming support. */ - typedef T element_type; - - /** The default constructor creates a null Ptr - one that owns and stores a null pointer. - */ - Ptr(); - - /** - If p is null, these are equivalent to the default constructor. - Otherwise, these constructors assume ownership of p - that is, the created Ptr owns and stores p - and assumes it is the sole owner of it. Don't use them if p is already owned by another Ptr, or - else p will get deleted twice. - With the first constructor, DefaultDeleter\() becomes the associated deleter (so p will - eventually be deleted with the standard delete operator). Y must be a complete type at the point - of invocation. - With the second constructor, d becomes the associated deleter. - Y\* must be convertible to T\*. - @param p Pointer to own. - @note It is often easier to use makePtr instead. - */ - template -#ifdef DISABLE_OPENCV_24_COMPATIBILITY - explicit -#endif - Ptr(Y* p); - - /** @overload - @param d Deleter to use for the owned pointer. - @param p Pointer to own. - */ - template - Ptr(Y* p, D d); - - /** - These constructors create a Ptr that shares ownership with another Ptr - that is, own the same - pointer as o. - With the first two, the same pointer is stored, as well; for the second, Y\* must be convertible - to T\*. - With the third, p is stored, and Y may be any type. This constructor allows to have completely - unrelated owned and stored pointers, and should be used with care to avoid confusion. A relatively - benign use is to create a non-owning Ptr, like this: - @code - ptr = Ptr(Ptr(), dont_delete_me); // owns nothing; will not delete the pointer. - @endcode - @param o Ptr to share ownership with. - */ - Ptr(const Ptr& o); - - /** @overload - @param o Ptr to share ownership with. - */ - template - Ptr(const Ptr& o); - - /** @overload - @param o Ptr to share ownership with. - @param p Pointer to store. - */ - template - Ptr(const Ptr& o, T* p); - - /** The destructor is equivalent to calling Ptr::release. */ - ~Ptr(); - - /** - Assignment replaces the current Ptr instance with one that owns and stores same pointers as o and - then destroys the old instance. - @param o Ptr to share ownership with. - */ - Ptr& operator = (const Ptr& o); - - /** @overload */ - template - Ptr& operator = (const Ptr& o); - - /** If no other Ptr instance owns the owned pointer, deletes it with the associated deleter. Then sets - both the owned and the stored pointers to NULL. - */ - void release(); - - /** - `ptr.reset(...)` is equivalent to `ptr = Ptr(...)`. - @param p Pointer to own. - */ - template - void reset(Y* p); - - /** @overload - @param d Deleter to use for the owned pointer. - @param p Pointer to own. - */ - template - void reset(Y* p, D d); - - /** - Swaps the owned and stored pointers (and deleters, if any) of this and o. - @param o Ptr to swap with. - */ - void swap(Ptr& o); - - /** Returns the stored pointer. */ - T* get() const; - - /** Ordinary pointer emulation. */ - typename detail::RefOrVoid::type operator * () const; - - /** Ordinary pointer emulation. */ - T* operator -> () const; - - /** Equivalent to get(). */ - operator T* () const; - - /** ptr.empty() is equivalent to `!ptr.get()`. */ - bool empty() const; - - /** Returns a Ptr that owns the same pointer as this, and stores the same - pointer as this, except converted via static_cast to Y*. - */ - template - Ptr staticCast() const; - - /** Ditto for const_cast. */ - template - Ptr constCast() const; - - /** Ditto for dynamic_cast. */ - template - Ptr dynamicCast() const; - -#ifdef CV_CXX_MOVE_SEMANTICS - Ptr(Ptr&& o); - Ptr& operator = (Ptr&& o); -#endif - -private: - detail::PtrOwner* owner; - T* stored; - - template - friend struct Ptr; // have to do this for the cross-type copy constructor -}; - -/** Equivalent to ptr1.swap(ptr2). Provided to help write generic algorithms. */ -template -void swap(Ptr& ptr1, Ptr& ptr2); - -/** Return whether ptr1.get() and ptr2.get() are equal and not equal, respectively. */ -template -bool operator == (const Ptr& ptr1, const Ptr& ptr2); -template -bool operator != (const Ptr& ptr1, const Ptr& ptr2); - -/** `makePtr(...)` is equivalent to `Ptr(new T(...))`. It is shorter than the latter, and it's -marginally safer than using a constructor or Ptr::reset, since it ensures that the owned pointer -is new and thus not owned by any other Ptr instance. -Unfortunately, perfect forwarding is impossible to implement in C++03, and so makePtr is limited -to constructors of T that have up to 10 arguments, none of which are non-const references. - */ -template -Ptr makePtr(); -/** @overload */ -template -Ptr makePtr(const A1& a1); -/** @overload */ -template -Ptr makePtr(const A1& a1, const A2& a2); -/** @overload */ -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3); -/** @overload */ -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4); -/** @overload */ -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5); -/** @overload */ -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6); -/** @overload */ -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7); -/** @overload */ -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8); -/** @overload */ -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9); -/** @overload */ -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10); - //////////////////////////////// string class //////////////////////////////// class CV_EXPORTS FileNode; //for string constructor from FileNode -class CV_EXPORTS String -{ -public: - typedef char value_type; - typedef char& reference; - typedef const char& const_reference; - typedef char* pointer; - typedef const char* const_pointer; - typedef ptrdiff_t difference_type; - typedef size_t size_type; - typedef char* iterator; - typedef const char* const_iterator; - - static const size_t npos = size_t(-1); - - String(); - String(const String& str); - String(const String& str, size_t pos, size_t len = npos); - String(const char* s); - String(const char* s, size_t n); - String(size_t n, char c); - String(const char* first, const char* last); - template String(Iterator first, Iterator last); - explicit String(const FileNode& fn); - ~String(); - - String& operator=(const String& str); - String& operator=(const char* s); - String& operator=(char c); - - String& operator+=(const String& str); - String& operator+=(const char* s); - String& operator+=(char c); - - size_t size() const; - size_t length() const; - - char operator[](size_t idx) const; - char operator[](int idx) const; - - const char* begin() const; - const char* end() const; - - const char* c_str() const; - - bool empty() const; - void clear(); - - int compare(const char* s) const; - int compare(const String& str) const; - - void swap(String& str); - String substr(size_t pos = 0, size_t len = npos) const; - - size_t find(const char* s, size_t pos, size_t n) const; - size_t find(char c, size_t pos = 0) const; - size_t find(const String& str, size_t pos = 0) const; - size_t find(const char* s, size_t pos = 0) const; - - size_t rfind(const char* s, size_t pos, size_t n) const; - size_t rfind(char c, size_t pos = npos) const; - size_t rfind(const String& str, size_t pos = npos) const; - size_t rfind(const char* s, size_t pos = npos) const; - - size_t find_first_of(const char* s, size_t pos, size_t n) const; - size_t find_first_of(char c, size_t pos = 0) const; - size_t find_first_of(const String& str, size_t pos = 0) const; - size_t find_first_of(const char* s, size_t pos = 0) const; - - size_t find_last_of(const char* s, size_t pos, size_t n) const; - size_t find_last_of(char c, size_t pos = npos) const; - size_t find_last_of(const String& str, size_t pos = npos) const; - size_t find_last_of(const char* s, size_t pos = npos) const; - - friend String operator+ (const String& lhs, const String& rhs); - friend String operator+ (const String& lhs, const char* rhs); - friend String operator+ (const char* lhs, const String& rhs); - friend String operator+ (const String& lhs, char rhs); - friend String operator+ (char lhs, const String& rhs); - - String toLowerCase() const; - - String(const std::string& str); - String(const std::string& str, size_t pos, size_t len = npos); - String& operator=(const std::string& str); - String& operator+=(const std::string& str); - operator std::string() const; - - friend String operator+ (const String& lhs, const std::string& rhs); - friend String operator+ (const std::string& lhs, const String& rhs); - -private: - char* cstr_; - size_t len_; - - char* allocate(size_t len); // len without trailing 0 - void deallocate(); - - String(int); // disabled and invalid. Catch invalid usages like, commandLineParser.has(0) problem -}; - -//! @} core_basic - -////////////////////////// cv::String implementation ///////////////////////// - -//! @cond IGNORED - -inline -String::String() - : cstr_(0), len_(0) -{} - -inline -String::String(const String& str) - : cstr_(str.cstr_), len_(str.len_) -{ - if (cstr_) - CV_XADD(((int*)cstr_)-1, 1); -} - -inline -String::String(const String& str, size_t pos, size_t len) - : cstr_(0), len_(0) -{ - pos = min(pos, str.len_); - len = min(str.len_ - pos, len); - if (!len) return; - if (len == str.len_) - { - CV_XADD(((int*)str.cstr_)-1, 1); - cstr_ = str.cstr_; - len_ = str.len_; - return; - } - memcpy(allocate(len), str.cstr_ + pos, len); -} - -inline -String::String(const char* s) - : cstr_(0), len_(0) -{ - if (!s) return; - size_t len = strlen(s); - if (!len) return; - memcpy(allocate(len), s, len); -} - -inline -String::String(const char* s, size_t n) - : cstr_(0), len_(0) -{ - if (!n) return; - if (!s) return; - memcpy(allocate(n), s, n); -} - -inline -String::String(size_t n, char c) - : cstr_(0), len_(0) -{ - if (!n) return; - memset(allocate(n), c, n); -} - -inline -String::String(const char* first, const char* last) - : cstr_(0), len_(0) -{ - size_t len = (size_t)(last - first); - if (!len) return; - memcpy(allocate(len), first, len); -} - -template inline -String::String(Iterator first, Iterator last) - : cstr_(0), len_(0) -{ - size_t len = (size_t)(last - first); - if (!len) return; - char* str = allocate(len); - while (first != last) - { - *str++ = *first; - ++first; - } -} - -inline -String::~String() -{ - deallocate(); -} - -inline -String& String::operator=(const String& str) -{ - if (&str == this) return *this; - - deallocate(); - if (str.cstr_) CV_XADD(((int*)str.cstr_)-1, 1); - cstr_ = str.cstr_; - len_ = str.len_; - return *this; -} - -inline -String& String::operator=(const char* s) -{ - deallocate(); - if (!s) return *this; - size_t len = strlen(s); - if (len) memcpy(allocate(len), s, len); - return *this; -} - -inline -String& String::operator=(char c) -{ - deallocate(); - allocate(1)[0] = c; - return *this; -} - -inline -String& String::operator+=(const String& str) -{ - *this = *this + str; - return *this; -} - -inline -String& String::operator+=(const char* s) -{ - *this = *this + s; - return *this; -} - -inline -String& String::operator+=(char c) -{ - *this = *this + c; - return *this; -} - -inline -size_t String::size() const -{ - return len_; -} - -inline -size_t String::length() const -{ - return len_; -} - -inline -char String::operator[](size_t idx) const -{ - return cstr_[idx]; -} - -inline -char String::operator[](int idx) const -{ - return cstr_[idx]; -} - -inline -const char* String::begin() const -{ - return cstr_; -} - -inline -const char* String::end() const -{ - return len_ ? cstr_ + len_ : NULL; -} - -inline -bool String::empty() const -{ - return len_ == 0; -} - -inline -const char* String::c_str() const -{ - return cstr_ ? cstr_ : ""; -} - -inline -void String::swap(String& str) -{ - cv::swap(cstr_, str.cstr_); - cv::swap(len_, str.len_); -} - -inline -void String::clear() -{ - deallocate(); -} - -inline -int String::compare(const char* s) const -{ - if (cstr_ == s) return 0; - return strcmp(c_str(), s); -} - -inline -int String::compare(const String& str) const -{ - if (cstr_ == str.cstr_) return 0; - return strcmp(c_str(), str.c_str()); -} - -inline -String String::substr(size_t pos, size_t len) const -{ - return String(*this, pos, len); -} - -inline -size_t String::find(const char* s, size_t pos, size_t n) const -{ - if (n == 0 || pos + n > len_) return npos; - const char* lmax = cstr_ + len_ - n; - for (const char* i = cstr_ + pos; i <= lmax; ++i) - { - size_t j = 0; - while (j < n && s[j] == i[j]) ++j; - if (j == n) return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::find(char c, size_t pos) const -{ - return find(&c, pos, 1); -} - -inline -size_t String::find(const String& str, size_t pos) const -{ - return find(str.c_str(), pos, str.len_); -} - -inline -size_t String::find(const char* s, size_t pos) const -{ - if (pos >= len_ || !s[0]) return npos; - const char* lmax = cstr_ + len_; - for (const char* i = cstr_ + pos; i < lmax; ++i) - { - size_t j = 0; - while (s[j] && s[j] == i[j]) - { if(i + j >= lmax) return npos; - ++j; - } - if (!s[j]) return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::rfind(const char* s, size_t pos, size_t n) const -{ - if (n > len_) return npos; - if (pos > len_ - n) pos = len_ - n; - for (const char* i = cstr_ + pos; i >= cstr_; --i) - { - size_t j = 0; - while (j < n && s[j] == i[j]) ++j; - if (j == n) return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::rfind(char c, size_t pos) const -{ - return rfind(&c, pos, 1); -} - -inline -size_t String::rfind(const String& str, size_t pos) const -{ - return rfind(str.c_str(), pos, str.len_); -} - -inline -size_t String::rfind(const char* s, size_t pos) const -{ - return rfind(s, pos, strlen(s)); -} - -inline -size_t String::find_first_of(const char* s, size_t pos, size_t n) const -{ - if (n == 0 || pos + n > len_) return npos; - const char* lmax = cstr_ + len_; - for (const char* i = cstr_ + pos; i < lmax; ++i) - { - for (size_t j = 0; j < n; ++j) - if (s[j] == *i) - return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::find_first_of(char c, size_t pos) const -{ - return find_first_of(&c, pos, 1); -} - -inline -size_t String::find_first_of(const String& str, size_t pos) const -{ - return find_first_of(str.c_str(), pos, str.len_); -} - -inline -size_t String::find_first_of(const char* s, size_t pos) const -{ - if (len_ == 0) return npos; - if (pos >= len_ || !s[0]) return npos; - const char* lmax = cstr_ + len_; - for (const char* i = cstr_ + pos; i < lmax; ++i) - { - for (size_t j = 0; s[j]; ++j) - if (s[j] == *i) - return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::find_last_of(const char* s, size_t pos, size_t n) const -{ - if (len_ == 0) return npos; - if (pos >= len_) pos = len_ - 1; - for (const char* i = cstr_ + pos; i >= cstr_; --i) - { - for (size_t j = 0; j < n; ++j) - if (s[j] == *i) - return (size_t)(i - cstr_); - } - return npos; -} - -inline -size_t String::find_last_of(char c, size_t pos) const -{ - return find_last_of(&c, pos, 1); -} - -inline -size_t String::find_last_of(const String& str, size_t pos) const -{ - return find_last_of(str.c_str(), pos, str.len_); -} - -inline -size_t String::find_last_of(const char* s, size_t pos) const -{ - if (len_ == 0) return npos; - if (pos >= len_) pos = len_ - 1; - for (const char* i = cstr_ + pos; i >= cstr_; --i) - { - for (size_t j = 0; s[j]; ++j) - if (s[j] == *i) - return (size_t)(i - cstr_); - } - return npos; -} - -inline -String String::toLowerCase() const -{ - if (!cstr_) - return String(); - String res(cstr_, len_); - for (size_t i = 0; i < len_; ++i) - res.cstr_[i] = (char) ::tolower(cstr_[i]); - - return res; -} - -//! @endcond - -// ************************* cv::String non-member functions ************************* - -//! @relates cv::String -//! @{ - -inline -String operator + (const String& lhs, const String& rhs) -{ - String s; - s.allocate(lhs.len_ + rhs.len_); - if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); - if (rhs.len_) memcpy(s.cstr_ + lhs.len_, rhs.cstr_, rhs.len_); - return s; -} - -inline -String operator + (const String& lhs, const char* rhs) -{ - String s; - size_t rhslen = strlen(rhs); - s.allocate(lhs.len_ + rhslen); - if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); - if (rhslen) memcpy(s.cstr_ + lhs.len_, rhs, rhslen); - return s; -} - -inline -String operator + (const char* lhs, const String& rhs) -{ - String s; - size_t lhslen = strlen(lhs); - s.allocate(lhslen + rhs.len_); - if (lhslen) memcpy(s.cstr_, lhs, lhslen); - if (rhs.len_) memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); - return s; -} - -inline -String operator + (const String& lhs, char rhs) -{ - String s; - s.allocate(lhs.len_ + 1); - if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); - s.cstr_[lhs.len_] = rhs; - return s; -} - -inline -String operator + (char lhs, const String& rhs) -{ - String s; - s.allocate(rhs.len_ + 1); - s.cstr_[0] = lhs; - if (rhs.len_) memcpy(s.cstr_ + 1, rhs.cstr_, rhs.len_); - return s; -} - -static inline bool operator== (const String& lhs, const String& rhs) { return 0 == lhs.compare(rhs); } -static inline bool operator== (const char* lhs, const String& rhs) { return 0 == rhs.compare(lhs); } -static inline bool operator== (const String& lhs, const char* rhs) { return 0 == lhs.compare(rhs); } -static inline bool operator!= (const String& lhs, const String& rhs) { return 0 != lhs.compare(rhs); } -static inline bool operator!= (const char* lhs, const String& rhs) { return 0 != rhs.compare(lhs); } -static inline bool operator!= (const String& lhs, const char* rhs) { return 0 != lhs.compare(rhs); } -static inline bool operator< (const String& lhs, const String& rhs) { return lhs.compare(rhs) < 0; } -static inline bool operator< (const char* lhs, const String& rhs) { return rhs.compare(lhs) > 0; } -static inline bool operator< (const String& lhs, const char* rhs) { return lhs.compare(rhs) < 0; } -static inline bool operator<= (const String& lhs, const String& rhs) { return lhs.compare(rhs) <= 0; } -static inline bool operator<= (const char* lhs, const String& rhs) { return rhs.compare(lhs) >= 0; } -static inline bool operator<= (const String& lhs, const char* rhs) { return lhs.compare(rhs) <= 0; } -static inline bool operator> (const String& lhs, const String& rhs) { return lhs.compare(rhs) > 0; } -static inline bool operator> (const char* lhs, const String& rhs) { return rhs.compare(lhs) < 0; } -static inline bool operator> (const String& lhs, const char* rhs) { return lhs.compare(rhs) > 0; } -static inline bool operator>= (const String& lhs, const String& rhs) { return lhs.compare(rhs) >= 0; } -static inline bool operator>= (const char* lhs, const String& rhs) { return rhs.compare(lhs) <= 0; } -static inline bool operator>= (const String& lhs, const char* rhs) { return lhs.compare(rhs) >= 0; } - +typedef std::string String; #ifndef OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS @@ -1060,15 +184,7 @@ static inline std::string toUpperCase(const std::string& str) #endif // OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS -//! @} relates cv::String - +//! @} core_basic } // cv -namespace std -{ - static inline void swap(cv::String& a, cv::String& b) { a.swap(b); } -} - -#include "opencv2/core/ptr.inl.hpp" - #endif //OPENCV_CORE_CVSTD_HPP diff --git a/3rdparty/include/opencv2/core/cvstd.inl.hpp b/3rdparty/include/opencv2/core/cvstd.inl.hpp index 36c83e285e..37ad1e6906 100644 --- a/3rdparty/include/opencv2/core/cvstd.inl.hpp +++ b/3rdparty/include/opencv2/core/cvstd.inl.hpp @@ -74,95 +74,6 @@ public: typedef Vec vec_type; }; -inline -String::String(const std::string& str) - : cstr_(0), len_(0) -{ - size_t len = str.size(); - if (len) memcpy(allocate(len), str.c_str(), len); -} - -inline -String::String(const std::string& str, size_t pos, size_t len) - : cstr_(0), len_(0) -{ - size_t strlen = str.size(); - pos = min(pos, strlen); - len = min(strlen - pos, len); - if (!len) return; - memcpy(allocate(len), str.c_str() + pos, len); -} - -inline -String& String::operator = (const std::string& str) -{ - deallocate(); - size_t len = str.size(); - if (len) memcpy(allocate(len), str.c_str(), len); - return *this; -} - -inline -String& String::operator += (const std::string& str) -{ - *this = *this + str; - return *this; -} - -inline -String::operator std::string() const -{ - return std::string(cstr_, len_); -} - -inline -String operator + (const String& lhs, const std::string& rhs) -{ - String s; - size_t rhslen = rhs.size(); - s.allocate(lhs.len_ + rhslen); - if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); - if (rhslen) memcpy(s.cstr_ + lhs.len_, rhs.c_str(), rhslen); - return s; -} - -inline -String operator + (const std::string& lhs, const String& rhs) -{ - String s; - size_t lhslen = lhs.size(); - s.allocate(lhslen + rhs.len_); - if (lhslen) memcpy(s.cstr_, lhs.c_str(), lhslen); - if (rhs.len_) memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); - return s; -} - -inline -FileNode::operator std::string() const -{ - String value; - read(*this, value, value); - return value; -} - -template<> inline -void operator >> (const FileNode& n, std::string& value) -{ - read(n, value, std::string()); -} - -template<> inline -FileStorage& operator << (FileStorage& fs, const std::string& value) -{ - return fs << cv::String(value); -} - -static inline -std::ostream& operator << (std::ostream& os, const String& str) -{ - return os << str.c_str(); -} - static inline std::ostream& operator << (std::ostream& out, Ptr fmtd) { diff --git a/3rdparty/include/opencv2/core/cvstd_wrapper.hpp b/3rdparty/include/opencv2/core/cvstd_wrapper.hpp new file mode 100644 index 0000000000..e2c2ea5076 --- /dev/null +++ b/3rdparty/include/opencv2/core/cvstd_wrapper.hpp @@ -0,0 +1,154 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_CVSTD_WRAPPER_HPP +#define OPENCV_CORE_CVSTD_WRAPPER_HPP + +#include "opencv2/core/cvdef.h" + +#include +#include // std::shared_ptr +#include // std::enable_if + +namespace cv { + +using std::nullptr_t; + +//! @addtogroup core_basic +//! @{ + +#ifdef CV_DOXYGEN + +template using Ptr = std::shared_ptr<_Tp>; // In ideal world it should look like this, but we need some compatibility workarounds below + +template static inline +Ptr<_Tp> makePtr(const A1&... a1) { return std::make_shared<_Tp>(a1...); } + +#else // cv::Ptr with compatibility workarounds + +// It should be defined for C-API types only. +// C++ types should use regular "delete" operator. +template struct DefaultDeleter; +#if 0 +{ + void operator()(Y* p) const; +}; +#endif + +namespace sfinae { +template +struct has_parenthesis_operator +{ +private: + template + static CV_CONSTEXPR std::true_type check(typename std::is_same().operator()(std::declval()...))>::type, Ret>::type*); + + template static CV_CONSTEXPR std::false_type check(...); + + typedef decltype(check(0)) type; + +public: +#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) + static CV_CONSTEXPR bool value = type::value; +#else + // support MSVS 2013 + static const int value = type::value; +#endif +}; +} // namespace sfinae + +template +struct has_custom_delete + : public std::false_type {}; + +// Force has_custom_delete to std::false_type when NVCC is compiling CUDA source files +#ifndef __CUDACC__ +template +struct has_custom_delete, void, T*>::value >::type > + : public std::true_type {}; +#endif + +template +struct Ptr : public std::shared_ptr +{ +#if 0 + using std::shared_ptr::shared_ptr; // GCC 5.x can't handle this +#else + inline Ptr() CV_NOEXCEPT : std::shared_ptr() {} + inline Ptr(nullptr_t) CV_NOEXCEPT : std::shared_ptr(nullptr) {} + template inline Ptr(Y* p, D d) : std::shared_ptr(p, d) {} + template inline Ptr(nullptr_t, D d) : std::shared_ptr(nullptr, d) {} + + template inline Ptr(const Ptr& r, T* ptr) CV_NOEXCEPT : std::shared_ptr(r, ptr) {} + + inline Ptr(const Ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} + inline Ptr(Ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} + + template inline Ptr(const Ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} + template inline Ptr(Ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} +#endif + inline Ptr(const std::shared_ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} + inline Ptr(std::shared_ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} + + // Overload with custom DefaultDeleter: Ptr(...) + template + inline Ptr(const std::true_type&, Y* ptr) : std::shared_ptr(ptr, DefaultDeleter()) {} + + // Overload without custom deleter: Ptr(...); + template + inline Ptr(const std::false_type&, Y* ptr) : std::shared_ptr(ptr) {} + + template + inline Ptr(Y* ptr) : Ptr(has_custom_delete(), ptr) {} + + // Overload with custom DefaultDeleter: Ptr(...) + template + inline void reset(const std::true_type&, Y* ptr) { std::shared_ptr::reset(ptr, DefaultDeleter()); } + + // Overload without custom deleter: Ptr(...); + template + inline void reset(const std::false_type&, Y* ptr) { std::shared_ptr::reset(ptr); } + + template + inline void reset(Y* ptr) { Ptr::reset(has_custom_delete(), ptr); } + + template + void reset(Y* ptr, Deleter d) { std::shared_ptr::reset(ptr, d); } + + void reset() CV_NOEXCEPT { std::shared_ptr::reset(); } + + Ptr& operator=(const Ptr& o) { std::shared_ptr::operator =(o); return *this; } + template inline Ptr& operator=(const Ptr& o) { std::shared_ptr::operator =(o); return *this; } + + T* operator->() const CV_NOEXCEPT { return std::shared_ptr::get();} + typename std::add_lvalue_reference::type operator*() const CV_NOEXCEPT { return *std::shared_ptr::get(); } + + // OpenCV 3.x methods (not a part of standard C++ library) + inline void release() { std::shared_ptr::reset(); } + inline operator T* () const { return std::shared_ptr::get(); } + inline bool empty() const { return std::shared_ptr::get() == nullptr; } + + template inline + Ptr staticCast() const CV_NOEXCEPT { return std::static_pointer_cast(*this); } + + template inline + Ptr constCast() const CV_NOEXCEPT { return std::const_pointer_cast(*this); } + + template inline + Ptr dynamicCast() const CV_NOEXCEPT { return std::dynamic_pointer_cast(*this); } +}; + +template static inline +Ptr<_Tp> makePtr(const A1&... a1) +{ + static_assert( !has_custom_delete<_Tp>::value, "Can't use this makePtr with custom DefaultDeleter"); + return (Ptr<_Tp>)std::make_shared<_Tp>(a1...); +} + +#endif // CV_DOXYGEN + +//! @} core_basic +} // cv + +#endif //OPENCV_CORE_CVSTD_WRAPPER_HPP diff --git a/3rdparty/include/opencv2/core/dualquaternion.hpp b/3rdparty/include/opencv2/core/dualquaternion.hpp new file mode 100644 index 0000000000..1f644e9dc8 --- /dev/null +++ b/3rdparty/include/opencv2/core/dualquaternion.hpp @@ -0,0 +1,979 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved. +// Third party copyrights are property of their respective owners. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Author: Liangqian Kong +// Longbu Wang +#ifndef OPENCV_CORE_DUALQUATERNION_HPP +#define OPENCV_CORE_DUALQUATERNION_HPP + +#include +#include + +namespace cv{ +//! @addtogroup core +//! @{ + +template class DualQuat; +template std::ostream& operator<<(std::ostream&, const DualQuat<_Tp>&); + +/** + * Dual quaternions were introduced to describe rotation together with translation while ordinary + * quaternions can only describe rotation. It can be used for shortest path pose interpolation, + * local pose optimization or volumetric deformation. More details can be found + * - https://en.wikipedia.org/wiki/Dual_quaternion + * - ["A beginners guide to dual-quaternions: what they are, how they work, and how to use them for 3D character hierarchies", Ben Kenwright, 2012](https://borodust.org/public/shared/beginner_dual_quats.pdf) + * - ["Dual Quaternions", Yan-Bin Jia, 2013](http://web.cs.iastate.edu/~cs577/handouts/dual-quaternion.pdf) + * - ["Geometric Skinning with Approximate Dual Quaternion Blending", Kavan, 2008](https://www.cs.utah.edu/~ladislav/kavan08geometric/kavan08geometric) + * - http://rodolphe-vaillant.fr/?e=29 + * + * A unit dual quaternion can be classically represented as: + * \f[ + * \begin{equation} + * \begin{split} + * \sigma &= \left(r+\frac{\epsilon}{2}tr\right)\\ + * &= [w, x, y, z, w\_, x\_, y\_, z\_] + * \end{split} + * \end{equation} + * \f] + * where \f$r, t\f$ represents the rotation (ordinary unit quaternion) and translation (pure ordinary quaternion) respectively. + * + * A general dual quaternions which consist of two quaternions is usually represented in form of: + * \f[ + * \sigma = p + \epsilon q + * \f] + * where the introduced dual unit \f$\epsilon\f$ satisfies \f$\epsilon^2 = \epsilon^3 =...=0\f$, and \f$p, q\f$ are quaternions. + * + * Alternatively, dual quaternions can also be interpreted as four components which are all [dual numbers](https://www.cs.utah.edu/~ladislav/kavan08geometric/kavan08geometric): + * \f[ + * \sigma = \hat{q}_w + \hat{q}_xi + \hat{q}_yj + \hat{q}_zk + * \f] + * If we set \f$\hat{q}_x, \hat{q}_y\f$ and \f$\hat{q}_z\f$ equal to 0, a dual quaternion is transformed to a dual number. see normalize(). + * + * If you want to create a dual quaternion, you can use: + * + * ``` + * using namespace cv; + * double angle = CV_PI; + * + * // create from eight number + * DualQuatd dq1(1, 2, 3, 4, 5, 6, 7, 8); //p = [1,2,3,4]. q=[5,6,7,8] + * + * // create from Vec + * Vec v{1,2,3,4,5,6,7,8}; + * DualQuatd dq_v{v}; + * + * // create from two quaternion + * Quatd p(1, 2, 3, 4); + * Quatd q(5, 6, 7, 8); + * DualQuatd dq2 = DualQuatd::createFromQuat(p, q); + * + * // create from an angle, an axis and a translation + * Vec3d axis{0, 0, 1}; + * Vec3d trans{3, 4, 5}; + * DualQuatd dq3 = DualQuatd::createFromAngleAxisTrans(angle, axis, trans); + * + * // If you already have an instance of class Affine3, then you can use + * Affine3d R = dq3.toAffine3(); + * DualQuatd dq4 = DualQuatd::createFromAffine3(R); + * + * // or create directly by affine transformation matrix Rt + * // see createFromMat() in detail for the form of Rt + * Matx44d Rt = dq3.toMat(); + * DualQuatd dq5 = DualQuatd::createFromMat(Rt); + * + * // Any rotation + translation movement can + * // be expressed as a rotation + translation around the same line in space (expressed by Plucker + * // coords), and here's a way to represent it this way. + * Vec3d axis{1, 1, 1}; // axis will be normalized in createFromPitch + * Vec3d trans{3, 4 ,5}; + * axis = axis / std::sqrt(axis.dot(axis));// The formula for computing moment that I use below requires a normalized axis + * Vec3d moment = 1.0 / 2 * (trans.cross(axis) + axis.cross(trans.cross(axis)) * + * std::cos(rotation_angle / 2) / std::sin(rotation_angle / 2)); + * double d = trans.dot(qaxis); + * DualQuatd dq6 = DualQuatd::createFromPitch(angle, d, axis, moment); + * ``` + * + * A point \f$v=(x, y, z)\f$ in form of dual quaternion is \f$[1+\epsilon v]=[1,0,0,0,0,x,y,z]\f$. + * The transformation of a point \f$v_1\f$ to another point \f$v_2\f$ under the dual quaternion \f$\sigma\f$ is + * \f[ + * 1 + \epsilon v_2 = \sigma * (1 + \epsilon v_1) * \sigma^{\star} + * \f] + * where \f$\sigma^{\star}=p^*-\epsilon q^*.\f$ + * + * A line in the \f$Pl\ddot{u}cker\f$ coordinates \f$(\hat{l}, m)\f$ defined by the dual quaternion \f$l=\hat{l}+\epsilon m\f$. + * To transform a line, \f[l_2 = \sigma * l_1 * \sigma^*,\f] where \f$\sigma=r+\frac{\epsilon}{2}rt\f$ and + * \f$\sigma^*=p^*+\epsilon q^*\f$. + * + * To extract the Vec or Vec, see toVec(); + * + * To extract the affine transformation matrix, see toMat(); + * + * To extract the instance of Affine3, see toAffine3(); + * + * If two quaternions \f$q_0, q_1\f$ are needed to be interpolated, you can use sclerp() + * ``` + * DualQuatd::sclerp(q0, q1, t) + * ``` + * or dqblend(). + * ``` + * DualQuatd::dqblend(q0, q1, t) + * ``` + * With more than two dual quaternions to be blended, you can use generalize linear dual quaternion blending + * with the corresponding weights, i.e. gdqblend(). + * + */ +template +class CV_EXPORTS DualQuat{ + static_assert(std::is_floating_point<_Tp>::value, "Dual quaternion only make sense with type of float or double"); + using value_type = _Tp; + +public: + static constexpr _Tp CV_DUAL_QUAT_EPS = (_Tp)1.e-6; + + DualQuat(); + + /** + * @brief create from eight same type numbers. + */ + DualQuat(const _Tp w, const _Tp x, const _Tp y, const _Tp z, const _Tp w_, const _Tp x_, const _Tp y_, const _Tp z_); + + /** + * @brief create from a double or float vector. + */ + DualQuat(const Vec<_Tp, 8> &q); + + _Tp w, x, y, z, w_, x_, y_, z_; + + /** + * @brief create Dual Quaternion from two same type quaternions p and q. + * A Dual Quaternion \f$\sigma\f$ has the form: + * \f[\sigma = p + \epsilon q\f] + * where p and q are defined as follows: + * \f[\begin{equation} + * \begin{split} + * p &= w + x\boldsymbol{i} + y\boldsymbol{j} + z\boldsymbol{k}\\ + * q &= w\_ + x\_\boldsymbol{i} + y\_\boldsymbol{j} + z\_\boldsymbol{k}. + * \end{split} + * \end{equation} + * \f] + * The p and q are the real part and dual part respectively. + * @param realPart a quaternion, real part of dual quaternion. + * @param dualPart a quaternion, dual part of dual quaternion. + * @sa Quat + */ + static DualQuat<_Tp> createFromQuat(const Quat<_Tp> &realPart, const Quat<_Tp> &dualPart); + + /** + * @brief create a dual quaternion from a rotation angle \f$\theta\f$, a rotation axis + * \f$\boldsymbol{u}\f$ and a translation \f$\boldsymbol{t}\f$. + * It generates a dual quaternion \f$\sigma\f$ in the form of + * \f[\begin{equation} + * \begin{split} + * \sigma &= r + \frac{\epsilon}{2}\boldsymbol{t}r \\ + * &= [\cos(\frac{\theta}{2}), \boldsymbol{u}\sin(\frac{\theta}{2})] + * + \frac{\epsilon}{2}[0, \boldsymbol{t}][[\cos(\frac{\theta}{2}), + * \boldsymbol{u}\sin(\frac{\theta}{2})]]\\ + * &= \cos(\frac{\theta}{2}) + \boldsymbol{u}\sin(\frac{\theta}{2}) + * + \frac{\epsilon}{2}(-(\boldsymbol{t} \cdot \boldsymbol{u})\sin(\frac{\theta}{2}) + * + \boldsymbol{t}\cos(\frac{\theta}{2}) + \boldsymbol{u} \times \boldsymbol{t} \sin(\frac{\theta}{2})). + * \end{split} + * \end{equation}\f] + * @param angle rotation angle. + * @param axis rotation axis. + * @param translation a vector of length 3. + * @note Axis will be normalized in this function. And translation is applied + * after the rotation. Use @ref createFromQuat(r, r * t / 2) to create a dual quaternion + * which translation is applied before rotation. + * @sa Quat + */ + static DualQuat<_Tp> createFromAngleAxisTrans(const _Tp angle, const Vec<_Tp, 3> &axis, const Vec<_Tp, 3> &translation); + + /** + * @brief Transform this dual quaternion to an affine transformation matrix \f$M\f$. + * Dual quaternion consists of a rotation \f$r=[a,b,c,d]\f$ and a translation \f$t=[\Delta x,\Delta y,\Delta z]\f$. The + * affine transformation matrix \f$M\f$ has the form + * \f[ + * \begin{bmatrix} + * 1-2(e_2^2 +e_3^2) &2(e_1e_2-e_0e_3) &2(e_0e_2+e_1e_3) &\Delta x\\ + * 2(e_0e_3+e_1e_2) &1-2(e_1^2+e_3^2) &2(e_2e_3-e_0e_1) &\Delta y\\ + * 2(e_1e_3-e_0e_2) &2(e_0e_1+e_2e_3) &1-2(e_1^2-e_2^2) &\Delta z\\ + * 0&0&0&1 + * \end{bmatrix} + * \f] + * if A is a matrix consisting of n points to be transformed, this could be achieved by + * \f[ + * new\_A = M * A + * \f] + * where A has the form + * \f[ + * \begin{bmatrix} + * x_0& x_1& x_2&...&x_n\\ + * y_0& y_1& y_2&...&y_n\\ + * z_0& z_1& z_2&...&z_n\\ + * 1&1&1&...&1 + * \end{bmatrix} + * \f] + * where the same subscript represent the same point. The size of A should be \f$[4,n]\f$. + * and the same size for matrix new_A. + * @param _R 4x4 matrix that represents rotations and translation. + * @note Translation is applied after the rotation. Use createFromQuat(r, r * t / 2) to create + * a dual quaternion which translation is applied before rotation. + */ + static DualQuat<_Tp> createFromMat(InputArray _R); + + /** + * @brief create dual quaternion from an affine matrix. The definition of affine matrix can refer to createFromMat() + */ + static DualQuat<_Tp> createFromAffine3(const Affine3<_Tp> &R); + + /** + * @brief A dual quaternion is a vector in form of + * \f[ + * \begin{equation} + * \begin{split} + * \sigma &=\boldsymbol{p} + \epsilon \boldsymbol{q}\\ + * &= \cos\hat{\frac{\theta}{2}}+\overline{\hat{l}}\sin\frac{\hat{\theta}}{2} + * \end{split} + * \end{equation} + * \f] + * where \f$\hat{\theta}\f$ is dual angle and \f$\overline{\hat{l}}\f$ is dual axis: + * \f[ + * \hat{\theta}=\theta + \epsilon d,\\ + * \overline{\hat{l}}= \hat{l} +\epsilon m. + * \f] + * In this representation, \f$\theta\f$ is rotation angle and \f$(\hat{l},m)\f$ is the screw axis, d is the translation distance along the axis. + * + * @param angle rotation angle. + * @param d translation along the rotation axis. + * @param axis rotation axis represented by quaternion with w = 0. + * @param moment the moment of line, and it should be orthogonal to axis. + * @note Translation is applied after the rotation. Use createFromQuat(r, r * t / 2) to create + * a dual quaternion which translation is applied before rotation. + */ + static DualQuat<_Tp> createFromPitch(const _Tp angle, const _Tp d, const Vec<_Tp, 3> &axis, const Vec<_Tp, 3> &moment); + + /** + * @brief return a quaternion which represent the real part of dual quaternion. + * The definition of real part is in createFromQuat(). + * @sa createFromQuat, getDualPart + */ + Quat<_Tp> getRealPart() const; + + /** + * @brief return a quaternion which represent the dual part of dual quaternion. + * The definition of dual part is in createFromQuat(). + * @sa createFromQuat, getRealPart + */ + Quat<_Tp> getDualPart() const; + + /** + * @brief return the conjugate of a dual quaternion. + * \f[ + * \begin{equation} + * \begin{split} + * \sigma^* &= (p + \epsilon q)^* + * &= (p^* + \epsilon q^*) + * \end{split} + * \end{equation} + * \f] + * @param dq a dual quaternion. + */ + template + friend DualQuat conjugate(const DualQuat &dq); + + /** + * @brief return the conjugate of a dual quaternion. + * \f[ + * \begin{equation} + * \begin{split} + * \sigma^* &= (p + \epsilon q)^* + * &= (p^* + \epsilon q^*) + * \end{split} + * \end{equation} + * \f] + */ + DualQuat<_Tp> conjugate() const; + + /** + * @brief return the rotation in quaternion form. + */ + Quat<_Tp> getRotation(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return the translation vector. + * The rotation \f$r\f$ in this dual quaternion \f$\sigma\f$ is applied before translation \f$t\f$. + * The dual quaternion \f$\sigma\f$ is defined as + * \f[\begin{equation} + * \begin{split} + * \sigma &= p + \epsilon q \\ + * &= r + \frac{\epsilon}{2}{t}r. + * \end{split} + * \end{equation}\f] + * Thus, the translation can be obtained as follows + * \f[t = 2qp^*.\f] + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion + * and this function will save some computations. + * @note This dual quaternion's translation is applied after the rotation. + */ + Vec<_Tp, 3> getTranslation(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return the norm \f$||\sigma||\f$ of dual quaternion \f$\sigma = p + \epsilon q\f$. + * \f[ + * \begin{equation} + * \begin{split} + * ||\sigma|| &= \sqrt{\sigma * \sigma^*} \\ + * &= ||p|| + \epsilon \frac{p \cdot q}{||p||}. + * \end{split} + * \end{equation} + * \f] + * Generally speaking, the norm of a not unit dual + * quaternion is a dual number. For convenience, we return it in the form of a dual quaternion + * , i.e. + * \f[ ||\sigma|| = [||p||, 0, 0, 0, \frac{p \cdot q}{||p||}, 0, 0, 0].\f] + * + * @note The data type of dual number is dual quaternion. + */ + DualQuat<_Tp> norm() const; + + /** + * @brief return a normalized dual quaternion. + * A dual quaternion can be expressed as + * \f[ + * \begin{equation} + * \begin{split} + * \sigma &= p + \epsilon q\\ + * &=||\sigma||\left(r+\frac{1}{2}tr\right) + * \end{split} + * \end{equation} + * \f] + * where \f$r, t\f$ represents the rotation (ordinary quaternion) and translation (pure ordinary quaternion) respectively, + * and \f$||\sigma||\f$ is the norm of dual quaternion(a dual number). + * A dual quaternion is unit if and only if + * \f[ + * ||p||=1, p \cdot q=0 + * \f] + * where \f$\cdot\f$ means dot product. + * The process of normalization is + * \f[ + * \sigma_{u}=\frac{\sigma}{||\sigma||} + * \f] + * Next, we simply proof \f$\sigma_u\f$ is a unit dual quaternion: + * \f[ + * \renewcommand{\Im}{\operatorname{Im}} + * \begin{equation} + * \begin{split} + * \sigma_{u}=\frac{\sigma}{||\sigma||}&=\frac{p + \epsilon q}{||p||+\epsilon\frac{p\cdot q}{||p||}}\\ + * &=\frac{p}{||p||}+\epsilon\left(\frac{q}{||p||}-p\frac{p\cdot q}{||p||^3}\right)\\ + * &=\frac{p}{||p||}+\epsilon\frac{1}{||p||^2}\left(qp^{*}-p\cdot q\right)\frac{p}{||p||}\\ + * &=\frac{p}{||p||}+\epsilon\frac{1}{||p||^2}\Im(qp^*)\frac{p}{||p||}.\\ + * \end{split} + * \end{equation} + * \f] + * As expected, the real part is a rotation and dual part is a pure quaternion. + */ + DualQuat<_Tp> normalize() const; + + /** + * @brief if \f$\sigma = p + \epsilon q\f$ is a dual quaternion, p is not zero, + * the inverse dual quaternion is + * \f[\sigma^{-1} = \frac{\sigma^*}{||\sigma||^2}, \f] + * or equivalentlly, + * \f[\sigma^{-1} = p^{-1} - \epsilon p^{-1}qp^{-1}.\f] + * @param dq a dual quaternion. + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, dual quaternion dq assume to be a unit dual quaternion + * and this function will save some computations. + */ + template + friend DualQuat inv(const DualQuat &dq, QuatAssumeType assumeUnit); + + /** + * @brief if \f$\sigma = p + \epsilon q\f$ is a dual quaternion, p is not zero, + * the inverse dual quaternion is + * \f[\sigma^{-1} = \frac{\sigma^*}{||\sigma||^2}, \f] + * or equivalentlly, + * \f[\sigma^{-1} = p^{-1} - \epsilon p^{-1}qp^{-1}.\f] + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion + * and this function will save some computations. + */ + DualQuat<_Tp> inv(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return the dot product of two dual quaternion. + * @param p other dual quaternion. + */ + _Tp dot(DualQuat<_Tp> p) const; + + /** + ** @brief return the value of \f$p^t\f$ where p is a dual quaternion. + * This could be calculated as: + * \f[ + * p^t = \exp(t\ln p) + * \f] + * @param dq a dual quaternion. + * @param t index of power function. + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, dual quaternion dq assume to be a unit dual quaternion + * and this function will save some computations. + */ + template + friend DualQuat power(const DualQuat &dq, const T t, QuatAssumeType assumeUnit); + + /** + ** @brief return the value of \f$p^t\f$ where p is a dual quaternion. + * This could be calculated as: + * \f[ + * p^t = \exp(t\ln p) + * \f] + * + * @param t index of power function. + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion + * and this function will save some computations. + */ + DualQuat<_Tp> power(const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return the value of \f$p^q\f$ where p and q are dual quaternions. + * This could be calculated as: + * \f[ + * p^q = \exp(q\ln p) + * \f] + * @param p a dual quaternion. + * @param q a dual quaternion. + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, dual quaternion p assume to be a dual unit quaternion + * and this function will save some computations. + */ + template + friend DualQuat power(const DualQuat& p, const DualQuat& q, QuatAssumeType assumeUnit); + + /** + * @brief return the value of \f$p^q\f$ where p and q are dual quaternions. + * This could be calculated as: + * \f[ + * p^q = \exp(q\ln p) + * \f] + * + * @param q a dual quaternion + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, this dual quaternion assume to be a dual unit quaternion + * and this function will save some computations. + */ + DualQuat<_Tp> power(const DualQuat<_Tp>& q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return the value of exponential function value + * @param dq a dual quaternion. + */ + template + friend DualQuat exp(const DualQuat &dq); + + /** + * @brief return the value of exponential function value + */ + DualQuat<_Tp> exp() const; + + /** + * @brief return the value of logarithm function value + * + * @param dq a dual quaternion. + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, dual quaternion dq assume to be a unit dual quaternion + * and this function will save some computations. + */ + template + friend DualQuat log(const DualQuat &dq, QuatAssumeType assumeUnit); + + /** + * @brief return the value of logarithm function value + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion + * and this function will save some computations. + */ + DualQuat<_Tp> log(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief Transform this dual quaternion to a vector. + */ + Vec<_Tp, 8> toVec() const; + + /** + * @brief Transform this dual quaternion to a affine transformation matrix + * the form of matrix, see createFromMat(). + */ + Matx<_Tp, 4, 4> toMat(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief Transform this dual quaternion to a instance of Affine3. + */ + Affine3<_Tp> toAffine3(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief The screw linear interpolation(ScLERP) is an extension of spherical linear interpolation of dual quaternion. + * If \f$\sigma_1\f$ and \f$\sigma_2\f$ are two dual quaternions representing the initial and final pose. + * The interpolation of ScLERP function can be defined as: + * \f[ + * ScLERP(t;\sigma_1,\sigma_2) = \sigma_1 * (\sigma_1^{-1} * \sigma_2)^t, t\in[0,1] + * \f] + * + * @param q1 a dual quaternion represents a initial pose. + * @param q2 a dual quaternion represents a final pose. + * @param t interpolation parameter + * @param directChange if true, it always return the shortest path. + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion + * and this function will save some computations. + * + * For example + * ``` + * double angle1 = CV_PI / 2; + * Vec3d axis{0, 0, 1}; + * Vec3d t(0, 0, 3); + * DualQuatd initial = DualQuatd::createFromAngleAxisTrans(angle1, axis, t); + * double angle2 = CV_PI; + * DualQuatd final = DualQuatd::createFromAngleAxisTrans(angle2, axis, t); + * DualQuatd inter = DualQuatd::sclerp(initial, final, 0.5); + * ``` + */ + static DualQuat<_Tp> sclerp(const DualQuat<_Tp> &q1, const DualQuat<_Tp> &q2, const _Tp t, + bool directChange=true, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + /** + * @brief The method of Dual Quaternion linear Blending(DQB) is to compute a transformation between dual quaternion + * \f$q_1\f$ and \f$q_2\f$ and can be defined as: + * \f[ + * DQB(t;{\boldsymbol{q}}_1,{\boldsymbol{q}}_2)= + * \frac{(1-t){\boldsymbol{q}}_1+t{\boldsymbol{q}}_2}{||(1-t){\boldsymbol{q}}_1+t{\boldsymbol{q}}_2||}. + * \f] + * where \f$q_1\f$ and \f$q_2\f$ are unit dual quaternions representing the input transformations. + * If you want to use DQB that works for more than two rigid transformations, see @ref gdqblend + * + * @param q1 a unit dual quaternion representing the input transformations. + * @param q2 a unit dual quaternion representing the input transformations. + * @param t parameter \f$t\in[0,1]\f$. + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion + * and this function will save some computations. + * + * @sa gdqblend + */ + static DualQuat<_Tp> dqblend(const DualQuat<_Tp> &q1, const DualQuat<_Tp> &q2, const _Tp t, + QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + + /** + * @brief The generalized Dual Quaternion linear Blending works for more than two rigid transformations. + * If these transformations are expressed as unit dual quaternions \f$q_1,...,q_n\f$ with convex weights + * \f$w = (w_1,...,w_n)\f$, the generalized DQB is simply + * \f[ + * gDQB(\boldsymbol{w};{\boldsymbol{q}}_1,...,{\boldsymbol{q}}_n)=\frac{w_1{\boldsymbol{q}}_1+...+w_n{\boldsymbol{q}}_n} + * {||w_1{\boldsymbol{q}}_1+...+w_n{\boldsymbol{q}}_n||}. + * \f] + * @param dualquat vector of dual quaternions + * @param weights vector of weights, the size of weights should be the same as dualquat, and the weights should + * satisfy \f$\sum_0^n w_{i} = 1\f$ and \f$w_i>0\f$. + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, these dual quaternions assume to be unit quaternions + * and this function will save some computations. + * @note the type of weights' element should be the same as the date type of dual quaternion inside the dualquat. + */ + template + static DualQuat<_Tp> gdqblend(const Vec, cn> &dualquat, InputArray weights, + QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + + /** + * @brief The generalized Dual Quaternion linear Blending works for more than two rigid transformations. + * If these transformations are expressed as unit dual quaternions \f$q_1,...,q_n\f$ with convex weights + * \f$w = (w_1,...,w_n)\f$, the generalized DQB is simply + * \f[ + * gDQB(\boldsymbol{w};{\boldsymbol{q}}_1,...,{\boldsymbol{q}}_n)=\frac{w_1{\boldsymbol{q}}_1+...+w_n{\boldsymbol{q}}_n} + * {||w_1{\boldsymbol{q}}_1+...+w_n{\boldsymbol{q}}_n||}. + * \f] + * @param dualquat The dual quaternions which have 8 channels and 1 row or 1 col. + * @param weights vector of weights, the size of weights should be the same as dualquat, and the weights should + * satisfy \f$\sum_0^n w_{i} = 1\f$ and \f$w_i>0\f$. + * @param assumeUnit if @ref QUAT_ASSUME_UNIT, these dual quaternions assume to be unit quaternions + * and this function will save some computations. + * @note the type of weights' element should be the same as the date type of dual quaternion inside the dualquat. + */ + static DualQuat<_Tp> gdqblend(InputArray dualquat, InputArray weights, + QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + + /** + * @brief Return opposite dual quaternion \f$-p\f$ + * which satisfies \f$p + (-p) = 0.\f$ + * + * For example + * ``` + * DualQuatd q{1, 2, 3, 4, 5, 6, 7, 8}; + * std::cout << -q << std::endl; // [-1, -2, -3, -4, -5, -6, -7, -8] + * ``` + */ + DualQuat<_Tp> operator-() const; + + /** + * @brief return true if two dual quaternions p and q are nearly equal, i.e. when the absolute + * value of each \f$p_i\f$ and \f$q_i\f$ is less than CV_DUAL_QUAT_EPS. + */ + bool operator==(const DualQuat<_Tp>&) const; + + /** + * @brief Subtraction operator of two dual quaternions p and q. + * It returns a new dual quaternion that each value is the sum of \f$p_i\f$ and \f$-q_i\f$. + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * DualQuatd q{5, 6, 7, 8, 9, 10, 11, 12}; + * std::cout << p - q << std::endl; //[-4, -4, -4, -4, 4, -4, -4, -4] + * ``` + */ + DualQuat<_Tp> operator-(const DualQuat<_Tp>&) const; + + /** + * @brief Subtraction assignment operator of two dual quaternions p and q. + * It subtracts right operand from the left operand and assign the result to left operand. + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * DualQuatd q{5, 6, 7, 8, 9, 10, 11, 12}; + * p -= q; // equivalent to p = p - q + * std::cout << p << std::endl; //[-4, -4, -4, -4, 4, -4, -4, -4] + * + * ``` + */ + DualQuat<_Tp>& operator-=(const DualQuat<_Tp>&); + + /** + * @brief Addition operator of two dual quaternions p and q. + * It returns a new dual quaternion that each value is the sum of \f$p_i\f$ and \f$q_i\f$. + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * DualQuatd q{5, 6, 7, 8, 9, 10, 11, 12}; + * std::cout << p + q << std::endl; //[6, 8, 10, 12, 14, 16, 18, 20] + * ``` + */ + DualQuat<_Tp> operator+(const DualQuat<_Tp>&) const; + + /** + * @brief Addition assignment operator of two dual quaternions p and q. + * It adds right operand to the left operand and assign the result to left operand. + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * DualQuatd q{5, 6, 7, 8, 9, 10, 11, 12}; + * p += q; // equivalent to p = p + q + * std::cout << p << std::endl; //[6, 8, 10, 12, 14, 16, 18, 20] + * + * ``` + */ + DualQuat<_Tp>& operator+=(const DualQuat<_Tp>&); + + /** + * @brief Multiplication assignment operator of two quaternions. + * It multiplies right operand with the left operand and assign the result to left operand. + * + * Rule of dual quaternion multiplication: + * The dual quaternion can be written as an ordered pair of quaternions [A, B]. Thus + * \f[ + * \begin{equation} + * \begin{split} + * p * q &= [A, B][C, D]\\ + * &=[AC, AD + BC] + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * DualQuatd q{5, 6, 7, 8, 9, 10, 11, 12}; + * p *= q; + * std::cout << p << std::endl; //[-60, 12, 30, 24, -216, 80, 124, 120] + * ``` + */ + DualQuat<_Tp>& operator*=(const DualQuat<_Tp>&); + + /** + * @brief Multiplication assignment operator of a quaternions and a scalar. + * It multiplies right operand with the left operand and assign the result to left operand. + * + * Rule of dual quaternion multiplication with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p * s &= [w, x, y, z, w\_, x\_, y\_, z\_] * s\\ + * &=[w s, x s, y s, z s, w\_ \space s, x\_ \space s, y\_ \space s, z\_ \space s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * double s = 2.0; + * p *= s; + * std::cout << p << std::endl; //[2, 4, 6, 8, 10, 12, 14, 16] + * ``` + * @note the type of scalar should be equal to the dual quaternion. + */ + DualQuat<_Tp> operator*=(const _Tp s); + + + /** + * @brief Multiplication operator of two dual quaternions q and p. + * Multiplies values on either side of the operator. + * + * Rule of dual quaternion multiplication: + * The dual quaternion can be written as an ordered pair of quaternions [A, B]. Thus + * \f[ + * \begin{equation} + * \begin{split} + * p * q &= [A, B][C, D]\\ + * &=[AC, AD + BC] + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * DualQuatd q{5, 6, 7, 8, 9, 10, 11, 12}; + * std::cout << p * q << std::endl; //[-60, 12, 30, 24, -216, 80, 124, 120] + * ``` + */ + DualQuat<_Tp> operator*(const DualQuat<_Tp>&) const; + + /** + * @brief Division operator of a dual quaternions and a scalar. + * It divides left operand with the right operand and assign the result to left operand. + * + * Rule of dual quaternion division with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p / s &= [w, x, y, z, w\_, x\_, y\_, z\_] / s\\ + * &=[w/s, x/s, y/s, z/s, w\_/s, x\_/s, y\_/s, z\_/s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * double s = 2.0; + * p /= s; // equivalent to p = p / s + * std::cout << p << std::endl; //[0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4] + * ``` + * @note the type of scalar should be equal to this dual quaternion. + */ + DualQuat<_Tp> operator/(const _Tp s) const; + + /** + * @brief Division operator of two dual quaternions p and q. + * Divides left hand operand by right hand operand. + * + * Rule of dual quaternion division with a dual quaternion: + * \f[ + * \begin{equation} + * \begin{split} + * p / q &= p * q.inv()\\ + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * DualQuatd q{5, 6, 7, 8, 9, 10, 11, 12}; + * std::cout << p / q << std::endl; // equivalent to p * q.inv() + * ``` + */ + DualQuat<_Tp> operator/(const DualQuat<_Tp>&) const; + + /** + * @brief Division assignment operator of two dual quaternions p and q; + * It divides left operand with the right operand and assign the result to left operand. + * + * Rule of dual quaternion division with a quaternion: + * \f[ + * \begin{equation} + * \begin{split} + * p / q&= p * q.inv()\\ + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * DualQuatd q{5, 6, 7, 8, 9, 10, 11, 12}; + * p /= q; // equivalent to p = p * q.inv() + * std::cout << p << std::endl; + * ``` + */ + DualQuat<_Tp>& operator/=(const DualQuat<_Tp>&); + + /** + * @brief Division assignment operator of a dual quaternions and a scalar. + * It divides left operand with the right operand and assign the result to left operand. + * + * Rule of dual quaternion division with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p / s &= [w, x, y, z, w\_, x\_, y\_ ,z\_] / s\\ + * &=[w / s, x / s, y / s, z / s, w\_ / \space s, x\_ / \space s, y\_ / \space s, z\_ / \space s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * double s = 2.0;; + * p /= s; // equivalent to p = p / s + * std::cout << p << std::endl; //[0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0] + * ``` + * @note the type of scalar should be equal to the dual quaternion. + */ + Quat<_Tp>& operator/=(const _Tp s); + + /** + * @brief Addition operator of a scalar and a dual quaternions. + * Adds right hand operand from left hand operand. + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * double scalar = 2.0; + * std::cout << scalar + p << std::endl; //[3.0, 2, 3, 4, 5, 6, 7, 8] + * ``` + * @note the type of scalar should be equal to the dual quaternion. + */ + template + friend DualQuat cv::operator+(const T s, const DualQuat&); + + /** + * @brief Addition operator of a dual quaternions and a scalar. + * Adds right hand operand from left hand operand. + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * double scalar = 2.0; + * std::cout << p + scalar << std::endl; //[3.0, 2, 3, 4, 5, 6, 7, 8] + * ``` + * @note the type of scalar should be equal to the dual quaternion. + */ + template + friend DualQuat cv::operator+(const DualQuat&, const T s); + + /** + * @brief Multiplication operator of a scalar and a dual quaternions. + * It multiplies right operand with the left operand and assign the result to left operand. + * + * Rule of dual quaternion multiplication with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p * s &= [w, x, y, z, w\_, x\_, y\_, z\_] * s\\ + * &=[w s, x s, y s, z s, w\_ \space s, x\_ \space s, y\_ \space s, z\_ \space s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * double s = 2.0; + * std::cout << s * p << std::endl; //[2, 4, 6, 8, 10, 12, 14, 16] + * ``` + * @note the type of scalar should be equal to the dual quaternion. + */ + template + friend DualQuat cv::operator*(const T s, const DualQuat&); + + /** + * @brief Subtraction operator of a dual quaternion and a scalar. + * Subtracts right hand operand from left hand operand. + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * double scalar = 2.0; + * std::cout << p - scalar << std::endl; //[-1, 2, 3, 4, 5, 6, 7, 8] + * ``` + * @note the type of scalar should be equal to the dual quaternion. + */ + template + friend DualQuat cv::operator-(const DualQuat&, const T s); + + /** + * @brief Subtraction operator of a scalar and a dual quaternions. + * Subtracts right hand operand from left hand operand. + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * double scalar = 2.0; + * std::cout << scalar - p << std::endl; //[1.0, -2, -3, -4, -5, -6, -7, -8] + * ``` + * @note the type of scalar should be equal to the dual quaternion. + */ + template + friend DualQuat cv::operator-(const T s, const DualQuat&); + + /** + * @brief Multiplication operator of a dual quaternions and a scalar. + * It multiplies right operand with the left operand and assign the result to left operand. + * + * Rule of dual quaternion multiplication with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p * s &= [w, x, y, z, w\_, x\_, y\_, z\_] * s\\ + * &=[w s, x s, y s, z s, w\_ \space s, x\_ \space s, y\_ \space s, z\_ \space s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8}; + * double s = 2.0; + * std::cout << p * s << std::endl; //[2, 4, 6, 8, 10, 12, 14, 16] + * ``` + * @note the type of scalar should be equal to the dual quaternion. + */ + template + friend DualQuat cv::operator*(const DualQuat&, const T s); + + template + friend std::ostream& cv::operator<<(std::ostream&, const DualQuat&); + +}; + +using DualQuatd = DualQuat; +using DualQuatf = DualQuat; + +//! @} core +}//namespace + +#include "dualquaternion.inl.hpp" + +#endif /* OPENCV_CORE_QUATERNION_HPP */ diff --git a/3rdparty/include/opencv2/core/dualquaternion.inl.hpp b/3rdparty/include/opencv2/core/dualquaternion.inl.hpp new file mode 100644 index 0000000000..4aec961dd2 --- /dev/null +++ b/3rdparty/include/opencv2/core/dualquaternion.inl.hpp @@ -0,0 +1,487 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved. +// Third party copyrights are property of their respective owners. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Author: Liangqian Kong +// Longbu Wang + +#ifndef OPENCV_CORE_DUALQUATERNION_INL_HPP +#define OPENCV_CORE_DUALQUATERNION_INL_HPP + +#ifndef OPENCV_CORE_DUALQUATERNION_HPP +#error This is not a standalone header. Include dualquaternion.hpp instead. +#endif + +/////////////////////////////////////////////////////////////////////////////////////// +//Implementation +namespace cv { + +template +DualQuat::DualQuat():w(0), x(0), y(0), z(0), w_(0), x_(0), y_(0), z_(0){}; + +template +DualQuat::DualQuat(const T vw, const T vx, const T vy, const T vz, const T _w, const T _x, const T _y, const T _z): + w(vw), x(vx), y(vy), z(vz), w_(_w), x_(_x), y_(_y), z_(_z){}; + +template +DualQuat::DualQuat(const Vec &q):w(q[0]), x(q[1]), y(q[2]), z(q[3]), + w_(q[4]), x_(q[5]), y_(q[6]), z_(q[7]){}; + +template +DualQuat DualQuat::createFromQuat(const Quat &realPart, const Quat &dualPart) +{ + T w = realPart.w; + T x = realPart.x; + T y = realPart.y; + T z = realPart.z; + T w_ = dualPart.w; + T x_ = dualPart.x; + T y_ = dualPart.y; + T z_ = dualPart.z; + return DualQuat(w, x, y, z, w_, x_, y_, z_); +} + +template +DualQuat DualQuat::createFromAngleAxisTrans(const T angle, const Vec &axis, const Vec &trans) +{ + Quat r = Quat::createFromAngleAxis(angle, axis); + Quat t{0, trans[0], trans[1], trans[2]}; + return createFromQuat(r, t * r / 2); +} + +template +DualQuat DualQuat::createFromMat(InputArray _R) +{ + CV_CheckTypeEQ(_R.type(), cv::traits::Type::value, ""); + if (_R.size() != Size(4, 4)) + { + CV_Error(Error::StsBadArg, "The input matrix must have 4 columns and 4 rows"); + } + Mat R = _R.getMat(); + Quat r = Quat::createFromRotMat(R.colRange(0, 3).rowRange(0, 3)); + Quat trans(0, R.at(0, 3), R.at(1, 3), R.at(2, 3)); + return createFromQuat(r, trans * r / 2); +} + +template +DualQuat DualQuat::createFromAffine3(const Affine3 &R) +{ + return createFromMat(R.matrix); +} + +template +DualQuat DualQuat::createFromPitch(const T angle, const T d, const Vec &axis, const Vec &moment) +{ + T half_angle = angle / 2, half_d = d / 2; + Quat qaxis = Quat(0, axis[0], axis[1], axis[2]).normalize(); + Quat qmoment = Quat(0, moment[0], moment[1], moment[2]); + qmoment -= qaxis * axis.dot(moment); + Quat dual = -half_d * std::sin(half_angle) + std::sin(half_angle) * qmoment + + half_d * std::cos(half_angle) * qaxis; + return createFromQuat(Quat::createFromAngleAxis(angle, axis), dual); +} + +template +inline bool DualQuat::operator==(const DualQuat &q) const +{ + return (abs(w - q.w) < CV_DUAL_QUAT_EPS && abs(x - q.x) < CV_DUAL_QUAT_EPS && + abs(y - q.y) < CV_DUAL_QUAT_EPS && abs(z - q.z) < CV_DUAL_QUAT_EPS && + abs(w_ - q.w_) < CV_DUAL_QUAT_EPS && abs(x_ - q.x_) < CV_DUAL_QUAT_EPS && + abs(y_ - q.y_) < CV_DUAL_QUAT_EPS && abs(z_ - q.z_) < CV_DUAL_QUAT_EPS); +} + +template +inline Quat DualQuat::getRealPart() const +{ + return Quat(w, x, y, z); +} + +template +inline Quat DualQuat::getDualPart() const +{ + return Quat(w_, x_, y_, z_); +} + +template +inline DualQuat conjugate(const DualQuat &dq) +{ + return dq.conjugate(); +} + +template +inline DualQuat DualQuat::conjugate() const +{ + return DualQuat(w, -x, -y, -z, w_, -x_, -y_, -z_); +} + +template +DualQuat DualQuat::norm() const +{ + Quat real = getRealPart(); + T realNorm = real.norm(); + Quat dual = getDualPart(); + if (realNorm < CV_DUAL_QUAT_EPS){ + return DualQuat(0, 0, 0, 0, 0, 0, 0, 0); + } + return DualQuat(realNorm, 0, 0, 0, real.dot(dual) / realNorm, 0, 0, 0); +} + +template +inline Quat DualQuat::getRotation(QuatAssumeType assumeUnit) const +{ + if (assumeUnit) + { + return getRealPart(); + } + return getRealPart().normalize(); +} + +template +inline Vec DualQuat::getTranslation(QuatAssumeType assumeUnit) const +{ + Quat trans = 2.0 * (getDualPart() * getRealPart().inv(assumeUnit)); + return Vec{trans[1], trans[2], trans[3]}; +} + +template +DualQuat DualQuat::normalize() const +{ + Quat p = getRealPart(); + Quat q = getDualPart(); + T p_norm = p.norm(); + if (p_norm < CV_DUAL_QUAT_EPS) + { + CV_Error(Error::StsBadArg, "Cannot normalize this dual quaternion: the norm is too small."); + } + Quat p_nr = p / p_norm; + Quat q_nr = q / p_norm; + return createFromQuat(p_nr, q_nr - p_nr * p_nr.dot(q_nr)); +} + +template +inline T DualQuat::dot(DualQuat q) const +{ + return q.w * w + q.x * x + q.y * y + q.z * z + q.w_ * w_ + q.x_ * x_ + q.y_ * y_ + q.z_ * z_; +} + +template +inline DualQuat inv(const DualQuat &dq, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) +{ + return dq.inv(assumeUnit); +} + +template +inline DualQuat DualQuat::inv(QuatAssumeType assumeUnit) const +{ + Quat real = getRealPart(); + Quat dual = getDualPart(); + return createFromQuat(real.inv(assumeUnit), -real.inv(assumeUnit) * dual * real.inv(assumeUnit)); +} + +template +inline DualQuat DualQuat::operator-(const DualQuat &q) const +{ + return DualQuat(w - q.w, x - q.x, y - q.y, z - q.z, w_ - q.w_, x_ - q.x_, y_ - q.y_, z_ - q.z_); +} + +template +inline DualQuat DualQuat::operator-() const +{ + return DualQuat(-w, -x, -y, -z, -w_, -x_, -y_, -z_); +} + +template +inline DualQuat DualQuat::operator+(const DualQuat &q) const +{ + return DualQuat(w + q.w, x + q.x, y + q.y, z + q.z, w_ + q.w_, x_ + q.x_, y_ + q.y_, z_ + q.z_); +} + +template +inline DualQuat& DualQuat::operator+=(const DualQuat &q) +{ + *this = *this + q; + return *this; +} + +template +inline DualQuat DualQuat::operator*(const DualQuat &q) const +{ + Quat A = getRealPart(); + Quat B = getDualPart(); + Quat C = q.getRealPart(); + Quat D = q.getDualPart(); + return DualQuat::createFromQuat(A * C, A * D + B * C); +} + +template +inline DualQuat& DualQuat::operator*=(const DualQuat &q) +{ + *this = *this * q; + return *this; +} + +template +inline DualQuat operator+(const T a, const DualQuat &q) +{ + return DualQuat(a + q.w, q.x, q.y, q.z, q.w_, q.x_, q.y_, q.z_); +} + +template +inline DualQuat operator+(const DualQuat &q, const T a) +{ + return DualQuat(a + q.w, q.x, q.y, q.z, q.w_, q.x_, q.y_, q.z_); +} + +template +inline DualQuat operator-(const DualQuat &q, const T a) +{ + return DualQuat(q.w - a, q.x, q.y, q.z, q.w_, q.x_, q.y_, q.z_); +} + +template +inline DualQuat& DualQuat::operator-=(const DualQuat &q) +{ + *this = *this - q; + return *this; +} + +template +inline DualQuat operator-(const T a, const DualQuat &q) +{ + return DualQuat(a - q.w, -q.x, -q.y, -q.z, -q.w_, -q.x_, -q.y_, -q.z_); +} + +template +inline DualQuat operator*(const T a, const DualQuat &q) +{ + return DualQuat(q.w * a, q.x * a, q.y * a, q.z * a, q.w_ * a, q.x_ * a, q.y_ * a, q.z_ * a); +} + +template +inline DualQuat operator*(const DualQuat &q, const T a) +{ + return DualQuat(q.w * a, q.x * a, q.y * a, q.z * a, q.w_ * a, q.x_ * a, q.y_ * a, q.z_ * a); +} + +template +inline DualQuat DualQuat::operator/(const T a) const +{ + return DualQuat(w / a, x / a, y / a, z / a, w_ / a, x_ / a, y_ / a, z_ / a); +} + +template +inline DualQuat DualQuat::operator/(const DualQuat &q) const +{ + return *this * q.inv(); +} + +template +inline DualQuat& DualQuat::operator/=(const DualQuat &q) +{ + *this = *this / q; + return *this; +} + +template +std::ostream & operator<<(std::ostream &os, const DualQuat &q) +{ + os << "DualQuat " << Vec{q.w, q.x, q.y, q.z, q.w_, q.x_, q.y_, q.z_}; + return os; +} + +template +inline DualQuat exp(const DualQuat &dq) +{ + return dq.exp(); +} + +namespace detail { + +template +Matx<_Tp, 4, 4> jacob_exp(const Quat<_Tp> &q) +{ + _Tp nv = std::sqrt(q.x * q.x + q.y * q.y + q.z * q.z); + _Tp sinc_nv = abs(nv) < cv::DualQuat<_Tp>::CV_DUAL_QUAT_EPS ? 1 - nv * nv / 6 : std::sin(nv) / nv; + _Tp csiii_nv = abs(nv) < cv::DualQuat<_Tp>::CV_DUAL_QUAT_EPS ? -(_Tp)1.0 / 3 : (std::cos(nv) - sinc_nv) / nv / nv; + Matx<_Tp, 4, 4> J_exp_quat { + std::cos(nv), -sinc_nv * q.x, -sinc_nv * q.y, -sinc_nv * q.z, + sinc_nv * q.x, csiii_nv * q.x * q.x + sinc_nv, csiii_nv * q.x * q.y, csiii_nv * q.x * q.z, + sinc_nv * q.y, csiii_nv * q.y * q.x, csiii_nv * q.y * q.y + sinc_nv, csiii_nv * q.y * q.z, + sinc_nv * q.z, csiii_nv * q.z * q.x, csiii_nv * q.z * q.y, csiii_nv * q.z * q.z + sinc_nv + }; + return std::exp(q.w) * J_exp_quat; +} + +} // namespace detail + +template +DualQuat DualQuat::exp() const +{ + Quat real = getRealPart(); + return createFromQuat(real.exp(), Quat(detail::jacob_exp(real) * getDualPart().toVec())); +} + +template +DualQuat log(const DualQuat &dq, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) +{ + return dq.log(assumeUnit); +} + +template +DualQuat DualQuat::log(QuatAssumeType assumeUnit) const +{ + Quat plog = getRealPart().log(assumeUnit); + Matx jacob = detail::jacob_exp(plog); + return createFromQuat(plog, Quat(jacob.inv() * getDualPart().toVec())); +} + +template +inline DualQuat power(const DualQuat &dq, const T t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) +{ + return dq.power(t, assumeUnit); +} + +template +inline DualQuat DualQuat::power(const T t, QuatAssumeType assumeUnit) const +{ + return (t * log(assumeUnit)).exp(); +} + +template +inline DualQuat power(const DualQuat &p, const DualQuat &q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) +{ + return p.power(q, assumeUnit); +} + +template +inline DualQuat DualQuat::power(const DualQuat &q, QuatAssumeType assumeUnit) const +{ + return (q * log(assumeUnit)).exp(); +} + +template +inline Vec DualQuat::toVec() const +{ + return Vec(w, x, y, z, w_, x_, y_, z_); +} + +template +Affine3 DualQuat::toAffine3(QuatAssumeType assumeUnit) const +{ + return Affine3(toMat(assumeUnit)); +} + +template +Matx DualQuat::toMat(QuatAssumeType assumeUnit) const +{ + Matx rot44 = getRotation(assumeUnit).toRotMat4x4(); + Vec translation = getTranslation(assumeUnit); + rot44(0, 3) = translation[0]; + rot44(1, 3) = translation[1]; + rot44(2, 3) = translation[2]; + return rot44; +} + +template +DualQuat DualQuat::sclerp(const DualQuat &q0, const DualQuat &q1, const T t, bool directChange, QuatAssumeType assumeUnit) +{ + DualQuat v0(q0), v1(q1); + if (!assumeUnit) + { + v0 = v0.normalize(); + v1 = v1.normalize(); + } + Quat v0Real = v0.getRealPart(); + Quat v1Real = v1.getRealPart(); + if (directChange && v1Real.dot(v0Real) < 0) + { + v0 = -v0; + } + DualQuat v0inv1 = v0.inv() * v1; + return v0 * v0inv1.power(t, QUAT_ASSUME_UNIT); +} + +template +DualQuat DualQuat::dqblend(const DualQuat &q1, const DualQuat &q2, const T t, QuatAssumeType assumeUnit) +{ + DualQuat v1(q1), v2(q2); + if (!assumeUnit) + { + v1 = v1.normalize(); + v2 = v2.normalize(); + } + if (v1.getRotation(assumeUnit).dot(v2.getRotation(assumeUnit)) < 0) + { + return ((1 - t) * v1 - t * v2).normalize(); + } + return ((1 - t) * v1 + t * v2).normalize(); +} + +template +DualQuat DualQuat::gdqblend(InputArray _dualquat, InputArray _weight, QuatAssumeType assumeUnit) +{ + CV_CheckTypeEQ(_weight.type(), cv::traits::Type::value, ""); + CV_CheckTypeEQ(_dualquat.type(), CV_MAKETYPE(CV_MAT_DEPTH(cv::traits::Type::value), 8), ""); + Size dq_s = _dualquat.size(); + if (dq_s != _weight.size() || (dq_s.height != 1 && dq_s.width != 1)) + { + CV_Error(Error::StsBadArg, "The size of weight must be the same as dualquat, both of them should be (1, n) or (n, 1)"); + } + Mat dualquat = _dualquat.getMat(), weight = _weight.getMat(); + const int cn = std::max(dq_s.width, dq_s.height); + if (!assumeUnit) + { + for (int i = 0; i < cn; ++i) + { + dualquat.at>(i) = DualQuat{dualquat.at>(i)}.normalize().toVec(); + } + } + Vec dq_blend = dualquat.at>(0) * weight.at(0); + Quat q0 = DualQuat {dualquat.at>(0)}.getRotation(assumeUnit); + for (int i = 1; i < cn; ++i) + { + T k = q0.dot(DualQuat{dualquat.at>(i)}.getRotation(assumeUnit)) < 0 ? -1: 1; + dq_blend = dq_blend + dualquat.at>(i) * k * weight.at(i); + } + return DualQuat{dq_blend}.normalize(); +} + +template +template +DualQuat DualQuat::gdqblend(const Vec, cn> &_dualquat, InputArray _weight, QuatAssumeType assumeUnit) +{ + Vec, cn> dualquat(_dualquat); + if (cn == 0) + { + return DualQuat(1, 0, 0, 0, 0, 0, 0, 0); + } + Mat dualquat_mat(cn, 1, CV_64FC(8)); + for (int i = 0; i < cn ; ++i) + { + dualquat_mat.at>(i) = dualquat[i].toVec(); + } + return gdqblend(dualquat_mat, _weight, assumeUnit); +} + +} //namespace cv + +#endif /*OPENCV_CORE_DUALQUATERNION_INL_HPP*/ diff --git a/3rdparty/include/opencv2/core/fast_math.hpp b/3rdparty/include/opencv2/core/fast_math.hpp index 0f53cf5c1b..eb4fbe213b 100644 --- a/3rdparty/include/opencv2/core/fast_math.hpp +++ b/3rdparty/include/opencv2/core/fast_math.hpp @@ -76,6 +76,9 @@ #if defined __PPC64__ && defined __GNUC__ && defined _ARCH_PWR8 \ && !defined(OPENCV_SKIP_INCLUDE_ALTIVEC_H) #include + #undef vector + #undef bool + #undef pixel #endif #if defined(CV_INLINE_ROUND_FLT) diff --git a/3rdparty/include/opencv2/core/hal/hal.hpp b/3rdparty/include/opencv2/core/hal/hal.hpp index 68900ec428..0d68078d98 100644 --- a/3rdparty/include/opencv2/core/hal/hal.hpp +++ b/3rdparty/include/opencv2/core/hal/hal.hpp @@ -195,6 +195,12 @@ CV_EXPORTS void addWeighted32s( const int* src1, size_t step1, const int* src2, CV_EXPORTS void addWeighted32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scalars ); CV_EXPORTS void addWeighted64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void cvt16f32f( const float16_t* src, float* dst, int len ); +CV_EXPORTS void cvt32f16f( const float* src, float16_t* dst, int len ); + +CV_EXPORTS void addRNGBias32f( float* arr, const float* scaleBiasPairs, int len ); +CV_EXPORTS void addRNGBias64f( double* arr, const double* scaleBiasPairs, int len ); + struct CV_EXPORTS DFT1D { static Ptr create(int len, int count, int depth, int flags, bool * useBuffer = 0); diff --git a/3rdparty/include/opencv2/core/hal/interface.h b/3rdparty/include/opencv2/core/hal/interface.h index 8f640254c3..6f0a83d359 100644 --- a/3rdparty/include/opencv2/core/hal/interface.h +++ b/3rdparty/include/opencv2/core/hal/interface.h @@ -64,6 +64,8 @@ typedef signed char schar; # define CV_BIG_UINT(n) n##ULL #endif +#define CV_USRTYPE1 (void)"CV_USRTYPE1 support has been dropped in OpenCV 4.0" + #define CV_CN_MAX 512 #define CV_CN_SHIFT 3 #define CV_DEPTH_MAX (1 << CV_CN_SHIFT) @@ -75,7 +77,7 @@ typedef signed char schar; #define CV_32S 4 #define CV_32F 5 #define CV_64F 6 -#define CV_USRTYPE1 7 +#define CV_16F 7 #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) @@ -124,6 +126,12 @@ typedef signed char schar; #define CV_64FC3 CV_MAKETYPE(CV_64F,3) #define CV_64FC4 CV_MAKETYPE(CV_64F,4) #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) + +#define CV_16FC1 CV_MAKETYPE(CV_16F,1) +#define CV_16FC2 CV_MAKETYPE(CV_16F,2) +#define CV_16FC3 CV_MAKETYPE(CV_16F,3) +#define CV_16FC4 CV_MAKETYPE(CV_16F,4) +#define CV_16FC(n) CV_MAKETYPE(CV_16F,(n)) //! @} //! @name Comparison operation diff --git a/3rdparty/include/opencv2/core/hal/intrin.hpp b/3rdparty/include/opencv2/core/hal/intrin.hpp index 52f6b5d552..ac331f2154 100644 --- a/3rdparty/include/opencv2/core/hal/intrin.hpp +++ b/3rdparty/include/opencv2/core/hal/intrin.hpp @@ -104,7 +104,7 @@ template struct V_TypeTraits { }; -#define CV_INTRIN_DEF_TYPE_TRAITS(type, int_type_, uint_type_, abs_type_, w_type_, q_type_, sum_type_, nlanes128_) \ +#define CV_INTRIN_DEF_TYPE_TRAITS(type, int_type_, uint_type_, abs_type_, w_type_, q_type_, sum_type_) \ template<> struct V_TypeTraits \ { \ typedef type value_type; \ @@ -114,7 +114,6 @@ template struct V_TypeTraits typedef w_type_ w_type; \ typedef q_type_ q_type; \ typedef sum_type_ sum_type; \ - enum { nlanes128 = nlanes128_ }; \ \ static inline int_type reinterpret_int(type x) \ { \ @@ -131,7 +130,7 @@ template struct V_TypeTraits } \ } -#define CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(type, int_type_, uint_type_, abs_type_, w_type_, sum_type_, nlanes128_) \ +#define CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(type, int_type_, uint_type_, abs_type_, w_type_, sum_type_) \ template<> struct V_TypeTraits \ { \ typedef type value_type; \ @@ -140,7 +139,6 @@ template struct V_TypeTraits typedef uint_type_ uint_type; \ typedef w_type_ w_type; \ typedef sum_type_ sum_type; \ - enum { nlanes128 = nlanes128_ }; \ \ static inline int_type reinterpret_int(type x) \ { \ @@ -157,16 +155,16 @@ template struct V_TypeTraits } \ } -CV_INTRIN_DEF_TYPE_TRAITS(uchar, schar, uchar, uchar, ushort, unsigned, unsigned, 16); -CV_INTRIN_DEF_TYPE_TRAITS(schar, schar, uchar, uchar, short, int, int, 16); -CV_INTRIN_DEF_TYPE_TRAITS(ushort, short, ushort, ushort, unsigned, uint64, unsigned, 8); -CV_INTRIN_DEF_TYPE_TRAITS(short, short, ushort, ushort, int, int64, int, 8); -CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(unsigned, int, unsigned, unsigned, uint64, unsigned, 4); -CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(int, int, unsigned, unsigned, int64, int, 4); -CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(float, int, unsigned, float, double, float, 4); -CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(uint64, int64, uint64, uint64, void, uint64, 2); -CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(int64, int64, uint64, uint64, void, int64, 2); -CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(double, int64, uint64, double, void, double, 2); +CV_INTRIN_DEF_TYPE_TRAITS(uchar, schar, uchar, uchar, ushort, unsigned, unsigned); +CV_INTRIN_DEF_TYPE_TRAITS(schar, schar, uchar, uchar, short, int, int); +CV_INTRIN_DEF_TYPE_TRAITS(ushort, short, ushort, ushort, unsigned, uint64, unsigned); +CV_INTRIN_DEF_TYPE_TRAITS(short, short, ushort, ushort, int, int64, int); +CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(unsigned, int, unsigned, unsigned, uint64, unsigned); +CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(int, int, unsigned, unsigned, int64, int); +CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(float, int, unsigned, float, double, float); +CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(uint64, int64, uint64, uint64, void, uint64); +CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(int64, int64, uint64, uint64, void, int64); +CV_INTRIN_DEF_TYPE_TRAITS_NO_Q_TYPE(double, int64, uint64, double, void, double); #ifndef CV_DOXYGEN @@ -199,9 +197,10 @@ using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE; # undef CV_VSX # undef CV_FP16 # undef CV_MSA +# undef CV_RVV #endif -#if (CV_SSE2 || CV_NEON || CV_VSX || CV_MSA || CV_WASM_SIMD) && !defined(CV_FORCE_SIMD128_CPP) +#if (CV_SSE2 || CV_NEON || CV_VSX || CV_MSA || CV_WASM_SIMD || CV_RVV071 || CV_RVV) && !defined(CV_FORCE_SIMD128_CPP) #define CV__SIMD_FORWARD 128 #include "opencv2/core/hal/intrin_forward.hpp" #endif @@ -215,6 +214,10 @@ using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE; #include "opencv2/core/hal/intrin_neon.hpp" +#elif CV_RVV071 && !defined(CV_FORCE_SIMD128_CPP) +#define CV_SIMD128_CPP 0 +#include "opencv2/core/hal/intrin_rvv071.hpp" + #elif CV_VSX && !defined(CV_FORCE_SIMD128_CPP) #include "opencv2/core/hal/intrin_vsx.hpp" @@ -226,6 +229,9 @@ using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE; #elif CV_WASM_SIMD && !defined(CV_FORCE_SIMD128_CPP) #include "opencv2/core/hal/intrin_wasm.hpp" +#elif CV_RVV && !defined(CV_FORCE_SIMD128_CPP) +#include "opencv2/core/hal/intrin_rvv.hpp" + #else #include "opencv2/core/hal/intrin_cpp.hpp" @@ -310,54 +316,6 @@ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN //================================================================================================== -#define CV_INTRIN_DEFINE_WIDE_INTRIN(typ, vtyp, short_typ, prefix, loadsfx) \ - inline vtyp vx_setall_##short_typ(typ v) { return prefix##_setall_##short_typ(v); } \ - inline vtyp vx_setzero_##short_typ() { return prefix##_setzero_##short_typ(); } \ - inline vtyp vx_##loadsfx(const typ* ptr) { return prefix##_##loadsfx(ptr); } \ - inline vtyp vx_##loadsfx##_aligned(const typ* ptr) { return prefix##_##loadsfx##_aligned(ptr); } \ - inline vtyp vx_##loadsfx##_low(const typ* ptr) { return prefix##_##loadsfx##_low(ptr); } \ - inline vtyp vx_##loadsfx##_halves(const typ* ptr0, const typ* ptr1) { return prefix##_##loadsfx##_halves(ptr0, ptr1); } \ - inline void vx_store(typ* ptr, const vtyp& v) { return v_store(ptr, v); } \ - inline void vx_store_aligned(typ* ptr, const vtyp& v) { return v_store_aligned(ptr, v); } \ - inline vtyp vx_lut(const typ* ptr, const int* idx) { return prefix##_lut(ptr, idx); } \ - inline vtyp vx_lut_pairs(const typ* ptr, const int* idx) { return prefix##_lut_pairs(ptr, idx); } - -#define CV_INTRIN_DEFINE_WIDE_LUT_QUAD(typ, vtyp, prefix) \ - inline vtyp vx_lut_quads(const typ* ptr, const int* idx) { return prefix##_lut_quads(ptr, idx); } - -#define CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(typ, wtyp, prefix) \ - inline wtyp vx_load_expand(const typ* ptr) { return prefix##_load_expand(ptr); } - -#define CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND_Q(typ, qtyp, prefix) \ - inline qtyp vx_load_expand_q(const typ* ptr) { return prefix##_load_expand_q(ptr); } - -#define CV_INTRIN_DEFINE_WIDE_INTRIN_WITH_EXPAND(typ, vtyp, short_typ, wtyp, qtyp, prefix, loadsfx) \ - CV_INTRIN_DEFINE_WIDE_INTRIN(typ, vtyp, short_typ, prefix, loadsfx) \ - CV_INTRIN_DEFINE_WIDE_LUT_QUAD(typ, vtyp, prefix) \ - CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(typ, wtyp, prefix) \ - CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND_Q(typ, qtyp, prefix) - -#define CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(prefix) \ - CV_INTRIN_DEFINE_WIDE_INTRIN_WITH_EXPAND(uchar, v_uint8, u8, v_uint16, v_uint32, prefix, load) \ - CV_INTRIN_DEFINE_WIDE_INTRIN_WITH_EXPAND(schar, v_int8, s8, v_int16, v_int32, prefix, load) \ - CV_INTRIN_DEFINE_WIDE_INTRIN(ushort, v_uint16, u16, prefix, load) \ - CV_INTRIN_DEFINE_WIDE_LUT_QUAD(ushort, v_uint16, prefix) \ - CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(ushort, v_uint32, prefix) \ - CV_INTRIN_DEFINE_WIDE_INTRIN(short, v_int16, s16, prefix, load) \ - CV_INTRIN_DEFINE_WIDE_LUT_QUAD(short, v_int16, prefix) \ - CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(short, v_int32, prefix) \ - CV_INTRIN_DEFINE_WIDE_INTRIN(int, v_int32, s32, prefix, load) \ - CV_INTRIN_DEFINE_WIDE_LUT_QUAD(int, v_int32, prefix) \ - CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(int, v_int64, prefix) \ - CV_INTRIN_DEFINE_WIDE_INTRIN(unsigned, v_uint32, u32, prefix, load) \ - CV_INTRIN_DEFINE_WIDE_LUT_QUAD(unsigned, v_uint32, prefix) \ - CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(unsigned, v_uint64, prefix) \ - CV_INTRIN_DEFINE_WIDE_INTRIN(float, v_float32, f32, prefix, load) \ - CV_INTRIN_DEFINE_WIDE_LUT_QUAD(float, v_float32, prefix) \ - CV_INTRIN_DEFINE_WIDE_INTRIN(int64, v_int64, s64, prefix, load) \ - CV_INTRIN_DEFINE_WIDE_INTRIN(uint64, v_uint64, u64, prefix, load) \ - CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(float16_t, v_float32, prefix) - template struct V_RegTraits { }; @@ -417,6 +375,7 @@ template struct V_RegTraits CV_DEF_REG_TRAITS(v512, v_int64x8, int64, s64, v_uint64x8, void, void, v_int64x8, void); CV_DEF_REG_TRAITS(v512, v_float64x8, double, f64, v_float64x8, void, void, v_int64x8, v_int32x16); #endif +//! @endcond #if CV_SIMD512 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 512) #define CV__SIMD_NAMESPACE simd512 @@ -425,21 +384,33 @@ namespace CV__SIMD_NAMESPACE { #define CV_SIMD_64F CV_SIMD512_64F #define CV_SIMD_FP16 CV_SIMD512_FP16 #define CV_SIMD_WIDTH 64 +//! @addtogroup core_hal_intrin +//! @{ + //! @brief Maximum available vector register capacity 8-bit unsigned integer values typedef v_uint8x64 v_uint8; + //! @brief Maximum available vector register capacity 8-bit signed integer values typedef v_int8x64 v_int8; + //! @brief Maximum available vector register capacity 16-bit unsigned integer values typedef v_uint16x32 v_uint16; + //! @brief Maximum available vector register capacity 16-bit signed integer values typedef v_int16x32 v_int16; + //! @brief Maximum available vector register capacity 32-bit unsigned integer values typedef v_uint32x16 v_uint32; + //! @brief Maximum available vector register capacity 32-bit signed integer values typedef v_int32x16 v_int32; + //! @brief Maximum available vector register capacity 64-bit unsigned integer values typedef v_uint64x8 v_uint64; + //! @brief Maximum available vector register capacity 64-bit signed integer values typedef v_int64x8 v_int64; + //! @brief Maximum available vector register capacity 32-bit floating point values (single precision) typedef v_float32x16 v_float32; - CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v512) -#if CV_SIMD512_64F + #if CV_SIMD512_64F + //! @brief Maximum available vector register capacity 64-bit floating point values (double precision) typedef v_float64x8 v_float64; - CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v512, load) -#endif - inline void vx_cleanup() { v512_cleanup(); } + #endif +//! @} + + #define VXPREFIX(func) v512##func } // namespace using namespace CV__SIMD_NAMESPACE; #elif CV_SIMD256 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 256) @@ -449,21 +420,33 @@ namespace CV__SIMD_NAMESPACE { #define CV_SIMD_64F CV_SIMD256_64F #define CV_SIMD_FP16 CV_SIMD256_FP16 #define CV_SIMD_WIDTH 32 +//! @addtogroup core_hal_intrin +//! @{ + //! @brief Maximum available vector register capacity 8-bit unsigned integer values typedef v_uint8x32 v_uint8; + //! @brief Maximum available vector register capacity 8-bit signed integer values typedef v_int8x32 v_int8; + //! @brief Maximum available vector register capacity 16-bit unsigned integer values typedef v_uint16x16 v_uint16; + //! @brief Maximum available vector register capacity 16-bit signed integer values typedef v_int16x16 v_int16; + //! @brief Maximum available vector register capacity 32-bit unsigned integer values typedef v_uint32x8 v_uint32; + //! @brief Maximum available vector register capacity 32-bit signed integer values typedef v_int32x8 v_int32; + //! @brief Maximum available vector register capacity 64-bit unsigned integer values typedef v_uint64x4 v_uint64; + //! @brief Maximum available vector register capacity 64-bit signed integer values typedef v_int64x4 v_int64; + //! @brief Maximum available vector register capacity 32-bit floating point values (single precision) typedef v_float32x8 v_float32; - CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v256) #if CV_SIMD256_64F + //! @brief Maximum available vector register capacity 64-bit floating point values (double precision) typedef v_float64x4 v_float64; - CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v256, load) #endif - inline void vx_cleanup() { v256_cleanup(); } +//! @} + + #define VXPREFIX(func) v256##func } // namespace using namespace CV__SIMD_NAMESPACE; #elif (CV_SIMD128 || CV_SIMD128_CPP) && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 128) @@ -476,25 +459,228 @@ namespace CV__SIMD_NAMESPACE { #define CV_SIMD CV_SIMD128 #define CV_SIMD_64F CV_SIMD128_64F #define CV_SIMD_WIDTH 16 +//! @addtogroup core_hal_intrin +//! @{ + //! @brief Maximum available vector register capacity 8-bit unsigned integer values typedef v_uint8x16 v_uint8; + //! @brief Maximum available vector register capacity 8-bit signed integer values typedef v_int8x16 v_int8; + //! @brief Maximum available vector register capacity 16-bit unsigned integer values typedef v_uint16x8 v_uint16; + //! @brief Maximum available vector register capacity 16-bit signed integer values typedef v_int16x8 v_int16; + //! @brief Maximum available vector register capacity 32-bit unsigned integer values typedef v_uint32x4 v_uint32; + //! @brief Maximum available vector register capacity 32-bit signed integer values typedef v_int32x4 v_int32; + //! @brief Maximum available vector register capacity 64-bit unsigned integer values typedef v_uint64x2 v_uint64; + //! @brief Maximum available vector register capacity 64-bit signed integer values typedef v_int64x2 v_int64; + //! @brief Maximum available vector register capacity 32-bit floating point values (single precision) typedef v_float32x4 v_float32; - CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v) #if CV_SIMD128_64F + //! @brief Maximum available vector register capacity 64-bit floating point values (double precision) typedef v_float64x2 v_float64; - CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v, load) #endif - inline void vx_cleanup() { v_cleanup(); } +//! @} + + #define VXPREFIX(func) v##func } // namespace using namespace CV__SIMD_NAMESPACE; #endif +namespace CV__SIMD_NAMESPACE { +//! @addtogroup core_hal_intrin +//! @{ + //! @name Wide init with value + //! @{ + //! @brief Create maximum available capacity vector with elements set to a specific value + inline v_uint8 vx_setall_u8(uchar v) { return VXPREFIX(_setall_u8)(v); } + inline v_int8 vx_setall_s8(schar v) { return VXPREFIX(_setall_s8)(v); } + inline v_uint16 vx_setall_u16(ushort v) { return VXPREFIX(_setall_u16)(v); } + inline v_int16 vx_setall_s16(short v) { return VXPREFIX(_setall_s16)(v); } + inline v_int32 vx_setall_s32(int v) { return VXPREFIX(_setall_s32)(v); } + inline v_uint32 vx_setall_u32(unsigned v) { return VXPREFIX(_setall_u32)(v); } + inline v_float32 vx_setall_f32(float v) { return VXPREFIX(_setall_f32)(v); } + inline v_int64 vx_setall_s64(int64 v) { return VXPREFIX(_setall_s64)(v); } + inline v_uint64 vx_setall_u64(uint64 v) { return VXPREFIX(_setall_u64)(v); } +#if CV_SIMD_64F + inline v_float64 vx_setall_f64(double v) { return VXPREFIX(_setall_f64)(v); } +#endif + //! @} + + //! @name Wide init with zero + //! @{ + //! @brief Create maximum available capacity vector with elements set to zero + inline v_uint8 vx_setzero_u8() { return VXPREFIX(_setzero_u8)(); } + inline v_int8 vx_setzero_s8() { return VXPREFIX(_setzero_s8)(); } + inline v_uint16 vx_setzero_u16() { return VXPREFIX(_setzero_u16)(); } + inline v_int16 vx_setzero_s16() { return VXPREFIX(_setzero_s16)(); } + inline v_int32 vx_setzero_s32() { return VXPREFIX(_setzero_s32)(); } + inline v_uint32 vx_setzero_u32() { return VXPREFIX(_setzero_u32)(); } + inline v_float32 vx_setzero_f32() { return VXPREFIX(_setzero_f32)(); } + inline v_int64 vx_setzero_s64() { return VXPREFIX(_setzero_s64)(); } + inline v_uint64 vx_setzero_u64() { return VXPREFIX(_setzero_u64)(); } +#if CV_SIMD_64F + inline v_float64 vx_setzero_f64() { return VXPREFIX(_setzero_f64)(); } +#endif + //! @} + + //! @name Wide load from memory + //! @{ + //! @brief Load maximum available capacity register contents from memory + inline v_uint8 vx_load(const uchar * ptr) { return VXPREFIX(_load)(ptr); } + inline v_int8 vx_load(const schar * ptr) { return VXPREFIX(_load)(ptr); } + inline v_uint16 vx_load(const ushort * ptr) { return VXPREFIX(_load)(ptr); } + inline v_int16 vx_load(const short * ptr) { return VXPREFIX(_load)(ptr); } + inline v_int32 vx_load(const int * ptr) { return VXPREFIX(_load)(ptr); } + inline v_uint32 vx_load(const unsigned * ptr) { return VXPREFIX(_load)(ptr); } + inline v_float32 vx_load(const float * ptr) { return VXPREFIX(_load)(ptr); } + inline v_int64 vx_load(const int64 * ptr) { return VXPREFIX(_load)(ptr); } + inline v_uint64 vx_load(const uint64 * ptr) { return VXPREFIX(_load)(ptr); } +#if CV_SIMD_64F + inline v_float64 vx_load(const double * ptr) { return VXPREFIX(_load)(ptr); } +#endif + //! @} + + //! @name Wide load from memory(aligned) + //! @{ + //! @brief Load maximum available capacity register contents from memory(aligned) + inline v_uint8 vx_load_aligned(const uchar * ptr) { return VXPREFIX(_load_aligned)(ptr); } + inline v_int8 vx_load_aligned(const schar * ptr) { return VXPREFIX(_load_aligned)(ptr); } + inline v_uint16 vx_load_aligned(const ushort * ptr) { return VXPREFIX(_load_aligned)(ptr); } + inline v_int16 vx_load_aligned(const short * ptr) { return VXPREFIX(_load_aligned)(ptr); } + inline v_int32 vx_load_aligned(const int * ptr) { return VXPREFIX(_load_aligned)(ptr); } + inline v_uint32 vx_load_aligned(const unsigned * ptr) { return VXPREFIX(_load_aligned)(ptr); } + inline v_float32 vx_load_aligned(const float * ptr) { return VXPREFIX(_load_aligned)(ptr); } + inline v_int64 vx_load_aligned(const int64 * ptr) { return VXPREFIX(_load_aligned)(ptr); } + inline v_uint64 vx_load_aligned(const uint64 * ptr) { return VXPREFIX(_load_aligned)(ptr); } +#if CV_SIMD_64F + inline v_float64 vx_load_aligned(const double * ptr) { return VXPREFIX(_load_aligned)(ptr); } +#endif + //! @} + + //! @name Wide load lower half from memory + //! @{ + //! @brief Load lower half of maximum available capacity register from memory + inline v_uint8 vx_load_low(const uchar * ptr) { return VXPREFIX(_load_low)(ptr); } + inline v_int8 vx_load_low(const schar * ptr) { return VXPREFIX(_load_low)(ptr); } + inline v_uint16 vx_load_low(const ushort * ptr) { return VXPREFIX(_load_low)(ptr); } + inline v_int16 vx_load_low(const short * ptr) { return VXPREFIX(_load_low)(ptr); } + inline v_int32 vx_load_low(const int * ptr) { return VXPREFIX(_load_low)(ptr); } + inline v_uint32 vx_load_low(const unsigned * ptr) { return VXPREFIX(_load_low)(ptr); } + inline v_float32 vx_load_low(const float * ptr) { return VXPREFIX(_load_low)(ptr); } + inline v_int64 vx_load_low(const int64 * ptr) { return VXPREFIX(_load_low)(ptr); } + inline v_uint64 vx_load_low(const uint64 * ptr) { return VXPREFIX(_load_low)(ptr); } +#if CV_SIMD_64F + inline v_float64 vx_load_low(const double * ptr) { return VXPREFIX(_load_low)(ptr); } +#endif + //! @} + + //! @name Wide load halfs from memory + //! @{ + //! @brief Load maximum available capacity register contents from two memory blocks + inline v_uint8 vx_load_halves(const uchar * ptr0, const uchar * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } + inline v_int8 vx_load_halves(const schar * ptr0, const schar * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } + inline v_uint16 vx_load_halves(const ushort * ptr0, const ushort * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } + inline v_int16 vx_load_halves(const short * ptr0, const short * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } + inline v_int32 vx_load_halves(const int * ptr0, const int * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } + inline v_uint32 vx_load_halves(const unsigned * ptr0, const unsigned * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } + inline v_float32 vx_load_halves(const float * ptr0, const float * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } + inline v_int64 vx_load_halves(const int64 * ptr0, const int64 * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } + inline v_uint64 vx_load_halves(const uint64 * ptr0, const uint64 * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } +#if CV_SIMD_64F + inline v_float64 vx_load_halves(const double * ptr0, const double * ptr1) { return VXPREFIX(_load_halves)(ptr0, ptr1); } +#endif + //! @} + + //! @name Wide LUT of elements + //! @{ + //! @brief Load maximum available capacity register contents with array elements by provided indexes + inline v_uint8 vx_lut(const uchar * ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } + inline v_int8 vx_lut(const schar * ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } + inline v_uint16 vx_lut(const ushort * ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } + inline v_int16 vx_lut(const short* ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } + inline v_int32 vx_lut(const int* ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } + inline v_uint32 vx_lut(const unsigned* ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } + inline v_float32 vx_lut(const float* ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } + inline v_int64 vx_lut(const int64 * ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } + inline v_uint64 vx_lut(const uint64 * ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } +#if CV_SIMD_64F + inline v_float64 vx_lut(const double* ptr, const int* idx) { return VXPREFIX(_lut)(ptr, idx); } +#endif + //! @} + + //! @name Wide LUT of element pairs + //! @{ + //! @brief Load maximum available capacity register contents with array element pairs by provided indexes + inline v_uint8 vx_lut_pairs(const uchar * ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } + inline v_int8 vx_lut_pairs(const schar * ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } + inline v_uint16 vx_lut_pairs(const ushort * ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } + inline v_int16 vx_lut_pairs(const short* ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } + inline v_int32 vx_lut_pairs(const int* ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } + inline v_uint32 vx_lut_pairs(const unsigned* ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } + inline v_float32 vx_lut_pairs(const float* ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } + inline v_int64 vx_lut_pairs(const int64 * ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } + inline v_uint64 vx_lut_pairs(const uint64 * ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } +#if CV_SIMD_64F + inline v_float64 vx_lut_pairs(const double* ptr, const int* idx) { return VXPREFIX(_lut_pairs)(ptr, idx); } +#endif + //! @} + + //! @name Wide LUT of element quads + //! @{ + //! @brief Load maximum available capacity register contents with array element quads by provided indexes + inline v_uint8 vx_lut_quads(const uchar* ptr, const int* idx) { return VXPREFIX(_lut_quads)(ptr, idx); } + inline v_int8 vx_lut_quads(const schar* ptr, const int* idx) { return VXPREFIX(_lut_quads)(ptr, idx); } + inline v_uint16 vx_lut_quads(const ushort* ptr, const int* idx) { return VXPREFIX(_lut_quads)(ptr, idx); } + inline v_int16 vx_lut_quads(const short* ptr, const int* idx) { return VXPREFIX(_lut_quads)(ptr, idx); } + inline v_int32 vx_lut_quads(const int* ptr, const int* idx) { return VXPREFIX(_lut_quads)(ptr, idx); } + inline v_uint32 vx_lut_quads(const unsigned* ptr, const int* idx) { return VXPREFIX(_lut_quads)(ptr, idx); } + inline v_float32 vx_lut_quads(const float* ptr, const int* idx) { return VXPREFIX(_lut_quads)(ptr, idx); } + //! @} + + //! @name Wide load with double expansion + //! @{ + //! @brief Load maximum available capacity register contents from memory with double expand + inline v_uint16 vx_load_expand(const uchar * ptr) { return VXPREFIX(_load_expand)(ptr); } + inline v_int16 vx_load_expand(const schar * ptr) { return VXPREFIX(_load_expand)(ptr); } + inline v_uint32 vx_load_expand(const ushort * ptr) { return VXPREFIX(_load_expand)(ptr); } + inline v_int32 vx_load_expand(const short* ptr) { return VXPREFIX(_load_expand)(ptr); } + inline v_int64 vx_load_expand(const int* ptr) { return VXPREFIX(_load_expand)(ptr); } + inline v_uint64 vx_load_expand(const unsigned* ptr) { return VXPREFIX(_load_expand)(ptr); } + inline v_float32 vx_load_expand(const float16_t * ptr) { return VXPREFIX(_load_expand)(ptr); } + //! @} + + //! @name Wide load with quad expansion + //! @{ + //! @brief Load maximum available capacity register contents from memory with quad expand + inline v_uint32 vx_load_expand_q(const uchar * ptr) { return VXPREFIX(_load_expand_q)(ptr); } + inline v_int32 vx_load_expand_q(const schar * ptr) { return VXPREFIX(_load_expand_q)(ptr); } + //! @} + + /** @brief SIMD processing state cleanup call */ + inline void vx_cleanup() { VXPREFIX(_cleanup)(); } + + +//! @cond IGNORED + + // backward compatibility + template static inline + void vx_store(_Tp* dst, const _Tvec& v) { return v_store(dst, v); } + // backward compatibility + template static inline + void vx_store_aligned(_Tp* dst, const _Tvec& v) { return v_store_aligned(dst, v); } + +//! @endcond + + +//! @} + #undef VXPREFIX +} // namespace + +//! @cond IGNORED #ifndef CV_SIMD_64F #define CV_SIMD_64F 0 #endif diff --git a/3rdparty/include/opencv2/core/hal/intrin_cpp.hpp b/3rdparty/include/opencv2/core/hal/intrin_cpp.hpp index 859bfd72dc..46222140e6 100644 --- a/3rdparty/include/opencv2/core/hal/intrin_cpp.hpp +++ b/3rdparty/include/opencv2/core/hal/intrin_cpp.hpp @@ -52,10 +52,21 @@ //! @cond IGNORED #define CV_SIMD128_CPP 1 -#if defined(CV_FORCE_SIMD128_CPP) || defined(CV_DOXYGEN) +#if defined(CV_FORCE_SIMD128_CPP) #define CV_SIMD128 1 #define CV_SIMD128_64F 1 #endif +#if defined(CV_DOXYGEN) +#define CV_SIMD128 1 +#define CV_SIMD128_64F 1 +#define CV_SIMD256 1 +#define CV_SIMD256_64F 1 +#define CV_SIMD512 1 +#define CV_SIMD512_64F 1 +#else +#define CV_SIMD256 0 // Explicitly disable SIMD256 and SIMD512 support for scalar intrinsic implementation +#define CV_SIMD512 0 // to avoid warnings during compilation +#endif //! @endcond namespace cv @@ -68,17 +79,33 @@ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN /** @addtogroup core_hal_intrin "Universal intrinsics" is a types and functions set intended to simplify vectorization of code on -different platforms. Currently there are two supported SIMD extensions: __SSE/SSE2__ on x86 -architectures and __NEON__ on ARM architectures, both allow working with 128 bit registers -containing packed values of different types. In case when there is no SIMD extension available -during compilation, fallback C++ implementation of intrinsics will be chosen and code will work as -expected although it could be slower. +different platforms. Currently a few different SIMD extensions on different architectures are supported. +128 bit registers of various types support is implemented for a wide range of architectures +including x86(__SSE/SSE2/SSE4.2__), ARM(__NEON__), PowerPC(__VSX__), MIPS(__MSA__). +256 bit long registers are supported on x86(__AVX2__) and 512 bit long registers are supported on x86(__AVX512__). +In case when there is no SIMD extension available during compilation, fallback C++ implementation of intrinsics +will be chosen and code will work as expected although it could be slower. ### Types -There are several types representing 128-bit register as a vector of packed values, each type is +There are several types representing packed values vector registers, each type is implemented as a structure based on a one SIMD register. +- cv::v_uint8 and cv::v_int8: 8-bit integer values (unsigned/signed) - char +- cv::v_uint16 and cv::v_int16: 16-bit integer values (unsigned/signed) - short +- cv::v_uint32 and cv::v_int32: 32-bit integer values (unsigned/signed) - int +- cv::v_uint64 and cv::v_int64: 64-bit integer values (unsigned/signed) - int64 +- cv::v_float32: 32-bit floating point values (signed) - float +- cv::v_float64: 64-bit floating point values (signed) - double + +Exact bit length(and value quantity) of listed types is compile time deduced and depends on architecture SIMD +capabilities chosen as available during compilation of the library. All the types contains __nlanes__ enumeration +to check for exact value quantity of the type. + +In case the exact bit length of the type is important it is possible to use specific fixed length register types. + +There are several types representing 128-bit registers. + - cv::v_uint8x16 and cv::v_int8x16: sixteen 8-bit integer values (unsigned/signed) - char - cv::v_uint16x8 and cv::v_int16x8: eight 16-bit integer values (unsigned/signed) - short - cv::v_uint32x4 and cv::v_int32x4: four 32-bit integer values (unsigned/signed) - int @@ -86,28 +113,96 @@ implemented as a structure based on a one SIMD register. - cv::v_float32x4: four 32-bit floating point values (signed) - float - cv::v_float64x2: two 64-bit floating point values (signed) - double +There are several types representing 256-bit registers. + +- cv::v_uint8x32 and cv::v_int8x32: thirty two 8-bit integer values (unsigned/signed) - char +- cv::v_uint16x16 and cv::v_int16x16: sixteen 16-bit integer values (unsigned/signed) - short +- cv::v_uint32x8 and cv::v_int32x8: eight 32-bit integer values (unsigned/signed) - int +- cv::v_uint64x4 and cv::v_int64x4: four 64-bit integer values (unsigned/signed) - int64 +- cv::v_float32x8: eight 32-bit floating point values (signed) - float +- cv::v_float64x4: four 64-bit floating point values (signed) - double + @note -cv::v_float64x2 is not implemented in NEON variant, if you want to use this type, don't forget to -check the CV_SIMD128_64F preprocessor definition: +256 bit registers at the moment implemented for AVX2 SIMD extension only, if you want to use this type directly, +don't forget to check the CV_SIMD256 preprocessor definition: @code -#if CV_SIMD128_64F +#if CV_SIMD256 //... #endif @endcode +There are several types representing 512-bit registers. + +- cv::v_uint8x64 and cv::v_int8x64: sixty four 8-bit integer values (unsigned/signed) - char +- cv::v_uint16x32 and cv::v_int16x32: thirty two 16-bit integer values (unsigned/signed) - short +- cv::v_uint32x16 and cv::v_int32x16: sixteen 32-bit integer values (unsigned/signed) - int +- cv::v_uint64x8 and cv::v_int64x8: eight 64-bit integer values (unsigned/signed) - int64 +- cv::v_float32x16: sixteen 32-bit floating point values (signed) - float +- cv::v_float64x8: eight 64-bit floating point values (signed) - double +@note +512 bit registers at the moment implemented for AVX512 SIMD extension only, if you want to use this type directly, +don't forget to check the CV_SIMD512 preprocessor definition. + +@note +cv::v_float64x2 is not implemented in NEON variant, if you want to use this type, don't forget to +check the CV_SIMD128_64F preprocessor definition. + ### Load and store operations These operations allow to set contents of the register explicitly or by loading it from some memory block and to save contents of the register to memory block. +There are variable size register load operations that provide result of maximum available size +depending on chosen platform capabilities. +- Constructors: +@ref v_reg::v_reg(const _Tp *ptr) "from memory", +- Other create methods: +vx_setall_s8, vx_setall_u8, ..., +vx_setzero_u8, vx_setzero_s8, ... +- Memory load operations: +vx_load, vx_load_aligned, vx_load_low, vx_load_halves, +- Memory operations with expansion of values: +vx_load_expand, vx_load_expand_q + +Also there are fixed size register load/store operations. + +For 128 bit registers - Constructors: @ref v_reg::v_reg(const _Tp *ptr) "from memory", @ref v_reg::v_reg(_Tp s0, _Tp s1) "from two values", ... - Other create methods: @ref v_setall_s8, @ref v_setall_u8, ..., @ref v_setzero_u8, @ref v_setzero_s8, ... -- Memory operations: +- Memory load operations: @ref v_load, @ref v_load_aligned, @ref v_load_low, @ref v_load_halves, +- Memory operations with expansion of values: +@ref v_load_expand, @ref v_load_expand_q + +For 256 bit registers(check CV_SIMD256 preprocessor definition) +- Constructors: +@ref v_reg::v_reg(const _Tp *ptr) "from memory", +@ref v_reg::v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3) "from four values", ... +- Other create methods: +@ref v256_setall_s8, @ref v256_setall_u8, ..., +@ref v256_setzero_u8, @ref v256_setzero_s8, ... +- Memory load operations: +@ref v256_load, @ref v256_load_aligned, @ref v256_load_low, @ref v256_load_halves, +- Memory operations with expansion of values: +@ref v256_load_expand, @ref v256_load_expand_q + +For 512 bit registers(check CV_SIMD512 preprocessor definition) +- Constructors: +@ref v_reg::v_reg(const _Tp *ptr) "from memory", +@ref v_reg::v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3, _Tp s4, _Tp s5, _Tp s6, _Tp s7) "from eight values", ... +- Other create methods: +@ref v512_setall_s8, @ref v512_setall_u8, ..., +@ref v512_setzero_u8, @ref v512_setzero_s8, ... +- Memory load operations: +@ref v512_load, @ref v512_load_aligned, @ref v512_load_low, @ref v512_load_halves, +- Memory operations with expansion of values: +@ref v512_load_expand, @ref v512_load_expand_q + +Store to memory operations are similar across different platform capabilities: @ref v_store, @ref v_store_aligned, @ref v_store_high, @ref v_store_low @@ -116,7 +211,7 @@ block and to save contents of the register to memory block. These operations allow to reorder or recombine elements in one or multiple vectors. - Interleave, deinterleave (2, 3 and 4 channels): @ref v_load_deinterleave, @ref v_store_interleave -- Expand: @ref v_load_expand, @ref v_load_expand_q, @ref v_expand, @ref v_expand_low, @ref v_expand_high +- Expand: @ref v_expand, @ref v_expand_low, @ref v_expand_high - Pack: @ref v_pack, @ref v_pack_u, @ref v_pack_b, @ref v_rshr_pack, @ref v_rshr_pack_u, @ref v_pack_store, @ref v_pack_u_store, @ref v_rshr_pack_store, @ref v_rshr_pack_u_store - Recombine: @ref v_zip, @ref v_recombine, @ref v_combine_low, @ref v_combine_high @@ -153,7 +248,7 @@ Element-wise binary and unary operations. @ref operator >=(const v_reg &a, const v_reg &b) ">=", @ref operator <(const v_reg &a, const v_reg &b) "<", @ref operator <=(const v_reg &a, const v_reg &b) "<=", -@ref operator==(const v_reg &a, const v_reg &b) "==", +@ref operator ==(const v_reg &a, const v_reg &b) "==", @ref operator !=(const v_reg &a, const v_reg &b) "!=" - min/max: @ref v_min, @ref v_max @@ -190,7 +285,7 @@ shows the applicability of different operations to the types. Regular integers: -| Operations\\Types | uint 8x16 | int 8x16 | uint 16x8 | int 16x8 | uint 32x4 | int 32x4 | +| Operations\\Types | uint 8 | int 8 | uint 16 | int 16 | uint 32 | int 32 | |-------------------|:-:|:-:|:-:|:-:|:-:|:-:| |load, store | x | x | x | x | x | x | |interleave | x | x | x | x | x | x | @@ -230,7 +325,7 @@ Regular integers: Big integers: -| Operations\\Types | uint 64x2 | int 64x2 | +| Operations\\Types | uint 64 | int 64 | |-------------------|:-:|:-:| |load, store | x | x | |add, sub | x | x | @@ -244,7 +339,7 @@ Big integers: Floating point: -| Operations\\Types | float 32x4 | float 64x2 | +| Operations\\Types | float 32 | float 64 | |-------------------|:-:|:-:| |load, store | x | x | |interleave | x | | @@ -410,6 +505,67 @@ typedef v_reg v_uint64x2; /** @brief Two 64-bit signed integer values */ typedef v_reg v_int64x2; +#if CV_SIMD256 +/** @brief Thirty two 8-bit unsigned integer values */ +typedef v_reg v_uint8x32; +/** @brief Thirty two 8-bit signed integer values */ +typedef v_reg v_int8x32; +/** @brief Sixteen 16-bit unsigned integer values */ +typedef v_reg v_uint16x16; +/** @brief Sixteen 16-bit signed integer values */ +typedef v_reg v_int16x16; +/** @brief Eight 32-bit unsigned integer values */ +typedef v_reg v_uint32x8; +/** @brief Eight 32-bit signed integer values */ +typedef v_reg v_int32x8; +/** @brief Eight 32-bit floating point values (single precision) */ +typedef v_reg v_float32x8; +/** @brief Four 64-bit floating point values (double precision) */ +typedef v_reg v_float64x4; +/** @brief Four 64-bit unsigned integer values */ +typedef v_reg v_uint64x4; +/** @brief Four 64-bit signed integer values */ +typedef v_reg v_int64x4; +#endif + +#if CV_SIMD512 +/** @brief Sixty four 8-bit unsigned integer values */ +typedef v_reg v_uint8x64; +/** @brief Sixty four 8-bit signed integer values */ +typedef v_reg v_int8x64; +/** @brief Thirty two 16-bit unsigned integer values */ +typedef v_reg v_uint16x32; +/** @brief Thirty two 16-bit signed integer values */ +typedef v_reg v_int16x32; +/** @brief Sixteen 32-bit unsigned integer values */ +typedef v_reg v_uint32x16; +/** @brief Sixteen 32-bit signed integer values */ +typedef v_reg v_int32x16; +/** @brief Sixteen 32-bit floating point values (single precision) */ +typedef v_reg v_float32x16; +/** @brief Eight 64-bit floating point values (double precision) */ +typedef v_reg v_float64x8; +/** @brief Eight 64-bit unsigned integer values */ +typedef v_reg v_uint64x8; +/** @brief Eight 64-bit signed integer values */ +typedef v_reg v_int64x8; +#endif + +enum { + simd128_width = 16, +#if CV_SIMD256 + simd256_width = 32, +#endif +#if CV_SIMD512 + simd512_width = 64, + simdmax_width = simd512_width +#elif CV_SIMD256 + simdmax_width = simd256_width +#else + simdmax_width = simd128_width +#endif +}; + /** @brief Add values For all types. */ @@ -559,27 +715,6 @@ template inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a) return c; \ } -//! @brief Helper macro -//! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(func, cfunc) \ -inline v_reg func(const v_reg& a) \ -{ \ - v_reg c; \ - for( int i = 0; i < 4; i++ ) \ - c.s[i] = cfunc(a.s[i]); \ - return c; \ -} \ -inline v_reg func(const v_reg& a) \ -{ \ - v_reg c; \ - for( int i = 0; i < 2; i++ ) \ - { \ - c.s[i] = cfunc(a.s[i]); \ - c.s[i + 2] = 0; \ - } \ - return c; \ -} - /** @brief Square root of elements Only for floating point types.*/ @@ -598,26 +733,6 @@ Only for floating point types.*/ OPENCV_HAL_IMPL_MATH_FUNC(v_abs, (typename V_TypeTraits<_Tp>::abs_type)std::abs, typename V_TypeTraits<_Tp>::abs_type) -/** @brief Round elements - -Only for floating point types.*/ -OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(v_round, cvRound) - -/** @brief Floor elements - -Only for floating point types.*/ -OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(v_floor, cvFloor) - -/** @brief Ceil elements - -Only for floating point types.*/ -OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(v_ceil, cvCeil) - -/** @brief Truncate elements - -Only for floating point types.*/ -OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(v_trunc, int) - //! @brief Helper macro //! @ingroup core_hal_intrin_impl #define OPENCV_HAL_IMPL_MINMAX_FUNC(func, cfunc) \ @@ -855,9 +970,9 @@ inline v_reg::abs_type, n> v_absdiff(const v_reg<_Tp, /** @overload For 32-bit floating point values */ -inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) +template inline v_reg v_absdiff(const v_reg& a, const v_reg& b) { - v_float32x4 c; + v_reg c; for( int i = 0; i < c.nlanes; i++ ) c.s[i] = _absdiff(a.s[i], b.s[i]); return c; @@ -866,9 +981,9 @@ inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) /** @overload For 64-bit floating point values */ -inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b) +template inline v_reg v_absdiff(const v_reg& a, const v_reg& b) { - v_float64x2 c; + v_reg c; for( int i = 0; i < c.nlanes; i++ ) c.s[i] = _absdiff(a.s[i], b.s[i]); return c; @@ -1238,14 +1353,17 @@ template inline typename V_TypeTraits<_Tp>::sum_type v_redu result[3] = d[0] + d[1] + d[2] + d[3] @endcode */ -inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, - const v_float32x4& c, const v_float32x4& d) +template inline v_reg v_reduce_sum4(const v_reg& a, const v_reg& b, + const v_reg& c, const v_reg& d) { - v_float32x4 r; - r.s[0] = a.s[0] + a.s[1] + a.s[2] + a.s[3]; - r.s[1] = b.s[0] + b.s[1] + b.s[2] + b.s[3]; - r.s[2] = c.s[0] + c.s[1] + c.s[2] + c.s[3]; - r.s[3] = d.s[0] + d.s[1] + d.s[2] + d.s[3]; + v_reg r; + for(int i = 0; i < (n/4); i++) + { + r.s[i*4 + 0] = a.s[i*4 + 0] + a.s[i*4 + 1] + a.s[i*4 + 2] + a.s[i*4 + 3]; + r.s[i*4 + 1] = b.s[i*4 + 0] + b.s[i*4 + 1] + b.s[i*4 + 2] + b.s[i*4 + 3]; + r.s[i*4 + 2] = c.s[i*4 + 0] + c.s[i*4 + 1] + c.s[i*4 + 2] + c.s[i*4 + 3]; + r.s[i*4 + 3] = d.s[i*4 + 0] + d.s[i*4 + 1] + d.s[i*4 + 2] + d.s[i*4 + 3]; + } return r; } @@ -1459,30 +1577,116 @@ template inline void v_zip( const v_reg<_Tp, n>& a0, const @note Returned type will be detected from passed pointer type, for example uchar ==> cv::v_uint8x16, int ==> cv::v_int32x4, etc. +@note Use vx_load version to get maximum available register length result + @note Alignment requirement: if CV_STRONG_ALIGNMENT=1 then passed pointer must be aligned (`sizeof(lane type)` should be enough). Do not cast pointer types without runtime check for pointer alignment (like `uchar*` => `int*`). */ template -inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load(const _Tp* ptr) +inline v_reg<_Tp, simd128_width / sizeof(_Tp)> v_load(const _Tp* ptr) { #if CV_STRONG_ALIGNMENT CV_Assert(isAligned(ptr)); #endif - return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); + return v_reg<_Tp, simd128_width / sizeof(_Tp)>(ptr); } +#if CV_SIMD256 +/** @brief Load 256-bit length register contents from memory + +@param ptr pointer to memory block with data +@return register object + +@note Returned type will be detected from passed pointer type, for example uchar ==> cv::v_uint8x32, int ==> cv::v_int32x8, etc. + +@note Check CV_SIMD256 preprocessor definition prior to use. +Use vx_load version to get maximum available register length result + +@note Alignment requirement: +if CV_STRONG_ALIGNMENT=1 then passed pointer must be aligned (`sizeof(lane type)` should be enough). +Do not cast pointer types without runtime check for pointer alignment (like `uchar*` => `int*`). + */ +template +inline v_reg<_Tp, simd256_width / sizeof(_Tp)> v256_load(const _Tp* ptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(ptr)); +#endif + return v_reg<_Tp, simd256_width / sizeof(_Tp)>(ptr); +} +#endif + +#if CV_SIMD512 +/** @brief Load 512-bit length register contents from memory + +@param ptr pointer to memory block with data +@return register object + +@note Returned type will be detected from passed pointer type, for example uchar ==> cv::v_uint8x64, int ==> cv::v_int32x16, etc. + +@note Check CV_SIMD512 preprocessor definition prior to use. +Use vx_load version to get maximum available register length result + +@note Alignment requirement: +if CV_STRONG_ALIGNMENT=1 then passed pointer must be aligned (`sizeof(lane type)` should be enough). +Do not cast pointer types without runtime check for pointer alignment (like `uchar*` => `int*`). + */ +template +inline v_reg<_Tp, simd512_width / sizeof(_Tp)> v512_load(const _Tp* ptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(ptr)); +#endif + return v_reg<_Tp, simd512_width / sizeof(_Tp)>(ptr); +} +#endif + /** @brief Load register contents from memory (aligned) similar to cv::v_load, but source memory block should be aligned (to 16-byte boundary in case of SIMD128, 32-byte - SIMD256, etc) - */ + +@note Use vx_load_aligned version to get maximum available register length result +*/ template -inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_aligned(const _Tp* ptr) +inline v_reg<_Tp, simd128_width / sizeof(_Tp)> v_load_aligned(const _Tp* ptr) { - CV_Assert(isAligned::nlanes128>)>(ptr)); - return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); + CV_Assert(isAligned)>(ptr)); + return v_reg<_Tp, simd128_width / sizeof(_Tp)>(ptr); } +#if CV_SIMD256 +/** @brief Load register contents from memory (aligned) + +similar to cv::v256_load, but source memory block should be aligned (to 32-byte boundary in case of SIMD256, 64-byte - SIMD512, etc) + +@note Check CV_SIMD256 preprocessor definition prior to use. +Use vx_load_aligned version to get maximum available register length result +*/ +template +inline v_reg<_Tp, simd256_width / sizeof(_Tp)> v256_load_aligned(const _Tp* ptr) +{ + CV_Assert(isAligned)>(ptr)); + return v_reg<_Tp, simd256_width / sizeof(_Tp)>(ptr); +} +#endif + +#if CV_SIMD512 +/** @brief Load register contents from memory (aligned) + +similar to cv::v512_load, but source memory block should be aligned (to 64-byte boundary in case of SIMD512, etc) + +@note Check CV_SIMD512 preprocessor definition prior to use. +Use vx_load_aligned version to get maximum available register length result +*/ +template +inline v_reg<_Tp, simd512_width / sizeof(_Tp)> v512_load_aligned(const _Tp* ptr) +{ + CV_Assert(isAligned)>(ptr)); + return v_reg<_Tp, simd512_width / sizeof(_Tp)>(ptr); +} +#endif + /** @brief Load 64-bits of data to lower part (high part is undefined). @param ptr memory block containing data for first half (0..n/2) @@ -1491,14 +1695,16 @@ inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_aligned(const _Tp* ptr) int lo[2] = { 1, 2 }; v_int32x4 r = v_load_low(lo); @endcode - */ + +@note Use vx_load_low version to get maximum available register length result +*/ template -inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_low(const _Tp* ptr) +inline v_reg<_Tp, simd128_width / sizeof(_Tp)> v_load_low(const _Tp* ptr) { #if CV_STRONG_ALIGNMENT CV_Assert(isAligned(ptr)); #endif - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + v_reg<_Tp, simd128_width / sizeof(_Tp)> c; for( int i = 0; i < c.nlanes/2; i++ ) { c.s[i] = ptr[i]; @@ -1506,6 +1712,62 @@ inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_low(const _Tp* ptr) return c; } +#if CV_SIMD256 +/** @brief Load 128-bits of data to lower part (high part is undefined). + +@param ptr memory block containing data for first half (0..n/2) + +@code{.cpp} +int lo[4] = { 1, 2, 3, 4 }; +v_int32x8 r = v256_load_low(lo); +@endcode + +@note Check CV_SIMD256 preprocessor definition prior to use. +Use vx_load_low version to get maximum available register length result +*/ +template +inline v_reg<_Tp, simd256_width / sizeof(_Tp)> v256_load_low(const _Tp* ptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(ptr)); +#endif + v_reg<_Tp, simd256_width / sizeof(_Tp)> c; + for (int i = 0; i < c.nlanes / 2; i++) + { + c.s[i] = ptr[i]; + } + return c; +} +#endif + +#if CV_SIMD512 +/** @brief Load 256-bits of data to lower part (high part is undefined). + +@param ptr memory block containing data for first half (0..n/2) + +@code{.cpp} +int lo[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; +v_int32x16 r = v512_load_low(lo); +@endcode + +@note Check CV_SIMD512 preprocessor definition prior to use. +Use vx_load_low version to get maximum available register length result +*/ +template +inline v_reg<_Tp, simd512_width / sizeof(_Tp)> v512_load_low(const _Tp* ptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(ptr)); +#endif + v_reg<_Tp, simd512_width / sizeof(_Tp)> c; + for (int i = 0; i < c.nlanes / 2; i++) + { + c.s[i] = ptr[i]; + } + return c; +} +#endif + /** @brief Load register contents from two memory blocks @param loptr memory block containing data for first half (0..n/2) @@ -1515,15 +1777,17 @@ inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_low(const _Tp* ptr) int lo[2] = { 1, 2 }, hi[2] = { 3, 4 }; v_int32x4 r = v_load_halves(lo, hi); @endcode - */ + +@note Use vx_load_halves version to get maximum available register length result +*/ template -inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_halves(const _Tp* loptr, const _Tp* hiptr) +inline v_reg<_Tp, simd128_width / sizeof(_Tp)> v_load_halves(const _Tp* loptr, const _Tp* hiptr) { #if CV_STRONG_ALIGNMENT CV_Assert(isAligned(loptr)); CV_Assert(isAligned(hiptr)); #endif - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + v_reg<_Tp, simd128_width / sizeof(_Tp)> c; for( int i = 0; i < c.nlanes/2; i++ ) { c.s[i] = loptr[i]; @@ -1532,6 +1796,68 @@ inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_halves(const _Tp* loptr, return c; } +#if CV_SIMD256 +/** @brief Load register contents from two memory blocks + +@param loptr memory block containing data for first half (0..n/2) +@param hiptr memory block containing data for second half (n/2..n) + +@code{.cpp} +int lo[4] = { 1, 2, 3, 4 }, hi[4] = { 5, 6, 7, 8 }; +v_int32x8 r = v256_load_halves(lo, hi); +@endcode + +@note Check CV_SIMD256 preprocessor definition prior to use. +Use vx_load_halves version to get maximum available register length result +*/ +template +inline v_reg<_Tp, simd256_width / sizeof(_Tp)> v256_load_halves(const _Tp* loptr, const _Tp* hiptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(loptr)); + CV_Assert(isAligned(hiptr)); +#endif + v_reg<_Tp, simd256_width / sizeof(_Tp)> c; + for (int i = 0; i < c.nlanes / 2; i++) + { + c.s[i] = loptr[i]; + c.s[i + c.nlanes / 2] = hiptr[i]; + } + return c; +} +#endif + +#if CV_SIMD512 +/** @brief Load register contents from two memory blocks + +@param loptr memory block containing data for first half (0..n/2) +@param hiptr memory block containing data for second half (n/2..n) + +@code{.cpp} +int lo[4] = { 1, 2, 3, 4, 5, 6, 7, 8 }, hi[4] = { 9, 10, 11, 12, 13, 14, 15, 16 }; +v_int32x16 r = v512_load_halves(lo, hi); +@endcode + +@note Check CV_SIMD512 preprocessor definition prior to use. +Use vx_load_halves version to get maximum available register length result +*/ +template +inline v_reg<_Tp, simd512_width / sizeof(_Tp)> v512_load_halves(const _Tp* loptr, const _Tp* hiptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(loptr)); + CV_Assert(isAligned(hiptr)); +#endif + v_reg<_Tp, simd512_width / sizeof(_Tp)> c; + for (int i = 0; i < c.nlanes / 2; i++) + { + c.s[i] = loptr[i]; + c.s[i + c.nlanes / 2] = hiptr[i]; + } + return c; +} +#endif + /** @brief Load register contents from memory with double expand Same as cv::v_load, but result pack type will be 2x wider than memory type. @@ -1540,16 +1866,19 @@ Same as cv::v_load, but result pack type will be 2x wider than memory type. short buf[4] = {1, 2, 3, 4}; // type is int16 v_int32x4 r = v_load_expand(buf); // r = {1, 2, 3, 4} - type is int32 @endcode -For 8-, 16-, 32-bit integer source types. */ +For 8-, 16-, 32-bit integer source types. + +@note Use vx_load_expand version to get maximum available register length result +*/ template -inline v_reg::w_type, V_TypeTraits<_Tp>::nlanes128 / 2> +inline v_reg::w_type, simd128_width / sizeof(typename V_TypeTraits<_Tp>::w_type)> v_load_expand(const _Tp* ptr) { #if CV_STRONG_ALIGNMENT CV_Assert(isAligned(ptr)); #endif typedef typename V_TypeTraits<_Tp>::w_type w_type; - v_reg::nlanes128> c; + v_reg c; for( int i = 0; i < c.nlanes; i++ ) { c.s[i] = ptr[i]; @@ -1557,23 +1886,88 @@ v_load_expand(const _Tp* ptr) return c; } +#if CV_SIMD256 +/** @brief Load register contents from memory with double expand + +Same as cv::v256_load, but result pack type will be 2x wider than memory type. + +@code{.cpp} +short buf[8] = {1, 2, 3, 4, 5, 6, 7, 8}; // type is int16 +v_int32x8 r = v256_load_expand(buf); // r = {1, 2, 3, 4, 5, 6, 7, 8} - type is int32 +@endcode +For 8-, 16-, 32-bit integer source types. + +@note Check CV_SIMD256 preprocessor definition prior to use. +Use vx_load_expand version to get maximum available register length result +*/ +template +inline v_reg::w_type, simd256_width / sizeof(typename V_TypeTraits<_Tp>::w_type)> +v256_load_expand(const _Tp* ptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(ptr)); +#endif + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg c; + for (int i = 0; i < c.nlanes; i++) + { + c.s[i] = ptr[i]; + } + return c; +} +#endif + +#if CV_SIMD512 +/** @brief Load register contents from memory with double expand + +Same as cv::v512_load, but result pack type will be 2x wider than memory type. + +@code{.cpp} +short buf[8] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; // type is int16 +v_int32x16 r = v512_load_expand(buf); // r = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} - type is int32 +@endcode +For 8-, 16-, 32-bit integer source types. + +@note Check CV_SIMD512 preprocessor definition prior to use. +Use vx_load_expand version to get maximum available register length result +*/ +template +inline v_reg::w_type, simd512_width / sizeof(typename V_TypeTraits<_Tp>::w_type)> +v512_load_expand(const _Tp* ptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(ptr)); +#endif + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg c; + for (int i = 0; i < c.nlanes; i++) + { + c.s[i] = ptr[i]; + } + return c; +} +#endif + /** @brief Load register contents from memory with quad expand Same as cv::v_load_expand, but result type is 4 times wider than source. @code{.cpp} char buf[4] = {1, 2, 3, 4}; // type is int8 -v_int32x4 r = v_load_q(buf); // r = {1, 2, 3, 4} - type is int32 +v_int32x4 r = v_load_expand_q(buf); // r = {1, 2, 3, 4} - type is int32 @endcode -For 8-bit integer source types. */ +For 8-bit integer source types. + +@note Use vx_load_expand_q version to get maximum available register length result +*/ template -inline v_reg::q_type, V_TypeTraits<_Tp>::nlanes128 / 4> +inline v_reg::q_type, simd128_width / sizeof(typename V_TypeTraits<_Tp>::q_type)> v_load_expand_q(const _Tp* ptr) { #if CV_STRONG_ALIGNMENT CV_Assert(isAligned(ptr)); #endif typedef typename V_TypeTraits<_Tp>::q_type q_type; - v_reg::nlanes128> c; + v_reg c; for( int i = 0; i < c.nlanes; i++ ) { c.s[i] = ptr[i]; @@ -1581,6 +1975,66 @@ v_load_expand_q(const _Tp* ptr) return c; } +#if CV_SIMD256 +/** @brief Load register contents from memory with quad expand + +Same as cv::v256_load_expand, but result type is 4 times wider than source. +@code{.cpp} +char buf[8] = {1, 2, 3, 4, 5, 6, 7, 8}; // type is int8 +v_int32x8 r = v256_load_expand_q(buf); // r = {1, 2, 3, 4, 5, 6, 7, 8} - type is int32 +@endcode +For 8-bit integer source types. + +@note Check CV_SIMD256 preprocessor definition prior to use. +Use vx_load_expand_q version to get maximum available register length result +*/ +template +inline v_reg::q_type, simd256_width / sizeof(typename V_TypeTraits<_Tp>::q_type)> +v256_load_expand_q(const _Tp* ptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(ptr)); +#endif + typedef typename V_TypeTraits<_Tp>::q_type q_type; + v_reg c; + for (int i = 0; i < c.nlanes; i++) + { + c.s[i] = ptr[i]; + } + return c; +} +#endif + +#if CV_SIMD512 +/** @brief Load register contents from memory with quad expand + +Same as cv::v512_load_expand, but result type is 4 times wider than source. +@code{.cpp} +char buf[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; // type is int8 +v_int32x16 r = v512_load_expand_q(buf); // r = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} - type is int32 +@endcode +For 8-bit integer source types. + +@note Check CV_SIMD512 preprocessor definition prior to use. +Use vx_load_expand_q version to get maximum available register length result +*/ +template +inline v_reg::q_type, simd512_width / sizeof(typename V_TypeTraits<_Tp>::q_type)> +v512_load_expand_q(const _Tp* ptr) +{ +#if CV_STRONG_ALIGNMENT + CV_Assert(isAligned(ptr)); +#endif + typedef typename V_TypeTraits<_Tp>::q_type q_type; + v_reg c; + for (int i = 0; i < c.nlanes; i++) + { + c.s[i] = ptr[i]; + } + return c; +} +#endif + /** @brief Load and deinterleave (2 channels) Load data from memory deinterleave and store to 2 registers. @@ -1965,9 +2419,11 @@ inline v_reg<_Tp, n> v_broadcast_element(const v_reg<_Tp, n>& a) return v_reg<_Tp, n>::all(a.s[i]); } -/** @brief Round +/** @brief Round elements -Rounds each value. Input type is float vector ==> output type is int vector.*/ +Rounds each value. Input type is float vector ==> output type is int vector. +@note Only for floating point types. +*/ template inline v_reg v_round(const v_reg& a) { v_reg c; @@ -1988,9 +2444,11 @@ template inline v_reg v_round(const v_reg& a, const return c; } -/** @brief Floor +/** @brief Floor elements -Floor each value. Input type is float vector ==> output type is int vector.*/ +Floor each value. Input type is float vector ==> output type is int vector. +@note Only for floating point types. +*/ template inline v_reg v_floor(const v_reg& a) { v_reg c; @@ -1999,9 +2457,11 @@ template inline v_reg v_floor(const v_reg& a) return c; } -/** @brief Ceil +/** @brief Ceil elements -Ceil each value. Input type is float vector ==> output type is int vector.*/ +Ceil each value. Input type is float vector ==> output type is int vector. +@note Only for floating point types. +*/ template inline v_reg v_ceil(const v_reg& a) { v_reg c; @@ -2010,9 +2470,11 @@ template inline v_reg v_ceil(const v_reg& a) return c; } -/** @brief Trunc +/** @brief Truncate elements -Truncate each value. Input type is float vector ==> output type is int vector.*/ +Truncate each value. Input type is float vector ==> output type is int vector. +@note Only for floating point types. +*/ template inline v_reg v_trunc(const v_reg& a) { v_reg c; @@ -2036,7 +2498,7 @@ template inline v_reg v_round(const v_reg& a) /** @overload */ template inline v_reg v_floor(const v_reg& a) { - v_reg c; + v_reg c; for( int i = 0; i < n; i++ ) { c.s[i] = cvFloor(a.s[i]); @@ -2048,7 +2510,7 @@ template inline v_reg v_floor(const v_reg& a) /** @overload */ template inline v_reg v_ceil(const v_reg& a) { - v_reg c; + v_reg c; for( int i = 0; i < n; i++ ) { c.s[i] = cvCeil(a.s[i]); @@ -2060,10 +2522,10 @@ template inline v_reg v_ceil(const v_reg& a) /** @overload */ template inline v_reg v_trunc(const v_reg& a) { - v_reg c; + v_reg c; for( int i = 0; i < n; i++ ) { - c.s[i] = cvCeil(a.s[i]); + c.s[i] = (int)(a.s[i]); c.s[i+n] = 0; } return c; @@ -2071,7 +2533,7 @@ template inline v_reg v_trunc(const v_reg& a) /** @brief Convert to float -Supported input type is cv::v_int32x4. */ +Supported input type is cv::v_int32. */ template inline v_reg v_cvt_f32(const v_reg& a) { v_reg c; @@ -2080,6 +2542,9 @@ template inline v_reg v_cvt_f32(const v_reg& a) return c; } +/** @brief Convert lower half to float + +Supported input type is cv::v_float64. */ template inline v_reg v_cvt_f32(const v_reg& a) { v_reg c; @@ -2091,6 +2556,9 @@ template inline v_reg v_cvt_f32(const v_reg& a) return c; } +/** @brief Convert to float + +Supported input type is cv::v_float64. */ template inline v_reg v_cvt_f32(const v_reg& a, const v_reg& b) { v_reg c; @@ -2102,72 +2570,55 @@ template inline v_reg v_cvt_f32(const v_reg& a, co return c; } -/** @brief Convert to double +/** @brief Convert lower half to double -Supported input type is cv::v_int32x4. */ -CV_INLINE v_reg v_cvt_f64(const v_reg& a) +Supported input type is cv::v_int32. */ +template CV_INLINE v_reg v_cvt_f64(const v_reg& a) { - enum { n = 2 }; - v_reg c; - for( int i = 0; i < n; i++ ) + v_reg c; + for( int i = 0; i < (n/2); i++ ) c.s[i] = (double)a.s[i]; return c; } /** @brief Convert to double high part of vector -Supported input type is cv::v_int32x4. */ -CV_INLINE v_reg v_cvt_f64_high(const v_reg& a) +Supported input type is cv::v_int32. */ +template CV_INLINE v_reg v_cvt_f64_high(const v_reg& a) { - enum { n = 2 }; - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = (double)a.s[i + 2]; + v_reg c; + for( int i = 0; i < (n/2); i++ ) + c.s[i] = (double)a.s[i + (n/2)]; return c; } -/** @brief Convert to double +/** @brief Convert lower half to double -Supported input type is cv::v_float32x4. */ -CV_INLINE v_reg v_cvt_f64(const v_reg& a) +Supported input type is cv::v_float32. */ +template CV_INLINE v_reg v_cvt_f64(const v_reg& a) { - enum { n = 2 }; - v_reg c; - for( int i = 0; i < n; i++ ) + v_reg c; + for( int i = 0; i < (n/2); i++ ) c.s[i] = (double)a.s[i]; return c; } /** @brief Convert to double high part of vector -Supported input type is cv::v_float32x4. */ -CV_INLINE v_reg v_cvt_f64_high(const v_reg& a) +Supported input type is cv::v_float32. */ +template CV_INLINE v_reg v_cvt_f64_high(const v_reg& a) { - enum { n = 2 }; - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = (double)a.s[i + 2]; + v_reg c; + for( int i = 0; i < (n/2); i++ ) + c.s[i] = (double)a.s[i + (n/2)]; return c; } /** @brief Convert to double -Supported input type is cv::v_int64x2. */ -CV_INLINE v_reg v_cvt_f64(const v_reg& a) +Supported input type is cv::v_int64. */ +template CV_INLINE v_reg v_cvt_f64(const v_reg& a) { - enum { n = 2 }; - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = (double)a.s[i]; - return c; -} - -/** @brief Convert to double high part of vector - -Supported input type is cv::v_int64x2. */ -CV_INLINE v_reg v_cvt_f64_high(const v_reg& a) -{ - enum { n = 2 }; v_reg c; for( int i = 0; i < n; i++ ) c.s[i] = (double)a.s[i]; @@ -2175,24 +2626,24 @@ CV_INLINE v_reg v_cvt_f64_high(const v_reg& a) } -template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut(const _Tp* tab, const int* idx) +template inline v_reg<_Tp, simd128_width / sizeof(_Tp)> v_lut(const _Tp* tab, const int* idx) { - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; - for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + v_reg<_Tp, simd128_width / sizeof(_Tp)> c; + for (int i = 0; i < c.nlanes; i++) c.s[i] = tab[idx[i]]; return c; } -template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_pairs(const _Tp* tab, const int* idx) +template inline v_reg<_Tp, simd128_width / sizeof(_Tp)> v_lut_pairs(const _Tp* tab, const int* idx) { - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; - for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + v_reg<_Tp, simd128_width / sizeof(_Tp)> c; + for (int i = 0; i < c.nlanes; i++) c.s[i] = tab[idx[i / 2] + i % 2]; return c; } -template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_quads(const _Tp* tab, const int* idx) +template inline v_reg<_Tp, simd128_width / sizeof(_Tp)> v_lut_quads(const _Tp* tab, const int* idx) { - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; - for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + v_reg<_Tp, simd128_width / sizeof(_Tp)> c; + for (int i = 0; i < c.nlanes; i++) c.s[i] = tab[idx[i / 4] + i % 4]; return c; } @@ -2221,36 +2672,15 @@ template inline v_reg v_lut(const float* tab, const v_reg inline v_reg v_lut(const double* tab, const v_reg& idx) +template inline v_reg v_lut(const double* tab, const v_reg& idx) { - v_reg c; - for( int i = 0; i < n; i++ ) + v_reg c; + for( int i = 0; i < n/2; i++ ) c.s[i] = tab[idx.s[i]]; return c; } -inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) -{ - return v_lut(tab, idxvec.s); -} - -inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) -{ - return v_lut(tab, idxvec.s); -} - -inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) -{ - return v_lut(tab, idxvec.s); -} - -inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) -{ - return v_lut(tab, idxvec.s); -} - - template inline void v_lut_deinterleave(const float* tab, const v_reg& idx, v_reg& x, v_reg& y) { @@ -2330,146 +2760,205 @@ b2 {A3 B3 C3 D3} b3 {A4 B4 C4 D4} @endcode */ -template -inline void v_transpose4x4( v_reg<_Tp, 4>& a0, const v_reg<_Tp, 4>& a1, - const v_reg<_Tp, 4>& a2, const v_reg<_Tp, 4>& a3, - v_reg<_Tp, 4>& b0, v_reg<_Tp, 4>& b1, - v_reg<_Tp, 4>& b2, v_reg<_Tp, 4>& b3 ) +template +inline void v_transpose4x4( v_reg<_Tp, n>& a0, const v_reg<_Tp, n>& a1, + const v_reg<_Tp, n>& a2, const v_reg<_Tp, n>& a3, + v_reg<_Tp, n>& b0, v_reg<_Tp, n>& b1, + v_reg<_Tp, n>& b2, v_reg<_Tp, n>& b3 ) { - b0 = v_reg<_Tp, 4>(a0.s[0], a1.s[0], a2.s[0], a3.s[0]); - b1 = v_reg<_Tp, 4>(a0.s[1], a1.s[1], a2.s[1], a3.s[1]); - b2 = v_reg<_Tp, 4>(a0.s[2], a1.s[2], a2.s[2], a3.s[2]); - b3 = v_reg<_Tp, 4>(a0.s[3], a1.s[3], a2.s[3], a3.s[3]); + for (int i = 0; i < n / 4; i++) + { + b0.s[0 + i*4] = a0.s[0 + i*4]; b0.s[1 + i*4] = a1.s[0 + i*4]; + b0.s[2 + i*4] = a2.s[0 + i*4]; b0.s[3 + i*4] = a3.s[0 + i*4]; + b1.s[0 + i*4] = a0.s[1 + i*4]; b1.s[1 + i*4] = a1.s[1 + i*4]; + b1.s[2 + i*4] = a2.s[1 + i*4]; b1.s[3 + i*4] = a3.s[1 + i*4]; + b2.s[0 + i*4] = a0.s[2 + i*4]; b2.s[1 + i*4] = a1.s[2 + i*4]; + b2.s[2 + i*4] = a2.s[2 + i*4]; b2.s[3 + i*4] = a3.s[2 + i*4]; + b3.s[0 + i*4] = a0.s[3 + i*4]; b3.s[1 + i*4] = a1.s[3 + i*4]; + b3.s[2 + i*4] = a2.s[3 + i*4]; b3.s[3 + i*4] = a3.s[3 + i*4]; + } } //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_INIT_ZERO(_Tpvec, _Tp, suffix) \ -inline _Tpvec v_setzero_##suffix() { return _Tpvec::zero(); } +#define OPENCV_HAL_IMPL_C_INIT_ZERO(_Tpvec, prefix, suffix) \ +inline _Tpvec prefix##_setzero_##suffix() { return _Tpvec::zero(); } //! @name Init with zero //! @{ //! @brief Create new vector with zero elements -OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint8x16, uchar, u8) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_int8x16, schar, s8) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint16x8, ushort, u16) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_int16x8, short, s16) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint32x4, unsigned, u32) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_int32x4, int, s32) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_float32x4, float, f32) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_float64x2, double, f64) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint64x2, uint64, u64) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_int64x2, int64, s64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint8x16, v, u8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int8x16, v, s8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint16x8, v, u16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int16x8, v, s16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint32x4, v, u32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int32x4, v, s32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float32x4, v, f32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float64x2, v, f64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint64x2, v, u64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int64x2, v, s64) + +#if CV_SIMD256 +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint8x32, v256, u8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int8x32, v256, s8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint16x16, v256, u16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int16x16, v256, s16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint32x8, v256, u32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int32x8, v256, s32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float32x8, v256, f32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float64x4, v256, f64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint64x4, v256, u64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int64x4, v256, s64) +#endif + +#if CV_SIMD512 +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint8x64, v512, u8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int8x64, v512, s8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint16x32, v512, u16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int16x32, v512, s16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint32x16, v512, u32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int32x16, v512, s32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float32x16, v512, f32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float64x8, v512, f64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint64x8, v512, u64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int64x8, v512, s64) +#endif //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_INIT_VAL(_Tpvec, _Tp, suffix) \ -inline _Tpvec v_setall_##suffix(_Tp val) { return _Tpvec::all(val); } +#define OPENCV_HAL_IMPL_C_INIT_VAL(_Tpvec, _Tp, prefix, suffix) \ +inline _Tpvec prefix##_setall_##suffix(_Tp val) { return _Tpvec::all(val); } //! @name Init with value //! @{ //! @brief Create new vector with elements set to a specific value -OPENCV_HAL_IMPL_C_INIT_VAL(v_uint8x16, uchar, u8) -OPENCV_HAL_IMPL_C_INIT_VAL(v_int8x16, schar, s8) -OPENCV_HAL_IMPL_C_INIT_VAL(v_uint16x8, ushort, u16) -OPENCV_HAL_IMPL_C_INIT_VAL(v_int16x8, short, s16) -OPENCV_HAL_IMPL_C_INIT_VAL(v_uint32x4, unsigned, u32) -OPENCV_HAL_IMPL_C_INIT_VAL(v_int32x4, int, s32) -OPENCV_HAL_IMPL_C_INIT_VAL(v_float32x4, float, f32) -OPENCV_HAL_IMPL_C_INIT_VAL(v_float64x2, double, f64) -OPENCV_HAL_IMPL_C_INIT_VAL(v_uint64x2, uint64, u64) -OPENCV_HAL_IMPL_C_INIT_VAL(v_int64x2, int64, s64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint8x16, uchar, v, u8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int8x16, schar, v, s8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint16x8, ushort, v, u16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int16x8, short, v, s16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint32x4, unsigned, v, u32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int32x4, int, v, s32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float32x4, float, v, f32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float64x2, double, v, f64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint64x2, uint64, v, u64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int64x2, int64, v, s64) + +#if CV_SIMD256 +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint8x32, uchar, v256, u8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int8x32, schar, v256, s8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint16x16, ushort, v256, u16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int16x16, short, v256, s16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint32x8, unsigned, v256, u32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int32x8, int, v256, s32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float32x8, float, v256, f32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float64x4, double, v256, f64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint64x4, uint64, v256, u64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int64x4, int64, v256, s64) +#endif + +#if CV_SIMD512 +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint8x64, uchar, v512, u8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int8x64, schar, v512, s8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint16x32, ushort, v512, u16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int16x32, short, v512, s16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint32x16, unsigned, v512, u32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int32x16, int, v512, s32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float32x16, float, v512, f32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float64x8, double, v512, f64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint64x8, uint64, v512, u64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int64x8, int64, v512, s64) +#endif //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_REINTERPRET(_Tpvec, _Tp, suffix) \ -template inline _Tpvec \ +#define OPENCV_HAL_IMPL_C_REINTERPRET(_Tp, suffix) \ +template inline v_reg<_Tp, n0*sizeof(_Tp0)/sizeof(_Tp)> \ v_reinterpret_as_##suffix(const v_reg<_Tp0, n0>& a) \ -{ return a.template reinterpret_as<_Tp, _Tpvec::nlanes>(); } +{ return a.template reinterpret_as<_Tp, n0*sizeof(_Tp0)/sizeof(_Tp)>(); } //! @name Reinterpret //! @{ //! @brief Convert vector to different type without modifying underlying data. -OPENCV_HAL_IMPL_C_REINTERPRET(v_uint8x16, uchar, u8) -OPENCV_HAL_IMPL_C_REINTERPRET(v_int8x16, schar, s8) -OPENCV_HAL_IMPL_C_REINTERPRET(v_uint16x8, ushort, u16) -OPENCV_HAL_IMPL_C_REINTERPRET(v_int16x8, short, s16) -OPENCV_HAL_IMPL_C_REINTERPRET(v_uint32x4, unsigned, u32) -OPENCV_HAL_IMPL_C_REINTERPRET(v_int32x4, int, s32) -OPENCV_HAL_IMPL_C_REINTERPRET(v_float32x4, float, f32) -OPENCV_HAL_IMPL_C_REINTERPRET(v_float64x2, double, f64) -OPENCV_HAL_IMPL_C_REINTERPRET(v_uint64x2, uint64, u64) -OPENCV_HAL_IMPL_C_REINTERPRET(v_int64x2, int64, s64) +OPENCV_HAL_IMPL_C_REINTERPRET(uchar, u8) +OPENCV_HAL_IMPL_C_REINTERPRET(schar, s8) +OPENCV_HAL_IMPL_C_REINTERPRET(ushort, u16) +OPENCV_HAL_IMPL_C_REINTERPRET(short, s16) +OPENCV_HAL_IMPL_C_REINTERPRET(unsigned, u32) +OPENCV_HAL_IMPL_C_REINTERPRET(int, s32) +OPENCV_HAL_IMPL_C_REINTERPRET(float, f32) +OPENCV_HAL_IMPL_C_REINTERPRET(double, f64) +OPENCV_HAL_IMPL_C_REINTERPRET(uint64, u64) +OPENCV_HAL_IMPL_C_REINTERPRET(int64, s64) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_SHIFTL(_Tpvec, _Tp) \ -template inline _Tpvec v_shl(const _Tpvec& a) \ -{ return a << n; } +#define OPENCV_HAL_IMPL_C_SHIFTL(_Tp) \ +template inline v_reg<_Tp, n> v_shl(const v_reg<_Tp, n>& a) \ +{ return a << shift; } //! @name Left shift //! @{ //! @brief Shift left -OPENCV_HAL_IMPL_C_SHIFTL(v_uint16x8, ushort) -OPENCV_HAL_IMPL_C_SHIFTL(v_int16x8, short) -OPENCV_HAL_IMPL_C_SHIFTL(v_uint32x4, unsigned) -OPENCV_HAL_IMPL_C_SHIFTL(v_int32x4, int) -OPENCV_HAL_IMPL_C_SHIFTL(v_uint64x2, uint64) -OPENCV_HAL_IMPL_C_SHIFTL(v_int64x2, int64) +OPENCV_HAL_IMPL_C_SHIFTL(ushort) +OPENCV_HAL_IMPL_C_SHIFTL(short) +OPENCV_HAL_IMPL_C_SHIFTL(unsigned) +OPENCV_HAL_IMPL_C_SHIFTL(int) +OPENCV_HAL_IMPL_C_SHIFTL(uint64) +OPENCV_HAL_IMPL_C_SHIFTL(int64) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_SHIFTR(_Tpvec, _Tp) \ -template inline _Tpvec v_shr(const _Tpvec& a) \ -{ return a >> n; } +#define OPENCV_HAL_IMPL_C_SHIFTR(_Tp) \ +template inline v_reg<_Tp, n> v_shr(const v_reg<_Tp, n>& a) \ +{ return a >> shift; } //! @name Right shift //! @{ //! @brief Shift right -OPENCV_HAL_IMPL_C_SHIFTR(v_uint16x8, ushort) -OPENCV_HAL_IMPL_C_SHIFTR(v_int16x8, short) -OPENCV_HAL_IMPL_C_SHIFTR(v_uint32x4, unsigned) -OPENCV_HAL_IMPL_C_SHIFTR(v_int32x4, int) -OPENCV_HAL_IMPL_C_SHIFTR(v_uint64x2, uint64) -OPENCV_HAL_IMPL_C_SHIFTR(v_int64x2, int64) +OPENCV_HAL_IMPL_C_SHIFTR(ushort) +OPENCV_HAL_IMPL_C_SHIFTR(short) +OPENCV_HAL_IMPL_C_SHIFTR(unsigned) +OPENCV_HAL_IMPL_C_SHIFTR(int) +OPENCV_HAL_IMPL_C_SHIFTR(uint64) +OPENCV_HAL_IMPL_C_SHIFTR(int64) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_RSHIFTR(_Tpvec, _Tp) \ -template inline _Tpvec v_rshr(const _Tpvec& a) \ +#define OPENCV_HAL_IMPL_C_RSHIFTR(_Tp) \ +template inline v_reg<_Tp, n> v_rshr(const v_reg<_Tp, n>& a) \ { \ - _Tpvec c; \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ - c.s[i] = (_Tp)((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = (_Tp)((a.s[i] + ((_Tp)1 << (shift - 1))) >> shift); \ return c; \ } //! @name Rounding shift //! @{ //! @brief Rounding shift right -OPENCV_HAL_IMPL_C_RSHIFTR(v_uint16x8, ushort) -OPENCV_HAL_IMPL_C_RSHIFTR(v_int16x8, short) -OPENCV_HAL_IMPL_C_RSHIFTR(v_uint32x4, unsigned) -OPENCV_HAL_IMPL_C_RSHIFTR(v_int32x4, int) -OPENCV_HAL_IMPL_C_RSHIFTR(v_uint64x2, uint64) -OPENCV_HAL_IMPL_C_RSHIFTR(v_int64x2, int64) +OPENCV_HAL_IMPL_C_RSHIFTR(ushort) +OPENCV_HAL_IMPL_C_RSHIFTR(short) +OPENCV_HAL_IMPL_C_RSHIFTR(unsigned) +OPENCV_HAL_IMPL_C_RSHIFTR(int) +OPENCV_HAL_IMPL_C_RSHIFTR(uint64) +OPENCV_HAL_IMPL_C_RSHIFTR(int64) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_PACK(_Tpvec, _Tpnvec, _Tpn, pack_suffix, cast) \ -inline _Tpnvec v_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ +#define OPENCV_HAL_IMPL_C_PACK(_Tp, _Tpn, pack_suffix, cast) \ +template inline v_reg<_Tpn, 2*n> v_##pack_suffix(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ { \ - _Tpnvec c; \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + v_reg<_Tpn, 2*n> c; \ + for( int i = 0; i < n; i++ ) \ { \ c.s[i] = cast<_Tpn>(a.s[i]); \ - c.s[i+_Tpvec::nlanes] = cast<_Tpn>(b.s[i]); \ + c.s[i+n] = cast<_Tpn>(b.s[i]); \ } \ return c; \ } @@ -2485,26 +2974,26 @@ inline _Tpnvec v_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ //! - pack_u: for 16- and 32-bit signed integer input types //! //! @note All variants except 64-bit use saturation. -OPENCV_HAL_IMPL_C_PACK(v_uint16x8, v_uint8x16, uchar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_int8x16, schar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_uint32x4, v_uint16x8, ushort, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_int16x8, short, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_uint64x2, v_uint32x4, unsigned, pack, static_cast) -OPENCV_HAL_IMPL_C_PACK(v_int64x2, v_int32x4, int, pack, static_cast) -OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_uint8x16, uchar, pack_u, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_uint16x8, ushort, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(ushort, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(short, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(unsigned, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(int, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(uint64, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(int64, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(short, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(int, ushort, pack_u, saturate_cast) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_RSHR_PACK(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ -template inline _Tpnvec v_rshr_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ +#define OPENCV_HAL_IMPL_C_RSHR_PACK(_Tp, _Tpn, pack_suffix, cast) \ +template inline v_reg<_Tpn, 2*n> v_rshr_##pack_suffix(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ { \ - _Tpnvec c; \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + v_reg<_Tpn, 2*n> c; \ + for( int i = 0; i < n; i++ ) \ { \ - c.s[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ - c.s[i+_Tpvec::nlanes] = cast<_Tpn>((b.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + c.s[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (shift - 1))) >> shift); \ + c.s[i+n] = cast<_Tpn>((b.s[i] + ((_Tp)1 << (shift - 1))) >> shift); \ } \ return c; \ } @@ -2520,22 +3009,22 @@ template inline _Tpnvec v_rshr_##pack_suffix(const _Tpvec& a, const _Tpve //! - pack_u: for 16- and 32-bit signed integer input types //! //! @note All variants except 64-bit use saturation. -OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_int16x8, short, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int64x2, int64, v_int32x4, int, pack, static_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(ushort, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(short, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(unsigned, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(int, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(uint64, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(int64, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(short, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(int, ushort, pack_u, saturate_cast) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ -inline void v_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ +#define OPENCV_HAL_IMPL_C_PACK_STORE(_Tp, _Tpn, pack_suffix, cast) \ +template inline void v_##pack_suffix##_store(_Tpn* ptr, const v_reg<_Tp, n>& a) \ { \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + for( int i = 0; i < n; i++ ) \ ptr[i] = cast<_Tpn>(a.s[i]); \ } @@ -2550,23 +3039,23 @@ inline void v_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ //! - pack_u: for 16- and 32-bit signed integer input types //! //! @note All variants except 64-bit use saturation. -OPENCV_HAL_IMPL_C_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(ushort, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(short, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(unsigned, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(int, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(uint64, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(int64, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(short, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(int, ushort, pack_u, saturate_cast) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ -template inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ +#define OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(_Tp, _Tpn, pack_suffix, cast) \ +template inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const v_reg<_Tp, n>& a) \ { \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ - ptr[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + for( int i = 0; i < n; i++ ) \ + ptr[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (shift - 1))) >> shift); \ } //! @name Pack and store with rounding shift @@ -2580,14 +3069,14 @@ template inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const _Tpvec //! - pack_u: for 16- and 32-bit signed integer input types //! //! @note All variants except 64-bit use saturation. -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(ushort, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(short, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(unsigned, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(int, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(uint64, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(int64, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(short, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(int, ushort, pack_u, saturate_cast) //! @} //! @cond IGNORED @@ -2622,9 +3111,9 @@ b {0xFFFF 0 0xFFFF 0 0 0xFFFF 0 0xFFFF} } @endcode */ -inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +template inline v_reg v_pack_b(const v_reg& a, const v_reg& b) { - v_uint8x16 mask; + v_reg mask; _pack_b(mask.s, a, b); return mask; } @@ -2645,12 +3134,12 @@ d {0 0xFFFF.. 0 0xFFFF..} } @endcode */ -inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, - const v_uint32x4& c, const v_uint32x4& d) +template inline v_reg v_pack_b(const v_reg& a, const v_reg& b, + const v_reg& c, const v_reg& d) { - v_uint8x16 mask; + v_reg mask; _pack_b(mask.s, a, b); - _pack_b(mask.s + 8, c, d); + _pack_b(mask.s + 2*n, c, d); return mask; } @@ -2674,15 +3163,16 @@ h {0 0xFFFF..} 0xFF 0 0xFF 0 0 0xFF 0 0xFF } @endcode */ -inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, - const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, - const v_uint64x2& g, const v_uint64x2& h) +template inline v_reg v_pack_b(const v_reg& a, const v_reg& b, + const v_reg& c, const v_reg& d, + const v_reg& e, const v_reg& f, + const v_reg& g, const v_reg& h) { - v_uint8x16 mask; + v_reg mask; _pack_b(mask.s, a, b); - _pack_b(mask.s + 4, c, d); - _pack_b(mask.s + 8, e, f); - _pack_b(mask.s + 12, g, h); + _pack_b(mask.s + 2*n, c, d); + _pack_b(mask.s + 4*n, e, f); + _pack_b(mask.s + 6*n, g, h); return mask; } //! @} @@ -2697,71 +3187,109 @@ Scheme: {D0 D1 D2 D3} x |V3| ==================== {R0 R1 R2 R3}, where: -R0 = A0V0 + A1V1 + A2V2 + A3V3, -R1 = B0V0 + B1V1 + B2V2 + B3V3 +R0 = A0V0 + B0V1 + C0V2 + D0V3, +R1 = A1V0 + B1V1 + C1V2 + D1V3 ... @endcode */ -inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, - const v_float32x4& m1, const v_float32x4& m2, - const v_float32x4& m3) +template +inline v_reg v_matmul(const v_reg& v, + const v_reg& a, const v_reg& b, + const v_reg& c, const v_reg& d) { - return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + v.s[3]*m3.s[0], - v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + v.s[3]*m3.s[1], - v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + v.s[3]*m3.s[2], - v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + v.s[3]*m3.s[3]); + v_reg res; + for (int i = 0; i < n / 4; i++) + { + res.s[0 + i*4] = v.s[0 + i*4] * a.s[0 + i*4] + v.s[1 + i*4] * b.s[0 + i*4] + v.s[2 + i*4] * c.s[0 + i*4] + v.s[3 + i*4] * d.s[0 + i*4]; + res.s[1 + i*4] = v.s[0 + i*4] * a.s[1 + i*4] + v.s[1 + i*4] * b.s[1 + i*4] + v.s[2 + i*4] * c.s[1 + i*4] + v.s[3 + i*4] * d.s[1 + i*4]; + res.s[2 + i*4] = v.s[0 + i*4] * a.s[2 + i*4] + v.s[1 + i*4] * b.s[2 + i*4] + v.s[2 + i*4] * c.s[2 + i*4] + v.s[3 + i*4] * d.s[2 + i*4]; + res.s[3 + i*4] = v.s[0 + i*4] * a.s[3 + i*4] + v.s[1 + i*4] * b.s[3 + i*4] + v.s[2 + i*4] * c.s[3 + i*4] + v.s[3 + i*4] * d.s[3 + i*4]; + } + return res; } /** @brief Matrix multiplication and add Scheme: @code -{A0 A1 A2 } |V0| |D0| -{B0 B1 B2 } |V1| |D1| -{C0 C1 C2 } x |V2| + |D2| -==================== +{A0 A1 A2 A3} |V0| |D0| +{B0 B1 B2 B3} |V1| |D1| +{C0 C1 C2 C3} x |V2| + |D2| +==================== |D3| {R0 R1 R2 R3}, where: -R0 = A0V0 + A1V1 + A2V2 + D0, -R1 = B0V0 + B1V1 + B2V2 + D1 +R0 = A0V0 + B0V1 + C0V2 + D0, +R1 = A1V0 + B1V1 + C1V2 + D1 ... @endcode */ -inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, - const v_float32x4& m1, const v_float32x4& m2, - const v_float32x4& m3) +template +inline v_reg v_matmuladd(const v_reg& v, + const v_reg& a, const v_reg& b, + const v_reg& c, const v_reg& d) { - return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + m3.s[0], - v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + m3.s[1], - v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + m3.s[2], - v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + m3.s[3]); + v_reg res; + for (int i = 0; i < n / 4; i++) + { + res.s[0 + i * 4] = v.s[0 + i * 4] * a.s[0 + i * 4] + v.s[1 + i * 4] * b.s[0 + i * 4] + v.s[2 + i * 4] * c.s[0 + i * 4] + d.s[0 + i * 4]; + res.s[1 + i * 4] = v.s[0 + i * 4] * a.s[1 + i * 4] + v.s[1 + i * 4] * b.s[1 + i * 4] + v.s[2 + i * 4] * c.s[1 + i * 4] + d.s[1 + i * 4]; + res.s[2 + i * 4] = v.s[0 + i * 4] * a.s[2 + i * 4] + v.s[1 + i * 4] * b.s[2 + i * 4] + v.s[2 + i * 4] * c.s[2 + i * 4] + d.s[2 + i * 4]; + res.s[3 + i * 4] = v.s[0 + i * 4] * a.s[3 + i * 4] + v.s[1 + i * 4] * b.s[3 + i * 4] + v.s[2 + i * 4] * c.s[3 + i * 4] + d.s[3 + i * 4]; + } + return res; } -inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b) +template inline v_reg v_dotprod_expand(const v_reg& a, const v_reg& b) { return v_fma(v_cvt_f64(a), v_cvt_f64(b), v_cvt_f64_high(a) * v_cvt_f64_high(b)); } -inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +template inline v_reg v_dotprod_expand(const v_reg& a, const v_reg& b, + const v_reg& c) { return v_fma(v_cvt_f64(a), v_cvt_f64(b), v_fma(v_cvt_f64_high(a), v_cvt_f64_high(b), c)); } -inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b) +template inline v_reg v_dotprod_expand_fast(const v_reg& a, const v_reg& b) { return v_dotprod_expand(a, b); } -inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +template inline v_reg v_dotprod_expand_fast(const v_reg& a, const v_reg& b, + const v_reg& c) { return v_dotprod_expand(a, b, c); } ////// FP16 support /////// -inline v_reg::nlanes128> +inline v_reg v_load_expand(const float16_t* ptr) { - v_reg::nlanes128> v; + v_reg v; for( int i = 0; i < v.nlanes; i++ ) { v.s[i] = ptr[i]; } return v; } +#if CV_SIMD256 +inline v_reg +v256_load_expand(const float16_t* ptr) +{ + v_reg v; + for (int i = 0; i < v.nlanes; i++) + { + v.s[i] = ptr[i]; + } + return v; +} +#endif +#if CV_SIMD512 +inline v_reg +v512_load_expand(const float16_t* ptr) +{ + v_reg v; + for (int i = 0; i < v.nlanes; i++) + { + v.s[i] = ptr[i]; + } + return v; +} +#endif -inline void -v_pack_store(float16_t* ptr, const v_reg::nlanes128>& v) +template inline void +v_pack_store(float16_t* ptr, const v_reg& v) { for( int i = 0; i < v.nlanes; i++ ) { @@ -2770,6 +3298,12 @@ v_pack_store(float16_t* ptr, const v_reg::nlanes128>& } inline void v_cleanup() {} +#if CV_SIMD256 +inline void v256_cleanup() {} +#endif +#if CV_SIMD512 +inline void v512_cleanup() {} +#endif //! @} @@ -2778,4 +3312,9 @@ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END #endif } +#if !defined(CV_DOXYGEN) +#undef CV_SIMD256 +#undef CV_SIMD512 +#endif + #endif diff --git a/3rdparty/include/opencv2/core/hal/intrin_neon.hpp b/3rdparty/include/opencv2/core/hal/intrin_neon.hpp index 280691b448..e17972a3fc 100644 --- a/3rdparty/include/opencv2/core/hal/intrin_neon.hpp +++ b/3rdparty/include/opencv2/core/hal/intrin_neon.hpp @@ -62,6 +62,22 @@ CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN #define CV_SIMD128_64F 0 #endif +// The following macro checks if the code is being compiled for the +// AArch64 execution state of Armv8, to enable the 128-bit +// intrinsics. The macro `__ARM_64BIT_STATE` is the one recommended by +// the Arm C Language Extension (ACLE) specifications [1] to check the +// availability of 128-bit intrinsics, and it is supporrted by clang +// and gcc. The macro `_M_ARM64` is the equivalent one for Microsoft +// Visual Studio [2] . +// +// [1] https://developer.arm.com/documentation/101028/0012/13--Advanced-SIMD--Neon--intrinsics +// [2] https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros +#if defined(__ARM_64BIT_STATE) || defined(_M_ARM64) +#define CV_NEON_AARCH64 1 +#else +#define CV_NEON_AARCH64 0 +#endif + // TODO #define CV_NEON_DOT 0 @@ -522,49 +538,81 @@ inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b, v_int16x8& c, v_int16x8& d) { c.val = vmull_s8(vget_low_s8(a.val), vget_low_s8(b.val)); +#if CV_NEON_AARCH64 + d.val = vmull_high_s8(a.val, b.val); +#else // #if CV_NEON_AARCH64 d.val = vmull_s8(vget_high_s8(a.val), vget_high_s8(b.val)); +#endif // #if CV_NEON_AARCH64 } inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b, v_uint16x8& c, v_uint16x8& d) { c.val = vmull_u8(vget_low_u8(a.val), vget_low_u8(b.val)); +#if CV_NEON_AARCH64 + d.val = vmull_high_u8(a.val, b.val); +#else // #if CV_NEON_AARCH64 d.val = vmull_u8(vget_high_u8(a.val), vget_high_u8(b.val)); +#endif // #if CV_NEON_AARCH64 } inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, v_int32x4& c, v_int32x4& d) { c.val = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val)); +#if CV_NEON_AARCH64 + d.val = vmull_high_s16(a.val, b.val); +#else // #if CV_NEON_AARCH64 d.val = vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)); +#endif // #if CV_NEON_AARCH64 } inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b, v_uint32x4& c, v_uint32x4& d) { c.val = vmull_u16(vget_low_u16(a.val), vget_low_u16(b.val)); +#if CV_NEON_AARCH64 + d.val = vmull_high_u16(a.val, b.val); +#else // #if CV_NEON_AARCH64 d.val = vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val)); +#endif // #if CV_NEON_AARCH64 } inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, v_uint64x2& c, v_uint64x2& d) { c.val = vmull_u32(vget_low_u32(a.val), vget_low_u32(b.val)); +#if CV_NEON_AARCH64 + d.val = vmull_high_u32(a.val, b.val); +#else // #if CV_NEON_AARCH64 d.val = vmull_u32(vget_high_u32(a.val), vget_high_u32(b.val)); +#endif // #if CV_NEON_AARCH64 } inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) { return v_int16x8(vcombine_s16( vshrn_n_s32(vmull_s16( vget_low_s16(a.val), vget_low_s16(b.val)), 16), - vshrn_n_s32(vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)), 16) + vshrn_n_s32( +#if CV_NEON_AARCH64 + vmull_high_s16(a.val, b.val) +#else // #if CV_NEON_AARCH64 + vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)) +#endif // #if CV_NEON_AARCH64 + , 16) )); } inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) { return v_uint16x8(vcombine_u16( vshrn_n_u32(vmull_u16( vget_low_u16(a.val), vget_low_u16(b.val)), 16), - vshrn_n_u32(vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val)), 16) + vshrn_n_u32( +#if CV_NEON_AARCH64 + vmull_high_u16(a.val, b.val) +#else // #if CV_NEON_AARCH64 + vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val)) +#endif // #if CV_NEON_AARCH64 + , 16) )); } @@ -726,41 +774,61 @@ inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, // 16 >> 32 inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b) { +#if CV_NEON_AARCH64 + int32x4_t p = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val)); + return v_int32x4(vmlal_high_s16(p, a.val, b.val)); +#else int16x4_t a0 = vget_low_s16(a.val); int16x4_t a1 = vget_high_s16(a.val); int16x4_t b0 = vget_low_s16(b.val); int16x4_t b1 = vget_high_s16(b.val); int32x4_t p = vmull_s16(a0, b0); return v_int32x4(vmlal_s16(p, a1, b1)); +#endif } inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) { +#if CV_NEON_AARCH64 + int32x4_t p = vmlal_s16(c.val, vget_low_s16(a.val), vget_low_s16(b.val)); + return v_int32x4(vmlal_high_s16(p, a.val, b.val)); +#else int16x4_t a0 = vget_low_s16(a.val); int16x4_t a1 = vget_high_s16(a.val); int16x4_t b0 = vget_low_s16(b.val); int16x4_t b1 = vget_high_s16(b.val); int32x4_t p = vmlal_s16(c.val, a0, b0); return v_int32x4(vmlal_s16(p, a1, b1)); +#endif } // 32 >> 64 inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b) { +#if CV_NEON_AARCH64 + int64x2_t p = vmull_s32(vget_low_s32(a.val), vget_low_s32(b.val)); + return v_int64x2(vmlal_high_s32(p, a.val, b.val)); +#else int32x2_t a0 = vget_low_s32(a.val); int32x2_t a1 = vget_high_s32(a.val); int32x2_t b0 = vget_low_s32(b.val); int32x2_t b1 = vget_high_s32(b.val); int64x2_t p = vmull_s32(a0, b0); return v_int64x2(vmlal_s32(p, a1, b1)); +#endif } inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) { +#if CV_NEON_AARCH64 + int64x2_t p = vmlal_s32(c.val, vget_low_s32(a.val), vget_low_s32(b.val)); + return v_int64x2(vmlal_high_s32(p, a.val, b.val)); +#else int32x2_t a0 = vget_low_s32(a.val); int32x2_t a1 = vget_high_s32(a.val); int32x2_t b0 = vget_low_s32(b.val); int32x2_t b1 = vget_high_s32(b.val); int64x2_t p = vmlal_s32(c.val, a0, b0); return v_int64x2(vmlal_s32(p, a1, b1)); +#endif } // 8 >> 32 @@ -1218,29 +1286,56 @@ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float64x2, double, f64) inline unsigned v_reduce_sum(const v_uint8x16& a) { +#if CV_NEON_AARCH64 + uint16_t t0 = vaddlvq_u8(a.val); + return t0; +#else // #if CV_NEON_AARCH64 uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(a.val)); uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); return vget_lane_u32(vpadd_u32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline int v_reduce_sum(const v_int8x16& a) { +#if CV_NEON_AARCH64 + int16_t t0 = vaddlvq_s8(a.val); + return t0; +#else // #if CV_NEON_AARCH64 int32x4_t t0 = vpaddlq_s16(vpaddlq_s8(a.val)); int32x2_t t1 = vpadd_s32(vget_low_s32(t0), vget_high_s32(t0)); return vget_lane_s32(vpadd_s32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline unsigned v_reduce_sum(const v_uint16x8& a) { +#if CV_NEON_AARCH64 + uint32_t t0 = vaddlvq_u16(a.val); + return t0; +#else // #if CV_NEON_AARCH64 uint32x4_t t0 = vpaddlq_u16(a.val); uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); return vget_lane_u32(vpadd_u32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline int v_reduce_sum(const v_int16x8& a) { +#if CV_NEON_AARCH64 + int32_t t0 = vaddlvq_s16(a.val); + return t0; +#else // #if CV_NEON_AARCH64 int32x4_t t0 = vpaddlq_s16(a.val); int32x2_t t1 = vpadd_s32(vget_low_s32(t0), vget_high_s32(t0)); return vget_lane_s32(vpadd_s32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } +#if CV_NEON_AARCH64 +#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + return v##vectorfunc##vq_##suffix(a.val); \ +} +#else // #if CV_NEON_AARCH64 #define OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ inline scalartype v_reduce_##func(const _Tpvec& a) \ { \ @@ -1249,12 +1344,20 @@ inline scalartype v_reduce_##func(const _Tpvec& a) \ a0 = vp##vectorfunc##_##suffix(a0, a0); \ return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, a0),0); \ } +#endif // #if CV_NEON_AARCH64 OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(v_uint8x16, uint8x8, uchar, max, max, u8) OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(v_uint8x16, uint8x8, uchar, min, min, u8) OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(v_int8x16, int8x8, schar, max, max, s8) OPENCV_HAL_IMPL_NEON_REDUCE_OP_16(v_int8x16, int8x8, schar, min, min, s8) +#if CV_NEON_AARCH64 +#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + return v##vectorfunc##vq_##suffix(a.val); \ +} +#else // #if CV_NEON_AARCH64 #define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ inline scalartype v_reduce_##func(const _Tpvec& a) \ { \ @@ -1262,18 +1365,27 @@ inline scalartype v_reduce_##func(const _Tpvec& a) \ a0 = vp##vectorfunc##_##suffix(a0, a0); \ return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, a0),0); \ } +#endif // #if CV_NEON_AARCH64 OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, ushort, max, max, u16) OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, ushort, min, min, u16) OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, max, max, s16) OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, min, min, s16) +#if CV_NEON_AARCH64 +#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + return v##vectorfunc##vq_##suffix(a.val); \ +} +#else // #if CV_NEON_AARCH64 #define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ inline scalartype v_reduce_##func(const _Tpvec& a) \ { \ _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \ return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, vget_high_##suffix(a.val)),0); \ } +#endif // #if CV_NEON_AARCH64 OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, sum, add, u32) OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, max, max, u32) @@ -1286,19 +1398,36 @@ OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, max, max, f32) OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, min, min, f32) inline uint64 v_reduce_sum(const v_uint64x2& a) -{ return vget_lane_u64(vadd_u64(vget_low_u64(a.val), vget_high_u64(a.val)),0); } +{ +#if CV_NEON_AARCH64 + return vaddvq_u64(a.val); +#else // #if CV_NEON_AARCH64 + return vget_lane_u64(vadd_u64(vget_low_u64(a.val), vget_high_u64(a.val)),0); +#endif // #if CV_NEON_AARCH64 +} inline int64 v_reduce_sum(const v_int64x2& a) -{ return vget_lane_s64(vadd_s64(vget_low_s64(a.val), vget_high_s64(a.val)),0); } +{ +#if CV_NEON_AARCH64 + return vaddvq_s64(a.val); +#else // #if CV_NEON_AARCH64 + return vget_lane_s64(vadd_s64(vget_low_s64(a.val), vget_high_s64(a.val)),0); +#endif // #if CV_NEON_AARCH64 +} #if CV_SIMD128_64F inline double v_reduce_sum(const v_float64x2& a) { - return vgetq_lane_f64(a.val, 0) + vgetq_lane_f64(a.val, 1); + return vaddvq_f64(a.val); } #endif inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c, const v_float32x4& d) { +#if CV_NEON_AARCH64 + float32x4_t ab = vpaddq_f32(a.val, b.val); // a0+a1 a2+a3 b0+b1 b2+b3 + float32x4_t cd = vpaddq_f32(c.val, d.val); // c0+c1 d0+d1 c2+c3 d2+d3 + return v_float32x4(vpaddq_f32(ab, cd)); // sumA sumB sumC sumD +#else // #if CV_NEON_AARCH64 float32x4x2_t ab = vtrnq_f32(a.val, b.val); float32x4x2_t cd = vtrnq_f32(c.val, d.val); @@ -1309,49 +1438,91 @@ inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, float32x4_t v1 = vcombine_f32(vget_high_f32(u0), vget_high_f32(u1)); return v_float32x4(vaddq_f32(v0, v1)); +#endif // #if CV_NEON_AARCH64 } inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b) { +#if CV_NEON_AARCH64 + uint8x16_t t0 = vabdq_u8(a.val, b.val); + uint16_t t1 = vaddlvq_u8(t0); + return t1; +#else // #if CV_NEON_AARCH64 uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(vabdq_u8(a.val, b.val))); uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); return vget_lane_u32(vpadd_u32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b) { +#if CV_NEON_AARCH64 + uint8x16_t t0 = vreinterpretq_u8_s8(vabdq_s8(a.val, b.val)); + uint16_t t1 = vaddlvq_u8(t0); + return t1; +#else // #if CV_NEON_AARCH64 uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(vreinterpretq_u8_s8(vabdq_s8(a.val, b.val)))); uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); return vget_lane_u32(vpadd_u32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b) { +#if CV_NEON_AARCH64 + uint16x8_t t0 = vabdq_u16(a.val, b.val); + uint32_t t1 = vaddlvq_u16(t0); + return t1; +#else // #if CV_NEON_AARCH64 uint32x4_t t0 = vpaddlq_u16(vabdq_u16(a.val, b.val)); uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); return vget_lane_u32(vpadd_u32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b) { +#if CV_NEON_AARCH64 + uint16x8_t t0 = vreinterpretq_u16_s16(vabdq_s16(a.val, b.val)); + uint32_t t1 = vaddlvq_u16(t0); + return t1; +#else // #if CV_NEON_AARCH64 uint32x4_t t0 = vpaddlq_u16(vreinterpretq_u16_s16(vabdq_s16(a.val, b.val))); uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); return vget_lane_u32(vpadd_u32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b) { +#if CV_NEON_AARCH64 + uint32x4_t t0 = vabdq_u32(a.val, b.val); + uint32_t t1 = vaddvq_u32(t0); + return t1; +#else // #if CV_NEON_AARCH64 uint32x4_t t0 = vabdq_u32(a.val, b.val); uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); return vget_lane_u32(vpadd_u32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b) { +#if CV_NEON_AARCH64 + uint32x4_t t0 = vreinterpretq_u32_s32(vabdq_s32(a.val, b.val)); + uint32_t t1 = vaddvq_u32(t0); + return t1; +#else // #if CV_NEON_AARCH64 uint32x4_t t0 = vreinterpretq_u32_s32(vabdq_s32(a.val, b.val)); uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); return vget_lane_u32(vpadd_u32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) { +#if CV_NEON_AARCH64 + float32x4_t t0 = vabdq_f32(a.val, b.val); + return vaddvq_f32(t0); +#else // #if CV_NEON_AARCH64 float32x4_t t0 = vabdq_f32(a.val, b.val); float32x2_t t1 = vpadd_f32(vget_low_f32(t0), vget_high_f32(t0)); return vget_lane_f32(vpadd_f32(t1, t1), 0); +#endif // #if CV_NEON_AARCH64 } inline v_uint8x16 v_popcount(const v_uint8x16& a) @@ -1373,30 +1544,54 @@ inline v_uint64x2 v_popcount(const v_int64x2& a) inline int v_signmask(const v_uint8x16& a) { +#if CV_NEON_AARCH64 + const int8x16_t signPosition = {0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7}; + const uint8x16_t byteOrder = {0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15}; + uint8x16_t v0 = vshlq_u8(vshrq_n_u8(a.val, 7), signPosition); + uint8x16_t v1 = vqtbl1q_u8(v0, byteOrder); + uint32_t t0 = vaddlvq_u16(vreinterpretq_u16_u8(v1)); + return t0; +#else // #if CV_NEON_AARCH64 int8x8_t m0 = vcreate_s8(CV_BIG_UINT(0x0706050403020100)); uint8x16_t v0 = vshlq_u8(vshrq_n_u8(a.val, 7), vcombine_s8(m0, m0)); uint64x2_t v1 = vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(v0))); return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 8); +#endif // #if CV_NEON_AARCH64 } + inline int v_signmask(const v_int8x16& a) { return v_signmask(v_reinterpret_as_u8(a)); } inline int v_signmask(const v_uint16x8& a) { +#if CV_NEON_AARCH64 + const int16x8_t signPosition = {0,1,2,3,4,5,6,7}; + uint16x8_t v0 = vshlq_u16(vshrq_n_u16(a.val, 15), signPosition); + uint32_t t0 = vaddlvq_u16(v0); + return t0; +#else // #if CV_NEON_AARCH64 int16x4_t m0 = vcreate_s16(CV_BIG_UINT(0x0003000200010000)); uint16x8_t v0 = vshlq_u16(vshrq_n_u16(a.val, 15), vcombine_s16(m0, m0)); uint64x2_t v1 = vpaddlq_u32(vpaddlq_u16(v0)); return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 4); +#endif // #if CV_NEON_AARCH64 } inline int v_signmask(const v_int16x8& a) { return v_signmask(v_reinterpret_as_u16(a)); } inline int v_signmask(const v_uint32x4& a) { +#if CV_NEON_AARCH64 + const int32x4_t signPosition = {0,1,2,3}; + uint32x4_t v0 = vshlq_u32(vshrq_n_u32(a.val, 31), signPosition); + uint32_t t0 = vaddvq_u32(v0); + return t0; +#else // #if CV_NEON_AARCH64 int32x2_t m0 = vcreate_s32(CV_BIG_UINT(0x0000000100000000)); uint32x4_t v0 = vshlq_u32(vshrq_n_u32(a.val, 31), vcombine_s32(m0, m0)); uint64x2_t v1 = vpaddlq_u32(v0); return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 2); +#endif // #if CV_NEON_AARCH64 } inline int v_signmask(const v_int32x4& a) { return v_signmask(v_reinterpret_as_u32(a)); } @@ -1404,9 +1599,16 @@ inline int v_signmask(const v_float32x4& a) { return v_signmask(v_reinterpret_as_u32(a)); } inline int v_signmask(const v_uint64x2& a) { +#if CV_NEON_AARCH64 + const int64x2_t signPosition = {0,1}; + uint64x2_t v0 = vshlq_u64(vshrq_n_u64(a.val, 63), signPosition); + uint64_t t0 = vaddvq_u64(v0); + return t0; +#else // #if CV_NEON_AARCH64 int64x1_t m0 = vdup_n_s64(0); uint64x2_t v0 = vshlq_u64(vshrq_n_u64(a.val, 63), vcombine_s64(m0, m0)); return (int)vgetq_lane_u64(v0, 0) + ((int)vgetq_lane_u64(v0, 1) << 1); +#endif // #if CV_NEON_AARCH64 } inline int v_signmask(const v_int64x2& a) { return v_signmask(v_reinterpret_as_u64(a)); } @@ -1428,19 +1630,31 @@ inline int v_scan_forward(const v_uint64x2& a) { return trailingZeros32(v_signma inline int v_scan_forward(const v_float64x2& a) { return trailingZeros32(v_signmask(a)); } #endif -#define OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(_Tpvec, suffix, shift) \ -inline bool v_check_all(const v_##_Tpvec& a) \ -{ \ - _Tpvec##_t v0 = vshrq_n_##suffix(vmvnq_##suffix(a.val), shift); \ - uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \ - return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) == 0; \ -} \ -inline bool v_check_any(const v_##_Tpvec& a) \ -{ \ - _Tpvec##_t v0 = vshrq_n_##suffix(a.val, shift); \ - uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \ - return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) != 0; \ -} +#if CV_NEON_AARCH64 + #define OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(_Tpvec, suffix, shift) \ + inline bool v_check_all(const v_##_Tpvec& a) \ + { \ + return (vminvq_##suffix(a.val) >> shift) != 0; \ + } \ + inline bool v_check_any(const v_##_Tpvec& a) \ + { \ + return (vmaxvq_##suffix(a.val) >> shift) != 0; \ + } +#else // #if CV_NEON_AARCH64 + #define OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(_Tpvec, suffix, shift) \ + inline bool v_check_all(const v_##_Tpvec& a) \ + { \ + _Tpvec##_t v0 = vshrq_n_##suffix(vmvnq_##suffix(a.val), shift); \ + uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \ + return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) == 0; \ + } \ + inline bool v_check_any(const v_##_Tpvec& a) \ + { \ + _Tpvec##_t v0 = vshrq_n_##suffix(a.val, shift); \ + uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \ + return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) != 0; \ + } +#endif // #if CV_NEON_AARCH64 OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint8x16, u8, 7) OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint16x8, u16, 15) @@ -1503,6 +1717,26 @@ OPENCV_HAL_IMPL_NEON_SELECT(v_float32x4, f32, u32) OPENCV_HAL_IMPL_NEON_SELECT(v_float64x2, f64, u64) #endif +#if CV_NEON_AARCH64 +#define OPENCV_HAL_IMPL_NEON_EXPAND(_Tpvec, _Tpwvec, _Tp, suffix) \ +inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ +{ \ + b0.val = vmovl_##suffix(vget_low_##suffix(a.val)); \ + b1.val = vmovl_high_##suffix(a.val); \ +} \ +inline _Tpwvec v_expand_low(const _Tpvec& a) \ +{ \ + return _Tpwvec(vmovl_##suffix(vget_low_##suffix(a.val))); \ +} \ +inline _Tpwvec v_expand_high(const _Tpvec& a) \ +{ \ + return _Tpwvec(vmovl_high_##suffix(a.val)); \ +} \ +inline _Tpwvec v_load_expand(const _Tp* ptr) \ +{ \ + return _Tpwvec(vmovl_##suffix(vld1_##suffix(ptr))); \ +} +#else #define OPENCV_HAL_IMPL_NEON_EXPAND(_Tpvec, _Tpwvec, _Tp, suffix) \ inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ { \ @@ -1521,6 +1755,7 @@ inline _Tpwvec v_load_expand(const _Tp* ptr) \ { \ return _Tpwvec(vmovl_##suffix(vld1_##suffix(ptr))); \ } +#endif OPENCV_HAL_IMPL_NEON_EXPAND(v_uint8x16, v_uint16x8, uchar, u8) OPENCV_HAL_IMPL_NEON_EXPAND(v_int8x16, v_int16x8, schar, s8) @@ -1772,6 +2007,37 @@ inline v_int32x4 v_trunc(const v_float64x2& a) } #endif +#if CV_NEON_AARCH64 +#define OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(_Tpvec, suffix) \ +inline void v_transpose4x4(const v_##_Tpvec& a0, const v_##_Tpvec& a1, \ + const v_##_Tpvec& a2, const v_##_Tpvec& a3, \ + v_##_Tpvec& b0, v_##_Tpvec& b1, \ + v_##_Tpvec& b2, v_##_Tpvec& b3) \ +{ \ + /* -- Pass 1: 64b transpose */ \ + _Tpvec##_t t0 = vreinterpretq_##suffix##32_##suffix##64( \ + vtrn1q_##suffix##64(vreinterpretq_##suffix##64_##suffix##32(a0.val), \ + vreinterpretq_##suffix##64_##suffix##32(a2.val))); \ + _Tpvec##_t t1 = vreinterpretq_##suffix##32_##suffix##64( \ + vtrn1q_##suffix##64(vreinterpretq_##suffix##64_##suffix##32(a1.val), \ + vreinterpretq_##suffix##64_##suffix##32(a3.val))); \ + _Tpvec##_t t2 = vreinterpretq_##suffix##32_##suffix##64( \ + vtrn2q_##suffix##64(vreinterpretq_##suffix##64_##suffix##32(a0.val), \ + vreinterpretq_##suffix##64_##suffix##32(a2.val))); \ + _Tpvec##_t t3 = vreinterpretq_##suffix##32_##suffix##64( \ + vtrn2q_##suffix##64(vreinterpretq_##suffix##64_##suffix##32(a1.val), \ + vreinterpretq_##suffix##64_##suffix##32(a3.val))); \ + /* -- Pass 2: 32b transpose */ \ + b0.val = vtrn1q_##suffix##32(t0, t1); \ + b1.val = vtrn2q_##suffix##32(t0, t1); \ + b2.val = vtrn1q_##suffix##32(t2, t3); \ + b3.val = vtrn2q_##suffix##32(t2, t3); \ +} + +OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(uint32x4, u) +OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(int32x4, s) +OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(float32x4, f) +#else // #if CV_NEON_AARCH64 #define OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(_Tpvec, suffix) \ inline void v_transpose4x4(const v_##_Tpvec& a0, const v_##_Tpvec& a1, \ const v_##_Tpvec& a2, const v_##_Tpvec& a3, \ @@ -1797,6 +2063,7 @@ inline void v_transpose4x4(const v_##_Tpvec& a0, const v_##_Tpvec& a1, \ OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(uint32x4, u32) OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(int32x4, s32) OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(float32x4, f32) +#endif // #if CV_NEON_AARCH64 #define OPENCV_HAL_IMPL_NEON_INTERLEAVED(_Tpvec, _Tp, suffix) \ inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b) \ diff --git a/3rdparty/include/opencv2/core/hal/intrin_rvv.hpp b/3rdparty/include/opencv2/core/hal/intrin_rvv.hpp new file mode 100644 index 0000000000..cb2140df58 --- /dev/null +++ b/3rdparty/include/opencv2/core/hal/intrin_rvv.hpp @@ -0,0 +1,2902 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// The original implementation has been contributed by Yin Zhang. +// Copyright (C) 2020, Institute of Software, Chinese Academy of Sciences. + +#ifndef OPENCV_HAL_INTRIN_RVV_HPP +#define OPENCV_HAL_INTRIN_RVV_HPP + +#include + +namespace cv +{ + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +#define CV_SIMD128 1 +#define CV_SIMD128_64F 1 + +//////////// Unsupported native intrinsics in C++ //////////// + +struct vuint8mf2_t +{ + uchar val[8] = {0}; + vuint8mf2_t() {} + vuint8mf2_t(const uchar* ptr) + { + for (int i = 0; i < 8; ++i) + { + val[i] = ptr[i]; + } + } +}; +struct vint8mf2_t +{ + schar val[8] = {0}; + vint8mf2_t() {} + vint8mf2_t(const schar* ptr) + { + for (int i = 0; i < 8; ++i) + { + val[i] = ptr[i]; + } + } +}; +struct vuint16mf2_t +{ + ushort val[4] = {0}; + vuint16mf2_t() {} + vuint16mf2_t(const ushort* ptr) + { + for (int i = 0; i < 4; ++i) + { + val[i] = ptr[i]; + } + } +}; +struct vint16mf2_t +{ + short val[4] = {0}; + vint16mf2_t() {} + vint16mf2_t(const short* ptr) + { + for (int i = 0; i < 4; ++i) + { + val[i] = ptr[i]; + } + } +}; +struct vuint32mf2_t +{ + unsigned val[2] = {0}; + vuint32mf2_t() {} + vuint32mf2_t(const unsigned* ptr) + { + val[0] = ptr[0]; + val[1] = ptr[1]; + } +}; +struct vint32mf2_t +{ + int val[2] = {0}; + vint32mf2_t() {} + vint32mf2_t(const int* ptr) + { + val[0] = ptr[0]; + val[1] = ptr[1]; + } +}; +struct vfloat32mf2_t +{ + float val[2] = {0}; + vfloat32mf2_t() {} + vfloat32mf2_t(const float* ptr) + { + val[0] = ptr[0]; + val[1] = ptr[1]; + } +}; +struct vuint64mf2_t +{ + uint64 val[1] = {0}; + vuint64mf2_t() {} + vuint64mf2_t(const uint64* ptr) + { + val[0] = ptr[0]; + } +}; +struct vint64mf2_t +{ + int64 val[1] = {0}; + vint64mf2_t() {} + vint64mf2_t(const int64* ptr) + { + val[0] = ptr[0]; + } +}; +struct vfloat64mf2_t +{ + double val[1] = {0}; + vfloat64mf2_t() {} + vfloat64mf2_t(const double* ptr) + { + val[0] = ptr[0]; + } +}; +struct vuint8mf4_t +{ + uchar val[4] = {0}; + vuint8mf4_t() {} + vuint8mf4_t(const uchar* ptr) + { + for (int i = 0; i < 4; ++i) + { + val[i] = ptr[i]; + } + } +}; +struct vint8mf4_t +{ + schar val[4] = {0}; + vint8mf4_t() {} + vint8mf4_t(const schar* ptr) + { + for (int i = 0; i < 4; ++i) + { + val[i] = ptr[i]; + } + } +}; + +#define OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(_Tpvec, _Tp, suffix, width, n) \ +inline _Tpvec vle##width##_v_##suffix##mf2(const _Tp* ptr) \ +{ \ + return _Tpvec(ptr); \ +} \ +inline void vse##width##_v_##suffix##mf2(_Tp* ptr, _Tpvec v) \ +{ \ + for (int i = 0; i < n; ++i) \ + { \ + ptr[i] = v.val[i]; \ + } \ +} + +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vuint8mf2_t, uint8_t, u8, 8, 8) +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vint8mf2_t, int8_t, i8, 8, 8) +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vuint16mf2_t, uint16_t, u16, 16, 4) +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vint16mf2_t, int16_t, i16, 16, 4) +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vuint32mf2_t, uint32_t, u32, 32, 2) +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vint32mf2_t, int32_t, i32, 32, 2) +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vfloat32mf2_t, float32_t, f32, 32, 2) +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vuint64mf2_t, uint64_t, u64, 64, 1) +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vint64mf2_t, int64_t, i64, 64, 1) +OPENCV_HAL_IMPL_RVV_NATIVE_LOADSTORE_MF2(vfloat64mf2_t, float64_t, f64, 64, 1) + + +#define OPENCV_HAL_IMPL_RVV_NATIVE_WCVT(_Tpwvec, _Tpvec, _wTp, wcvt, suffix, width, n) \ +inline _Tpwvec wcvt (_Tpvec v) \ +{ \ + _wTp tmp[n]; \ + for (int i = 0; i < n; ++i) \ + { \ + tmp[i] = (_wTp)v.val[i]; \ + } \ + vsetvlmax_e##width##m1(); \ + return vle##width##_v_##suffix##m1(tmp); \ +} + +OPENCV_HAL_IMPL_RVV_NATIVE_WCVT(vuint16m1_t, vuint8mf2_t, ushort, vwcvtu_x_x_v_u16m1, u16, 16, 8) +OPENCV_HAL_IMPL_RVV_NATIVE_WCVT(vint16m1_t, vint8mf2_t, short, vwcvt_x_x_v_i16m1, i16, 16, 8) +OPENCV_HAL_IMPL_RVV_NATIVE_WCVT(vuint32m1_t, vuint16mf2_t, unsigned, vwcvtu_x_x_v_u32m1, u32, 32, 4) +OPENCV_HAL_IMPL_RVV_NATIVE_WCVT(vint32m1_t, vint16mf2_t, int, vwcvt_x_x_v_i32m1, i32, 32, 4) +OPENCV_HAL_IMPL_RVV_NATIVE_WCVT(vuint64m1_t, vuint32mf2_t, uint64, vwcvtu_x_x_v_u64m1, u64, 64, 2) +OPENCV_HAL_IMPL_RVV_NATIVE_WCVT(vint64m1_t, vint32mf2_t, int64, vwcvt_x_x_v_i64m1, i64, 64, 2) + +inline vuint8mf4_t vle8_v_u8mf4 (const uint8_t *base) +{ + return vuint8mf4_t(base); +} +inline vint8mf4_t vle8_v_i8mf4 (const int8_t *base) +{ + return vint8mf4_t(base); +} + +inline vuint16mf2_t vwcvtu_x_x_v_u16mf2 (vuint8mf4_t src) +{ + ushort tmp[4]; + for (int i = 0; i < 4; ++i) + { + tmp[i] = (ushort)src.val[i]; + } + return vle16_v_u16mf2(tmp); +} +inline vint16mf2_t vwcvt_x_x_v_i16mf2 (vint8mf4_t src) +{ + short tmp[4]; + for (int i = 0; i < 4; ++i) + { + tmp[i] = (short)src.val[i]; + } + return vle16_v_i16mf2(tmp); +} + +//////////// Types //////////// + +struct v_uint8x16 +{ + typedef uchar lane_type; + enum { nlanes = 16 }; + + v_uint8x16() {} + explicit v_uint8x16(vuint8m1_t v) + { + vsetvlmax_e8m1(); + vse8_v_u8m1(val, v); + } + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + { + uchar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vuint8m1_t() const + { + vsetvlmax_e8m1(); + return vle8_v_u8m1(val); + } + uchar get0() const + { + return val[0]; + } + + uchar val[16]; +}; + +struct v_int8x16 +{ + typedef schar lane_type; + enum { nlanes = 16 }; + + v_int8x16() {} + explicit v_int8x16(vint8m1_t v) + { + vsetvlmax_e8m1(); + vse8_v_i8m1(val, v); + } + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + { + schar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vint8m1_t() const + { + vsetvlmax_e8m1(); + return vle8_v_i8m1(val); + } + schar get0() const + { + return val[0]; + } + + schar val[16]; +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + enum { nlanes = 8 }; + + v_uint16x8() {} + explicit v_uint16x8(vuint16m1_t v) + { + vsetvlmax_e16m1(); + vse16_v_u16m1(val, v); + } + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + { + ushort v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vuint16m1_t() const + { + vsetvlmax_e16m1(); + return vle16_v_u16m1(val); + } + ushort get0() const + { + return val[0]; + } + + ushort val[8]; +}; + +struct v_int16x8 +{ + typedef short lane_type; + enum { nlanes = 8 }; + + v_int16x8() {} + explicit v_int16x8(vint16m1_t v) + { + vsetvlmax_e16m1(); + vse16_v_i16m1(val, v); + } + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + { + short v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vint16m1_t() const + { + vsetvlmax_e16m1(); + return vle16_v_i16m1(val); + } + short get0() const + { + return val[0]; + } + + short val[8]; +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + enum { nlanes = 4 }; + + v_uint32x4() {} + explicit v_uint32x4(vuint32m1_t v) + { + vsetvlmax_e32m1(); + vse32_v_u32m1(val, v); + } + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) + { + unsigned v[] = {v0, v1, v2, v3}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vuint32m1_t() const + { + vsetvlmax_e32m1(); + return vle32_v_u32m1(val); + } + unsigned get0() const + { + return val[0]; + } + + unsigned val[4]; +}; + +struct v_int32x4 +{ + typedef int lane_type; + enum { nlanes = 4 }; + + v_int32x4() {} + explicit v_int32x4(vint32m1_t v) + { + vsetvlmax_e32m1(); + vse32_v_i32m1(val, v); + } + v_int32x4(int v0, int v1, int v2, int v3) + { + int v[] = {v0, v1, v2, v3}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vint32m1_t() const + { + vsetvlmax_e32m1(); + return vle32_v_i32m1(val); + } + int get0() const + { + return val[0]; + } + int val[4]; +}; + +struct v_float32x4 +{ + typedef float lane_type; + enum { nlanes = 4 }; + + v_float32x4() {} + explicit v_float32x4(vfloat32m1_t v) + { + vsetvlmax_e32m1(); + vse32_v_f32m1(val, v); + } + v_float32x4(float v0, float v1, float v2, float v3) + { + float v[] = {v0, v1, v2, v3}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vfloat32m1_t() const + { + vsetvlmax_e32m1(); + return vle32_v_f32m1(val); + } + float get0() const + { + return val[0]; + } + float val[4]; +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + enum { nlanes = 2 }; + + v_uint64x2() {} + explicit v_uint64x2(vuint64m1_t v) + { + vsetvlmax_e64m1(); + vse64_v_u64m1(val, v); + } + v_uint64x2(uint64 v0, uint64 v1) + { + uint64 v[] = {v0, v1}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vuint64m1_t() const + { + vsetvlmax_e64m1(); + return vle64_v_u64m1(val); + } + uint64 get0() const + { + return val[0]; + } + + uint64 val[2]; +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + enum { nlanes = 2 }; + + v_int64x2() {} + explicit v_int64x2(vint64m1_t v) + { + vsetvlmax_e64m1(); + vse64_v_i64m1(val, v); + } + v_int64x2(int64 v0, int64 v1) + { + int64 v[] = {v0, v1}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vint64m1_t() const + { + vsetvlmax_e64m1(); + return vle64_v_i64m1(val); + } + int64 get0() const + { + return val[0]; + } + + int64 val[2]; +}; + +#if CV_SIMD128_64F +struct v_float64x2 +{ + typedef double lane_type; + enum { nlanes = 2 }; + + v_float64x2() {} + explicit v_float64x2(vfloat64m1_t v) + { + vsetvlmax_e64m1(); + vse64_v_f64m1(val, v); + } + v_float64x2(double v0, double v1) + { + double v[] = {v0, v1}; + for (int i = 0; i < nlanes; ++i) + { + val[i] = v[i]; + } + } + operator vfloat64m1_t() const + { + vsetvlmax_e64m1(); + return vle64_v_f64m1(val); + } + double get0() const + { + return val[0]; + } + + double val[2]; +}; +#endif + + +//////////// Initial //////////// + +#define OPENCV_HAL_IMPL_RVV_INIT_INTEGER(_Tpvec, _Tp, width, suffix1, suffix2) \ +inline v_##_Tpvec v_setzero_##suffix1() \ +{ \ + vsetvlmax_e##width##m1(); \ + return v_##_Tpvec(vzero_##suffix2##m1()); \ +} \ +inline v_##_Tpvec v_setall_##suffix1(_Tp v) \ +{ \ + vsetvlmax_e##width##m1(); \ + return v_##_Tpvec(vmv_v_x_##suffix2##m1(v)); \ +} + +OPENCV_HAL_IMPL_RVV_INIT_INTEGER(uint8x16, uchar, 8, u8, u8) +OPENCV_HAL_IMPL_RVV_INIT_INTEGER(int8x16, schar, 8, s8, i8) +OPENCV_HAL_IMPL_RVV_INIT_INTEGER(uint16x8, ushort, 16, u16, u16) +OPENCV_HAL_IMPL_RVV_INIT_INTEGER(int16x8, short, 16, s16, i16) +OPENCV_HAL_IMPL_RVV_INIT_INTEGER(uint32x4, unsigned, 32, u32, u32) +OPENCV_HAL_IMPL_RVV_INIT_INTEGER(int32x4, int, 32, s32, i32) +OPENCV_HAL_IMPL_RVV_INIT_INTEGER(uint64x2, uint64, 64, u64, u64) +OPENCV_HAL_IMPL_RVV_INIT_INTEGER(int64x2, int64, 64, s64, i64) + +#define OPENCV_HAL_IMPL_RVV_INIT_FP(_Tpv, _Tp, width, suffix) \ +inline v_##_Tpv v_setzero_##suffix() \ +{ \ + vsetvlmax_e##width##m1(); \ + return v_##_Tpv(vzero_##suffix##m1()); \ +} \ +inline v_##_Tpv v_setall_##suffix(_Tp v) \ +{ \ + vsetvlmax_e##width##m1(); \ + return v_##_Tpv(vfmv_v_f_##suffix##m1(v)); \ +} + +OPENCV_HAL_IMPL_RVV_INIT_FP(float32x4, float, 32, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_INIT_FP(float64x2, double, 64, f64) +#endif + +//////////// Reinterpret //////////// + +#define OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(_Tpvec, suffix) \ +inline v_##_Tpvec v_reinterpret_as_##suffix(const v_##_Tpvec& v) { return v; } + +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(uint8x16, u8) +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(int8x16, s8) +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(uint16x8, u16) +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(int16x8, s16) +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(uint32x4, u32) +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(int32x4, s32) +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(float32x4, f32) +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(uint64x2, u64) +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(int64x2, s64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_SELF_REINTERPRET(float64x2, f64) +#endif + +#define OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(_Tpvec1, _Tpvec2, _nTpvec1, _nTpvec2, suffix1, suffix2, nsuffix1, nsuffix2, width1, width2) \ +inline v_##_Tpvec1 v_reinterpret_as_##suffix1(const v_##_Tpvec2& v) \ +{ \ + vsetvlmax_e##width2##m1(); \ + return v_##_Tpvec1((_nTpvec1)vle##width2##_v_##nsuffix2##m1(v.val)); \ +} \ +inline v_##_Tpvec2 v_reinterpret_as_##suffix2(const v_##_Tpvec1& v) \ +{ \ + vsetvlmax_e##width1##m1(); \ + return v_##_Tpvec2((_nTpvec2)vle##width1##_v_##nsuffix1##m1(v.val)); \ +} + +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint8x16, int8x16, vuint8m1_t, vint8m1_t, u8, s8, u8, i8, 8, 8) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint16x8, int16x8, vuint16m1_t, vint16m1_t, u16, s16, u16, i16, 16, 16) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint32x4, int32x4, vuint32m1_t, vint32m1_t, u32, s32, u32, i32, 32, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint32x4, float32x4, vuint32m1_t, vfloat32m1_t, u32, f32, u32, f32, 32, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int32x4, float32x4, vint32m1_t, vfloat32m1_t, s32, f32, i32, f32, 32, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint64x2, int64x2, vuint64m1_t, vint64m1_t, u64, s64, u64, i64, 64, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint8x16, uint16x8, vuint8m1_t, vuint16m1_t, u8, u16, u8, u16, 8, 16) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint8x16, uint32x4, vuint8m1_t, vuint32m1_t, u8, u32, u8, u32, 8, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint8x16, uint64x2, vuint8m1_t, vuint64m1_t, u8, u64, u8, u64, 8, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint16x8, uint32x4, vuint16m1_t, vuint32m1_t, u16, u32, u16, u32, 16, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint16x8, uint64x2, vuint16m1_t, vuint64m1_t, u16, u64, u16, u64, 16, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint32x4, uint64x2, vuint32m1_t, vuint64m1_t, u32, u64, u32, u64, 32, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int8x16, int16x8, vint8m1_t, vint16m1_t, s8, s16, i8, i16, 8, 16) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int8x16, int32x4, vint8m1_t, vint32m1_t, s8, s32, i8, i32, 8, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int8x16, int64x2, vint8m1_t, vint64m1_t, s8, s64, i8, i64, 8, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int16x8, int32x4, vint16m1_t, vint32m1_t, s16, s32, i16, i32, 16, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int16x8, int64x2, vint16m1_t, vint64m1_t, s16, s64, i16, i64, 16, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int32x4, int64x2, vint32m1_t, vint64m1_t, s32, s64, i32, i64, 32, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint8x16, int16x8, vuint8m1_t, vint16m1_t, u8, s16, u8, i16, 8, 16) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint8x16, int32x4, vuint8m1_t, vint32m1_t, u8, s32, u8, i32, 8, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint8x16, int64x2, vuint8m1_t, vint64m1_t, u8, s64, u8, i64, 8, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint16x8, int8x16, vuint16m1_t, vint8m1_t, u16, s8, u16, i8, 16, 8) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint16x8, int32x4, vuint16m1_t, vint32m1_t, u16, s32, u16, i32, 16, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint16x8, int64x2, vuint16m1_t, vint64m1_t, u16, s64, u16, i64, 16, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint32x4, int8x16, vuint32m1_t, vint8m1_t, u32, s8, u32, i8, 32, 8) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint32x4, int16x8, vuint32m1_t, vint16m1_t, u32, s16, u32, i16, 32, 16) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint32x4, int64x2, vuint32m1_t, vint64m1_t, u32, s64, u32, i64, 32, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint64x2, int8x16, vuint64m1_t, vint8m1_t, u64, s8, u64, i8, 64, 8) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint64x2, int16x8, vuint64m1_t, vint16m1_t, u64, s16, u64, i16, 64, 16) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint64x2, int32x4, vuint64m1_t, vint32m1_t, u64, s32, u64, i32, 64, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint8x16, float32x4, vuint8m1_t, vfloat32m1_t, u8, f32, u8, f32, 8, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint16x8, float32x4, vuint16m1_t, vfloat32m1_t, u16, f32, u16, f32, 16, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint64x2, float32x4, vuint64m1_t, vfloat32m1_t, u64, f32, u64, f32, 64, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int8x16, float32x4, vint8m1_t, vfloat32m1_t, s8, f32, i8, f32, 8, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int16x8, float32x4, vint16m1_t, vfloat32m1_t, s16, f32, i16, f32, 16, 32) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int64x2, float32x4, vint64m1_t, vfloat32m1_t, s64, f32, i64, f32, 64, 32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint64x2, float64x2, vuint64m1_t, vfloat64m1_t, u64, f64, u64, f64, 64, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int64x2, float64x2, vint64m1_t, vfloat64m1_t, s64, f64, i64, f64, 64, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint8x16, float64x2, vuint8m1_t, vfloat64m1_t, u8, f64, u8, f64, 8, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint16x8, float64x2, vuint16m1_t, vfloat64m1_t, u16, f64, u16, f64, 16, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(uint32x4, float64x2, vuint32m1_t, vfloat64m1_t, u32, f64, u32, f64, 32, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int8x16, float64x2, vint8m1_t, vfloat64m1_t, s8, f64, i8, f64, 8, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int16x8, float64x2, vint16m1_t, vfloat64m1_t, s16, f64, i16, f64, 16, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(int32x4, float64x2, vint32m1_t, vfloat64m1_t, s32, f64, i32, f64, 32, 64) +OPENCV_HAL_IMPL_RVV_ONE_TIME_REINTERPRET(float32x4, float64x2, vfloat32m1_t, vfloat64m1_t, f32, f64, f32, f64, 32, 64) +#endif + +////////////// Extract ////////////// + +#define OPENCV_HAL_IMPL_RVV_EXTRACT(_Tpvec, _Tp, suffix, width, vmv) \ +template \ +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vslideup_vx_##suffix##m1(vslidedown_vx_##suffix##m1(vzero_##suffix##m1(), a, s), b, _Tpvec::nlanes - s)); \ +} \ +template inline _Tp v_extract_n(_Tpvec v) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tp(vmv(vslidedown_vx_##suffix##m1(vzero_##suffix##m1(), v, i))); \ +} + + +OPENCV_HAL_IMPL_RVV_EXTRACT(v_uint8x16, uchar, u8, 8, vmv_x_s_u8m1_u8) +OPENCV_HAL_IMPL_RVV_EXTRACT(v_int8x16, schar, i8, 8, vmv_x_s_i8m1_i8) +OPENCV_HAL_IMPL_RVV_EXTRACT(v_uint16x8, ushort, u16, 16, vmv_x_s_u16m1_u16) +OPENCV_HAL_IMPL_RVV_EXTRACT(v_int16x8, short, i16, 16, vmv_x_s_i16m1_i16) +OPENCV_HAL_IMPL_RVV_EXTRACT(v_uint32x4, uint, u32, 32, vmv_x_s_u32m1_u32) +OPENCV_HAL_IMPL_RVV_EXTRACT(v_int32x4, int, i32, 32, vmv_x_s_i32m1_i32) +OPENCV_HAL_IMPL_RVV_EXTRACT(v_uint64x2, uint64, u64, 64, vmv_x_s_u64m1_u64) +OPENCV_HAL_IMPL_RVV_EXTRACT(v_int64x2, int64, i64, 64, vmv_x_s_i64m1_i64) +OPENCV_HAL_IMPL_RVV_EXTRACT(v_float32x4, float, f32, 32, vfmv_f_s_f32m1_f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_EXTRACT(v_float64x2, double, f64, 64, vfmv_f_s_f64m1_f64) +#endif + +////////////// Load/Store ////////////// + +#define OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(_Tpvec, _nTpvec, _Tp, hvl, width, suffix) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ \ + vsetvlmax_e8m1(); \ + return _Tpvec((_nTpvec)vle8_v_u8m1((uchar*)ptr)); \ +} \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vle##width##_v_##suffix##m1(ptr)); \ +} \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ \ + vsetvl_e##width##m1(hvl); \ + _Tpvec res = _Tpvec(vle##width##_v_##suffix##m1(ptr)); \ + vsetvlmax_e##width##m1(); \ + return res; \ +} \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ \ + vsetvlmax_e8m1(); \ + vse8_v_u8m1((uchar*)ptr, vle8_v_u8m1((uchar*)a.val)); \ +} \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + vse##width##_v_##suffix##m1(ptr, a); \ +} \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + vse##width##_v_##suffix##m1(ptr, a); \ +} \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode /*mode*/) \ +{ \ + vsetvlmax_e##width##m1(); \ + vse##width##_v_##suffix##m1(ptr, a); \ +} \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ \ + _Tp CV_DECL_ALIGNED(32) tmp_ptr[_Tpvec::nlanes] = {0}; \ + vsetvlmax_e##width##m1(); \ + vse##width##_v_##suffix##m1(tmp_ptr, a); \ + for(int i = 0; i < _Tpvec::nlanes/2; ++i) \ + { \ + ptr[i] = tmp_ptr[i]; \ + } \ +} \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ \ + _Tp CV_DECL_ALIGNED(32) tmp_ptr[_Tpvec::nlanes] = {0}; \ + vsetvlmax_e##width##m1(); \ + vse##width##_v_##suffix##m1(tmp_ptr, a); \ + for(int i = 0; i < _Tpvec::nlanes/2; ++i) \ + { \ + ptr[i] = tmp_ptr[i+_Tpvec::nlanes/2]; \ + } \ +} + +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_uint8x16, vuint8m1_t, uchar, 8, 8, u8) +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_int8x16, vint8m1_t, schar, 8, 8, i8) +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_uint16x8, vuint16m1_t, ushort, 4, 16, u16) +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_int16x8, vint16m1_t, short, 4, 16, i16) +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_uint32x4, vuint32m1_t, unsigned, 2, 32, u32) +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_int32x4, vint32m1_t, int, 2, 32, i32) +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_uint64x2, vuint64m1_t, uint64, 1, 64, u64) +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_int64x2, vint64m1_t, int64, 1, 64, i64) +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float32x4, vfloat32m1_t, float, 2, 32, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float64x2, vfloat64m1_t, double, 1, 64, f64) +#endif + +inline v_int8x16 v_load_halves(const schar* ptr0, const schar* ptr1) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + ptr0[0], ptr0[1], ptr0[2], ptr0[3], ptr0[4], ptr0[5], ptr0[6], ptr0[7], + ptr1[0], ptr1[1], ptr1[2], ptr1[3], ptr1[4], ptr1[5], ptr1[6], ptr1[7] + }; + vsetvlmax_e8m1(); + return v_int8x16(vle8_v_i8m1(elems)); +} +inline v_uint8x16 v_load_halves(const uchar* ptr0, const uchar* ptr1) { return v_reinterpret_as_u8(v_load_halves((schar*)ptr0, (schar*)ptr1)); } + +inline v_int16x8 v_load_halves(const short* ptr0, const short* ptr1) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + ptr0[0], ptr0[1], ptr0[2], ptr0[3], ptr1[0], ptr1[1], ptr1[2], ptr1[3] + }; + vsetvlmax_e16m1(); + return v_int16x8(vle16_v_i16m1(elems)); +} +inline v_uint16x8 v_load_halves(const ushort* ptr0, const ushort* ptr1) { return v_reinterpret_as_u16(v_load_halves((short*)ptr0, (short*)ptr1)); } + +inline v_int32x4 v_load_halves(const int* ptr0, const int* ptr1) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + ptr0[0], ptr0[1], ptr1[0], ptr1[1] + }; + vsetvlmax_e32m1(); + return v_int32x4(vle32_v_i32m1(elems)); +} +inline v_float32x4 v_load_halves(const float* ptr0, const float* ptr1) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + ptr0[0], ptr0[1], ptr1[0], ptr1[1] + }; + vsetvlmax_e32m1(); + return v_float32x4(vle32_v_f32m1(elems)); +} +inline v_uint32x4 v_load_halves(const unsigned* ptr0, const unsigned* ptr1) { return v_reinterpret_as_u32(v_load_halves((int*)ptr0, (int*)ptr1)); } + +inline v_int64x2 v_load_halves(const int64* ptr0, const int64* ptr1) +{ + int64 CV_DECL_ALIGNED(32) elems[2] = + { + ptr0[0], ptr1[0] + }; + vsetvlmax_e64m1(); + return v_int64x2(vle64_v_i64m1(elems)); +} +inline v_uint64x2 v_load_halves(const uint64* ptr0, const uint64* ptr1) { return v_reinterpret_as_u64(v_load_halves((int64*)ptr0, (int64*)ptr1)); } + +#if CV_SIMD128_64F +inline v_float64x2 v_load_halves(const double* ptr0, const double* ptr1) +{ + double CV_DECL_ALIGNED(32) elems[2] = + { + ptr0[0], ptr1[0] + }; + vsetvlmax_e64m1(); + return v_float64x2(vle64_v_f64m1(elems)); +} +#endif + + +////////////// Lookup table access //////////////////// + +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[ 0]], + tab[idx[ 1]], + tab[idx[ 2]], + tab[idx[ 3]], + tab[idx[ 4]], + tab[idx[ 5]], + tab[idx[ 6]], + tab[idx[ 7]], + tab[idx[ 8]], + tab[idx[ 9]], + tab[idx[10]], + tab[idx[11]], + tab[idx[12]], + tab[idx[13]], + tab[idx[14]], + tab[idx[15]] + }; + vsetvlmax_e8m1(); + return v_int8x16(vle8_v_i8m1(elems)); +} +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[4]], + tab[idx[4] + 1], + tab[idx[5]], + tab[idx[5] + 1], + tab[idx[6]], + tab[idx[6] + 1], + tab[idx[7]], + tab[idx[7] + 1] + }; + vsetvlmax_e8m1(); + return v_int8x16(vle8_v_i8m1(elems)); +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[0] + 2], + tab[idx[0] + 3], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[1] + 2], + tab[idx[1] + 3], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[2] + 2], + tab[idx[2] + 3], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[3] + 2], + tab[idx[3] + 3] + }; + vsetvlmax_e8m1(); + return v_int8x16(vle8_v_i8m1(elems)); +} +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((schar*)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((schar*)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((schar*)tab, idx)); } + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]], + tab[idx[4]], + tab[idx[5]], + tab[idx[6]], + tab[idx[7]] + }; + vsetvlmax_e16m1(); + return v_int16x8(vle16_v_i16m1(elems)); +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1] + }; + vsetvlmax_e16m1(); + return v_int16x8(vle16_v_i16m1(elems)); +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[0] + 2], + tab[idx[0] + 3], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[1] + 2], + tab[idx[1] + 3] + }; + vsetvlmax_e16m1(); + return v_int16x8(vle16_v_i16m1(elems)); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((short*)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((short*)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((short*)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + vsetvlmax_e32m1(); + return v_int32x4(vle32_v_i32m1(elems)); +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1] + }; + vsetvlmax_e32m1(); + return v_int32x4(vle32_v_i32m1(elems)); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + vsetvlmax_e32m1(); + return v_int32x4(vle32_v_i32m1(tab + idx[0])); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((int*)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((int*)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((int*)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + int64_t CV_DECL_ALIGNED(32) elems[2] = + { + tab[idx[0]], + tab[idx[1]] + }; + vsetvlmax_e64m1(); + return v_int64x2(vle64_v_i64m1(elems)); +} +inline v_int64x2 v_lut_pairs(const int64* tab, const int* idx) +{ + vsetvlmax_e64m1(); + return v_int64x2(vle64_v_i64m1(tab + idx[0])); +} +inline v_uint64x2 v_lut(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); } +inline v_uint64x2 v_lut_pairs(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); } + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + vsetvlmax_e32m1(); + return v_float32x4(vle32_v_f32m1(elems)); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1] + }; + vsetvlmax_e32m1(); + return v_float32x4(vle32_v_f32m1(elems)); +} +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) +{ + vsetvlmax_e32m1(); + return v_float32x4(vle32_v_f32m1(tab + idx[0])); +} + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[v_extract_n<0>(idxvec)], + tab[v_extract_n<1>(idxvec)], + tab[v_extract_n<2>(idxvec)], + tab[v_extract_n<3>(idxvec)] + }; + vsetvlmax_e32m1(); + return v_int32x4(vle32_v_i32m1(elems)); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + unsigned CV_DECL_ALIGNED(32) elems[4] = + { + tab[v_extract_n<0>(idxvec)], + tab[v_extract_n<1>(idxvec)], + tab[v_extract_n<2>(idxvec)], + tab[v_extract_n<3>(idxvec)] + }; + vsetvlmax_e32m1(); + return v_uint32x4(vle32_v_u32m1(elems)); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[v_extract_n<0>(idxvec)], + tab[v_extract_n<1>(idxvec)], + tab[v_extract_n<2>(idxvec)], + tab[v_extract_n<3>(idxvec)] + }; + vsetvlmax_e32m1(); + return v_float32x4(vle32_v_f32m1(elems)); +} + +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + x = v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); + y = v_float32x4(tab[idx[0]+1], tab[idx[1]+1], tab[idx[2]+1], tab[idx[3]+1]); +} + +#if CV_SIMD128_64F +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + double CV_DECL_ALIGNED(32) elems[2] = + { + tab[idx[0]], + tab[idx[1]] + }; + vsetvlmax_e64m1(); + return v_float64x2(vle64_v_f64m1(elems)); +} + +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) +{ + vsetvlmax_e64m1(); + return v_float64x2(vle64_v_f64m1(tab + idx[0])); +} + +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + double CV_DECL_ALIGNED(32) elems[2] = + { + tab[v_extract_n<0>(idxvec)], + tab[v_extract_n<1>(idxvec)] + }; + vsetvlmax_e64m1(); + return v_float64x2(vle64_v_f64m1(elems)); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + int CV_DECL_ALIGNED(32) idx[4] = {0}; + v_store_aligned(idx, idxvec); + + x = v_float64x2(tab[idx[0]], tab[idx[1]]); + y = v_float64x2(tab[idx[0]+1], tab[idx[1]+1]); +} +#endif + +////////////// Pack boolean //////////////////// + +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + ushort CV_DECL_ALIGNED(32) ptr[16] = {0}; + v_store(ptr, a); + v_store(ptr + 8, b); + vsetvlmax_e8m1(); + return v_uint8x16(vnsrl_wx_u8m1(vle16_v_u16m2(ptr), 0)); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + unsigned CV_DECL_ALIGNED(32) ptr[16] = {0}; + v_store(ptr, a); + v_store(ptr + 4, b); + v_store(ptr + 8, c); + v_store(ptr + 12, d); + vsetvlmax_e8m1(); + return v_uint8x16(vnsrl_wx_u8m1(vnsrl_wx_u16m2(vle32_v_u32m4(ptr), 0), 0)); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + uint64 CV_DECL_ALIGNED(32) ptr[16] = {0}; + v_store(ptr, a); + v_store(ptr + 2, b); + v_store(ptr + 4, c); + v_store(ptr + 6, d); + v_store(ptr + 8, e); + v_store(ptr + 10, f); + v_store(ptr + 12, g); + v_store(ptr + 14, h); + vsetvlmax_e8m1(); + return v_uint8x16(vnsrl_wx_u8m1(vnsrl_wx_u16m2(vnsrl_wx_u32m4(vle64_v_u64m8(ptr), 0), 0), 0)); +} + +////////////// Arithmetics ////////////// +#define OPENCV_HAL_IMPL_RVV_BIN_OP(bin_op, _Tpvec, intrin, width) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(intrin(a, b)); \ +} \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + a = _Tpvec(intrin(a, b)); \ + return a; \ +} + +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_uint8x16, vsaddu_vv_u8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_uint8x16, vssubu_vv_u8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_uint8x16, vdivu_vv_u8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_int8x16, vsadd_vv_i8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_int8x16, vssub_vv_i8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_int8x16, vdiv_vv_i8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_uint16x8, vsaddu_vv_u16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_uint16x8, vssubu_vv_u16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_uint16x8, vdivu_vv_u16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_int16x8, vsadd_vv_i16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_int16x8, vssub_vv_i16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_int16x8, vdiv_vv_i16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_uint32x4, vadd_vv_u32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_uint32x4, vsub_vv_u32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(*, v_uint32x4, vmul_vv_u32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_uint32x4, vdivu_vv_u32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_int32x4, vadd_vv_i32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_int32x4, vsub_vv_i32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(*, v_int32x4, vmul_vv_i32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_int32x4, vdiv_vv_i32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_float32x4, vfadd_vv_f32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_float32x4, vfsub_vv_f32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(*, v_float32x4, vfmul_vv_f32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_float32x4, vfdiv_vv_f32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_uint64x2, vadd_vv_u64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_uint64x2, vsub_vv_u64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(*, v_uint64x2, vmul_vv_u64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_uint64x2, vdivu_vv_u64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_int64x2, vadd_vv_i64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_int64x2, vsub_vv_i64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(*, v_int64x2, vmul_vv_i64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_int64x2, vdiv_vv_i64m1, 64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_BIN_OP(+, v_float64x2, vfadd_vv_f64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(-, v_float64x2, vfsub_vv_f64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(*, v_float64x2, vfmul_vv_f64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_OP(/, v_float64x2, vfdiv_vv_f64m1, 64) +#endif + + +////////////// Bitwise logic ////////////// + +#define OPENCV_HAL_IMPL_RVV_LOGIC_OP(_Tpvec, suffix, width) \ +OPENCV_HAL_IMPL_RVV_BIN_OP(&, _Tpvec, vand_vv_##suffix##m1, width) \ +OPENCV_HAL_IMPL_RVV_BIN_OP(|, _Tpvec, vor_vv_##suffix##m1, width) \ +OPENCV_HAL_IMPL_RVV_BIN_OP(^, _Tpvec, vxor_vv_##suffix##m1, width) \ +inline _Tpvec operator ~ (const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vnot_v_##suffix##m1(a)); \ +} + +OPENCV_HAL_IMPL_RVV_LOGIC_OP(v_uint8x16, u8, 8) +OPENCV_HAL_IMPL_RVV_LOGIC_OP(v_int8x16, i8, 8) +OPENCV_HAL_IMPL_RVV_LOGIC_OP(v_uint16x8, u16, 16) +OPENCV_HAL_IMPL_RVV_LOGIC_OP(v_int16x8, i16, 16) +OPENCV_HAL_IMPL_RVV_LOGIC_OP(v_uint32x4, u32, 32) +OPENCV_HAL_IMPL_RVV_LOGIC_OP(v_int32x4, i32, 32) +OPENCV_HAL_IMPL_RVV_LOGIC_OP(v_uint64x2, u64, 64) +OPENCV_HAL_IMPL_RVV_LOGIC_OP(v_int64x2, i64, 64) + +#define OPENCV_HAL_IMPL_RVV_FLT_BIT_OP(bin_op, intrin) \ +inline v_float32x4 operator bin_op (const v_float32x4& a, const v_float32x4& b) \ +{ \ + vsetvlmax_e32m1(); \ + return v_float32x4(vreinterpret_v_i32m1_f32m1(intrin(vreinterpret_v_f32m1_i32m1(a), vreinterpret_v_f32m1_i32m1(b)))); \ +} \ +inline v_float32x4& operator bin_op##= (v_float32x4& a, const v_float32x4& b) \ +{ \ + vsetvlmax_e32m1(); \ + a = v_float32x4(vreinterpret_v_i32m1_f32m1(intrin(vreinterpret_v_f32m1_i32m1(a), vreinterpret_v_f32m1_i32m1(b)))); \ + return a; \ +} + +OPENCV_HAL_IMPL_RVV_FLT_BIT_OP(&, vand_vv_i32m1) +OPENCV_HAL_IMPL_RVV_FLT_BIT_OP(|, vor_vv_i32m1) +OPENCV_HAL_IMPL_RVV_FLT_BIT_OP(^, vxor_vv_i32m1) + +inline v_float32x4 operator ~ (const v_float32x4& a) +{ + vsetvlmax_e32m1(); + return v_float32x4(vreinterpret_v_i32m1_f32m1(vnot_v_i32m1(vreinterpret_v_f32m1_i32m1(a)))); +} + +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_RVV_FLT64_BIT_OP(bin_op, intrin) \ +inline v_float64x2 operator bin_op (const v_float64x2& a, const v_float64x2& b) \ +{ \ + vsetvlmax_e64m1(); \ + return v_float64x2(vreinterpret_v_i64m1_f64m1(intrin(vreinterpret_v_f64m1_i64m1(a), vreinterpret_v_f64m1_i64m1(b)))); \ +} \ +inline v_float64x2& operator bin_op##= (v_float64x2& a, const v_float64x2& b) \ +{ \ + vsetvlmax_e64m1(); \ + a = v_float64x2(vreinterpret_v_i64m1_f64m1(intrin(vreinterpret_v_f64m1_i64m1(a), vreinterpret_v_f64m1_i64m1(b)))); \ + return a; \ +} + +OPENCV_HAL_IMPL_RVV_FLT64_BIT_OP(&, vand_vv_i64m1) +OPENCV_HAL_IMPL_RVV_FLT64_BIT_OP(|, vor_vv_i64m1) +OPENCV_HAL_IMPL_RVV_FLT64_BIT_OP(^, vxor_vv_i64m1) + +inline v_float64x2 operator ~ (const v_float64x2& a) +{ + vsetvlmax_e64m1(); + return v_float64x2(vreinterpret_v_i64m1_f64m1(vnot_v_i64m1(vreinterpret_v_f64m1_i64m1(a)))); +} +#endif + +////////////// Bitwise shifts ////////////// + +#define OPENCV_HAL_IMPL_RVV_UNSIGNED_SHIFT_OP(_Tpvec, suffix, width) \ +inline _Tpvec operator << (const _Tpvec& a, int n) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vsll_vx_##suffix##m1(a, uint8_t(n))); \ +} \ +inline _Tpvec operator >> (const _Tpvec& a, int n) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vsrl_vx_##suffix##m1(a, uint8_t(n))); \ +} \ +template inline _Tpvec v_shl(const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vsll_vx_##suffix##m1(a, uint8_t(n))); \ +} \ +template inline _Tpvec v_shr(const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vsrl_vx_##suffix##m1(a, uint8_t(n))); \ +} + +#define OPENCV_HAL_IMPL_RVV_SIGNED_SHIFT_OP(_Tpvec, suffix, width) \ +inline _Tpvec operator << (const _Tpvec& a, int n) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vsll_vx_##suffix##m1(a, uint8_t(n))); \ +} \ +inline _Tpvec operator >> (const _Tpvec& a, int n) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vsra_vx_##suffix##m1(a, uint8_t(n))); \ +} \ +template inline _Tpvec v_shl(const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vsll_vx_##suffix##m1(a, uint8_t(n))); \ +} \ +template inline _Tpvec v_shr(const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vsra_vx_##suffix##m1(a, uint8_t(n))); \ +} + +OPENCV_HAL_IMPL_RVV_UNSIGNED_SHIFT_OP(v_uint8x16, u8, 8) +OPENCV_HAL_IMPL_RVV_UNSIGNED_SHIFT_OP(v_uint16x8, u16, 16) +OPENCV_HAL_IMPL_RVV_UNSIGNED_SHIFT_OP(v_uint32x4, u32, 32) +OPENCV_HAL_IMPL_RVV_UNSIGNED_SHIFT_OP(v_uint64x2, u64, 64) +OPENCV_HAL_IMPL_RVV_SIGNED_SHIFT_OP(v_int8x16, i8, 8) +OPENCV_HAL_IMPL_RVV_SIGNED_SHIFT_OP(v_int16x8, i16, 16) +OPENCV_HAL_IMPL_RVV_SIGNED_SHIFT_OP(v_int32x4, i32, 32) +OPENCV_HAL_IMPL_RVV_SIGNED_SHIFT_OP(v_int64x2, i64, 64) + + +////////////// Comparison ////////////// + +#define OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, op, intrin, suffix, width) \ +inline _Tpvec operator op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vmerge_vxm_##suffix##m1(intrin(a, b), vzero_##suffix##m1(), 1)); \ +} + +#define OPENCV_HAL_IMPL_RVV_FLOAT_CMP_OP(_Tpvec, op, intrin, suffix, width) \ +inline _Tpvec operator op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vfmerge_vfm_##suffix##m1(intrin(a, b), vzero_##suffix##m1(), 1)); \ +} + +#define OPENCV_HAL_IMPL_RVV_UNSIGNED_CMP(_Tpvec, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, ==, vmseq_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, !=, vmsne_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, <, vmsltu_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, >, vmsgtu_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, <=, vmsleu_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, >=, vmsgeu_vv_##suffix##m1_b##width, suffix, width) + +#define OPENCV_HAL_IMPL_RVV_SIGNED_CMP(_Tpvec, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, ==, vmseq_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, !=, vmsne_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, <, vmslt_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, >, vmsgt_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, <=, vmsle_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_INT_CMP_OP(_Tpvec, >=, vmsge_vv_##suffix##m1_b##width, suffix, width) + +#define OPENCV_HAL_IMPL_RVV_FLOAT_CMP(_Tpvec, suffix, width) \ +OPENCV_HAL_IMPL_RVV_FLOAT_CMP_OP(_Tpvec, ==, vmfeq_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_FLOAT_CMP_OP(_Tpvec, !=, vmfne_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_FLOAT_CMP_OP(_Tpvec, <, vmflt_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_FLOAT_CMP_OP(_Tpvec, >, vmfgt_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_FLOAT_CMP_OP(_Tpvec, <=, vmfle_vv_##suffix##m1_b##width, suffix, width) \ +OPENCV_HAL_IMPL_RVV_FLOAT_CMP_OP(_Tpvec, >=, vmfge_vv_##suffix##m1_b##width, suffix, width) + + +OPENCV_HAL_IMPL_RVV_UNSIGNED_CMP(v_uint8x16, u8, 8) +OPENCV_HAL_IMPL_RVV_UNSIGNED_CMP(v_uint16x8, u16, 16) +OPENCV_HAL_IMPL_RVV_UNSIGNED_CMP(v_uint32x4, u32, 32) +OPENCV_HAL_IMPL_RVV_UNSIGNED_CMP(v_uint64x2, u64, 64) +OPENCV_HAL_IMPL_RVV_SIGNED_CMP(v_int8x16, i8, 8) +OPENCV_HAL_IMPL_RVV_SIGNED_CMP(v_int16x8, i16, 16) +OPENCV_HAL_IMPL_RVV_SIGNED_CMP(v_int32x4, i32, 32) +OPENCV_HAL_IMPL_RVV_SIGNED_CMP(v_int64x2, i64, 64) +OPENCV_HAL_IMPL_RVV_FLOAT_CMP(v_float32x4, f32, 32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_FLOAT_CMP(v_float64x2, f64, 64) +#endif + +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ return a == a; } + +#if CV_SIMD128_64F +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ return a == a; } +#endif + +////////////// Min/Max ////////////// + +#define OPENCV_HAL_IMPL_RVV_BIN_FUNC(_Tpvec, func, intrin, width) \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(intrin(a, b)); \ +} + +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint8x16, v_min, vminu_vv_u8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint8x16, v_max, vmaxu_vv_u8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int8x16, v_min, vmin_vv_i8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int8x16, v_max, vmax_vv_i8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint16x8, v_min, vminu_vv_u16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint16x8, v_max, vmaxu_vv_u16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int16x8, v_min, vmin_vv_i16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int16x8, v_max, vmax_vv_i16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint32x4, v_min, vminu_vv_u32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint32x4, v_max, vmaxu_vv_u32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int32x4, v_min, vmin_vv_i32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int32x4, v_max, vmax_vv_i32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_float32x4, v_min, vfmin_vv_f32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_float32x4, v_max, vfmax_vv_f32m1, 32) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint64x2, v_min, vminu_vv_u64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint64x2, v_max, vmaxu_vv_u64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int64x2, v_min, vmin_vv_i64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int64x2, v_max, vmax_vv_i64m1, 64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_float64x2, v_min, vfmin_vv_f64m1, 64) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_float64x2, v_max, vfmax_vv_f64m1, 64) +#endif + +////////////// Arithmetics wrap ////////////// + +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint8x16, v_add_wrap, vadd_vv_u8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int8x16, v_add_wrap, vadd_vv_i8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint16x8, v_add_wrap, vadd_vv_u16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int16x8, v_add_wrap, vadd_vv_i16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint8x16, v_sub_wrap, vsub_vv_u8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int8x16, v_sub_wrap, vsub_vv_i8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint16x8, v_sub_wrap, vsub_vv_u16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int16x8, v_sub_wrap, vsub_vv_i16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint8x16, v_mul_wrap, vmul_vv_u8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int8x16, v_mul_wrap, vmul_vv_i8m1, 8) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_uint16x8, v_mul_wrap, vmul_vv_u16m1, 16) +OPENCV_HAL_IMPL_RVV_BIN_FUNC(v_int16x8, v_mul_wrap, vmul_vv_i16m1, 16) + +////////////// Reduce ////////////// + +#define OPENCV_HAL_IMPL_RVV_REDUCE_SUM(_Tpvec, _wTpvec, _nwTpvec, scalartype, suffix, wsuffix, wwidth, red) \ +inline scalartype v_reduce_sum(const _Tpvec& a) \ +{ \ + vsetvlmax_e##wwidth##m1(); \ + _nwTpvec zero = vzero_##wsuffix##m1(); \ + _nwTpvec res = vzero_##wsuffix##m1(); \ + res = v##red##_vs_##suffix##m1_##wsuffix##m1(res, a, zero); \ + return (scalartype)(_wTpvec(res).get0()); \ +} + +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_uint8x16, v_uint16x8, vuint16m1_t, unsigned, u8, u16, 16, wredsumu) +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_int8x16, v_int16x8, vint16m1_t, int, i8, i16, 16, wredsum) +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_uint16x8, v_uint32x4, vuint32m1_t, unsigned, u16, u32, 32, wredsumu) +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_int16x8, v_int32x4, vint32m1_t, int, i16, i32, 32, wredsum) +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_uint32x4, v_uint64x2, vuint64m1_t, unsigned, u32, u64, 64, wredsumu) +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_int32x4, v_int64x2, vint64m1_t, int, i32, i64, 64, wredsum) +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_float32x4, v_float32x4, vfloat32m1_t, float, f32, f32, 32, fredsum) +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_uint64x2, v_uint64x2, vuint64m1_t, uint64, u64, u64, 64, redsum) +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_int64x2, v_int64x2, vint64m1_t, int64, i64, i64, 64, redsum) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_REDUCE_SUM(v_float64x2, v_float64x2, vfloat64m1_t, double, f64, f64, 64, fredsum) +#endif + + +#define OPENCV_HAL_IMPL_RVV_REDUCE(_Tpvec, func, scalartype, suffix, width, red) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + _Tpvec res = _Tpvec(v##red##_vs_##suffix##m1_##suffix##m1(a, a, a)); \ + return scalartype(res.get0()); \ +} + +OPENCV_HAL_IMPL_RVV_REDUCE(v_uint8x16, min, uchar, u8, 8, redminu) +OPENCV_HAL_IMPL_RVV_REDUCE(v_int8x16, min, schar, i8, 8, redmin) +OPENCV_HAL_IMPL_RVV_REDUCE(v_uint16x8, min, ushort, u16, 16, redminu) +OPENCV_HAL_IMPL_RVV_REDUCE(v_int16x8, min, short, i16, 16, redmin) +OPENCV_HAL_IMPL_RVV_REDUCE(v_uint32x4, min, unsigned, u32, 32, redminu) +OPENCV_HAL_IMPL_RVV_REDUCE(v_int32x4, min, int, i32, 32, redmin) +OPENCV_HAL_IMPL_RVV_REDUCE(v_float32x4, min, float, f32, 32, fredmin) +OPENCV_HAL_IMPL_RVV_REDUCE(v_uint8x16, max, uchar, u8, 8, redmaxu) +OPENCV_HAL_IMPL_RVV_REDUCE(v_int8x16, max, schar, i8, 8, redmax) +OPENCV_HAL_IMPL_RVV_REDUCE(v_uint16x8, max, ushort, u16, 16, redmaxu) +OPENCV_HAL_IMPL_RVV_REDUCE(v_int16x8, max, short, i16, 16, redmax) +OPENCV_HAL_IMPL_RVV_REDUCE(v_uint32x4, max, unsigned, u32, 32, redmaxu) +OPENCV_HAL_IMPL_RVV_REDUCE(v_int32x4, max, int, i32, 32, redmax) +OPENCV_HAL_IMPL_RVV_REDUCE(v_float32x4, max, float, f32, 32, fredmax) + + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + v_reduce_sum(a), + v_reduce_sum(b), + v_reduce_sum(c), + v_reduce_sum(d) + }; + vsetvlmax_e32m1(); + return v_float32x4(vle32_v_f32m1(elems)); +} + +////////////// Square-Root ////////////// + +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ + vsetvlmax_e32m1(); + return v_float32x4(vfsqrt_v_f32m1(x)); +} + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ + v_float32x4 one = v_setall_f32(1.0f); + return one / v_sqrt(x); +} + +#if CV_SIMD128_64F +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ + vsetvlmax_e64m1(); + return v_float64x2(vfsqrt_v_f64m1(x)); +} + +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ + v_float64x2 one = v_setall_f64(1.0f); + return one / v_sqrt(x); +} +#endif + +inline v_float32x4 v_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + vsetvlmax_e32m1(); + v_float32x4 x(vfmacc_vv_f32m1(vfmul_vv_f32m1(a, a), b, b)); + return v_sqrt(x); +} + +inline v_float32x4 v_sqr_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + vsetvlmax_e32m1(); + return v_float32x4(vfmacc_vv_f32m1(vfmul_vv_f32m1(a, a), b, b)); +} + +#if CV_SIMD128_64F +inline v_float64x2 v_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + vsetvlmax_e64m1(); + v_float64x2 x(vfmacc_vv_f64m1(vfmul_vv_f64m1(a, a), b, b)); + return v_sqrt(x); +} + +inline v_float64x2 v_sqr_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + vsetvlmax_e64m1(); + return v_float64x2(vfmacc_vv_f64m1(vfmul_vv_f64m1(a, a), b, b)); +} +#endif + +////////////// Multiply-Add ////////////// + +inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ + vsetvlmax_e32m1(); + return v_float32x4(vfmacc_vv_f32m1(c, a, b)); +} +inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + vsetvlmax_e32m1(); + return v_int32x4(vmacc_vv_i32m1(c, a, b)); +} + +inline v_float32x4 v_muladd(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_fma(a, b, c); +} + +#if CV_SIMD128_64F +inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + vsetvlmax_e64m1(); + return v_float64x2(vfmacc_vv_f64m1(c, a, b)); +} + +inline v_float64x2 v_muladd(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_fma(a, b, c); +} +#endif + +////////////// Check all/any ////////////// + +#define OPENCV_HAL_IMPL_RVV_CHECK_ALLANY(_Tpvec, suffix, shift, width) \ +inline bool v_check_all(const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + v_uint64x2 v = v_uint64x2((vuint64m1_t)vsrl_vx_##suffix##m1(vnot_v_##suffix##m1(a), shift)); \ + return (v.val[0] | v.val[1]) == 0; \ +} \ +inline bool v_check_any(const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + v_uint64x2 v = v_uint64x2((vuint64m1_t)vsrl_vx_##suffix##m1(a, shift)); \ + return (v.val[0] | v.val[1]) != 0; \ +} + +OPENCV_HAL_IMPL_RVV_CHECK_ALLANY(v_uint8x16, u8, 7, 8) +OPENCV_HAL_IMPL_RVV_CHECK_ALLANY(v_uint16x8, u16, 15, 16) +OPENCV_HAL_IMPL_RVV_CHECK_ALLANY(v_uint32x4, u32, 31, 32) +OPENCV_HAL_IMPL_RVV_CHECK_ALLANY(v_uint64x2, u64, 63, 64) + + +inline bool v_check_all(const v_int8x16& a) +{ return v_check_all(v_reinterpret_as_u8(a)); } +inline bool v_check_any(const v_int8x16& a) +{ return v_check_any(v_reinterpret_as_u8(a)); } + +inline bool v_check_all(const v_int16x8& a) +{ return v_check_all(v_reinterpret_as_u16(a)); } +inline bool v_check_any(const v_int16x8& a) +{ return v_check_any(v_reinterpret_as_u16(a)); } + +inline bool v_check_all(const v_int32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } +inline bool v_check_any(const v_int32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } + +inline bool v_check_all(const v_float32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } +inline bool v_check_any(const v_float32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } + +inline bool v_check_all(const v_int64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_int64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } + +#if CV_SIMD128_64F +inline bool v_check_all(const v_float64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_float64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } +#endif + +////////////// abs ////////////// + +#define OPENCV_HAL_IMPL_RVV_ABSDIFF(_Tpvec, abs) \ +inline _Tpvec v_##abs(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return v_max(a, b) - v_min(a, b); \ +} + +OPENCV_HAL_IMPL_RVV_ABSDIFF(v_uint8x16, absdiff) +OPENCV_HAL_IMPL_RVV_ABSDIFF(v_uint16x8, absdiff) +OPENCV_HAL_IMPL_RVV_ABSDIFF(v_uint32x4, absdiff) +OPENCV_HAL_IMPL_RVV_ABSDIFF(v_float32x4, absdiff) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_ABSDIFF(v_float64x2, absdiff) +#endif +OPENCV_HAL_IMPL_RVV_ABSDIFF(v_int8x16, absdiffs) +OPENCV_HAL_IMPL_RVV_ABSDIFF(v_int16x8, absdiffs) + +#define OPENCV_HAL_IMPL_RVV_ABSDIFF_S(_Tpvec, _rTpvec, _nwTpvec, sub, rshr, width) \ +inline _rTpvec v_absdiff(const _Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _rTpvec(rshr((_nwTpvec)sub(v_max(a, b), v_min(a, b)), 0)); \ +} + +OPENCV_HAL_IMPL_RVV_ABSDIFF_S(v_int8x16, v_uint8x16, vuint16m2_t, vwsub_vv_i16m2, vnclipu_wx_u8m1, 8) +OPENCV_HAL_IMPL_RVV_ABSDIFF_S(v_int16x8, v_uint16x8, vuint32m2_t, vwsub_vv_i32m2, vnclipu_wx_u16m1, 16) +OPENCV_HAL_IMPL_RVV_ABSDIFF_S(v_int32x4, v_uint32x4, vuint64m2_t, vwsub_vv_i64m2, vnclipu_wx_u32m1, 32) + +#define OPENCV_HAL_IMPL_RVV_ABS(_Tprvec, _Tpvec, suffix) \ +inline _Tprvec v_abs(const _Tpvec& a) \ +{ \ + return v_absdiff(a, v_setzero_##suffix()); \ +} + +OPENCV_HAL_IMPL_RVV_ABS(v_uint8x16, v_int8x16, s8) +OPENCV_HAL_IMPL_RVV_ABS(v_uint16x8, v_int16x8, s16) +OPENCV_HAL_IMPL_RVV_ABS(v_uint32x4, v_int32x4, s32) +OPENCV_HAL_IMPL_RVV_ABS(v_float32x4, v_float32x4, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_ABS(v_float64x2, v_float64x2, f64) +#endif + + +#define OPENCV_HAL_IMPL_RVV_REDUCE_SAD(_Tpvec, scalartype) \ +inline scalartype v_reduce_sad(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return v_reduce_sum(v_absdiff(a, b)); \ +} + +OPENCV_HAL_IMPL_RVV_REDUCE_SAD(v_uint8x16, unsigned) +OPENCV_HAL_IMPL_RVV_REDUCE_SAD(v_int8x16, unsigned) +OPENCV_HAL_IMPL_RVV_REDUCE_SAD(v_uint16x8, unsigned) +OPENCV_HAL_IMPL_RVV_REDUCE_SAD(v_int16x8, unsigned) +OPENCV_HAL_IMPL_RVV_REDUCE_SAD(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_RVV_REDUCE_SAD(v_int32x4, unsigned) +OPENCV_HAL_IMPL_RVV_REDUCE_SAD(v_float32x4, float) + +////////////// Select ////////////// + +#define OPENCV_HAL_IMPL_RVV_SELECT(_Tpvec, merge, ne, width) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(merge(ne(mask, 0), b, a)); \ +} + +OPENCV_HAL_IMPL_RVV_SELECT(v_uint8x16, vmerge_vvm_u8m1, vmsne_vx_u8m1_b8, 8) +OPENCV_HAL_IMPL_RVV_SELECT(v_int8x16, vmerge_vvm_i8m1, vmsne_vx_i8m1_b8, 8) +OPENCV_HAL_IMPL_RVV_SELECT(v_uint16x8, vmerge_vvm_u16m1, vmsne_vx_u16m1_b16, 16) +OPENCV_HAL_IMPL_RVV_SELECT(v_int16x8, vmerge_vvm_i16m1, vmsne_vx_i16m1_b16, 16) +OPENCV_HAL_IMPL_RVV_SELECT(v_uint32x4, vmerge_vvm_u32m1, vmsne_vx_u32m1_b32, 32) +OPENCV_HAL_IMPL_RVV_SELECT(v_int32x4, vmerge_vvm_i32m1, vmsne_vx_i32m1_b32, 32) +OPENCV_HAL_IMPL_RVV_SELECT(v_float32x4, vmerge_vvm_f32m1, vmfne_vf_f32m1_b32, 32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_SELECT(v_float64x2, vmerge_vvm_f64m1, vmfne_vf_f64m1_b64, 64) +#endif + +////////////// Rotate shift ////////////// + +#define OPENCV_HAL_IMPL_RVV_ROTATE_OP(_Tpvec, suffix, width) \ +template inline _Tpvec v_rotate_right(const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vslidedown_vx_##suffix##m1(vzero_##suffix##m1(), a, n)); \ +} \ +template inline _Tpvec v_rotate_left(const _Tpvec& a) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vslideup_vx_##suffix##m1(vzero_##suffix##m1(), a, n)); \ +} \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a) \ +{ return a; } \ +template inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vslideup_vx_##suffix##m1(vslidedown_vx_##suffix##m1(vzero_##suffix##m1(), a, n), b, _Tpvec::nlanes - n)); \ +} \ +template inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \ +{ \ + vsetvlmax_e##width##m1(); \ + return _Tpvec(vslideup_vx_##suffix##m1(vslidedown_vx_##suffix##m1(vzero_##suffix##m1(), b, _Tpvec::nlanes - n), a, n)); \ +} \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a, const _Tpvec& b) \ +{ CV_UNUSED(b); return a; } + + +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_uint8x16, u8, 8) +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_int8x16, i8, 8) +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_uint16x8, u16, 16) +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_int16x8, i16, 16) +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_uint32x4, u32, 32) +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_int32x4, i32, 32) +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_float32x4, f32, 32) +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_uint64x2, u64, 64) +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_int64x2, i64, 64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_ROTATE_OP(v_float64x2, f64, 64) +#endif + +////////////// Convert to float ////////////// + +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ + vsetvlmax_e32m1(); + return v_float32x4(vfcvt_f_x_v_f32m1(a)); +} + +#if CV_SIMD128_64F +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ + double arr[4] = {a.val[0], a.val[1], 0, 0}; + vsetvlmax_e64m2(); + vfloat64m2_t tmp = vle64_v_f64m2(arr); + vsetvlmax_e32m1(); + return v_float32x4(vfncvt_f_f_w_f32m1(tmp)); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ + double arr[4] = {a.val[0], a.val[1], b.val[0], b.val[1]}; + vsetvlmax_e64m2(); + vfloat64m2_t tmp = vle64_v_f64m2(arr); + vsetvlmax_e32m1(); + return v_float32x4(vfncvt_f_f_w_f32m1(tmp)); +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ + double CV_DECL_ALIGNED(32) ptr[4] = {0}; + vsetvlmax_e64m2(); + vse64_v_f64m2(ptr, vfwcvt_f_x_v_f64m2(a)); + double CV_DECL_ALIGNED(32) elems[2] = + { + ptr[0], ptr[1] + }; + vsetvlmax_e64m1(); + return v_float64x2(vle64_v_f64m1(elems)); +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + double CV_DECL_ALIGNED(32) ptr[4] = {0}; + vsetvlmax_e64m2(); + vse64_v_f64m2(ptr, vfwcvt_f_x_v_f64m2(a)); + double CV_DECL_ALIGNED(32) elems[2] = + { + ptr[2], ptr[3] + }; + vsetvlmax_e64m1(); + return v_float64x2(vle64_v_f64m1(elems)); +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + double CV_DECL_ALIGNED(32) ptr[4] = {0}; + vsetvlmax_e64m2(); + vse64_v_f64m2(ptr, vfwcvt_f_f_v_f64m2(a)); + double CV_DECL_ALIGNED(32) elems[2] = + { + ptr[0], ptr[1] + }; + vsetvlmax_e64m1(); + return v_float64x2(vle64_v_f64m1(elems)); +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + double CV_DECL_ALIGNED(32) ptr[4] = {0}; + vsetvlmax_e64m2(); + vse64_v_f64m2(ptr, vfwcvt_f_f_v_f64m2(a)); + double CV_DECL_ALIGNED(32) elems[2] = + { + ptr[2], ptr[3] + }; + vsetvlmax_e64m1(); + return v_float64x2(vle64_v_f64m1(elems)); +} + +inline v_float64x2 v_cvt_f64(const v_int64x2& a) +{ + vsetvlmax_e64m1(); + return v_float64x2(vfcvt_f_x_v_f64m1(a)); +} +#endif + +////////////// Broadcast ////////////// + +#define OPENCV_HAL_IMPL_RVV_BROADCAST(_Tpvec, suffix) \ +template inline _Tpvec v_broadcast_element(_Tpvec v) \ +{ \ + return v_setall_##suffix(v_extract_n(v)); \ +} + +OPENCV_HAL_IMPL_RVV_BROADCAST(v_uint8x16, u8) +OPENCV_HAL_IMPL_RVV_BROADCAST(v_int8x16, s8) +OPENCV_HAL_IMPL_RVV_BROADCAST(v_uint16x8, u16) +OPENCV_HAL_IMPL_RVV_BROADCAST(v_int16x8, s16) +OPENCV_HAL_IMPL_RVV_BROADCAST(v_uint32x4, u32) +OPENCV_HAL_IMPL_RVV_BROADCAST(v_int32x4, s32) +OPENCV_HAL_IMPL_RVV_BROADCAST(v_uint64x2, u64) +OPENCV_HAL_IMPL_RVV_BROADCAST(v_int64x2, s64) +OPENCV_HAL_IMPL_RVV_BROADCAST(v_float32x4, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_BROADCAST(v_float64x2, f64) +#endif + +////////////// Transpose4x4 ////////////// + +#define OPENCV_HAL_IMPL_RVV_TRANSPOSE4x4(_Tpvec, _Tp, suffix) \ +inline void v_transpose4x4(const v_##_Tpvec& a0, const v_##_Tpvec& a1, \ + const v_##_Tpvec& a2, const v_##_Tpvec& a3, \ + v_##_Tpvec& b0, v_##_Tpvec& b1, \ + v_##_Tpvec& b2, v_##_Tpvec& b3) \ +{ \ + _Tp CV_DECL_ALIGNED(32) elems0[4] = \ + { \ + v_extract_n<0>(a0), \ + v_extract_n<0>(a1), \ + v_extract_n<0>(a2), \ + v_extract_n<0>(a3) \ + }; \ + b0 = v_load(elems0); \ + _Tp CV_DECL_ALIGNED(32) elems1[4] = \ + { \ + v_extract_n<1>(a0), \ + v_extract_n<1>(a1), \ + v_extract_n<1>(a2), \ + v_extract_n<1>(a3) \ + }; \ + b1 = v_load(elems1); \ + _Tp CV_DECL_ALIGNED(32) elems2[4] = \ + { \ + v_extract_n<2>(a0), \ + v_extract_n<2>(a1), \ + v_extract_n<2>(a2), \ + v_extract_n<2>(a3) \ + }; \ + b2 = v_load(elems2); \ + _Tp CV_DECL_ALIGNED(32) elems3[4] = \ + { \ + v_extract_n<3>(a0), \ + v_extract_n<3>(a1), \ + v_extract_n<3>(a2), \ + v_extract_n<3>(a3) \ + }; \ + b3 = v_load(elems3); \ +} + +OPENCV_HAL_IMPL_RVV_TRANSPOSE4x4(uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_RVV_TRANSPOSE4x4(int32x4, int, i32) +OPENCV_HAL_IMPL_RVV_TRANSPOSE4x4(float32x4, float, f32) + +////////////// Reverse ////////////// + +#define OPENCV_HAL_IMPL_RVV_REVERSE(_Tpvec, _Tp, width, suffix) \ +inline _Tpvec v_reverse(const _Tpvec& a) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptr[_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptra[_Tpvec::nlanes] = {0}; \ + v_store(ptra, a); \ + for (int i = 0; i < _Tpvec::nlanes; i++) \ + { \ + ptr[i] = ptra[_Tpvec::nlanes-i-1]; \ + } \ + return v_load(ptr); \ +} + +OPENCV_HAL_IMPL_RVV_REVERSE(v_uint8x16, uchar, 8, u8) +OPENCV_HAL_IMPL_RVV_REVERSE(v_int8x16, schar, 8, i8) +OPENCV_HAL_IMPL_RVV_REVERSE(v_uint16x8, ushort, 16, u16) +OPENCV_HAL_IMPL_RVV_REVERSE(v_int16x8, short, 16, i16) +OPENCV_HAL_IMPL_RVV_REVERSE(v_uint32x4, unsigned, 32, u32) +OPENCV_HAL_IMPL_RVV_REVERSE(v_int32x4, int, 32, i32) +OPENCV_HAL_IMPL_RVV_REVERSE(v_float32x4, float, 32, f32) +OPENCV_HAL_IMPL_RVV_REVERSE(v_uint64x2, uint64, 64, u64) +OPENCV_HAL_IMPL_RVV_REVERSE(v_int64x2, int64, 64, i64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_REVERSE(v_float64x2, double, 64, f64) +#endif + +//////////// Value reordering //////////// + +#define OPENCV_HAL_IMPL_RVV_EXPAND(_Tpwvec, _Tp, _Tpvec, width, suffix, wcvt) \ +inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ +{ \ + _Tp CV_DECL_ALIGNED(32) lptr[_Tpvec::nlanes/2] = {0}; \ + _Tp CV_DECL_ALIGNED(32) hptr[_Tpvec::nlanes/2] = {0}; \ + v_store_low(lptr, a); \ + v_store_high(hptr, a); \ + b0 = _Tpwvec(wcvt(vle##width##_v_##suffix##mf2(lptr))); \ + b1 = _Tpwvec(wcvt(vle##width##_v_##suffix##mf2(hptr))); \ +} \ +inline _Tpwvec v_expand_low(const _Tpvec& a) \ +{ \ + _Tp CV_DECL_ALIGNED(32) lptr[_Tpvec::nlanes/2] = {0}; \ + v_store_low(lptr, a); \ + return _Tpwvec(wcvt(vle##width##_v_##suffix##mf2(lptr))); \ +} \ +inline _Tpwvec v_expand_high(const _Tpvec& a) \ +{ \ + _Tp CV_DECL_ALIGNED(32) hptr[_Tpvec::nlanes/2] = {0}; \ + v_store_high(hptr, a); \ + return _Tpwvec(wcvt(vle##width##_v_##suffix##mf2(hptr))); \ +} \ +inline _Tpwvec v_load_expand(const _Tp* ptr) \ +{ \ + return _Tpwvec(wcvt(vle##width##_v_##suffix##mf2(ptr))); \ +} + +OPENCV_HAL_IMPL_RVV_EXPAND(v_uint16x8, uchar, v_uint8x16, 8, u8, vwcvtu_x_x_v_u16m1) +OPENCV_HAL_IMPL_RVV_EXPAND(v_int16x8, schar, v_int8x16, 8, i8, vwcvt_x_x_v_i16m1) +OPENCV_HAL_IMPL_RVV_EXPAND(v_uint32x4, ushort, v_uint16x8, 16, u16, vwcvtu_x_x_v_u32m1) +OPENCV_HAL_IMPL_RVV_EXPAND(v_int32x4, short, v_int16x8, 16, i16, vwcvt_x_x_v_i32m1) +OPENCV_HAL_IMPL_RVV_EXPAND(v_uint64x2, uint, v_uint32x4, 32, u32, vwcvtu_x_x_v_u64m1) +OPENCV_HAL_IMPL_RVV_EXPAND(v_int64x2, int, v_int32x4, 32, i32, vwcvt_x_x_v_i64m1) + +inline v_uint32x4 v_load_expand_q(const uchar* ptr) +{ + vsetvlmax_e32m1(); + return v_uint32x4(vwcvtu_x_x_v_u32m1(vwcvtu_x_x_v_u16mf2(vle8_v_u8mf4(ptr)))); +} + +inline v_int32x4 v_load_expand_q(const schar* ptr) +{ + vsetvlmax_e32m1(); + return v_int32x4(vwcvt_x_x_v_i32m1(vwcvt_x_x_v_i16mf2(vle8_v_i8mf4(ptr)))); +} + + +#define OPENCV_HAL_IMPL_RVV_PACK(_Tpvec, _Tp, _wTpvec, _wTp, width, suffix, rshr, shr) \ +inline _Tpvec v_pack(const _wTpvec& a, const _wTpvec& b) \ +{ \ + _wTp CV_DECL_ALIGNED(32) arr[_Tpvec::nlanes] = {0}; \ + v_store(arr, a); \ + v_store(arr + _wTpvec::nlanes, b); \ + vsetvlmax_e##width##m2(); \ + return _Tpvec(shr(vle##width##_v_##suffix##m2(arr), 0)); \ +} \ +inline void v_pack_store(_Tp* ptr, const _wTpvec& a) \ +{ \ + _wTp CV_DECL_ALIGNED(32) arr[_Tpvec::nlanes] = {0}; \ + v_store(arr, a); \ + v_store(arr + _wTpvec::nlanes, _wTpvec(vzero_##suffix##m1())); \ + vsetvlmax_e##width##m2(); \ + v_store(ptr, _Tpvec(shr(vle##width##_v_##suffix##m2(arr), 0))); \ +} \ +template inline \ +_Tpvec v_rshr_pack(const _wTpvec& a, const _wTpvec& b) \ +{ \ + _wTp CV_DECL_ALIGNED(32) arr[_Tpvec::nlanes] = {0}; \ + v_store(arr, a); \ + v_store(arr + _wTpvec::nlanes, b); \ + vsetvlmax_e##width##m2(); \ + return _Tpvec(rshr(vle##width##_v_##suffix##m2(arr), n)); \ +} \ +template inline \ +void v_rshr_pack_store(_Tp* ptr, const _wTpvec& a) \ +{ \ + _wTp CV_DECL_ALIGNED(32) arr[_Tpvec::nlanes] = {0}; \ + v_store(arr, a); \ + v_store(arr + _wTpvec::nlanes, _wTpvec(vzero_##suffix##m1())); \ + vsetvlmax_e##width##m2(); \ + v_store(ptr, _Tpvec(rshr(vle##width##_v_##suffix##m2(arr), n))); \ +} + +OPENCV_HAL_IMPL_RVV_PACK(v_uint8x16, uchar, v_uint16x8, ushort, 16, u16, vnclipu_wx_u8m1, vnclipu_wx_u8m1) +OPENCV_HAL_IMPL_RVV_PACK(v_int8x16, schar, v_int16x8, short, 16, i16, vnclip_wx_i8m1, vnclip_wx_i8m1) +OPENCV_HAL_IMPL_RVV_PACK(v_uint16x8, ushort, v_uint32x4, unsigned, 32, u32, vnclipu_wx_u16m1, vnclipu_wx_u16m1) +OPENCV_HAL_IMPL_RVV_PACK(v_int16x8, short, v_int32x4, int, 32, i32, vnclip_wx_i16m1, vnclip_wx_i16m1) +OPENCV_HAL_IMPL_RVV_PACK(v_uint32x4, unsigned, v_uint64x2, uint64, 64, u64, vnclipu_wx_u32m1, vnsrl_wx_u32m1) +OPENCV_HAL_IMPL_RVV_PACK(v_int32x4, int, v_int64x2, int64, 64, i64, vnclip_wx_i32m1, vnsra_wx_i32m1) + + +#define OPENCV_HAL_IMPL_RVV_PACK_U(_Tpvec, _Tp, _wTpvec, _wTp, width, suffix, rshr, cast) \ +inline _Tpvec v_pack_u(const _wTpvec& a, const _wTpvec& b) \ +{ \ + _wTp CV_DECL_ALIGNED(32) arr[_Tpvec::nlanes] = {0}; \ + v_store(arr, a); \ + v_store(arr + _wTpvec::nlanes, b); \ + vsetvlmax_e##width##m2(); \ + return _Tpvec(rshr(cast(vmax_vx_##suffix##m2(vle##width##_v_##suffix##m2(arr), 0)), 0)); \ +} \ +inline void v_pack_u_store(_Tp* ptr, const _wTpvec& a) \ +{ \ + _wTp CV_DECL_ALIGNED(32) arr[_Tpvec::nlanes] = {0}; \ + v_store(arr, a); \ + v_store(arr + _wTpvec::nlanes, _wTpvec(vzero_##suffix##m1())); \ + vsetvlmax_e##width##m2(); \ + v_store(ptr, _Tpvec(rshr(cast(vmax_vx_##suffix##m2(vle##width##_v_##suffix##m2(arr), 0)), 0))); \ +} \ +template inline \ +_Tpvec v_rshr_pack_u(const _wTpvec& a, const _wTpvec& b) \ +{ \ + _wTp CV_DECL_ALIGNED(32) arr[_Tpvec::nlanes] = {0}; \ + v_store(arr, a); \ + v_store(arr + _wTpvec::nlanes, b); \ + vsetvlmax_e##width##m2(); \ + return _Tpvec(rshr(cast(vmax_vx_##suffix##m2(vle##width##_v_##suffix##m2(arr), 0)), n)); \ +} \ +template inline \ +void v_rshr_pack_u_store(_Tp* ptr, const _wTpvec& a) \ +{ \ + _wTp CV_DECL_ALIGNED(32) arr[_Tpvec::nlanes] = {0}; \ + v_store(arr, a); \ + v_store(arr + _wTpvec::nlanes, _wTpvec(vzero_##suffix##m1())); \ + vsetvlmax_e##width##m2(); \ + v_store(ptr, _Tpvec(rshr(cast(vmax_vx_##suffix##m2(vle##width##_v_##suffix##m2(arr), 0)), n))); \ +} + +OPENCV_HAL_IMPL_RVV_PACK_U(v_uint8x16, uchar, v_int16x8, short, 16, i16, vnclipu_wx_u8m1, vreinterpret_v_i16m2_u16m2) +OPENCV_HAL_IMPL_RVV_PACK_U(v_uint16x8, ushort, v_int32x4, int, 32, i32, vnclipu_wx_u16m1, vreinterpret_v_i32m2_u32m2) + + +#define OPENCV_HAL_IMPL_RVV_UNPACKS(_Tpvec, _Tp, width, suffix) \ +inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptra0[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptra1[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb0[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb1[v_##_Tpvec::nlanes] = {0}; \ + v_store(ptra0, a0); \ + v_store(ptra1, a1); \ + int i; \ + for( i = 0; i < v_##_Tpvec::nlanes/2; i++ ) \ + { \ + ptrb0[i*2] = ptra0[i]; \ + ptrb0[i*2+1] = ptra1[i]; \ + } \ + for( ; i < v_##_Tpvec::nlanes; i++ ) \ + { \ + ptrb1[i*2-v_##_Tpvec::nlanes] = ptra0[i]; \ + ptrb1[i*2-v_##_Tpvec::nlanes+1] = ptra1[i]; \ + } \ + b0 = v_load(ptrb0); \ + b1 = v_load(ptrb1); \ +} \ +inline v_##_Tpvec v_combine_low(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptra[v_##_Tpvec::nlanes/2] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb[v_##_Tpvec::nlanes/2] = {0}; \ + v_store_low(ptra, a); \ + v_store_low(ptrb, b); \ + return v_load_halves(ptra, ptrb); \ +} \ +inline v_##_Tpvec v_combine_high(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptra[v_##_Tpvec::nlanes/2] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb[v_##_Tpvec::nlanes/2] = {0}; \ + v_store_high(ptra, a); \ + v_store_high(ptrb, b); \ + return v_load_halves(ptra, ptrb); \ +} \ +inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + c = v_combine_low(a, b); \ + d = v_combine_high(a, b); \ +} + +OPENCV_HAL_IMPL_RVV_UNPACKS(uint8x16, uchar, 8, u8) +OPENCV_HAL_IMPL_RVV_UNPACKS(int8x16, schar, 8, i8) +OPENCV_HAL_IMPL_RVV_UNPACKS(uint16x8, ushort, 16, u16) +OPENCV_HAL_IMPL_RVV_UNPACKS(int16x8, short, 16, i16) +OPENCV_HAL_IMPL_RVV_UNPACKS(uint32x4, unsigned, 32, u32) +OPENCV_HAL_IMPL_RVV_UNPACKS(int32x4, int, 32, i32) +OPENCV_HAL_IMPL_RVV_UNPACKS(float32x4, float, 32, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_UNPACKS(float64x2, double, 64, f64) +#endif + + +#define OPENCV_HAL_IMPL_RVV_INTERLEAVED(_Tpvec, _Tp, suffix, width) \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptra[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb[v_##_Tpvec::nlanes] = {0}; \ + int i, i2; \ + for( i = i2 = 0; i < v_##_Tpvec::nlanes; i++, i2 += 2 ) \ + { \ + ptra[i] = ptr[i2]; \ + ptrb[i] = ptr[i2+1]; \ + } \ + a = v_load(ptra); \ + b = v_load(ptrb); \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, v_##_Tpvec& c) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptra[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrc[v_##_Tpvec::nlanes] = {0}; \ + int i, i3; \ + for( i = i3 = 0; i < v_##_Tpvec::nlanes; i++, i3 += 3 ) \ + { \ + ptra[i] = ptr[i3]; \ + ptrb[i] = ptr[i3+1]; \ + ptrc[i] = ptr[i3+2]; \ + } \ + a = v_load(ptra); \ + b = v_load(ptrb); \ + c = v_load(ptrc); \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, \ + v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptra[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrc[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrd[v_##_Tpvec::nlanes] = {0}; \ + int i, i4; \ + for( i = i4 = 0; i < v_##_Tpvec::nlanes; i++, i4 += 4 ) \ + { \ + ptra[i] = ptr[i4]; \ + ptrb[i] = ptr[i4+1]; \ + ptrc[i] = ptr[i4+2]; \ + ptrd[i] = ptr[i4+3]; \ + } \ + a = v_load(ptra); \ + b = v_load(ptrb); \ + c = v_load(ptrc); \ + d = v_load(ptrd); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + int i, i2; \ + _Tp CV_DECL_ALIGNED(32) ptra[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb[v_##_Tpvec::nlanes] = {0}; \ + v_store(ptra, a); \ + v_store(ptrb, b); \ + for( i = i2 = 0; i < v_##_Tpvec::nlanes; i++, i2 += 2 ) \ + { \ + ptr[i2] = ptra[i]; \ + ptr[i2+1] = ptrb[i]; \ + } \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + const v_##_Tpvec& c, hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + int i, i3; \ + _Tp CV_DECL_ALIGNED(32) ptra[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrc[v_##_Tpvec::nlanes] = {0}; \ + v_store(ptra, a); \ + v_store(ptrb, b); \ + v_store(ptrc, c); \ + for( i = i3 = 0; i < v_##_Tpvec::nlanes; i++, i3 += 3 ) \ + { \ + ptr[i3] = ptra[i]; \ + ptr[i3+1] = ptrb[i]; \ + ptr[i3+2] = ptrc[i]; \ + } \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + const v_##_Tpvec& c, const v_##_Tpvec& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED ) \ +{ \ + int i, i4; \ + _Tp CV_DECL_ALIGNED(32) ptra[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrb[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrc[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrd[v_##_Tpvec::nlanes] = {0}; \ + v_store(ptra, a); \ + v_store(ptrb, b); \ + v_store(ptrc, c); \ + v_store(ptrd, d); \ + for( i = i4 = 0; i < v_##_Tpvec::nlanes; i++, i4 += 4 ) \ + { \ + ptr[i4] = ptra[i]; \ + ptr[i4+1] = ptrb[i]; \ + ptr[i4+2] = ptrc[i]; \ + ptr[i4+3] = ptrd[i]; \ + } \ +} \ +inline v_##_Tpvec v_interleave_pairs(const v_##_Tpvec& vec) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptr[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrvec[v_##_Tpvec::nlanes] = {0}; \ + v_store(ptrvec, vec); \ + for (int i = 0; i < v_##_Tpvec::nlanes/4; i++) \ + { \ + ptr[4*i ] = ptrvec[4*i ]; \ + ptr[4*i+1] = ptrvec[4*i+2]; \ + ptr[4*i+2] = ptrvec[4*i+1]; \ + ptr[4*i+3] = ptrvec[4*i+3]; \ + } \ + return v_load(ptr); \ +} \ +inline v_##_Tpvec v_interleave_quads(const v_##_Tpvec& vec) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptr[v_##_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrvec[v_##_Tpvec::nlanes] = {0}; \ + v_store(ptrvec, vec); \ + for (int i = 0; i < v_##_Tpvec::nlanes/8; i++) \ + { \ + ptr[8*i ] = ptrvec[4*i ]; \ + ptr[8*i+1] = ptrvec[4*i+4]; \ + ptr[8*i+2] = ptrvec[4*i+1]; \ + ptr[8*i+3] = ptrvec[4*i+5]; \ + ptr[8*i+4] = ptrvec[4*i+2]; \ + ptr[8*i+5] = ptrvec[4*i+6]; \ + ptr[8*i+6] = ptrvec[4*i+3]; \ + ptr[8*i+7] = ptrvec[4*i+7]; \ + } \ + return v_load(ptr); \ +} + +OPENCV_HAL_IMPL_RVV_INTERLEAVED(uint8x16, uchar, u8, 8) +OPENCV_HAL_IMPL_RVV_INTERLEAVED(int8x16, schar, i8, 8) +OPENCV_HAL_IMPL_RVV_INTERLEAVED(uint16x8, ushort, u16, 16) +OPENCV_HAL_IMPL_RVV_INTERLEAVED(int16x8, short, i16, 16) +OPENCV_HAL_IMPL_RVV_INTERLEAVED(uint32x4, unsigned, u32, 32) +OPENCV_HAL_IMPL_RVV_INTERLEAVED(int32x4, int, i32, 32) +OPENCV_HAL_IMPL_RVV_INTERLEAVED(float32x4, float, f32, 32) +OPENCV_HAL_IMPL_RVV_INTERLEAVED(uint64x2, uint64, u64, 64) +OPENCV_HAL_IMPL_RVV_INTERLEAVED(int64x2, int64, i64, 64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_INTERLEAVED(float64x2, double, f64, 64) +#endif + +//////////// PopCount //////////// + +static const unsigned char popCountTable[] = +{ + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, +}; + +#define OPENCV_HAL_IMPL_RVV_POPCOUNT_OP(_rTpvec, _Tpvec, _rTp, _Tp, suffix) \ +inline _rTpvec v_popcount(const _Tpvec& a) \ +{ \ + uchar CV_DECL_ALIGNED(32) ptra[16] = {0}; \ + v_store(ptra, v_reinterpret_as_u8(a)); \ + _rTp CV_DECL_ALIGNED(32) ptr[_Tpvec::nlanes] = {0}; \ + v_store(ptr, v_setzero_##suffix()); \ + for (int i = 0; i < _Tpvec::nlanes*(int)sizeof(_Tp); i++) \ + ptr[i/sizeof(_Tp)] += popCountTable[ptra[i]]; \ + return v_load(ptr); \ +} + +OPENCV_HAL_IMPL_RVV_POPCOUNT_OP(v_uint8x16, v_uint8x16, uchar, uchar, u8) +OPENCV_HAL_IMPL_RVV_POPCOUNT_OP(v_uint8x16, v_int8x16, uchar, schar, u8) +OPENCV_HAL_IMPL_RVV_POPCOUNT_OP(v_uint16x8, v_uint16x8, ushort, ushort, u16) +OPENCV_HAL_IMPL_RVV_POPCOUNT_OP(v_uint16x8, v_int16x8, ushort, short, u16) +OPENCV_HAL_IMPL_RVV_POPCOUNT_OP(v_uint32x4, v_uint32x4, unsigned, unsigned, u32) +OPENCV_HAL_IMPL_RVV_POPCOUNT_OP(v_uint32x4, v_int32x4, unsigned, int, u32) +OPENCV_HAL_IMPL_RVV_POPCOUNT_OP(v_uint64x2, v_uint64x2, uint64, uint64, u64) +OPENCV_HAL_IMPL_RVV_POPCOUNT_OP(v_uint64x2, v_int64x2, uint64, int64, u64) + +//////////// SignMask //////////// + +#define OPENCV_HAL_IMPL_RVV_SIGNMASK_OP(_Tpvec, _Tp, suffix, width, shift) \ +inline int v_signmask(const _Tpvec& a) \ +{ \ + int mask = 0; \ + vsetvlmax_e##width##m1(); \ + _Tpvec tmp = _Tpvec(vsrl_vx_##suffix##m1(a, shift)); \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + mask |= (int)(tmp.val[i]) << i; \ + return mask; \ +} + +OPENCV_HAL_IMPL_RVV_SIGNMASK_OP(v_uint8x16, uchar, u8, 8, 7) +OPENCV_HAL_IMPL_RVV_SIGNMASK_OP(v_uint16x8, ushort, u16, 16, 15) +OPENCV_HAL_IMPL_RVV_SIGNMASK_OP(v_uint32x4, unsigned, u32, 32, 31) +OPENCV_HAL_IMPL_RVV_SIGNMASK_OP(v_uint64x2, uint64, u64, 64, 63) + +inline int v_signmask(const v_int8x16& a) +{ return v_signmask(v_reinterpret_as_u8(a)); } +inline int v_signmask(const v_int16x8& a) +{ return v_signmask(v_reinterpret_as_u16(a)); } +inline int v_signmask(const v_int32x4& a) +{ return v_signmask(v_reinterpret_as_u32(a)); } +inline int v_signmask(const v_float32x4& a) +{ return v_signmask(v_reinterpret_as_u32(a)); } +inline int v_signmask(const v_int64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } +#if CV_SIMD128_64F +inline int v_signmask(const v_float64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } +#endif + + +//////////// Scan forward //////////// + +#define OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(_Tpvec, _Tp, suffix) \ +inline int v_scan_forward(const _Tpvec& a) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptr[_Tpvec::nlanes] = {0}; \ + v_store(ptr, v_reinterpret_as_##suffix(a)); \ + for (int i = 0; i < _Tpvec::nlanes; i++) \ + if(int(ptr[i]) < 0) \ + return i; \ + return 0; \ +} + +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_int16x8, short, s16) +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_int32x4, int, s32) +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_float32x4, float, f32) +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_int64x2, int64, s64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_RVV_SCAN_FORWOARD_OP(v_float64x2, double, f64) +#endif + +//////////// Pack triplets //////////// + +#define OPENCV_HAL_IMPL_RVV_PACK_TRIPLETS(_Tpvec, _Tp) \ +inline _Tpvec v_pack_triplets(const _Tpvec& vec) \ +{ \ + _Tp CV_DECL_ALIGNED(32) ptr[_Tpvec::nlanes] = {0}; \ + _Tp CV_DECL_ALIGNED(32) ptrvec[_Tpvec::nlanes] = {0}; \ + v_store(ptrvec, vec); \ + for (int i = 0; i < _Tpvec::nlanes/4; i++) \ + { \ + ptr[3*i ] = ptrvec[4*i ]; \ + ptr[3*i+1] = ptrvec[4*i+2]; \ + ptr[3*i+2] = ptrvec[4*i+2]; \ + } \ + return v_load(ptr); \ +} + +OPENCV_HAL_IMPL_RVV_PACK_TRIPLETS(v_uint8x16, uchar) +OPENCV_HAL_IMPL_RVV_PACK_TRIPLETS(v_int8x16, schar) +OPENCV_HAL_IMPL_RVV_PACK_TRIPLETS(v_uint16x8, ushort) +OPENCV_HAL_IMPL_RVV_PACK_TRIPLETS(v_int16x8, short) +OPENCV_HAL_IMPL_RVV_PACK_TRIPLETS(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_RVV_PACK_TRIPLETS(v_int32x4, int) +OPENCV_HAL_IMPL_RVV_PACK_TRIPLETS(v_float32x4, float) + + +////// FP16 support /////// + +#if CV_FP16 +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + return v_float32x4(vfwcvt_f_f_v_f32m1(vle16_v_f16mf2(ptr))); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + vse16_v_f16mf2(ptr, vfncvt_f_f_w_f16mf2(v)); +} +#else +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + const int N = 4; + float buf[N]; + for( int i = 0; i < N; i++ ) buf[i] = (float)ptr[i]; + return v_load(buf); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + const int N = 4; + float buf[N]; + v_store(buf, v); + for( int i = 0; i < N; i++ ) ptr[i] = float16_t(buf[i]); +} +#endif + +////////////// Rounding ////////////// + +inline v_int32x4 v_round(const v_float32x4& a) +{ + vsetvlmax_e32m1(); + return v_int32x4(vfcvt_x_f_v_i32m1(a)); +} + +inline v_int32x4 v_floor(const v_float32x4& a) +{ + v_float32x4 ZP5 = v_setall_f32(0.5f); + v_float32x4 t = a - ZP5; + vsetvlmax_e32m1(); + return v_int32x4(vfcvt_x_f_v_i32m1(t)); +} + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ + v_float32x4 ZP5 = v_setall_f32(0.5f); + v_float32x4 t = a + ZP5; + vsetvlmax_e32m1(); + return v_int32x4(vfcvt_x_f_v_i32m1(t)); +} + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ + vsetvlmax_e32m1(); + return v_int32x4(vfcvt_rtz_x_f_v_i32m1(a)); +} +#if CV_SIMD128_64F +inline v_int32x4 v_round(const v_float64x2& a) +{ + double arr[4] = {a.val[0], a.val[1], 0, 0}; + vsetvlmax_e64m2(); + vfloat64m2_t tmp = vle64_v_f64m2(arr); + return v_int32x4(vfncvt_x_f_w_i32m1(tmp)); +} + +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ + double arr[4] = {a.val[0], a.val[1], b.val[0], b.val[1]}; + vsetvlmax_e64m2(); + vfloat64m2_t tmp = vle64_v_f64m2(arr); + return v_int32x4(vfncvt_x_f_w_i32m1(tmp)); +} + +inline v_int32x4 v_floor(const v_float64x2& a) +{ + double arr[4] = {a.val[0]-0.5f, a.val[1]-0.5f, 0, 0}; + vsetvlmax_e64m2(); + vfloat64m2_t tmp = vle64_v_f64m2(arr); + return v_int32x4(vfncvt_x_f_w_i32m1(tmp)); +} + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ + double arr[4] = {a.val[0]+0.5f, a.val[1]+0.5f, 0, 0}; + vsetvlmax_e64m2(); + vfloat64m2_t tmp = vle64_v_f64m2(arr); + return v_int32x4(vfncvt_x_f_w_i32m1(tmp)); +} + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ + double arr[4] = {a.val[0], a.val[1], 0, 0}; + vsetvlmax_e64m2(); + vfloat64m2_t tmp = vle64_v_f64m2(arr); + return v_int32x4(vfncvt_rtz_x_f_w_i32m1(tmp)); +} +#endif + + +//////// Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ + int CV_DECL_ALIGNED(32) ptr[8] = {0}; + v_int32x4 t1, t2; + vsetvlmax_e32m2(); + vse32_v_i32m2(ptr, vwmul_vv_i32m2(a, b)); + v_load_deinterleave(ptr, t1, t2); + return t1 + t2; +} +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ + int CV_DECL_ALIGNED(32) ptr[8] = {0}; + v_int32x4 t1, t2; + vsetvlmax_e32m2(); + vse32_v_i32m2(ptr, vwmul_vv_i32m2(a, b)); + v_load_deinterleave(ptr, t1, t2); + return t1 + t2 + c; +} + +// 32 >> 64 +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b) +{ + int64 CV_DECL_ALIGNED(32) ptr[4] = {0}; + v_int64x2 t1, t2; + vsetvlmax_e64m2(); + vse64_v_i64m2(ptr, vwmul_vv_i64m2(a, b)); + v_load_deinterleave(ptr, t1, t2); + return t1 + t2; +} +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ + int64 CV_DECL_ALIGNED(32) ptr[4] = {0}; + v_int64x2 t1, t2; + vsetvlmax_e64m2(); + vse64_v_i64m2(ptr, vwmul_vv_i64m2(a, b)); + v_load_deinterleave(ptr, t1, t2); + return t1 + t2 + c; +} + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b) +{ + unsigned CV_DECL_ALIGNED(32) ptr[16] = {0}; + v_uint32x4 t1, t2, t3, t4; + vsetvlmax_e32m4(); + vse32_v_u32m4(ptr, vqmaccu_vv_u32m4(vzero_u32m4(), a, b)); + v_load_deinterleave(ptr, t1, t2, t3, t4); + return t1 + t2 + t3 + t4; +} +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b, + const v_uint32x4& c) +{ + unsigned CV_DECL_ALIGNED(32) ptr[16] = {0}; + v_uint32x4 t1, t2, t3, t4; + vsetvlmax_e32m4(); + vse32_v_u32m4(ptr, vqmaccu_vv_u32m4(vzero_u32m4(), a, b)); + v_load_deinterleave(ptr, t1, t2, t3, t4); + return t1 + t2 + t3 + t4 + c; +} + +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b) +{ + int CV_DECL_ALIGNED(32) ptr[16] = {0}; + v_int32x4 t1, t2, t3, t4; + vsetvlmax_e32m4(); + vse32_v_i32m4(ptr, vqmacc_vv_i32m4(vzero_i32m4(), a, b)); + v_load_deinterleave(ptr, t1, t2, t3, t4); + return t1 + t2 + t3 + t4; +} +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b, + const v_int32x4& c) +{ + int CV_DECL_ALIGNED(32) ptr[16] = {0}; + v_int32x4 t1, t2, t3, t4; + vsetvlmax_e32m4(); + vse32_v_i32m4(ptr, vqmacc_vv_i32m4(vzero_i32m4(), a, b)); + v_load_deinterleave(ptr, t1, t2, t3, t4); + return t1 + t2 + t3 + t4 + c; +} + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b) +{ + uint64 CV_DECL_ALIGNED(32) ptr[8] = {0}; + v_uint64x2 t1, t2, t3, t4; + vsetvlmax_e64m4(); + vse64_v_u64m4(ptr, vqmaccu_vv_u64m4(vzero_u64m4(), a, b)); + v_load_deinterleave(ptr, t1, t2, t3, t4); + return t1 + t2 + t3 + t4; +} +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ + uint64 CV_DECL_ALIGNED(32) ptr[8] = {0}; + v_uint64x2 t1, t2, t3, t4; + vsetvlmax_e64m4(); + vse64_v_u64m4(ptr, vqmaccu_vv_u64m4(vzero_u64m4(), a, b)); + v_load_deinterleave(ptr, t1, t2, t3, t4); + return t1 + t2 + t3 + t4 + c; +} + +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b) +{ + int64 CV_DECL_ALIGNED(32) ptr[8] = {0}; + v_int64x2 t1, t2, t3, t4; + vsetvlmax_e64m4(); + vse64_v_i64m4(ptr, vqmacc_vv_i64m4(vzero_i64m4(), a, b)); + v_load_deinterleave(ptr, t1, t2, t3, t4); + return t1 + t2 + t3 + t4; +} +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b, + const v_int64x2& c) +{ + int64 CV_DECL_ALIGNED(32) ptr[8] = {0}; + v_int64x2 t1, t2, t3, t4; + vsetvlmax_e64m4(); + vse64_v_i64m4(ptr, vqmacc_vv_i64m4(vzero_i64m4(), a, b)); + v_load_deinterleave(ptr, t1, t2, t3, t4); + return t1 + t2 + t3 + t4 + c; +} + +// 32 >> 64f +#if CV_SIMD128_64F +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b) +{ return v_cvt_f64(v_dotprod(a, b)); } +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, + const v_float64x2& c) +{ return v_dotprod_expand(a, b) + c; } +#endif + +//////// Fast Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b) +{ + int CV_DECL_ALIGNED(32) ptr[8] = {0}; + vsetvlmax_e32m2(); + vse32_v_i32m2(ptr, vwmul_vv_i32m2(a, b)); + v_int32x4 t1 = v_load(ptr); + v_int32x4 t2 = v_load(ptr+4); + return t1 + t2; +} +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ + int CV_DECL_ALIGNED(32) ptr[8] = {0}; + vsetvlmax_e32m2(); + vse32_v_i32m2(ptr, vwmul_vv_i32m2(a, b)); + v_int32x4 t1 = v_load(ptr); + v_int32x4 t2 = v_load(ptr+4); + return t1 + t2 + c; +} + +// 32 >> 64 +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b) +{ + int64 CV_DECL_ALIGNED(32) ptr[4] = {0}; + vsetvlmax_e64m2(); + vse64_v_i64m2(ptr, vwmul_vv_i64m2(a, b)); + v_int64x2 t1 = v_load(ptr); + v_int64x2 t2 = v_load(ptr+2); + return t1 + t2; +} +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ + int64 CV_DECL_ALIGNED(32) ptr[4] = {0}; + vsetvlmax_e64m2(); + vse64_v_i64m2(ptr, vwmul_vv_i64m2(a, b)); + v_int64x2 t1 = v_load(ptr); + v_int64x2 t2 = v_load(ptr+2); + return t1 + t2 + c; +} + + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b) +{ + unsigned CV_DECL_ALIGNED(32) ptr[16] = {0}; + vsetvlmax_e32m4(); + vse32_v_u32m4(ptr, vqmaccu_vv_u32m4(vzero_u32m4(), a, b)); + v_uint32x4 t1 = v_load(ptr); + v_uint32x4 t2 = v_load(ptr+4); + v_uint32x4 t3 = v_load(ptr+8); + v_uint32x4 t4 = v_load(ptr+12); + return t1 + t2 + t3 + t4; +} +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ + unsigned CV_DECL_ALIGNED(32) ptr[16] = {0}; + vsetvlmax_e32m4(); + vse32_v_u32m4(ptr, vqmaccu_vv_u32m4(vzero_u32m4(), a, b)); + v_uint32x4 t1 = v_load(ptr); + v_uint32x4 t2 = v_load(ptr+4); + v_uint32x4 t3 = v_load(ptr+8); + v_uint32x4 t4 = v_load(ptr+12); + return t1 + t2 + t3 + t4 + c; +} +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b) +{ + int CV_DECL_ALIGNED(32) ptr[16] = {0}; + vsetvlmax_e32m4(); + vse32_v_i32m4(ptr, vqmacc_vv_i32m4(vzero_i32m4(), a, b)); + v_int32x4 t1 = v_load(ptr); + v_int32x4 t2 = v_load(ptr+4); + v_int32x4 t3 = v_load(ptr+8); + v_int32x4 t4 = v_load(ptr+12); + return t1 + t2 + t3 + t4; +} +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ + int CV_DECL_ALIGNED(32) ptr[16] = {0}; + vsetvlmax_e32m4(); + vse32_v_i32m4(ptr, vqmacc_vv_i32m4(vzero_i32m4(), a, b)); + v_int32x4 t1 = v_load(ptr); + v_int32x4 t2 = v_load(ptr+4); + v_int32x4 t3 = v_load(ptr+8); + v_int32x4 t4 = v_load(ptr+12); + return t1 + t2 + t3 + t4 + c; +} + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b) +{ + uint64 CV_DECL_ALIGNED(32) ptr[8] = {0}; + vsetvlmax_e64m4(); + vse64_v_u64m4(ptr, vqmaccu_vv_u64m4(vzero_u64m4(), a, b)); + v_uint64x2 t1 = v_load(ptr); + v_uint64x2 t2 = v_load(ptr+2); + v_uint64x2 t3 = v_load(ptr+4); + v_uint64x2 t4 = v_load(ptr+6); + return t1 + t2 + t3 + t4; +} +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ + uint64 CV_DECL_ALIGNED(32) ptr[8] = {0}; + vsetvlmax_e64m4(); + vse64_v_u64m4(ptr, vqmaccu_vv_u64m4(vzero_u64m4(), a, b)); + v_uint64x2 t1 = v_load(ptr); + v_uint64x2 t2 = v_load(ptr+2); + v_uint64x2 t3 = v_load(ptr+4); + v_uint64x2 t4 = v_load(ptr+6); + return t1 + t2 + t3 + t4 + c; +} +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b) +{ + int64 CV_DECL_ALIGNED(32) ptr[8] = {0}; + vsetvlmax_e64m4(); + vse64_v_i64m4(ptr, vqmacc_vv_i64m4(vzero_i64m4(), a, b)); + v_int64x2 t1 = v_load(ptr); + v_int64x2 t2 = v_load(ptr+2); + v_int64x2 t3 = v_load(ptr+4); + v_int64x2 t4 = v_load(ptr+6); + return t1 + t2 + t3 + t4; +} +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ + int64 CV_DECL_ALIGNED(32) ptr[8] = {0}; + vsetvlmax_e64m4(); + vse64_v_i64m4(ptr, vqmacc_vv_i64m4(vzero_i64m4(), a, b)); + v_int64x2 t1 = v_load(ptr); + v_int64x2 t2 = v_load(ptr+2); + v_int64x2 t3 = v_load(ptr+4); + v_int64x2 t4 = v_load(ptr+6); + return t1 + t2 + t3 + t4 + c; +} + +// 32 >> 64f +#if CV_SIMD128_64F +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_cvt_f64(v_dotprod_fast(a, b)); } +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_dotprod_expand_fast(a, b) + c; } +#endif + + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + vsetvlmax_e32m1(); + vfloat32m1_t res = vfmul_vf_f32m1(m0, v_extract_n<0>(v)); + res = vfmacc_vf_f32m1(res, v_extract_n<1>(v), m1); + res = vfmacc_vf_f32m1(res, v_extract_n<2>(v), m2); + res = vfmacc_vf_f32m1(res, v_extract_n<3>(v), m3); + return v_float32x4(res); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + vsetvlmax_e32m1(); + vfloat32m1_t res = vfmul_vf_f32m1(m0, v_extract_n<0>(v)); + res = vfmacc_vf_f32m1(res, v_extract_n<1>(v), m1); + res = vfmacc_vf_f32m1(res, v_extract_n<2>(v), m2); + return v_float32x4(res) + a; +} + +#define OPENCV_HAL_IMPL_RVV_MUL_EXPAND(_Tpvec, _Tpwvec, _Tpw, suffix, wmul, width) \ +inline void v_mul_expand(const _Tpvec& a, const _Tpvec& b, _Tpwvec& c, _Tpwvec& d) \ +{ \ + _Tpw CV_DECL_ALIGNED(32) ptr[_Tpwvec::nlanes*2] = {0}; \ + vsetvlmax_e##width##m2(); \ + vse##width##_v_##suffix##m2(ptr, wmul(a, b)); \ + vsetvlmax_e##width##m1(); \ + c = _Tpwvec(vle##width##_v_##suffix##m1(ptr)); \ + d = _Tpwvec(vle##width##_v_##suffix##m1(ptr+_Tpwvec::nlanes)); \ +} + +OPENCV_HAL_IMPL_RVV_MUL_EXPAND(v_uint8x16, v_uint16x8, ushort, u16, vwmulu_vv_u16m2, 16) +OPENCV_HAL_IMPL_RVV_MUL_EXPAND(v_int8x16, v_int16x8, short, i16, vwmul_vv_i16m2, 16) +OPENCV_HAL_IMPL_RVV_MUL_EXPAND(v_uint16x8, v_uint32x4, unsigned, u32, vwmulu_vv_u32m2, 32) +OPENCV_HAL_IMPL_RVV_MUL_EXPAND(v_int16x8, v_int32x4, int, i32, vwmul_vv_i32m2, 32) +OPENCV_HAL_IMPL_RVV_MUL_EXPAND(v_uint32x4, v_uint64x2, uint64, u64, vwmulu_vv_u64m2, 64) + + +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) +{ + vsetvlmax_e16m1(); + return v_int16x8(vnsra_wx_i16m1(vwmul_vv_i32m2(a, b), 16)); +} +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) +{ + vsetvlmax_e16m1(); + return v_uint16x8(vnsrl_wx_u16m1(vwmulu_vv_u32m2(a, b), 16)); +} + + +//////// Saturating Multiply //////// + +#define OPENCV_HAL_IMPL_RVV_MUL_SAT(_Tpvec, _wTpvec) \ +inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ +{ \ + _wTpvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ +} \ +inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ +{ \ + a = a * b; \ + return a; \ +} + +OPENCV_HAL_IMPL_RVV_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_RVV_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_RVV_MUL_SAT(v_uint16x8, v_uint32x4) +OPENCV_HAL_IMPL_RVV_MUL_SAT(v_int16x8, v_int32x4) + + +inline void v_cleanup() {} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + + +} + +#endif diff --git a/3rdparty/include/opencv2/core/hal/intrin_rvv071.hpp b/3rdparty/include/opencv2/core/hal/intrin_rvv071.hpp new file mode 100644 index 0000000000..2bdc622ffd --- /dev/null +++ b/3rdparty/include/opencv2/core/hal/intrin_rvv071.hpp @@ -0,0 +1,2545 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +// Copyright (C) 2015, PingTouGe Semiconductor Co., Ltd., all rights reserved. + +#ifndef OPENCV_HAL_INTRIN_RISCVV_HPP +#define OPENCV_HAL_INTRIN_RISCVV_HPP + +#include +#include +#include "opencv2/core/utility.hpp" + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +#define CV_SIMD128 1 +#define CV_SIMD128_64F 1 +//////////// Types //////////// +struct v_uint8x16 +{ + typedef uchar lane_type; + enum { nlanes = 16 }; + + v_uint8x16() {} + explicit v_uint8x16(vuint8m1_t v) : val(v) {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + { + uchar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = (vuint8m1_t)vle_v_u8m1((unsigned char*)v, 16); + } + uchar get0() const + { + return vmv_x_s_u8m1_u8(val, 16); + } + + vuint8m1_t val; +}; + +struct v_int8x16 +{ + typedef schar lane_type; + enum { nlanes = 16 }; + + v_int8x16() {} + explicit v_int8x16(vint8m1_t v) : val(v) {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + { + schar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = (vint8m1_t)vle_v_i8m1((schar*)v, 16); + } + schar get0() const + { + return vmv_x_s_i8m1_i8(val, 16); + } + + vint8m1_t val; +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + enum { nlanes = 8 }; + + v_uint16x8() {} + explicit v_uint16x8(vuint16m1_t v) : val(v) {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + { + ushort v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = (vuint16m1_t)vle_v_u16m1((unsigned short*)v, 8); + } + ushort get0() const + { + return vmv_x_s_u16m1_u16(val, 8); + } + + vuint16m1_t val; +}; + +struct v_int16x8 +{ + typedef short lane_type; + enum { nlanes = 8 }; + + v_int16x8() {} + explicit v_int16x8(vint16m1_t v) : val(v) {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + { + short v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = (vint16m1_t)vle_v_i16m1((signed short*)v, 8); + } + short get0() const + { + return vmv_x_s_i16m1_i16(val, 8); + } + + vint16m1_t val; +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + enum { nlanes = 4 }; + + v_uint32x4() {} + explicit v_uint32x4(vuint32m1_t v) : val(v) {} + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) + { + unsigned v[] = {v0, v1, v2, v3}; + val = (vuint32m1_t)vle_v_u32m1((unsigned int*)v, 4); + } + unsigned get0() const + { + return vmv_x_s_u32m1_u32(val, 4); + } + + vuint32m1_t val; +}; + +struct v_int32x4 +{ + typedef int lane_type; + enum { nlanes = 4 }; + + v_int32x4() {} + explicit v_int32x4(vint32m1_t v) : val(v) {} + v_int32x4(int v0, int v1, int v2, int v3) + { + int v[] = {v0, v1, v2, v3}; + val = (vint32m1_t)vle_v_i32m1((signed int*)v, 4); + } + int get0() const + { + return vmv_x_s_i32m1_i32(val, 4); + } + vint32m1_t val; +}; + +struct v_float32x4 +{ + typedef float lane_type; + enum { nlanes = 4 }; + + v_float32x4() {} + explicit v_float32x4(vfloat32m1_t v) : val(v) {} + v_float32x4(float v0, float v1, float v2, float v3) + { + float v[] = {v0, v1, v2, v3}; + val = (vfloat32m1_t)vle_v_f32m1((float*)v, 4); + } + float get0() const + { + return vfmv_f_s_f32m1_f32(val, 4); + } + vfloat32m1_t val; +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + enum { nlanes = 2 }; + + v_uint64x2() {} + explicit v_uint64x2(vuint64m1_t v) : val(v) {} + v_uint64x2(uint64 v0, uint64 v1) + { + uint64 v[] = {v0, v1}; + val = (vuint64m1_t)vle_v_u64m1((unsigned long*)v, 2); + } + uint64 get0() const + { + return vmv_x_s_u64m1_u64(val, 2); + } + vuint64m1_t val; +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + enum { nlanes = 2 }; + + v_int64x2() {} + explicit v_int64x2(vint64m1_t v) : val(v) {} + v_int64x2(int64 v0, int64 v1) + { + int64 v[] = {v0, v1}; + val = (vint64m1_t)vle_v_i64m1((long*)v, 2); + } + int64 get0() const + { + return vmv_x_s_i64m1_i64(val, 2); + } + vint64m1_t val; +}; + +struct v_float64x2 +{ + typedef double lane_type; + enum { nlanes = 2 }; + + v_float64x2() {} + explicit v_float64x2(vfloat64m1_t v) : val(v) {} + v_float64x2(double v0, double v1) + { + double v[] = {v0, v1}; + val = (vfloat64m1_t)vle_v_f64m1((double*)v, 2); + } + double get0() const + { + return vfmv_f_s_f64m1_f64(val, 2); + } + vfloat64m1_t val; +}; + +#define OPENCV_HAL_IMPL_RISCVV_INIT(_Tpv, _Tp, suffix) \ +inline _Tp##m1_t vreinterpretq_##suffix##_##suffix(_Tp##m1_t v) { return v; } \ +inline v_uint8x16 v_reinterpret_as_u8(const v_##_Tpv& v) { return v_uint8x16((vuint8m1_t)(v.val)); } \ +inline v_int8x16 v_reinterpret_as_s8(const v_##_Tpv& v) { return v_int8x16((vint8m1_t)(v.val)); } \ +inline v_uint16x8 v_reinterpret_as_u16(const v_##_Tpv& v) { return v_uint16x8((vuint16m1_t)(v.val)); } \ +inline v_int16x8 v_reinterpret_as_s16(const v_##_Tpv& v) { return v_int16x8((vint16m1_t)(v.val)); } \ +inline v_uint32x4 v_reinterpret_as_u32(const v_##_Tpv& v) { return v_uint32x4((vuint32m1_t)(v.val)); } \ +inline v_int32x4 v_reinterpret_as_s32(const v_##_Tpv& v) { return v_int32x4((vint32m1_t)(v.val)); } \ +inline v_uint64x2 v_reinterpret_as_u64(const v_##_Tpv& v) { return v_uint64x2((vuint64m1_t)(v.val)); } \ +inline v_int64x2 v_reinterpret_as_s64(const v_##_Tpv& v) { return v_int64x2((vint64m1_t)(v.val)); } \ +inline v_float32x4 v_reinterpret_as_f32(const v_##_Tpv& v) { return v_float32x4((vfloat32m1_t)(v.val)); }\ +inline v_float64x2 v_reinterpret_as_f64(const v_##_Tpv& v) { return v_float64x2((vfloat64m1_t)(v.val)); } + + +OPENCV_HAL_IMPL_RISCVV_INIT(uint8x16, vuint8, u8) +OPENCV_HAL_IMPL_RISCVV_INIT(int8x16, vint8, s8) +OPENCV_HAL_IMPL_RISCVV_INIT(uint16x8, vuint16, u16) +OPENCV_HAL_IMPL_RISCVV_INIT(int16x8, vint16, s16) +OPENCV_HAL_IMPL_RISCVV_INIT(uint32x4, vuint32, u32) +OPENCV_HAL_IMPL_RISCVV_INIT(int32x4, vint32, s32) +OPENCV_HAL_IMPL_RISCVV_INIT(uint64x2, vuint64, u64) +OPENCV_HAL_IMPL_RISCVV_INIT(int64x2, vint64, s64) +OPENCV_HAL_IMPL_RISCVV_INIT(float64x2, vfloat64, f64) +OPENCV_HAL_IMPL_RISCVV_INIT(float32x4, vfloat32, f32) +#define OPENCV_HAL_IMPL_RISCVV_INIT_SET(__Tp, _Tp, suffix, len, num) \ +inline v_##_Tp##x##num v_setzero_##suffix() { return v_##_Tp##x##num((v##_Tp##m1_t){0}); } \ +inline v_##_Tp##x##num v_setall_##suffix(__Tp v) { return v_##_Tp##x##num(vmv_v_x_##len##m1(v, num)); } + +OPENCV_HAL_IMPL_RISCVV_INIT_SET(uchar, uint8, u8, u8, 16) +OPENCV_HAL_IMPL_RISCVV_INIT_SET(char, int8, s8, i8, 16) +OPENCV_HAL_IMPL_RISCVV_INIT_SET(ushort, uint16, u16, u16, 8) +OPENCV_HAL_IMPL_RISCVV_INIT_SET(short, int16, s16, i16, 8) +OPENCV_HAL_IMPL_RISCVV_INIT_SET(unsigned int, uint32, u32, u32, 4) +OPENCV_HAL_IMPL_RISCVV_INIT_SET(int, int32, s32, i32, 4) +OPENCV_HAL_IMPL_RISCVV_INIT_SET(unsigned long, uint64, u64, u64, 2) +OPENCV_HAL_IMPL_RISCVV_INIT_SET(long, int64, s64, i64, 2) +inline v_float32x4 v_setzero_f32() { return v_float32x4((vfloat32m1_t){0}); } +inline v_float32x4 v_setall_f32(float v) { return v_float32x4(vfmv_v_f_f32m1(v, 4)); } + +inline v_float64x2 v_setzero_f64() { return v_float64x2(vfmv_v_f_f64m1(0, 2)); } +inline v_float64x2 v_setall_f64(double v) { return v_float64x2(vfmv_v_f_f64m1(v, 2)); } + + +#define OPENCV_HAL_IMPL_RISCVV_BIN_OP(bin_op, _Tpvec, intrin) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ \ + a.val = intrin(a.val, b.val); \ + return a; \ +} + +#define OPENCV_HAL_IMPL_RISCVV_BIN_OPN(bin_op, _Tpvec, intrin, num) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val, num)); \ +} \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ \ + a.val = intrin(a.val, b.val, num); \ + return a; \ +} + +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_uint8x16, vsaddu_vv_u8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_uint8x16, vssubu_vv_u8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_int8x16, vsadd_vv_i8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_int8x16, vssub_vv_i8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_uint16x8, vsaddu_vv_u16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_uint16x8, vssubu_vv_u16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_int16x8, vsadd_vv_i16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_int16x8, vssub_vv_i16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_int32x4, vsadd_vv_i32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_int32x4, vssub_vv_i32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(*, v_int32x4, vmul_vv_i32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_uint32x4, vadd_vv_u32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_uint32x4, vsub_vv_u32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(*, v_uint32x4, vmul_vv_u32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_int64x2, vsadd_vv_i64m1, 2) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_int64x2, vssub_vv_i64m1, 2) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_uint64x2, vadd_vv_u64m1, 2) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_uint64x2, vsub_vv_u64m1, 2) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_float32x4, vfadd_vv_f32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_float32x4, vfsub_vv_f32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(*, v_float32x4, vfmul_vv_f32m1, 4) +inline v_float32x4 operator / (const v_float32x4& a, const v_float32x4& b) +{ + return v_float32x4(vfdiv_vv_f32m1(a.val, b.val, 4)); +} +inline v_float32x4& operator /= (v_float32x4& a, const v_float32x4& b) +{ + a.val = vfdiv_vv_f32m1(a.val, b.val, 4); + return a; +} + +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(+, v_float64x2, vfadd_vv_f64m1, 2) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(-, v_float64x2, vfsub_vv_f64m1, 2) +OPENCV_HAL_IMPL_RISCVV_BIN_OPN(*, v_float64x2, vfmul_vv_f64m1, 2) +inline v_float64x2 operator / (const v_float64x2& a, const v_float64x2& b) +{ + return v_float64x2(vfdiv_vv_f64m1(a.val, b.val, 2)); +} +inline v_float64x2& operator /= (v_float64x2& a, const v_float64x2& b) +{ + a.val = vfdiv_vv_f64m1(a.val, b.val, 2); + return a; +} +// TODO: exp, log, sin, cos + +#define OPENCV_HAL_IMPL_RISCVV_BIN_FUNC(_Tpvec, func, intrin) \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} + +#define OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(_Tpvec, func, intrin, num) \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val, num)); \ +} +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint8x16, v_min, vminu_vv_u8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint8x16, v_max, vmaxu_vv_u8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int8x16, v_min, vmin_vv_i8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int8x16, v_max, vmax_vv_i8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint16x8, v_min, vminu_vv_u16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint16x8, v_max, vmaxu_vv_u16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int16x8, v_min, vmin_vv_i16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int16x8, v_max, vmax_vv_i16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint32x4, v_min, vminu_vv_u32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint32x4, v_max, vmaxu_vv_u32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int32x4, v_min, vmin_vv_i32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int32x4, v_max, vmax_vv_i32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_float32x4, v_min, vfmin_vv_f32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_float32x4, v_max, vfmax_vv_f32m1, 4) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_float64x2, v_min, vfmin_vv_f64m1, 2) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_float64x2, v_max, vfmax_vv_f64m1, 2) + +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ + return v_float32x4(vfsqrt_v_f32m1(x.val, 4)); +} + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ + return v_float32x4(vfrdiv_vf_f32m1(vfsqrt_v_f32m1(x.val, 4), 1, 4)); +} + +inline v_float32x4 v_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + v_float32x4 x(vfmacc_vv_f32m1(vfmul_vv_f32m1(a.val, a.val, 4), b.val, b.val, 4)); + return v_sqrt(x); +} + +inline v_float32x4 v_sqr_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + return v_float32x4(vfmacc_vv_f32m1(vfmul_vv_f32m1(a.val, a.val, 4), b.val, b.val, 4)); +} + +inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ + return v_float32x4(vfmacc_vv_f32m1(c.val, a.val, b.val, 4)); +} + +inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_int32x4(vmacc_vv_i32m1(c.val, a.val, b.val, 4)); +} + +inline v_float32x4 v_muladd(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + vfloat32m1_t res = vfmul_vf_f32m1(m0.val, v.val[0], 4);//vmuli_f32(m0.val, v.val, 0); + res = vfmacc_vf_f32m1(res, v.val[1], m1.val, 4);//vmulai_f32(res, m1.val, v.val, 1); + res = vfmacc_vf_f32m1(res, v.val[2], m2.val, 4);//vmulai_f32(res, m1.val, v.val, 1); + res = vfmacc_vf_f32m1(res, v.val[3], m3.val, 4);//vmulai_f32(res, m1.val, v.val, 1); + return v_float32x4(res); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + vfloat32m1_t res = vfmul_vf_f32m1(m0.val, v.val[0], 4);//vmuli_f32(m0.val, v.val, 0); + res = vfmacc_vf_f32m1(res, v.val[1], m1.val, 4);//vmulai_f32(res, m1.val, v.val, 1); + res = vfmacc_vf_f32m1(res, v.val[2], m2.val, 4);//vmulai_f32(res, m1.val, v.val, 1); + res = vfadd_vv_f32m1(res, a.val, 4);//vmulai_f32(res, m1.val, v.val, 1); + return v_float32x4(res); +} + +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ + return v_float64x2(vfsqrt_v_f64m1(x.val, 2)); +} + +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ + return v_float64x2(vfrdiv_vf_f64m1(vfsqrt_v_f64m1(x.val, 2), 1, 2)); +} + +inline v_float64x2 v_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + v_float64x2 x(vfmacc_vv_f64m1(vfmul_vv_f64m1(a.val, a.val, 2), b.val, b.val, 2)); + return v_sqrt(x); +} + +inline v_float64x2 v_sqr_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + return v_float64x2(vfmacc_vv_f64m1(vfmul_vv_f64m1(a.val, a.val, 2), b.val, b.val, 2)); +} + +inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_float64x2(vfmacc_vv_f64m1(c.val, a.val, b.val, 2)); +} + +inline v_float64x2 v_muladd(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_fma(a, b, c); +} + +#define OPENCV_HAL_IMPL_RISCVV_LOGIC_OPN(_Tpvec, suffix, num) \ + OPENCV_HAL_IMPL_RISCVV_BIN_OPN(&, _Tpvec, vand_vv_##suffix, num) \ + OPENCV_HAL_IMPL_RISCVV_BIN_OPN(|, _Tpvec, vor_vv_##suffix, num) \ + OPENCV_HAL_IMPL_RISCVV_BIN_OPN(^, _Tpvec, vxor_vv_##suffix, num) \ + inline _Tpvec operator ~ (const _Tpvec & a) \ + { \ + return _Tpvec(vnot_v_##suffix(a.val, num)); \ + } + +OPENCV_HAL_IMPL_RISCVV_LOGIC_OPN(v_uint8x16, u8m1, 16) +OPENCV_HAL_IMPL_RISCVV_LOGIC_OPN(v_uint16x8, u16m1, 8) +OPENCV_HAL_IMPL_RISCVV_LOGIC_OPN(v_uint32x4, u32m1, 4) +OPENCV_HAL_IMPL_RISCVV_LOGIC_OPN(v_uint64x2, u64m1, 2) +OPENCV_HAL_IMPL_RISCVV_LOGIC_OPN(v_int8x16, i8m1, 16) +OPENCV_HAL_IMPL_RISCVV_LOGIC_OPN(v_int16x8, i16m1, 8) +OPENCV_HAL_IMPL_RISCVV_LOGIC_OPN(v_int32x4, i32m1, 4) +OPENCV_HAL_IMPL_RISCVV_LOGIC_OPN(v_int64x2, i64m1, 2) + +#define OPENCV_HAL_IMPL_RISCVV_FLT_BIT_OP(bin_op, intrin) \ +inline v_float32x4 operator bin_op (const v_float32x4& a, const v_float32x4& b) \ +{ \ + return v_float32x4(vfloat32m1_t(intrin(vint32m1_t(a.val), vint32m1_t(b.val), 4))); \ +} \ +inline v_float32x4& operator bin_op##= (v_float32x4& a, const v_float32x4& b) \ +{ \ + a.val = vfloat32m1_t(intrin(vint32m1_t(a.val), vint32m1_t(b.val), 4)); \ + return a; \ +} + +OPENCV_HAL_IMPL_RISCVV_FLT_BIT_OP(&, vand_vv_i32m1) +OPENCV_HAL_IMPL_RISCVV_FLT_BIT_OP(|, vor_vv_i32m1) +OPENCV_HAL_IMPL_RISCVV_FLT_BIT_OP(^, vxor_vv_i32m1) + +inline v_float32x4 operator ~ (const v_float32x4& a) +{ + return v_float32x4((vfloat32m1_t)(vnot_v_i32m1((vint32m1_t)(a.val), 4))); +} + +#define OPENCV_HAL_IMPL_RISCVV_FLT_64BIT_OP(bin_op, intrin) \ +inline v_float64x2 operator bin_op (const v_float64x2& a, const v_float64x2& b) \ +{ \ + return v_float64x2(vfloat64m1_t(intrin(vint64m1_t(a.val), vint64m1_t(b.val), 2))); \ +} \ +inline v_float64x2& operator bin_op##= (v_float64x2& a, const v_float64x2& b) \ +{ \ + a.val = vfloat64m1_t(intrin(vint64m1_t(a.val), vint64m1_t(b.val), 2)); \ + return a; \ +} + +OPENCV_HAL_IMPL_RISCVV_FLT_64BIT_OP(&, vand_vv_i64m1) +OPENCV_HAL_IMPL_RISCVV_FLT_64BIT_OP(|, vor_vv_i64m1) +OPENCV_HAL_IMPL_RISCVV_FLT_64BIT_OP(^, vxor_vv_i64m1) + +inline v_float64x2 operator ~ (const v_float64x2& a) +{ + return v_float64x2((vfloat64m1_t)(vnot_v_i64m1((vint64m1_t)(a.val), 2))); +} +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) +{ + return v_int16x8(vmulh_vv_i16m1(a.val, b.val, 8)); +} +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) +{ + return v_uint16x8(vmulhu_vv_u16m1(a.val, b.val, 8)); +} + +//#define OPENCV_HAL_IMPL_RISCVV_ABS(_Tpuvec, _Tpsvec, usuffix, ssuffix) \ +//inline _Tpuvec v_abs(const _Tpsvec& a) { \ +// E##xm1_t mask=vmflt_vf_e32xm1_f32m1(x.val, 0.0, 4); + +//OPENCV_HAL_IMPL_RISCVV_ABS(v_uint8x16, v_int8x16, u8, s8) +//OPENCV_HAL_IMPL_RISCVV_ABS(v_uint16x8, v_int16x8, u16, s16) +//OPENCV_HAL_IMPL_RISCVV_ABS(v_uint32x4, v_int32x4, u32, s32) + +inline v_uint32x4 v_abs(v_int32x4 x) +{ + vbool32_t mask=vmslt_vx_i32m1_b32(x.val, 0, 4); + return v_uint32x4((vuint32m1_t)vrsub_vx_i32m1_m(mask, x.val, x.val, 0, 4)); +} + +inline v_uint16x8 v_abs(v_int16x8 x) +{ + vbool16_t mask=vmslt_vx_i16m1_b16(x.val, 0, 8); + return v_uint16x8((vuint16m1_t)vrsub_vx_i16m1_m(mask, x.val, x.val, 0, 8)); +} + +inline v_uint8x16 v_abs(v_int8x16 x) +{ + vbool8_t mask=vmslt_vx_i8m1_b8(x.val, 0, 16); + return v_uint8x16((vuint8m1_t)vrsub_vx_i8m1_m(mask, x.val, x.val, 0, 16)); +} + +inline v_float32x4 v_abs(v_float32x4 x) +{ + return (v_float32x4)vfsgnjx_vv_f32m1(x.val, x.val, 4); +} + +inline v_float64x2 v_abs(v_float64x2 x) +{ + return (v_float64x2)vfsgnjx_vv_f64m1(x.val, x.val, 2); +} + +inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) +{ + vfloat32m1_t ret = vfsub_vv_f32m1(a.val, b.val, 4); + return (v_float32x4)vfsgnjx_vv_f32m1(ret, ret, 4); +} + +inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b) +{ + vfloat64m1_t ret = vfsub_vv_f64m1(a.val, b.val, 2); + return (v_float64x2)vfsgnjx_vv_f64m1(ret, ret, 2); +} + +#define OPENCV_HAL_IMPL_RISCVV_ABSDIFF_U(bit, num) \ +inline v_uint##bit##x##num v_absdiff(v_uint##bit##x##num a, v_uint##bit##x##num b){ \ + vuint##bit##m1_t vmax = vmaxu_vv_u##bit##m1(a.val, b.val, num); \ + vuint##bit##m1_t vmin = vminu_vv_u##bit##m1(a.val, b.val, num); \ + return v_uint##bit##x##num(vsub_vv_u##bit##m1(vmax, vmin, num));\ +} + +OPENCV_HAL_IMPL_RISCVV_ABSDIFF_U(8, 16) +OPENCV_HAL_IMPL_RISCVV_ABSDIFF_U(16, 8) +OPENCV_HAL_IMPL_RISCVV_ABSDIFF_U(32, 4) + +/** Saturating absolute difference **/ +inline v_int8x16 v_absdiffs(v_int8x16 a, v_int8x16 b){ + vint8m1_t vmax = vmax_vv_i8m1(a.val, b.val, 16); + vint8m1_t vmin = vmin_vv_i8m1(a.val, b.val, 16); + return v_int8x16(vssub_vv_i8m1(vmax, vmin, 16)); +} +inline v_int16x8 v_absdiffs(v_int16x8 a, v_int16x8 b){ + vint16m1_t vmax = vmax_vv_i16m1(a.val, b.val, 8); + vint16m1_t vmin = vmin_vv_i16m1(a.val, b.val, 8); + return v_int16x8(vssub_vv_i16m1(vmax, vmin, 8)); +} + +#define OPENCV_HAL_IMPL_RISCVV_ABSDIFF(_Tpvec, _Tpv, num) \ +inline v_uint##_Tpvec v_absdiff(v_int##_Tpvec a, v_int##_Tpvec b){ \ + vint##_Tpv##_t max = vmax_vv_i##_Tpv(a.val, b.val, num);\ + vint##_Tpv##_t min = vmin_vv_i##_Tpv(a.val, b.val, num);\ + return v_uint##_Tpvec((vuint##_Tpv##_t)vsub_vv_i##_Tpv(max, min, num)); \ +} + +OPENCV_HAL_IMPL_RISCVV_ABSDIFF(8x16, 8m1, 16) +OPENCV_HAL_IMPL_RISCVV_ABSDIFF(16x8, 16m1, 8) +OPENCV_HAL_IMPL_RISCVV_ABSDIFF(32x4, 32m1, 4) + +// Multiply and expand +inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b, + v_int16x8& c, v_int16x8& d) +{ + vint16m2_t res = vundefined_i16m2(); + res = vwmul_vv_i16m2(a.val, b.val, 16); + c.val = vget_i16m2_i16m1(res, 0); + d.val = vget_i16m2_i16m1(res, 1); +} + +inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b, + v_uint16x8& c, v_uint16x8& d) +{ + vuint16m2_t res = vundefined_u16m2(); + res = vwmulu_vv_u16m2(a.val, b.val, 16); + c.val = vget_u16m2_u16m1(res, 0); + d.val = vget_u16m2_u16m1(res, 1); +} + +inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, + v_int32x4& c, v_int32x4& d) +{ + vint32m2_t res = vundefined_i32m2(); + res = vwmul_vv_i32m2(a.val, b.val, 8); + c.val = vget_i32m2_i32m1(res, 0); + d.val = vget_i32m2_i32m1(res, 1); +} + +inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b, + v_uint32x4& c, v_uint32x4& d) +{ + vuint32m2_t res = vundefined_u32m2(); + res = vwmulu_vv_u32m2(a.val, b.val, 8); + c.val = vget_u32m2_u32m1(res, 0); + d.val = vget_u32m2_u32m1(res, 1); +} + +inline void v_mul_expand(const v_int32x4& a, const v_int32x4& b, + v_int64x2& c, v_int64x2& d) +{ + vint64m2_t res = vundefined_i64m2(); + res = vwmul_vv_i64m2(a.val, b.val, 4); + c.val = vget_i64m2_i64m1(res, 0); + d.val = vget_i64m2_i64m1(res, 1); +} + +inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, + v_uint64x2& c, v_uint64x2& d) +{ + vuint64m2_t res = vundefined_u64m2(); + res = vwmulu_vv_u64m2(a.val, b.val, 4); + c.val = vget_u64m2_u64m1(res, 0); + d.val = vget_u64m2_u64m1(res, 1); +} + +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint8x16, v_add_wrap, vadd_vv_u8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int8x16, v_add_wrap, vadd_vv_i8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint16x8, v_add_wrap, vadd_vv_u16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int16x8, v_add_wrap, vadd_vv_i16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint8x16, v_sub_wrap, vsub_vv_u8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int8x16, v_sub_wrap, vsub_vv_i8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint16x8, v_sub_wrap, vsub_vv_u16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int16x8, v_sub_wrap, vsub_vv_i16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint8x16, v_mul_wrap, vmul_vv_u8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int8x16, v_mul_wrap, vmul_vv_i8m1, 16) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_uint16x8, v_mul_wrap, vmul_vv_u16m1, 8) +OPENCV_HAL_IMPL_RISCVV_BINN_FUNC(v_int16x8, v_mul_wrap, vmul_vv_i16m1, 8) +//////// Dot Product //////// +// 16 >> 32 +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ + vint32m2_t res = vundefined_i32m2(); + res = vwmul_vv_i32m2(a.val, b.val, 8); + res = vrgather_vv_i32m2(res, (vuint32m2_t){0, 2, 4, 6, 1, 3, 5, 7}, 8); + return v_int32x4(vadd_vv_i32m1(vget_i32m2_i32m1(res, 0), vget_i32m2_i32m1(res, 1), 4)); +} +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ + vint32m2_t res = vundefined_i32m2(); + res = vwmul_vv_i32m2(a.val, b.val, 8); + res = vrgather_vv_i32m2(res, (vuint32m2_t){0, 2, 4, 6, 1, 3, 5, 7}, 8); + return v_int32x4(vadd_vv_i32m1(vadd_vv_i32m1(vget_i32m2_i32m1(res, 0),vget_i32m2_i32m1(res, 1), 4), c.val, 4)); +} + +// 32 >> 64 +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b) +{ + vint64m2_t res = vundefined_i64m2(); + res = vwmul_vv_i64m2(a.val, b.val, 4); + res = vrgather_vv_i64m2(res, (vuint64m2_t){0, 2, 1, 3}, 4); + return v_int64x2(vadd_vv_i64m1(vget_i64m2_i64m1(res, 0), vget_i64m2_i64m1(res, 1), 2)); +} +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ + vint64m2_t res = vundefined_i64m2(); + res = vwmul_vv_i64m2(a.val, b.val, 4); + res = vrgather_vv_i64m2(res, (vuint64m2_t){0, 2, 1, 3}, 4); + return v_int64x2(vadd_vv_i64m1(vadd_vv_i64m1(vget_i64m2_i64m1(res, 0), vget_i64m2_i64m1(res, 1), 2), c.val, 2)); +} + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b) +{ + vuint16m2_t v1 = vundefined_u16m2(); + vuint32m2_t v2 = vundefined_u32m2(); + v1 = vwmulu_vv_u16m2(a.val, b.val, 16); + v1 = vrgather_vv_u16m2(v1, (vuint16m2_t){0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15}, 16); + v2 = vwaddu_vv_u32m2(vget_u16m2_u16m1(v1, 0), vget_u16m2_u16m1(v1, 1), 8); + return v_uint32x4(vadd_vv_u32m1(vget_u32m2_u32m1(v2, 0), vget_u32m2_u32m1(v2, 1), 4)); +} + +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b, + const v_uint32x4& c) +{ + vuint16m2_t v1 = vundefined_u16m2(); + vuint32m2_t v2 = vundefined_u32m2(); + v1 = vwmulu_vv_u16m2(a.val, b.val, 16); + v1 = vrgather_vv_u16m2(v1, (vuint16m2_t){0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15}, 16); + v2 = vwaddu_vv_u32m2(vget_u16m2_u16m1(v1, 0), vget_u16m2_u16m1(v1, 1), 8); + return v_uint32x4(vadd_vv_u32m1(vadd_vv_u32m1(vget_u32m2_u32m1(v2, 0), vget_u32m2_u32m1(v2, 1), 4), c.val, 4)); +} + +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b) +{ + vint16m2_t v1 = vundefined_i16m2(); + vint32m2_t v2 = vundefined_i32m2(); + v1 = vwmul_vv_i16m2(a.val, b.val, 16); + v1 = vrgather_vv_i16m2(v1, (vuint16m2_t){0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15}, 16); + v2 = vwadd_vv_i32m2(vget_i16m2_i16m1(v1, 0), vget_i16m2_i16m1(v1, 1), 8); + return v_int32x4(vadd_vv_i32m1(vget_i32m2_i32m1(v2, 0), vget_i32m2_i32m1(v2, 1), 4)); +} + +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b, + const v_int32x4& c) +{ + vint16m2_t v1 = vundefined_i16m2(); + vint32m2_t v2 = vundefined_i32m2(); + v1 = vwmul_vv_i16m2(a.val, b.val, 16); + v1 = vrgather_vv_i16m2(v1, (vuint16m2_t){0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15}, 16); + v2 = vwadd_vv_i32m2(vget_i16m2_i16m1(v1, 0), vget_i16m2_i16m1(v1, 1), 8); + return v_int32x4(vadd_vv_i32m1(vadd_vv_i32m1(vget_i32m2_i32m1(v2, 0), vget_i32m2_i32m1(v2, 1), 4), c.val, 4)); +} + +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b) +{ + vuint32m2_t v1 = vundefined_u32m2(); + vuint64m2_t v2 = vundefined_u64m2(); + v1 = vwmulu_vv_u32m2(a.val, b.val, 8); + v1 = vrgather_vv_u32m2(v1, (vuint32m2_t){0, 4, 1, 5, 2, 6, 3, 7}, 8); + v2 = vwaddu_vv_u64m2(vget_u32m2_u32m1(v1, 0), vget_u32m2_u32m1(v1, 1), 4); + return v_uint64x2(vadd_vv_u64m1(vget_u64m2_u64m1(v2, 0), vget_u64m2_u64m1(v2, 1), 2)); +} + +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b, + const v_uint64x2& c) +{ + vuint32m2_t v1 = vundefined_u32m2(); + vuint64m2_t v2 = vundefined_u64m2(); + v1 = vwmulu_vv_u32m2(a.val, b.val, 8); + v1 = vrgather_vv_u32m2(v1, (vuint32m2_t){0, 4, 1, 5, 2, 6, 3, 7}, 8); + v2 = vwaddu_vv_u64m2(vget_u32m2_u32m1(v1, 0), vget_u32m2_u32m1(v1, 1), 4); + return v_uint64x2(vadd_vv_u64m1(vadd_vv_u64m1(vget_u64m2_u64m1(v2, 0), vget_u64m2_u64m1(v2, 1), 2), c.val, 2)); +} + +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b) +{ + vint32m2_t v1 = vundefined_i32m2(); + vint64m2_t v2 = vundefined_i64m2(); + v1 = vwmul_vv_i32m2(a.val, b.val, 8); + v1 = vrgather_vv_i32m2(v1, (vuint32m2_t){0, 4, 1, 5, 2, 6, 3, 7}, 8); + v2 = vwadd_vv_i64m2(vget_i32m2_i32m1(v1, 0), vget_i32m2_i32m1(v1, 1), 4); + return v_int64x2(vadd_vv_i64m1(vget_i64m2_i64m1(v2, 0), vget_i64m2_i64m1(v2, 1), 2)); +} + +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b, + const v_int64x2& c) +{ + vint32m2_t v1 = vundefined_i32m2(); + vint64m2_t v2 = vundefined_i64m2(); + v1 = vwmul_vv_i32m2(a.val, b.val, 8); + v1 = vrgather_vv_i32m2(v1, (vuint32m2_t){0, 4, 1, 5, 2, 6, 3, 7}, 8); + v2 = vwadd_vv_i64m2(vget_i32m2_i32m1(v1, 0), vget_i32m2_i32m1(v1, 1), 4); + return v_int64x2(vadd_vv_i64m1(vadd_vv_i64m1(vget_i64m2_i64m1(v2, 0), vget_i64m2_i64m1(v2, 1), 2), c.val, 2)); +} + +//////// Fast Dot Product //////// +// 16 >> 32 +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b) +{ + vint32m2_t v1 = vundefined_i32m2(); + v1 = vwmul_vv_i32m2(a.val, b.val, 8); + return v_int32x4(vadd_vv_i32m1(vget_i32m2_i32m1(v1, 0), vget_i32m2_i32m1(v1, 1), 4)); +} + +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ + vint32m2_t v1 = vundefined_i32m2(); + v1 = vwmul_vv_i32m2(a.val, b.val, 8); + return v_int32x4(vadd_vv_i32m1(vadd_vv_i32m1(vget_i32m2_i32m1(v1, 0), vget_i32m2_i32m1(v1, 1), 4), c.val, 4)); +} + +// 32 >> 64 +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b) +{ + vint64m2_t v1 = vundefined_i64m2(); + v1 = vwmul_vv_i64m2(a.val, b.val, 4); + return v_int64x2(vadd_vv_i64m1(vget_i64m2_i64m1(v1, 0), vget_i64m2_i64m1(v1, 1), 2)); +} +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ + vint64m2_t v1 = vundefined_i64m2(); + v1 = vwmul_vv_i64m2(a.val, b.val, 8); + return v_int64x2(vadd_vv_i64m1(vadd_vv_i64m1(vget_i64m2_i64m1(v1, 0), vget_i64m2_i64m1(v1, 1), 4), c.val, 4)); +} + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b) +{ + vuint16m2_t v1 = vundefined_u16m2(); + vuint32m2_t v2 = vundefined_u32m2(); + v1 = vwmulu_vv_u16m2(a.val, b.val, 16); + v2 = vwaddu_vv_u32m2(vget_u16m2_u16m1(v1, 0), vget_u16m2_u16m1(v1, 1), 8); + return v_uint32x4(vadd_vv_u32m1(vget_u32m2_u32m1(v2, 0), vget_u32m2_u32m1(v2, 1), 4)); +} + +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ + vuint16m2_t v1 = vundefined_u16m2(); + vuint32m2_t v2 = vundefined_u32m2(); + v1 = vwmulu_vv_u16m2(a.val, b.val, 16); + v2 = vwaddu_vv_u32m2(vget_u16m2_u16m1(v1, 0), vget_u16m2_u16m1(v1, 1), 8); + return v_uint32x4(vadd_vv_u32m1(vadd_vv_u32m1(vget_u32m2_u32m1(v2, 0), vget_u32m2_u32m1(v2, 1), 4), c.val, 4)); +} + +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b) +{ + vint16m2_t v1 = vundefined_i16m2(); + vint32m2_t v2 = vundefined_i32m2(); + v1 = vwmul_vv_i16m2(a.val, b.val, 16); + v2 = vwadd_vv_i32m2(vget_i16m2_i16m1(v1, 0), vget_i16m2_i16m1(v1, 1), 8); + return v_int32x4(vadd_vv_i32m1(vget_i32m2_i32m1(v2, 0), vget_i32m2_i32m1(v2, 1), 4)); +} +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ + vint16m2_t v1 = vundefined_i16m2(); + vint32m2_t v2 = vundefined_i32m2(); + v1 = vwmul_vv_i16m2(a.val, b.val, 16); + v2 = vwadd_vv_i32m2(vget_i16m2_i16m1(v1, 0), vget_i16m2_i16m1(v1, 1), 8); + return v_int32x4(vadd_vv_i32m1(vadd_vv_i32m1(vget_i32m2_i32m1(v2, 0), vget_i32m2_i32m1(v2, 1), 4), c.val, 4)); +} + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b) +{ + vuint32m2_t v1 = vundefined_u32m2(); + vuint64m2_t v2 = vundefined_u64m2(); + v1 = vwmulu_vv_u32m2(a.val, b.val, 8); + v2 = vwaddu_vv_u64m2(vget_u32m2_u32m1(v1, 0), vget_u32m2_u32m1(v1, 1), 4); + return v_uint64x2(vadd_vv_u64m1(vget_u64m2_u64m1(v2, 0), vget_u64m2_u64m1(v2, 1), 2)); +} +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ + vuint32m2_t v1 = vundefined_u32m2(); + vuint64m2_t v2 = vundefined_u64m2(); + v1 = vwmulu_vv_u32m2(a.val, b.val, 8); + v2 = vwaddu_vv_u64m2(vget_u32m2_u32m1(v1, 0), vget_u32m2_u32m1(v1, 1), 4); + return v_uint64x2(vadd_vv_u64m1(vadd_vv_u64m1(vget_u64m2_u64m1(v2, 0), vget_u64m2_u64m1(v2, 1), 2), c.val, 2)); +} + +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b) +{ + vint32m2_t v1 = vundefined_i32m2(); + vint64m2_t v2 = vundefined_i64m2(); + v1 = vwmul_vv_i32m2(a.val, b.val, 8); + v2 = vwadd_vv_i64m2(vget_i32m2_i32m1(v1, 0), vget_i32m2_i32m1(v1, 1), 4); + return v_int64x2(vadd_vv_i64m1(vget_i64m2_i64m1(v2, 0), vget_i64m2_i64m1(v2, 1), 2)); +} +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ + vint32m2_t v1 = vundefined_i32m2(); + vint64m2_t v2 = vundefined_i64m2(); + v1 = vwmul_vv_i32m2(a.val, b.val, 8); + v2 = vwadd_vv_i64m2(vget_i32m2_i32m1(v1, 0), vget_i32m2_i32m1(v1, 1), 4); + return v_int64x2(vadd_vv_i64m1(vadd_vv_i64m1(vget_i64m2_i64m1(v2, 0), vget_i64m2_i64m1(v2, 1), 2), c.val, 2)); +} + + +#define OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_W(_Tpvec, _Tpvec2, len, scalartype, func, intrin, num) \ +inline scalartype v_reduce_##func(const v_##_Tpvec##x##num& a) \ +{\ + v##_Tpvec2##m1_t val = vmv_v_x_##len##m1(0, num); \ + val = intrin(val, a.val, val, num); \ + return vmv_x_s_##len##m1_##len(val, num); \ +} + + +#define OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_(_Tpvec, _Tpvec2, scalartype, func, funcu, num) \ +inline scalartype v_reduce_##func(const v_##_Tpvec##x##num& a) \ +{\ + v##_Tpvec##m1_t val = (v##_Tpvec##m1_t)vmv_v_x_i8m1(0, num); \ + val = v##funcu##_vs_##_Tpvec2##m1_##_Tpvec2##m1(val, a.val, a.val, num); \ + return val[0]; \ +} +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_W(int8, int16, i16, int, sum, vwredsum_vs_i8m1_i16m1, 16) +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_W(int16, int32, i32, int, sum, vwredsum_vs_i16m1_i32m1, 8) +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_W(int32, int64, i64, int, sum, vwredsum_vs_i32m1_i64m1, 4) +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_W(uint8, uint16, u16, unsigned, sum, vwredsumu_vs_u8m1_u16m1, 16) +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_W(uint16, uint32, u32, unsigned, sum, vwredsumu_vs_u16m1_u32m1, 8) +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_W(uint32, uint64, u64, unsigned, sum, vwredsumu_vs_u32m1_u64m1, 4) +inline float v_reduce_sum(const v_float32x4& a) \ +{\ + vfloat32m1_t val = vfmv_v_f_f32m1(0.0, 4); \ + val = vfredsum_vs_f32m1_f32m1(val, a.val, val, 4); \ + return vfmv_f_s_f32m1_f32(val, 4); \ +} +inline double v_reduce_sum(const v_float64x2& a) \ +{\ + vfloat64m1_t val = vfmv_v_f_f64m1(0.0, 2); \ + val = vfredsum_vs_f64m1_f64m1(val, a.val, val, 2); \ + return vfmv_f_s_f64m1_f64(val, 2); \ +} +inline uint64 v_reduce_sum(const v_uint64x2& a) +{ return vext_x_v_u64m1_u64((vuint64m1_t)a.val, 0, 2)+vext_x_v_u64m1_u64((vuint64m1_t)a.val, 1, 2); } + +inline int64 v_reduce_sum(const v_int64x2& a) +{ return vext_x_v_i64m1_i64((vint64m1_t)a.val, 0, 2)+vext_x_v_i64m1_i64((vint64m1_t)a.val, 1, 2); } + +#define OPENCV_HAL_IMPL_RISCVV_REDUCE_OP(func) \ +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_(int8, i8, int, func, red##func, 16) \ +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_(int16, i16, int, func, red##func, 8) \ +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_(int32, i32, int, func, red##func, 4) \ +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_(int64, i64, int, func, red##func, 2) \ +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_(uint8, u8, unsigned, func, red##func##u, 16) \ +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_(uint16, u16, unsigned, func, red##func##u, 8) \ +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_(uint32, u32, unsigned, func, red##func##u, 4) \ +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP_(float32, f32, float, func, fred##func, 4) +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP(max) +OPENCV_HAL_IMPL_RISCVV_REDUCE_OP(min) + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + vfloat32m1_t a0 = vfmv_v_f_f32m1(0.0, 4); + vfloat32m1_t b0 = vfmv_v_f_f32m1(0.0, 4); + vfloat32m1_t c0 = vfmv_v_f_f32m1(0.0, 4); + vfloat32m1_t d0 = vfmv_v_f_f32m1(0.0, 4); + a0 = vfredsum_vs_f32m1_f32m1(a0, a.val, a0, 4); + b0 = vfredsum_vs_f32m1_f32m1(b0, b.val, b0, 4); + c0 = vfredsum_vs_f32m1_f32m1(c0, c.val, c0, 4); + d0 = vfredsum_vs_f32m1_f32m1(d0, d.val, d0, 4); + return v_float32x4(a0[0], b0[0], c0[0], d0[0]); +} + +inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) +{ + vfloat32m1_t a0 = vfmv_v_f_f32m1(0.0, 4); + vfloat32m1_t x = vfsub_vv_f32m1(a.val, b.val, 4); + vbool32_t mask=vmflt_vf_f32m1_b32(x, 0, 4); + vfloat32m1_t val = vfrsub_vf_f32m1_m(mask, x, x, 0, 4); + a0 = vfredsum_vs_f32m1_f32m1(a0, val, a0, 4); + return a0[0]; +} + +#define OPENCV_HAL_IMPL_RISCVV_REDUCE_SAD(_Tpvec, _Tpvec2) \ +inline unsigned v_reduce_sad(const _Tpvec& a, const _Tpvec&b){ \ + _Tpvec2 x = v_absdiff(a, b); \ + return v_reduce_sum(x); \ +} + +OPENCV_HAL_IMPL_RISCVV_REDUCE_SAD(v_int8x16, v_uint8x16) +OPENCV_HAL_IMPL_RISCVV_REDUCE_SAD(v_uint8x16, v_uint8x16) +OPENCV_HAL_IMPL_RISCVV_REDUCE_SAD(v_int16x8, v_uint16x8) +OPENCV_HAL_IMPL_RISCVV_REDUCE_SAD(v_uint16x8, v_uint16x8) +OPENCV_HAL_IMPL_RISCVV_REDUCE_SAD(v_int32x4, v_uint32x4) +OPENCV_HAL_IMPL_RISCVV_REDUCE_SAD(v_uint32x4, v_uint32x4) + +#define OPENCV_HAL_IMPL_RISCVV_INT_CMP_OP(_Tpvec, _Tp, _T, num, uv) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ \ + vbool##_T##_t mask = vmseq_vv_##_Tp##_b##_T(a.val, b.val, num); \ + return _Tpvec(vmerge_vxm_##_Tp(mask, vmv_v_x_##_Tp(0, num), -1, num)); \ +} \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ \ + vbool##_T##_t mask = vmsne_vv_##_Tp##_b##_T(a.val, b.val, num); \ + return _Tpvec(vmerge_vxm_##_Tp(mask, vmv_v_x_##_Tp(0, num), -1, num)); \ +} \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ \ + vbool##_T##_t mask = vmslt##uv##_Tp##_b##_T(a.val, b.val, num); \ + return _Tpvec(vmerge_vxm_##_Tp(mask, vmv_v_x_##_Tp(0, num), -1, num)); \ +} \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ \ + vbool##_T##_t mask = vmslt##uv##_Tp##_b##_T(b.val, a.val, num); \ + return _Tpvec(vmerge_vxm_##_Tp(mask, vmv_v_x_##_Tp(0, num), -1, num)); \ +} \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ \ + vbool##_T##_t mask = vmsle##uv##_Tp##_b##_T(a.val, b.val, num); \ + return _Tpvec(vmerge_vxm_##_Tp(mask, vmv_v_x_##_Tp(0, num), -1, num)); \ +} \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ \ + vbool##_T##_t mask = vmsle##uv##_Tp##_b##_T(b.val, a.val, num); \ + return _Tpvec(vmerge_vxm_##_Tp(mask, vmv_v_x_##_Tp(0, num), -1, num)); \ +} \ + +OPENCV_HAL_IMPL_RISCVV_INT_CMP_OP(v_int8x16, i8m1, 8, 16, _vv_) +OPENCV_HAL_IMPL_RISCVV_INT_CMP_OP(v_int16x8, i16m1, 16, 8, _vv_) +OPENCV_HAL_IMPL_RISCVV_INT_CMP_OP(v_int32x4, i32m1, 32, 4, _vv_) +OPENCV_HAL_IMPL_RISCVV_INT_CMP_OP(v_int64x2, i64m1, 64, 2, _vv_) +OPENCV_HAL_IMPL_RISCVV_INT_CMP_OP(v_uint8x16, u8m1, 8, 16, u_vv_) +OPENCV_HAL_IMPL_RISCVV_INT_CMP_OP(v_uint16x8, u16m1, 16, 8, u_vv_) +OPENCV_HAL_IMPL_RISCVV_INT_CMP_OP(v_uint32x4, u32m1, 32, 4, u_vv_) +OPENCV_HAL_IMPL_RISCVV_INT_CMP_OP(v_uint64x2, u64m1, 64, 2, u_vv_) + +//TODO: == +inline v_float32x4 operator == (const v_float32x4& a, const v_float32x4& b) +{ + vbool32_t mask = vmfeq_vv_f32m1_b32(a.val, b.val, 4); + vint32m1_t res = vmerge_vxm_i32m1(mask, vmv_v_x_i32m1(0.0, 4), -1, 4); + return v_float32x4((vfloat32m1_t)res); +} +inline v_float32x4 operator != (const v_float32x4& a, const v_float32x4& b) +{ + vbool32_t mask = vmfne_vv_f32m1_b32(a.val, b.val, 4); + vint32m1_t res = vmerge_vxm_i32m1(mask, vmv_v_x_i32m1(0.0, 4), -1, 4); + return v_float32x4((vfloat32m1_t)res); +} +inline v_float32x4 operator < (const v_float32x4& a, const v_float32x4& b) +{ + vbool32_t mask = vmflt_vv_f32m1_b32(a.val, b.val, 4); + vint32m1_t res = vmerge_vxm_i32m1(mask, vmv_v_x_i32m1(0.0, 4), -1, 4); + return v_float32x4((vfloat32m1_t)res); +} +inline v_float32x4 operator <= (const v_float32x4& a, const v_float32x4& b) +{ + vbool32_t mask = vmfle_vv_f32m1_b32(a.val, b.val, 4); + vint32m1_t res = vmerge_vxm_i32m1(mask, vmv_v_x_i32m1(0.0, 4), -1, 4); + return v_float32x4((vfloat32m1_t)res); +} +inline v_float32x4 operator > (const v_float32x4& a, const v_float32x4& b) +{ + vbool32_t mask = vmfgt_vv_f32m1_b32(a.val, b.val, 4); + vint32m1_t res = vmerge_vxm_i32m1(mask, vmv_v_x_i32m1(0.0, 4), -1, 4); + return v_float32x4((vfloat32m1_t)res); +} +inline v_float32x4 operator >= (const v_float32x4& a, const v_float32x4& b) +{ + vbool32_t mask = vmfge_vv_f32m1_b32(a.val, b.val, 4); + vint32m1_t res = vmerge_vxm_i32m1(mask, vmv_v_x_i32m1(0.0, 4), -1, 4); + return v_float32x4((vfloat32m1_t)res); +} +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ + vbool32_t mask = vmford_vv_f32m1_b32(a.val, a.val, 4); + vint32m1_t res = vmerge_vxm_i32m1(mask, vmv_v_x_i32m1(0.0, 4), -1, 4); + return v_float32x4((vfloat32m1_t)res); +} + +//TODO: == +inline v_float64x2 operator == (const v_float64x2& a, const v_float64x2& b) +{ + vbool64_t mask = vmfeq_vv_f64m1_b64(a.val, b.val, 2); + vint64m1_t res = vmerge_vxm_i64m1(mask, vmv_v_x_i64m1(0.0, 2), -1, 2); + return v_float64x2((vfloat64m1_t)res); +} +inline v_float64x2 operator != (const v_float64x2& a, const v_float64x2& b) +{ + vbool64_t mask = vmfne_vv_f64m1_b64(a.val, b.val, 2); + vint64m1_t res = vmerge_vxm_i64m1(mask, vmv_v_x_i64m1(0.0, 2), -1, 2); + return v_float64x2((vfloat64m1_t)res); +} +inline v_float64x2 operator < (const v_float64x2& a, const v_float64x2& b) +{ + vbool64_t mask = vmflt_vv_f64m1_b64(a.val, b.val, 2); + vint64m1_t res = vmerge_vxm_i64m1(mask, vmv_v_x_i64m1(0.0, 2), -1, 2); + return v_float64x2((vfloat64m1_t)res); +} +inline v_float64x2 operator <= (const v_float64x2& a, const v_float64x2& b) +{ + vbool64_t mask = vmfle_vv_f64m1_b64(a.val, b.val, 2); + vint64m1_t res = vmerge_vxm_i64m1(mask, vmv_v_x_i64m1(0.0, 2), -1, 2); + return v_float64x2((vfloat64m1_t)res); +} +inline v_float64x2 operator > (const v_float64x2& a, const v_float64x2& b) +{ + vbool64_t mask = vmfgt_vv_f64m1_b64(a.val, b.val, 2); + vint64m1_t res = vmerge_vxm_i64m1(mask, vmv_v_x_i64m1(0.0, 2), -1, 2); + return v_float64x2((vfloat64m1_t)res); +} +inline v_float64x2 operator >= (const v_float64x2& a, const v_float64x2& b) +{ + vbool64_t mask = vmfge_vv_f64m1_b64(a.val, b.val, 2); + vint64m1_t res = vmerge_vxm_i64m1(mask, vmv_v_x_i64m1(0.0, 2), -1, 2); + return v_float64x2((vfloat64m1_t)res); +} +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ + vbool64_t mask = vmford_vv_f64m1_b64(a.val, a.val, 2); + vint64m1_t res = vmerge_vxm_i64m1(mask, vmv_v_x_i64m1(0.0, 2), -1, 2); + return v_float64x2((vfloat64m1_t)res); +} +#define OPENCV_HAL_IMPL_RISCVV_TRANSPOSE4x4(_Tp, _T) \ +inline void v_transpose4x4(const v_##_Tp##32x4& a0, const v_##_Tp##32x4& a1, \ + const v_##_Tp##32x4& a2, const v_##_Tp##32x4& a3, \ + v_##_Tp##32x4& b0, v_##_Tp##32x4& b1, \ + v_##_Tp##32x4& b2, v_##_Tp##32x4& b3) \ +{ \ + v##_Tp##32m4_t val = vundefined_##_T##m4(); \ + val = vset_##_T##m4(val, 0, a0.val); \ + val = vset_##_T##m4(val, 1, a1.val); \ + val = vset_##_T##m4(val, 2, a2.val); \ + val = vset_##_T##m4(val, 3, a3.val); \ + val = vrgather_vv_##_T##m4(val, (vuint32m4_t){0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15}, 16); \ + b0.val = vget_##_T##m4_##_T##m1(val, 0); \ + b1.val = vget_##_T##m4_##_T##m1(val, 1); \ + b2.val = vget_##_T##m4_##_T##m1(val, 2); \ + b3.val = vget_##_T##m4_##_T##m1(val, 3); \ +} +OPENCV_HAL_IMPL_RISCVV_TRANSPOSE4x4(uint, u32) +OPENCV_HAL_IMPL_RISCVV_TRANSPOSE4x4(int, i32) +OPENCV_HAL_IMPL_RISCVV_TRANSPOSE4x4(float, f32) + + +#define OPENCV_HAL_IMPL_RISCVV_SHIFT_LEFT(_Tpvec, suffix, _T, num) \ +inline _Tpvec operator << (const _Tpvec& a, int n) \ +{ return _Tpvec((vsll_vx_##_T##m1(a.val, n, num))); } \ +template inline _Tpvec v_shl(const _Tpvec& a) \ +{ return _Tpvec((vsll_vx_##_T##m1(a.val, n, num))); } + +#define OPENCV_HAL_IMPL_RISCVV_SHIFT_RIGHT(_Tpvec, suffix, _T, num, intric) \ +inline _Tpvec operator >> (const _Tpvec& a, int n) \ +{ return _Tpvec((v##intric##_vx_##_T##m1(a.val, n, num))); } \ +template inline _Tpvec v_shr(const _Tpvec& a) \ +{ return _Tpvec((v##intric##_vx_##_T##m1(a.val, n, num))); }\ +template inline _Tpvec v_rshr(const _Tpvec& a) \ +{ return _Tpvec((v##intric##_vx_##_T##m1(vadd_vx_##_T##m1(a.val, 1<<(n-1), num), n, num))); } + +// trade efficiency for convenience +#define OPENCV_HAL_IMPL_RISCVV_SHIFT_OP(suffix, _T, num, intrin) \ +OPENCV_HAL_IMPL_RISCVV_SHIFT_LEFT(v_##suffix##x##num, suffix, _T, num) \ +OPENCV_HAL_IMPL_RISCVV_SHIFT_RIGHT(v_##suffix##x##num, suffix, _T, num, intrin) + +OPENCV_HAL_IMPL_RISCVV_SHIFT_OP(uint8, u8, 16, srl) +OPENCV_HAL_IMPL_RISCVV_SHIFT_OP(uint16, u16, 8, srl) +OPENCV_HAL_IMPL_RISCVV_SHIFT_OP(uint32, u32, 4, srl) +OPENCV_HAL_IMPL_RISCVV_SHIFT_OP(uint64, u64, 2, srl) +OPENCV_HAL_IMPL_RISCVV_SHIFT_OP(int8, i8, 16, sra) +OPENCV_HAL_IMPL_RISCVV_SHIFT_OP(int16, i16, 8, sra) +OPENCV_HAL_IMPL_RISCVV_SHIFT_OP(int32, i32, 4, sra) +OPENCV_HAL_IMPL_RISCVV_SHIFT_OP(int64, i64, 2, sra) + +#if 0 +#define VUP4(n) {0, 1, 2, 3} +#define VUP8(n) {0, 1, 2, 3, 4, 5, 6, 7} +#define VUP16(n) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} +#define VUP2(n) {0, 1} +#endif +#define OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(_Tpvec, suffix, _T, num, num2, vmv, len) \ +template inline _Tpvec v_rotate_left(const _Tpvec& a) \ +{ \ + suffix##m1_t tmp = vmv##_##_T##m1(0, num);\ + tmp = vslideup_vx_##_T##m1_m(vmset_m_##len(num), tmp, a.val, n, num);\ + return _Tpvec(tmp);\ +} \ +template inline _Tpvec v_rotate_right(const _Tpvec& a) \ +{ \ + return _Tpvec(vslidedown_vx_##_T##m1(a.val, n, num));\ +} \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a) \ +{ return a; } \ +template inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \ +{ \ + suffix##m2_t tmp = vundefined_##_T##m2(); \ + tmp = vset_##_T##m2(tmp, 0, a.val); \ + tmp = vset_##_T##m2(tmp, 1, b.val); \ + tmp = vslidedown_vx_##_T##m2(tmp, n, num2);\ + return _Tpvec(vget_##_T##m2_##_T##m1(tmp, 0));\ +} \ +template inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \ +{ \ + suffix##m2_t tmp = vundefined_##_T##m2(); \ + tmp = vset_##_T##m2(tmp, 0, b.val); \ + tmp = vset_##_T##m2(tmp, 1, a.val); \ + tmp = vslideup_vx_##_T##m2(tmp, n, num2);\ + return _Tpvec(vget_##_T##m2_##_T##m1(tmp, 1));\ +} \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a, const _Tpvec& b) \ +{ \ + CV_UNUSED(b); return a; \ +} + +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_uint8x16, vuint8, u8, 16, 32, vmv_v_x, b8) +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_int8x16, vint8, i8, 16, 32, vmv_v_x, b8) +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_uint16x8, vuint16, u16, 8, 16, vmv_v_x, b16) +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_int16x8, vint16, i16, 8, 16, vmv_v_x, b16) +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_uint32x4, vuint32, u32, 4, 8, vmv_v_x, b32) +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_int32x4, vint32, i32, 4, 8, vmv_v_x, b32) +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_uint64x2, vuint64, u64, 2, 4, vmv_v_x, b64) +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_int64x2, vint64, i64, 2, 4, vmv_v_x, b64) +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_float32x4, vfloat32, f32, 4, 8, vfmv_v_f, b32) +OPENCV_HAL_IMPL_RISCVV_ROTATE_OP(v_float64x2, vfloat64, f64, 2, 4, vfmv_v_f, b64) + +#define OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(_Tpvec, _Tp, _Tp2, len, hnum, num) \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ \ + typedef uint64 CV_DECL_ALIGNED(1) unaligned_uint64; \ + vuint64m1_t tmp = {*(unaligned_uint64*)ptr0, *(unaligned_uint64*)ptr1};\ + return _Tpvec(_Tp2##_t(tmp)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(vle_v_##len(ptr, hnum)); }\ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(vle_v_##len(ptr, num)); } \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec((_Tp2##_t)vle_v_##len((const _Tp *)ptr, num)); } \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ vse_v_##len(ptr, a.val, hnum);}\ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ \ + _Tp2##_t a0 = vslidedown_vx_##len(a.val, hnum, num); \ + vse_v_##len(ptr, a0, hnum);}\ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ vse_v_##len(ptr, a.val, num); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ vse_v_##len(ptr, a.val, num); } \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ vse_v_##len(ptr, a.val, num); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode /*mode*/) \ +{ vse_v_##len(ptr, a.val, num); } + +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_uint8x16, uchar, vuint8m1, u8m1, 8, 16) +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_int8x16, schar, vint8m1, i8m1, 8, 16) +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_uint16x8, ushort, vuint16m1, u16m1, 4, 8) +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_int16x8, short, vint16m1, i16m1, 4, 8) +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_uint32x4, unsigned, vuint32m1, u32m1, 2, 4) +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_int32x4, int, vint32m1, i32m1, 2, 4) +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_uint64x2, unsigned long, vuint64m1, u64m1, 1, 2) +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_int64x2, long, vint64m1, i64m1, 1, 2) +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_float32x4, float, vfloat32m1, f32m1, 2, 4) +OPENCV_HAL_IMPL_RISCVV_LOADSTORE_OP(v_float64x2, double, vfloat64m1, f64m1, 1, 2) + + +////////////// Lookup table access //////////////////// + +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ +#if 1 + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[ 0]], + tab[idx[ 1]], + tab[idx[ 2]], + tab[idx[ 3]], + tab[idx[ 4]], + tab[idx[ 5]], + tab[idx[ 6]], + tab[idx[ 7]], + tab[idx[ 8]], + tab[idx[ 9]], + tab[idx[10]], + tab[idx[11]], + tab[idx[12]], + tab[idx[13]], + tab[idx[14]], + tab[idx[15]] + }; + return v_int8x16(vle_v_i8m1(elems, 16)); +#else + int32xm4_t index32 = vlev_int32xm4(idx, 16); + vint16m2_t index16 = vnsra_vx_i16m2_int32xm4(index32, 0, 16); + vint8m1_t index = vnsra_vx_i8m1_i16m2(index16, 0, 16); + return v_int8x16(vlxbv_i8m1(tab, index, 16)); +#endif +} + +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx){ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[4]], + tab[idx[4] + 1], + tab[idx[5]], + tab[idx[5] + 1], + tab[idx[6]], + tab[idx[6] + 1], + tab[idx[7]], + tab[idx[7] + 1] + }; + return v_int8x16(vle_v_i8m1(elems, 16)); +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[0] + 2], + tab[idx[0] + 3], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[1] + 2], + tab[idx[1] + 3], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[2] + 2], + tab[idx[2] + 3], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[3] + 2], + tab[idx[3] + 3] + }; + return v_int8x16(vle_v_i8m1(elems, 16)); +} + +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((schar*)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((schar*)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((schar*)tab, idx)); } + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]], + tab[idx[4]], + tab[idx[5]], + tab[idx[6]], + tab[idx[7]] + }; + return v_int16x8(vle_v_i16m1(elems, 8)); +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1] + }; + return v_int16x8(vle_v_i16m1(elems, 8)); +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[0] + 2], + tab[idx[0] + 3], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[1] + 2], + tab[idx[1] + 3] + }; + return v_int16x8(vle_v_i16m1(elems, 8)); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((short*)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((short*)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((short*)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + return v_int32x4(vle_v_i32m1(elems, 4)); +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1] + }; + return v_int32x4(vle_v_i32m1(elems, 4)); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + return v_int32x4(vle_v_i32m1(tab+idx[0], 4)); +} +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((int*)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((int*)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((int*)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + vint64m1_t res = {tab[idx[0]], tab[idx[1]]}; + return v_int64x2(res); +} +inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx) +{ + return v_int64x2(vle_v_i64m1(tab+idx[0], 2)); +} + +inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) +{ + vuint64m1_t res = {tab[idx[0]], tab[idx[1]]}; + return v_uint64x2(res); +} +inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) +{ + return v_uint64x2(vle_v_u64m1(tab+idx[0], 2)); +} + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + return v_float32x4(vle_v_f32m1(elems, 4)); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[0]+1], + tab[idx[1]], + tab[idx[1]+1] + }; + return v_float32x4(vle_v_f32m1(elems, 4)); +} +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) +{ + return v_float32x4(vle_v_f32m1(tab + idx[0], 4)); +} +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + vfloat64m1_t res = {tab[idx[0]], tab[idx[1]]}; + return v_float64x2(res); +} +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) +{ + return v_float64x2(vle_v_f64m1(tab+idx[0], 2)); +} + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[idxvec.val[0]], + tab[idxvec.val[1]], + tab[idxvec.val[2]], + tab[idxvec.val[3]] + }; + return v_int32x4(vle_v_i32m1(elems, 4)); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + unsigned CV_DECL_ALIGNED(32) elems[4] = + { + tab[idxvec.val[0]], + tab[idxvec.val[1]], + tab[idxvec.val[2]], + tab[idxvec.val[3]] + }; + return v_uint32x4(vle_v_u32m1(elems, 4)); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[idxvec.val[0]], + tab[idxvec.val[1]], + tab[idxvec.val[2]], + tab[idxvec.val[3]] + }; + return v_float32x4(vle_v_f32m1(elems, 4)); +} +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + vfloat64m1_t res = {tab[idxvec.val[0]], tab[idxvec.val[1]]}; + return v_float64x2(res); +} +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + vint32m1_t index_x = vmul_vx_i32m1(idxvec.val, 4, 4); + vint32m1_t index_y = vadd_vx_i32m1(index_x, 4, 4); + + x.val = vlxe_v_f32m1(tab, index_x, 4); + y.val = vlxe_v_f32m1(tab, index_y, 4); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + x = v_float64x2(tab[idx[0]], tab[idx[1]]); + y = v_float64x2(tab[idx[0]+1], tab[idx[1]+1]); +} + +#define OPENCV_HAL_IMPL_RISCVV_PACKS(_Tp, _Tp2, _T2, num2, _T1, num, intrin, shr, _Type) \ +inline v_##_Tp##x##num v_pack(const v_##_Tp2##x##num2& a, const v_##_Tp2##x##num2& b) \ +{ \ + v##_Tp2##m2_t tmp = vundefined_##_T2##m2(); \ + tmp = vset_##_T2##m2(tmp, 0, a.val); \ + tmp = vset_##_T2##m2(tmp, 1, b.val); \ + return v_##_Tp##x##num(shr##_##_T1##m1(tmp, 0, num)); \ +}\ +template inline \ +v_##_Tp##x##num v_rshr_pack(const v_##_Tp2##x##num2& a, const v_##_Tp2##x##num2& b) \ +{ \ + v##_Tp2##m2_t tmp = vundefined_##_T2##m2(); \ + tmp = vset_##_T2##m2(tmp, 0, a.val); \ + tmp = vset_##_T2##m2(tmp, 1, b.val); \ + return v_##_Tp##x##num(intrin##_##_T1##m1(tmp, n, num)); \ +}\ +inline void v_pack_store(_Type* ptr, const v_##_Tp2##x##num2& a) \ +{ \ + v##_Tp2##m2_t tmp = vundefined_##_T2##m2(); \ + tmp = vset_##_T2##m2(tmp, 0, a.val); \ + tmp = vset_##_T2##m2(tmp, 1, vmv_v_x_##_T2##m1(0, num2)); \ + asm("" ::: "memory"); \ + vse_v_##_T1##m1(ptr, shr##_##_T1##m1(tmp, 0, num), num2); \ +}\ +template inline \ +void v_rshr_pack_store(_Type* ptr, const v_##_Tp2##x##num2& a) \ +{ \ + v##_Tp2##m2_t tmp = vundefined_##_T2##m2(); \ + tmp = vset_##_T2##m2(tmp, 0, a.val); \ + tmp = vset_##_T2##m2(tmp, 1, vmv_v_x_##_T2##m1(0, num2)); \ + vse_v_##_T1##m1(ptr, intrin##_##_T1##m1(tmp, n, num), num2); \ +} +OPENCV_HAL_IMPL_RISCVV_PACKS(int8, int16, i16, 8, i8, 16, vnclip_vx, vnclip_vx, signed char) +OPENCV_HAL_IMPL_RISCVV_PACKS(int16, int32, i32, 4, i16, 8, vnclip_vx, vnclip_vx, signed short) +OPENCV_HAL_IMPL_RISCVV_PACKS(int32, int64, i64, 2, i32, 4, vnclip_vx, vnsra_vx, int) +OPENCV_HAL_IMPL_RISCVV_PACKS(uint8, uint16, u16, 8, u8, 16, vnclipu_vx, vnclipu_vx, unsigned char) +OPENCV_HAL_IMPL_RISCVV_PACKS(uint16, uint32, u32, 4, u16, 8, vnclipu_vx, vnclipu_vx, unsigned short) +OPENCV_HAL_IMPL_RISCVV_PACKS(uint32, uint64, u64, 2, u32, 4, vnclipu_vx, vnsrl_vx, unsigned int) + +// pack boolean +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + vuint16m2_t tmp = vundefined_u16m2(); \ + tmp = vset_u16m2(tmp, 0, a.val); \ + tmp = vset_u16m2(tmp, 1, b.val); \ + return v_uint8x16(vnsrl_vx_u8m1(tmp, 0, 16)); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + vuint32m4_t vabcd = vundefined_u32m4(); \ + vuint16m2_t v16 = vundefined_u16m2(); \ + vabcd = vset_u32m4(vabcd, 0, a.val); \ + vabcd = vset_u32m4(vabcd, 1, b.val); \ + vabcd = vset_u32m4(vabcd, 2, c.val); \ + vabcd = vset_u32m4(vabcd, 3, d.val); \ + v16 = vnsrl_vx_u16m2(vabcd, 0, 16); + return v_uint8x16(vnsrl_vx_u8m1(v16, 0, 16)); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + vuint64m8_t v64 = vundefined_u64m8(); \ + vuint32m4_t v32 = vundefined_u32m4(); \ + vuint16m2_t v16 = vundefined_u16m2(); \ + v64 = vset_u64m8(v64, 0, a.val); \ + v64 = vset_u64m8(v64, 1, b.val); \ + v64 = vset_u64m8(v64, 2, c.val); \ + v64 = vset_u64m8(v64, 3, d.val); \ + v64 = vset_u64m8(v64, 4, e.val); \ + v64 = vset_u64m8(v64, 5, f.val); \ + v64 = vset_u64m8(v64, 6, g.val); \ + v64 = vset_u64m8(v64, 7, h.val); \ + v32 = vnsrl_vx_u32m4(v64, 0, 16); + v16 = vnsrl_vx_u16m2(v32, 0, 16); + return v_uint8x16(vnsrl_vx_u8m1(v16, 0, 16)); +} + +//inline v_uint8x16 v_pack_u(const v_int16x8& a, const v_int16x8& b) \ +//{ \ +// int16xm2_u tmp; \ +// tmp.m1[0] = (vint16m1_t)a.val; \ +// tmp.m1[1] = (vint16m1_t)b.val; \ +// e8xm1_t mask = (e8xm1_t)vmsge_vx_e16xm2_i16m2(tmp.v, 0, 16);\ +// return v_uint8x16(vnclipuvi_mask_u8m1_u16m2(vmv_v_x_u8m1(0, 16), (vuint16m2_t)tmp.v, 0, mask, 16)); +//} + +#define OPENCV_HAL_IMPL_RISCVV_PACK_U(tp1, num1, tp2, num2, _Tp) \ +inline v_uint##tp1##x##num1 v_pack_u(const v_int##tp2##x##num2& a, const v_int##tp2##x##num2& b) \ +{ \ + vint##tp2##m2_t tmp = vundefined_##i##tp2##m2(); \ + tmp = vset_##i##tp2##m2(tmp, 0, a.val); \ + tmp = vset_##i##tp2##m2(tmp, 1, b.val); \ + vint##tp2##m2_t val = vmax_vx_i##tp2##m2(tmp, 0, num1);\ + return v_uint##tp1##x##num1(vnclipu_vx_u##tp1##m1((vuint##tp2##m2_t)val, 0, num1)); \ +} \ +inline void v_pack_u_store(_Tp* ptr, const v_int##tp2##x##num2& a) \ +{ \ + vint##tp2##m2_t tmp = vundefined_##i##tp2##m2(); \ + tmp = vset_##i##tp2##m2(tmp, 0, a.val); \ + vint##tp2##m2_t val = vmax_vx_i##tp2##m2(tmp, 0, num1);\ + return vse_v_u##tp1##m1(ptr, vnclipu_vx_u##tp1##m1((vuint##tp2##m2_t)val, 0, num1), num2); \ +} \ +template inline \ +v_uint##tp1##x##num1 v_rshr_pack_u(const v_int##tp2##x##num2& a, const v_int##tp2##x##num2& b) \ +{ \ + vint##tp2##m2_t tmp = vundefined_##i##tp2##m2(); \ + tmp = vset_##i##tp2##m2(tmp, 0, a.val); \ + tmp = vset_##i##tp2##m2(tmp, 1, b.val); \ + vint##tp2##m2_t val = vmax_vx_i##tp2##m2(tmp, 0, num1);\ + return v_uint##tp1##x##num1(vnclipu_vx_u##tp1##m1((vuint##tp2##m2_t)val, n, num1)); \ +} \ +template inline \ +void v_rshr_pack_u_store(_Tp* ptr, const v_int##tp2##x##num2& a) \ +{ \ + vint##tp2##m2_t tmp = vundefined_##i##tp2##m2(); \ + tmp = vset_##i##tp2##m2(tmp, 0, a.val); \ + vint##tp2##m2_t val_ = vmax_vx_i##tp2##m2(tmp, 0, num1);\ + vuint##tp1##m1_t val = vnclipu_vx_u##tp1##m1((vuint##tp2##m2_t)val_, n, num1); \ + return vse_v_u##tp1##m1(ptr, val, num2);\ +} +OPENCV_HAL_IMPL_RISCVV_PACK_U(8, 16, 16, 8, unsigned char ) +OPENCV_HAL_IMPL_RISCVV_PACK_U(16, 8, 32, 4, unsigned short) + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#endif + +// saturating multiply 8-bit, 16-bit +#define OPENCV_HAL_IMPL_RISCVV_MUL_SAT(_Tpvec, _Tpwvec) \ + inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ + { \ + _Tpwvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ + } \ + inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ + { a = a * b; return a; } + +OPENCV_HAL_IMPL_RISCVV_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_RISCVV_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_RISCVV_MUL_SAT(v_int16x8, v_int32x4) +OPENCV_HAL_IMPL_RISCVV_MUL_SAT(v_uint16x8, v_uint32x4) + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif +static const signed char popCountTable[256] = +{ + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, +}; + +inline vuint8m1_t vcnt_u8(vuint8m1_t val){ + vuint8m1_t v0 = val & 1; + return vlxe_v_u8m1((unsigned char*)popCountTable, val >> 1, 16)+v0; +} + +inline v_uint8x16 +v_popcount(const v_uint8x16& a) +{ + return v_uint8x16(vcnt_u8(a.val)); +} + +inline v_uint8x16 +v_popcount(const v_int8x16& a) +{ + return v_uint8x16(vcnt_u8((vuint8m1_t)a.val)); +} + +inline v_uint16x8 +v_popcount(const v_uint16x8& a) +{ + vuint8m2_t tmp = vundefined_u8m2(); + tmp = vset_u8m2(tmp, 0, vcnt_u8((vuint8m1_t)a.val)); + vuint64m2_t mask = (vuint64m2_t){0x0E0C0A0806040200, 0, 0x0F0D0B0907050301, 0}; + tmp = vrgather_vv_u8m2(tmp, (vuint8m2_t)mask, 32); \ + vuint16m2_t res = vwaddu_vv_u16m2(vget_u8m2_u8m1(tmp, 0), vget_u8m2_u8m1(tmp, 1), 8); + return v_uint16x8(vget_u16m2_u16m1(res, 0)); +} + +inline v_uint16x8 +v_popcount(const v_int16x8& a) +{ + vuint8m2_t tmp = vundefined_u8m2(); + tmp = vset_u8m2(tmp, 0, vcnt_u8((vuint8m1_t)a.val)); + vuint64m2_t mask = (vuint64m2_t){0x0E0C0A0806040200, 0, 0x0F0D0B0907050301, 0}; + tmp = vrgather_vv_u8m2(tmp, (vuint8m2_t)mask, 32); \ + vuint16m2_t res = vwaddu_vv_u16m2(vget_u8m2_u8m1(tmp, 0), vget_u8m2_u8m1(tmp, 1), 8); + return v_uint16x8(vget_u16m2_u16m1(res, 0)); +} + +inline v_uint32x4 +v_popcount(const v_uint32x4& a) +{ + vuint8m2_t tmp = vundefined_u8m2(); + tmp = vset_u8m2(tmp, 0, vcnt_u8((vuint8m1_t)a.val)); + vuint64m2_t mask = (vuint64m2_t){0xFFFFFFFF0C080400, 0xFFFFFFFF0D090501, + 0xFFFFFFFF0E0A0602, 0xFFFFFFFF0F0B0703}; + tmp = vrgather_vv_u8m2(tmp, (vuint8m2_t)mask, 32); \ + vuint16m2_t res_ = vwaddu_vv_u16m2(vget_u8m2_u8m1(tmp, 0), vget_u8m2_u8m1(tmp, 1), 16); + vuint32m2_t res = vwaddu_vv_u32m2(vget_u16m2_u16m1(res_, 0), vget_u16m2_u16m1(res_, 1), 8); + return v_uint32x4(vget_u32m2_u32m1(res, 0)); +} + +inline v_uint32x4 +v_popcount(const v_int32x4& a) +{ + vuint8m2_t tmp = vundefined_u8m2(); + tmp = vset_u8m2(tmp, 0, vcnt_u8((vuint8m1_t)a.val)); + vuint64m2_t mask = (vuint64m2_t){0xFFFFFFFF0C080400, 0xFFFFFFFF0D090501, + 0xFFFFFFFF0E0A0602, 0xFFFFFFFF0F0B0703}; + tmp = vrgather_vv_u8m2(tmp, (vuint8m2_t)mask, 32); \ + vuint16m2_t res_ = vwaddu_vv_u16m2(vget_u8m2_u8m1(tmp, 0), vget_u8m2_u8m1(tmp, 1), 16); + vuint32m2_t res = vwaddu_vv_u32m2(vget_u16m2_u16m1(res_, 0), vget_u16m2_u16m1(res_, 1), 8); + return v_uint32x4(vget_u32m2_u32m1(res, 0)); +} + +inline v_uint64x2 +v_popcount(const v_uint64x2& a) +{ + vuint8m2_t tmp = vundefined_u8m2(); + tmp = vset_u8m2(tmp, 0, vcnt_u8((vuint8m1_t)a.val)); + vuint64m2_t mask = (vuint64m2_t){0x0706050403020100, 0x0000000000000000, + 0x0F0E0D0C0B0A0908, 0x0000000000000000}; + tmp = vrgather_vv_u8m2(tmp, (vuint8m2_t)mask, 32); \ + vuint8m1_t zero = vmv_v_x_u8m1(0, 16); + vuint8m1_t res1 = zero; + vuint8m1_t res2 = zero; + res1 = vredsum_vs_u8m1_u8m1(res1, vget_u8m2_u8m1(tmp, 0), zero, 8); + res2 = vredsum_vs_u8m1_u8m1(res2, vget_u8m2_u8m1(tmp, 1), zero, 8); + + return v_uint64x2((unsigned long)vmv_x_s_u8m1_u8(res1, 8), (unsigned long)vmv_x_s_u8m1_u8(res2, 8)); +} + +inline v_uint64x2 +v_popcount(const v_int64x2& a) +{ + vuint8m2_t tmp = vundefined_u8m2(); + tmp = vset_u8m2(tmp, 0, vcnt_u8((vuint8m1_t)a.val)); + vuint64m2_t mask = (vuint64m2_t){0x0706050403020100, 0x0000000000000000, + 0x0F0E0D0C0B0A0908, 0x0000000000000000}; + tmp = vrgather_vv_u8m2(tmp, (vuint8m2_t)mask, 32); \ + vuint8m1_t zero = vmv_v_x_u8m1(0, 16); + vuint8m1_t res1 = zero; + vuint8m1_t res2 = zero; + res1 = vredsum_vs_u8m1_u8m1(res1, vget_u8m2_u8m1(tmp, 0), zero, 8); + res2 = vredsum_vs_u8m1_u8m1(res2, vget_u8m2_u8m1(tmp, 1), zero, 8); + + return v_uint64x2((unsigned long)vmv_x_s_u8m1_u8(res1, 8), (unsigned long)vmv_x_s_u8m1_u8(res2, 8)); +} + +#define SMASK 1, 2, 4, 8, 16, 32, 64, 128 +inline int v_signmask(const v_uint8x16& a) +{ + vuint8m1_t t0 = vsrl_vx_u8m1(a.val, 7, 16); + vuint8m1_t m1 = (vuint8m1_t){SMASK, SMASK}; + vuint16m2_t t1 = vwmulu_vv_u16m2(t0, m1, 16); + vuint32m1_t res = vmv_v_x_u32m1(0, 4); + vuint32m2_t t2 = vwmulu_vx_u32m2(vget_u16m2_u16m1(t1, 1), 256, 8); + res = vredsum_vs_u32m2_u32m1(res, t2, res, 8); + res = vwredsumu_vs_u16m1_u32m1(res, vget_u16m2_u16m1(t1, 0), res, 8); + return vmv_x_s_u32m1_u32(res, 8); +} +inline int v_signmask(const v_int8x16& a) +{ + vuint8m1_t t0 = vsrl_vx_u8m1((vuint8m1_t)a.val, 7, 16); + vuint8m1_t m1 = (vuint8m1_t){SMASK, SMASK}; + vint16m2_t t1 = (vint16m2_t)vwmulu_vv_u16m2(t0, m1, 16); + vint32m1_t res = vmv_v_x_i32m1(0, 4); + vint32m2_t t2 = vwmul_vx_i32m2(vget_i16m2_i16m1(t1, 1), 256, 8); + res = vredsum_vs_i32m2_i32m1(res, t2, res, 8); + res = vwredsum_vs_i16m1_i32m1(res, vget_i16m2_i16m1(t1, 0), res, 8); + return vmv_x_s_i32m1_i32(res, 8); +} + +inline int v_signmask(const v_int16x8& a) +{ + vint16m1_t t0 = (vint16m1_t)vsrl_vx_u16m1((vuint16m1_t)a.val, 15, 8); + vint16m1_t m1 = (vint16m1_t){SMASK}; + vint16m1_t t1 = vmul_vv_i16m1(t0, m1, 8); + vint16m1_t res = vmv_v_x_i16m1(0, 8); + res = vredsum_vs_i16m1_i16m1(res, t1, res, 8); + return vmv_x_s_i16m1_i16(res, 8); +} +inline int v_signmask(const v_uint16x8& a) +{ + vint16m1_t t0 = (vint16m1_t)vsrl_vx_u16m1((vuint16m1_t)a.val, 15, 8); + vint16m1_t m1 = (vint16m1_t){SMASK}; + vint16m1_t t1 = vmul_vv_i16m1(t0, m1, 8); + vint16m1_t res = vmv_v_x_i16m1(0, 8); + res = vredsum_vs_i16m1_i16m1(res, t1, res, 8); + return vmv_x_s_i16m1_i16(res, 8); +} +inline int v_signmask(const v_int32x4& a) +{ + vint32m1_t t0 = (vint32m1_t)vsrl_vx_u32m1((vuint32m1_t)a.val, 31, 4); + vint32m1_t m1 = (vint32m1_t){1, 2, 4, 8}; + vint32m1_t res = vmv_v_x_i32m1(0, 4); + vint32m1_t t1 = vmul_vv_i32m1(t0, m1, 4); + res = vredsum_vs_i32m1_i32m1(res, t1, res, 4); + return vmv_x_s_i32m1_i32(res, 4); +} +inline int v_signmask(const v_uint32x4& a) +{ + vint32m1_t t0 = (vint32m1_t)vsrl_vx_u32m1(a.val, 31, 4); + vint32m1_t m1 = (vint32m1_t){1, 2, 4, 8}; + vint32m1_t res = vmv_v_x_i32m1(0, 4); + vint32m1_t t1 = vmul_vv_i32m1(t0, m1, 4); + res = vredsum_vs_i32m1_i32m1(res, t1, res, 4); + return vmv_x_s_i32m1_i32(res, 4); +} +inline int v_signmask(const v_uint64x2& a) +{ + vuint64m1_t v0 = vsrl_vx_u64m1(a.val, 63, 2); + int res = (int)vext_x_v_u64m1_u64(v0, 0, 2) + ((int)vext_x_v_u64m1_u64(v0, 1, 2) << 1); + return res; +} +inline int v_signmask(const v_int64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } +inline int v_signmask(const v_float64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } +inline int v_signmask(const v_float32x4& a) +{ + vint32m1_t t0 = (vint32m1_t)vsrl_vx_u32m1((vuint32m1_t)a.val, 31, 4); + vint32m1_t m1 = (vint32m1_t){1, 2, 4, 8}; + vint32m1_t res = vmv_v_x_i32m1(0, 4); + vint32m1_t t1 = vmul_vv_i32m1(t0, m1, 4); + res = vredsum_vs_i32m1_i32m1(res, t1, res, 4); + return vmv_x_s_i32m1_i32(res, 4); +} + +inline int v_scan_forward(const v_int8x16& a) { +int val = v_signmask(a); +if(val==0) return 0; +else return trailingZeros32(val); } +inline int v_scan_forward(const v_uint8x16& a) { +int val = v_signmask(a); +if(val==0) return 0; +else return trailingZeros32(val); } +inline int v_scan_forward(const v_int16x8& a) { +int val = v_signmask(a); +if(val==0) return 0; +else return trailingZeros32(val); } +inline int v_scan_forward(const v_uint16x8& a) { +int val = v_signmask(a); +if(val==0) return 0; +else return trailingZeros32(val); } +inline int v_scan_forward(const v_int32x4& a) { +int val = v_signmask(a); +if(val==0) return 0; +else return trailingZeros32(val); } +inline int v_scan_forward(const v_uint32x4& a) { +int val = v_signmask(a); +if(val==0) return 0; +else return trailingZeros32(val); } +inline int v_scan_forward(const v_float32x4& a) { +int val = v_signmask(a); +if(val==0) return 0; +else return trailingZeros32(val); } +inline int v_scan_forward(const v_int64x2& a) { +int val = v_signmask(a); +if(val==0) return 0; +else return trailingZeros32(val); } +inline int v_scan_forward(const v_uint64x2& a) { +int val = v_signmask(a); +if(val==0) return 0; +else return trailingZeros32(val); } + +#define OPENCV_HAL_IMPL_RISCVV_CHECK_ALLANY(_Tpvec, suffix, _T, shift, num) \ +inline bool v_check_all(const v_##_Tpvec& a) \ +{ \ + suffix##m1_t v0 = vsrl_vx_##_T(vnot_v_##_T(a.val, num), shift, num); \ + vuint64m1_t v1 = vuint64m1_t(v0); \ + return (v1[0] | v1[1]) == 0; \ +} \ +inline bool v_check_any(const v_##_Tpvec& a) \ +{ \ + suffix##m1_t v0 = vsrl_vx_##_T(a.val, shift, num); \ + vuint64m1_t v1 = vuint64m1_t(v0); \ + return (v1[0] | v1[1]) != 0; \ +} + +OPENCV_HAL_IMPL_RISCVV_CHECK_ALLANY(uint8x16, vuint8, u8m1, 7, 16) +OPENCV_HAL_IMPL_RISCVV_CHECK_ALLANY(uint16x8, vuint16, u16m1, 15, 8) +OPENCV_HAL_IMPL_RISCVV_CHECK_ALLANY(uint32x4, vuint32, u32m1, 31, 4) +OPENCV_HAL_IMPL_RISCVV_CHECK_ALLANY(uint64x2, vuint64, u64m1, 63, 2) + +inline bool v_check_all(const v_int8x16& a) +{ return v_check_all(v_reinterpret_as_u8(a)); } +inline bool v_check_all(const v_int16x8& a) +{ return v_check_all(v_reinterpret_as_u16(a)); } +inline bool v_check_all(const v_int32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } +inline bool v_check_all(const v_float32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } +inline bool v_check_all(const v_int64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_all(const v_float64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } + +inline bool v_check_any(const v_int8x16& a) +{ return v_check_any(v_reinterpret_as_u8(a)); } +inline bool v_check_any(const v_int16x8& a) +{ return v_check_any(v_reinterpret_as_u16(a)); } +inline bool v_check_any(const v_int32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } +inline bool v_check_any(const v_float32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } +inline bool v_check_any(const v_int64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_float64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } + +#define OPENCV_HAL_IMPL_RISCVV_SELECT(_Tpvec, suffix, _Tpvec2, num) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(vmerge_vvm_##suffix(_Tpvec2(mask.val), b.val, a.val, num)); \ +} + +OPENCV_HAL_IMPL_RISCVV_SELECT(v_int8x16, i8m1, vbool8_t, 16) +OPENCV_HAL_IMPL_RISCVV_SELECT(v_int16x8, i16m1, vbool16_t, 8) +OPENCV_HAL_IMPL_RISCVV_SELECT(v_int32x4, i32m1, vbool32_t, 4) +OPENCV_HAL_IMPL_RISCVV_SELECT(v_uint8x16, u8m1, vbool8_t, 16) +OPENCV_HAL_IMPL_RISCVV_SELECT(v_uint16x8, u16m1, vbool16_t, 8) +OPENCV_HAL_IMPL_RISCVV_SELECT(v_uint32x4, u32m1, vbool32_t, 4) +inline v_float32x4 v_select(const v_float32x4& mask, const v_float32x4& a, const v_float32x4& b) +{ + return v_float32x4((vfloat32m1_t)vmerge_vvm_u32m1((vbool32_t)mask.val, (vuint32m1_t)b.val, (vuint32m1_t)a.val, 4)); +} +inline v_float64x2 v_select(const v_float64x2& mask, const v_float64x2& a, const v_float64x2& b) +{ + return v_float64x2((vfloat64m1_t)vmerge_vvm_u64m1((vbool64_t)mask.val, (vuint64m1_t)b.val, (vuint64m1_t)a.val, 2)); +} + +#define OPENCV_HAL_IMPL_RISCVV_EXPAND(add, _Tpvec, _Tpwvec, _Tp, _Tp1, num1, _Tp2, num2, _T1, _T2) \ +inline void v_expand(const _Tpvec& a, v_##_Tpwvec& b0, v_##_Tpwvec& b1) \ +{ \ + _T1##_t b = vw##add##_vv_##_Tp2##m2(a.val, vmv_v_x_##_Tp1(0, num1), num1); \ + b0.val = vget_##_Tp2##m2_##_Tp2##m1(b, 0); \ + b1.val = vget_##_Tp2##m2_##_Tp2##m1(b, 1); \ +} \ +inline v_##_Tpwvec v_expand_low(const _Tpvec& a) \ +{ \ + _T1##_t b = vw##add##_vv_##_Tp2##m2(a.val, vmv_v_x_##_Tp1(0, num2), num2); \ + return v_##_Tpwvec(vget_##_Tp2##m2_##_Tp2##m1(b, 0)); \ +} \ +inline v_##_Tpwvec v_expand_high(const _Tpvec& a) \ +{ \ + _T1##_t b = vw##add##_vv_##_Tp2##m2(a.val, vmv_v_x_##_Tp1(0, num1), num1); \ + return v_##_Tpwvec(vget_##_Tp2##m2_##_Tp2##m1(b, 1)); \ +} \ +inline v_##_Tpwvec v_load_expand(const _Tp* ptr) \ +{ \ + _T2##_t val = vle##_v_##_Tp1(ptr, num2); \ + _T1##_t b = vw##add##_vv_##_Tp2##m2(val, vmv_v_x_##_Tp1(0, num2), num2); \ + return v_##_Tpwvec(vget_##_Tp2##m2_##_Tp2##m1(b, 0)); \ +} + +OPENCV_HAL_IMPL_RISCVV_EXPAND(addu, v_uint8x16, uint16x8, uchar, u8m1, 16, u16, 8, vuint16m2, vuint8m1) +OPENCV_HAL_IMPL_RISCVV_EXPAND(addu, v_uint16x8, uint32x4, ushort, u16m1, 8, u32, 4, vuint32m2, vuint16m1) +OPENCV_HAL_IMPL_RISCVV_EXPAND(addu, v_uint32x4, uint64x2, uint, u32m1, 4, u64, 2, vuint64m2, vuint32m1) +OPENCV_HAL_IMPL_RISCVV_EXPAND(add, v_int8x16, int16x8, schar, i8m1, 16, i16, 8, vint16m2, vint8m1) +OPENCV_HAL_IMPL_RISCVV_EXPAND(add, v_int16x8, int32x4, short, i16m1, 8, i32, 4, vint32m2, vint16m1) +OPENCV_HAL_IMPL_RISCVV_EXPAND(add, v_int32x4, int64x2, int, i32m1, 4, i64, 2, vint64m2, vint32m1) + +inline v_uint32x4 v_load_expand_q(const uchar* ptr) +{ + vuint16m2_t b = vundefined_u16m2(); + vuint32m2_t c = vundefined_u32m2(); + vuint8m1_t val = vle_v_u8m1(ptr, 4); \ + b = vwaddu_vv_u16m2(val, vmv_v_x_u8m1(0, 4), 4); \ + c = vwaddu_vv_u32m2(vget_u16m2_u16m1(b, 0), vmv_v_x_u16m1(0, 4), 4); \ + return v_uint32x4(vget_u32m2_u32m1(c, 0)); +} + +inline v_int32x4 v_load_expand_q(const schar* ptr) +{ + vint16m2_t b = vundefined_i16m2(); + vint32m2_t c = vundefined_i32m2(); + vint8m1_t val = vle_v_i8m1(ptr, 4); \ + b = vwadd_vv_i16m2(val, vmv_v_x_i8m1(0, 4), 4); \ + c = vwadd_vv_i32m2(vget_i16m2_i16m1(b, 0), vmv_v_x_i16m1(0, 4), 4); \ + return v_int32x4(vget_i32m2_i32m1(c, 0)); +} +#define VITL_16 (vuint64m2_t){0x1303120211011000, 0x1707160615051404, 0x1B0B1A0A19091808, 0x1F0F1E0E1D0D1C0C} +#define VITL_8 (vuint64m2_t){0x0009000100080000, 0x000B0003000A0002, 0x000D0005000C0004, 0x000F0007000E0006} +#define VITL_4 (vuint64m2_t){0x0000000400000000, 0x0000000500000001, 0x0000000600000002, 0x0000000700000003} +#define VITL_2 (vuint64m2_t){0, 2, 1, 3} +#define LOW_4 0x0000000100000000, 0x0000000500000004 +#define LOW_8 0x0003000200010000, 0x000B000A00090008 +#define LOW_16 0x0706050403020100, 0x1716151413121110 +#define HIGH_4 0x0000000300000002, 0x0000000700000006 +#define HIGH_8 0x0007000600050004, 0x000F000E000D000C +#define HIGH_16 0x0F0E0D0C0B0A0908, 0x1F1E1D1C1B1A1918 +#define OPENCV_HAL_IMPL_RISCVV_UNPACKS(_Tpvec, _Tp, _T, _UTp, _UT, num, num2, len, numh) \ +inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \ +{ \ + v##_Tp##m2_t tmp = vundefined_##_T##m2();\ + tmp = vset_##_T##m2(tmp, 0, a0.val); \ + tmp = vset_##_T##m2(tmp, 1, a1.val); \ + vuint64m2_t mask = VITL_##num; \ + tmp = (v##_Tp##m2_t)vrgather_vv_##_T##m2((v##_Tp##m2_t)tmp, (v##_UTp##m2_t)mask, num2); \ + b0.val = vget_##_T##m2_##_T##m1(tmp, 0); \ + b1.val = vget_##_T##m2_##_T##m1(tmp, 1); \ +} \ +inline v_##_Tpvec v_combine_low(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + v##_Tp##m1_t b0 = vslideup_vx_##_T##m1_m(vmset_m_##len(num), a.val, b.val, numh, num); \ + return v_##_Tpvec(b0);\ +} \ +inline v_##_Tpvec v_combine_high(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + v##_Tp##m1_t b0 = vslidedown_vx_##_T##m1(b.val, numh, num); \ + v##_Tp##m1_t a0 = vslidedown_vx_##_T##m1(a.val, numh, num); \ + v##_Tp##m1_t b1 = vslideup_vx_##_T##m1_m(vmset_m_##len(num), a0, b0, numh, num); \ + return v_##_Tpvec(b1);\ +} \ +inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + c.val = vslideup_vx_##_T##m1_m(vmset_m_##len(num), a.val, b.val, numh, num); \ + v##_Tp##m1_t b0 = vslidedown_vx_##_T##m1(b.val, numh, num); \ + v##_Tp##m1_t a0 = vslidedown_vx_##_T##m1(a.val, numh, num); \ + d.val = vslideup_vx_##_T##m1_m(vmset_m_##len(num), a0, b0, numh, num); \ +} + +OPENCV_HAL_IMPL_RISCVV_UNPACKS(uint8x16, uint8, u8, uint8, u8, 16, 32, b8, 8) +OPENCV_HAL_IMPL_RISCVV_UNPACKS(int8x16, int8, i8, uint8, u8, 16, 32, b8, 8) +OPENCV_HAL_IMPL_RISCVV_UNPACKS(uint16x8, uint16, u16, uint16, u16, 8, 16, b16, 4) +OPENCV_HAL_IMPL_RISCVV_UNPACKS(int16x8, int16, i16, uint16, u16, 8, 16, b16, 4) +OPENCV_HAL_IMPL_RISCVV_UNPACKS(uint32x4, uint32, u32, uint32, u32, 4, 8, b32, 2) +OPENCV_HAL_IMPL_RISCVV_UNPACKS(int32x4, int32, i32, uint32, u32, 4, 8, b32, 2) +OPENCV_HAL_IMPL_RISCVV_UNPACKS(float32x4, float32, f32, uint32, u32, 4, 8, b32, 2) +OPENCV_HAL_IMPL_RISCVV_UNPACKS(float64x2, float64, f64, uint64, u64, 2, 4, b64, 1) + +inline v_uint8x16 v_reverse(const v_uint8x16 &a) +{ + vuint64m1_t mask = (vuint64m1_t){0x08090A0B0C0D0E0F, 0x0001020304050607}; + return v_uint8x16(vrgather_vv_u8m1(a.val, (vuint8m1_t)mask, 16)); +} +inline v_int8x16 v_reverse(const v_int8x16 &a) +{ + vint64m1_t mask = (vint64m1_t){0x08090A0B0C0D0E0F, 0x0001020304050607}; + return v_int8x16(vrgather_vv_i8m1(a.val, (vuint8m1_t)mask, 16)); +} + +inline v_uint16x8 v_reverse(const v_uint16x8 &a) +{ + vuint64m1_t mask = (vuint64m1_t){0x0004000500060007, 0x000000100020003}; + return v_uint16x8(vrgather_vv_u16m1(a.val, (vuint16m1_t)mask, 8)); +} + +inline v_int16x8 v_reverse(const v_int16x8 &a) +{ + vint64m1_t mask = (vint64m1_t){0x0004000500060007, 0x000000100020003}; + return v_int16x8(vrgather_vv_i16m1(a.val, (vuint16m1_t)mask, 8)); +} +inline v_uint32x4 v_reverse(const v_uint32x4 &a) +{ + return v_uint32x4(vrgather_vv_u32m1(a.val, (vuint32m1_t){3, 2, 1, 0}, 4)); +} + +inline v_int32x4 v_reverse(const v_int32x4 &a) +{ + return v_int32x4(vrgather_vv_i32m1(a.val, (vuint32m1_t){3, 2, 1, 0}, 4)); +} + +inline v_float32x4 v_reverse(const v_float32x4 &a) +{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_uint64x2 v_reverse(const v_uint64x2 &a) +{ + return v_uint64x2(a.val[1], a.val[0]); +} + +inline v_int64x2 v_reverse(const v_int64x2 &a) +{ + return v_int64x2(a.val[1], a.val[0]); +} + +inline v_float64x2 v_reverse(const v_float64x2 &a) +{ + return v_float64x2(a.val[1], a.val[0]); +} + +#define OPENCV_HAL_IMPL_RISCVV_EXTRACT(_Tpvec, suffix, size) \ +template \ +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \ +{ return v_rotate_right(a, b);} +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_uint8x16, u8, 0) +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_int8x16, s8, 0) +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_uint16x8, u16, 1) +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_int16x8, s16, 1) +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_uint32x4, u32, 2) +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_int32x4, s32, 2) +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_uint64x2, u64, 3) +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_int64x2, s64, 3) +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_float32x4, f32, 2) +OPENCV_HAL_IMPL_RISCVV_EXTRACT(v_float64x2, f64, 3) + + +#define OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(_Tpvec, _Tp, suffix) \ +template inline _Tp v_extract_n(_Tpvec v) { return v.val[i]; } + +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_int16x8, short, s16) +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_uint32x4, uint, u32) +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_int32x4, int, s32) +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_int64x2, int64, s64) +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_float32x4, float, f32) +OPENCV_HAL_IMPL_RISCVV_EXTRACT_N(v_float64x2, double, f64) + +#define OPENCV_HAL_IMPL_RISCVV_BROADCAST(_Tpvec, _Tp, num) \ +template inline _Tpvec v_broadcast_element(_Tpvec v) { return _Tpvec(vrgather_vx_##_Tp##m1(v.val, i, num)); } + +OPENCV_HAL_IMPL_RISCVV_BROADCAST(v_uint8x16, u8, 16) +OPENCV_HAL_IMPL_RISCVV_BROADCAST(v_int8x16, i8, 16) +OPENCV_HAL_IMPL_RISCVV_BROADCAST(v_uint16x8, u16, 8) +OPENCV_HAL_IMPL_RISCVV_BROADCAST(v_int16x8, i16, 8) +OPENCV_HAL_IMPL_RISCVV_BROADCAST(v_uint32x4, u32, 4) +OPENCV_HAL_IMPL_RISCVV_BROADCAST(v_int32x4, i32, 4) +OPENCV_HAL_IMPL_RISCVV_BROADCAST(v_uint64x2, u64, 2) +OPENCV_HAL_IMPL_RISCVV_BROADCAST(v_int64x2, i64, 2) +OPENCV_HAL_IMPL_RISCVV_BROADCAST(v_float32x4, f32, 4) +inline v_int32x4 v_round(const v_float32x4& a) +{ + __builtin_riscv_fsrm(0); + vint32m1_t nan = vand_vx_i32m1((vint32m1_t)a.val, 0x7f800000, 4); + vbool32_t mask = vmsne_vx_i32m1_b32(nan, 0x7f800000, 4); + vint32m1_t val = vfcvt_x_f_v_i32m1_m(mask, vmv_v_x_i32m1(0, 4), a.val, 4); + __builtin_riscv_fsrm(0); + return v_int32x4(val); +} +inline v_int32x4 v_floor(const v_float32x4& a) +{ + __builtin_riscv_fsrm(2); + vint32m1_t nan = vand_vx_i32m1((vint32m1_t)a.val, 0x7f800000, 4); + vbool32_t mask = vmsne_vx_i32m1_b32(nan, 0x7f800000, 4); + vint32m1_t val = vfcvt_x_f_v_i32m1_m(mask, vmv_v_x_i32m1(0, 4), a.val, 4); + __builtin_riscv_fsrm(0); + return v_int32x4(val); +} + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ + __builtin_riscv_fsrm(3); + vint32m1_t nan = vand_vx_i32m1((vint32m1_t)a.val, 0x7f800000, 4); + vbool32_t mask = vmsne_vx_i32m1_b32(nan, 0x7f800000, 4); + vint32m1_t val = vfcvt_x_f_v_i32m1_m(mask, vmv_v_x_i32m1(0, 4), a.val, 4); + __builtin_riscv_fsrm(0); + return v_int32x4(val); +} + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ + __builtin_riscv_fsrm(1); + vint32m1_t nan = vand_vx_i32m1((vint32m1_t)a.val, 0x7f800000, 4); + vbool32_t mask = vmsne_vx_i32m1_b32(nan, 0x7f800000, 4); + vint32m1_t val = vfcvt_x_f_v_i32m1_m(mask, vmv_v_x_i32m1(0, 4), a.val, 4); + __builtin_riscv_fsrm(0); + return v_int32x4(val); +} + +inline v_int32x4 v_round(const v_float64x2& a) +{ + __builtin_riscv_fsrm(0); + vfloat64m2_t _val = vundefined_f64m2(); + _val = vset_f64m2(_val, 0, a.val); + //_val = vset_f64m2(_val, 1, a.val); + _val = vset_f64m2(_val, 1, vfmv_v_f_f64m1(0, 2)); + vint32m1_t val = vfncvt_x_f_v_i32m1(_val, 4); + __builtin_riscv_fsrm(0); + return v_int32x4(val); +} +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ + __builtin_riscv_fsrm(0); + vfloat64m2_t _val = vundefined_f64m2(); + _val = vset_f64m2(_val, 0, a.val); + _val = vset_f64m2(_val, 1, b.val); + vint32m1_t val = vfncvt_x_f_v_i32m1(_val, 4); + __builtin_riscv_fsrm(0); + return v_int32x4(val); +} +inline v_int32x4 v_floor(const v_float64x2& a) +{ + __builtin_riscv_fsrm(2); + vfloat64m2_t _val = vundefined_f64m2(); + _val = vset_f64m2(_val, 0, a.val); + vfloat32m1_t aval = vfncvt_f_f_v_f32m1(_val, 2); + + vint32m1_t nan = vand_vx_i32m1((vint32m1_t)aval, 0x7f800000, 4); + vbool32_t mask = vmsne_vx_i32m1_b32(nan, 0x7f800000, 4); + vint32m1_t val = vfcvt_x_f_v_i32m1_m(mask, vmv_v_x_i32m1(0, 4), aval, 4); + __builtin_riscv_fsrm(0); + return v_int32x4(val); +} + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ + __builtin_riscv_fsrm(3); + vfloat64m2_t _val = vundefined_f64m2(); + _val = vset_f64m2(_val, 0, a.val); + vfloat32m1_t aval = vfncvt_f_f_v_f32m1(_val, 2); + + vint32m1_t nan = vand_vx_i32m1((vint32m1_t)aval, 0x7f800000, 4); + vbool32_t mask = vmsne_vx_i32m1_b32(nan, 0x7f800000, 4); + vint32m1_t val = vfcvt_x_f_v_i32m1_m(mask, vmv_v_x_i32m1(0, 4), aval, 4); + __builtin_riscv_fsrm(0); + return v_int32x4(val); +} + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ + __builtin_riscv_fsrm(1); + vfloat64m2_t _val = vundefined_f64m2(); + _val = vset_f64m2(_val, 0, a.val); + vfloat32m1_t aval = vfncvt_f_f_v_f32m1(_val, 2); + + vint32m1_t nan = vand_vx_i32m1((vint32m1_t)aval, 0x7f800000, 4); + vbool32_t mask = vmsne_vx_i32m1_b32(nan, 0x7f800000, 4); + vint32m1_t val = vfcvt_x_f_v_i32m1_m(mask, vmv_v_x_i32m1(0, 4), aval, 4); + __builtin_riscv_fsrm(0); + return v_int32x4(val); +} + +#define OPENCV_HAL_IMPL_RISCVV_LOAD_DEINTERLEAVED(intrin, _Tpvec, num, _Tp, _T) \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec##x##num& a, v_##_Tpvec##x##num& b) \ +{ \ + v##_Tpvec##m1x2_t ret = intrin##2e_v_##_T##m1x2(ptr, num);\ + a.val = vget_##_T##m1x2_##_T##m1(ret, 0); \ + b.val = vget_##_T##m1x2_##_T##m1(ret, 1); \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec##x##num& a, v_##_Tpvec##x##num& b, v_##_Tpvec##x##num& c) \ +{ \ + v##_Tpvec##m1x3_t ret = intrin##3e_v_##_T##m1x3(ptr, num);\ + a.val = vget_##_T##m1x3_##_T##m1(ret, 0); \ + b.val = vget_##_T##m1x3_##_T##m1(ret, 1); \ + c.val = vget_##_T##m1x3_##_T##m1(ret, 2); \ +}\ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec##x##num& a, v_##_Tpvec##x##num& b, \ + v_##_Tpvec##x##num& c, v_##_Tpvec##x##num& d) \ +{ \ + v##_Tpvec##m1x4_t ret = intrin##4e_v_##_T##m1x4(ptr, num);\ + a.val = vget_##_T##m1x4_##_T##m1(ret, 0); \ + b.val = vget_##_T##m1x4_##_T##m1(ret, 1); \ + c.val = vget_##_T##m1x4_##_T##m1(ret, 2); \ + d.val = vget_##_T##m1x4_##_T##m1(ret, 3); \ +} \ + +#define OPENCV_HAL_IMPL_RISCVV_STORE_INTERLEAVED(intrin, _Tpvec, num, _Tp, _T) \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec##x##num& a, const v_##_Tpvec##x##num& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + v##_Tpvec##m1x2_t ret = vundefined_##_T##m1x2(); \ + ret = vset_##_T##m1x2(ret, 0, a.val); \ + ret = vset_##_T##m1x2(ret, 1, b.val); \ + intrin##2e_v_##_T##m1x2(ptr, ret, num); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec##x##num& a, const v_##_Tpvec##x##num& b, \ + const v_##_Tpvec##x##num& c, hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + v##_Tpvec##m1x3_t ret = vundefined_##_T##m1x3(); \ + ret = vset_##_T##m1x3(ret, 0, a.val); \ + ret = vset_##_T##m1x3(ret, 1, b.val); \ + ret = vset_##_T##m1x3(ret, 2, c.val); \ + intrin##3e_v_##_T##m1x3(ptr, ret, num); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec##x##num& a, const v_##_Tpvec##x##num& b, \ + const v_##_Tpvec##x##num& c, const v_##_Tpvec##x##num& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED ) \ +{ \ + v##_Tpvec##m1x4_t ret = vundefined_##_T##m1x4(); \ + ret = vset_##_T##m1x4(ret, 0, a.val); \ + ret = vset_##_T##m1x4(ret, 1, b.val); \ + ret = vset_##_T##m1x4(ret, 2, c.val); \ + ret = vset_##_T##m1x4(ret, 3, d.val); \ + intrin##4e_v_##_T##m1x4(ptr, ret, num); \ +} + +#define OPENCV_HAL_IMPL_RISCVV_INTERLEAVED(_Tpvec, _Tp, num, ld, st, _T) \ +OPENCV_HAL_IMPL_RISCVV_LOAD_DEINTERLEAVED(ld, _Tpvec, num, _Tp, _T) \ +OPENCV_HAL_IMPL_RISCVV_STORE_INTERLEAVED(st, _Tpvec, num, _Tp, _T) + +//OPENCV_HAL_IMPL_RISCVV_INTERLEAVED(uint8, uchar, ) +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED(int8, schar, 16, vlseg, vsseg, i8) +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED(int16, short, 8, vlseg, vsseg, i16) +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED(int32, int, 4, vlseg, vsseg, i32) + +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED(uint8, unsigned char, 16, vlseg, vsseg, u8) +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED(uint16, unsigned short, 8, vlseg, vsseg, u16) +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED(uint32, unsigned int, 4, vlseg, vsseg, u32) + +#define OPENCV_HAL_IMPL_RISCVV_INTERLEAVED_(_Tpvec, _Tp, num, _T) \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec##x##num& a, v_##_Tpvec##x##num& b) \ +{ \ + v##_Tpvec##m1x2_t ret = vlseg2e_v_##_T##m1x2(ptr, num); \ + a.val = vget_##_T##m1x2_##_T##m1(ret, 0); \ + b.val = vget_##_T##m1x2_##_T##m1(ret, 1); \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec##x##num& a, v_##_Tpvec##x##num& b, v_##_Tpvec##x##num& c) \ +{ \ + v##_Tpvec##m1x3_t ret = vlseg3e_v_##_T##m1x3(ptr, num); \ + a.val = vget_##_T##m1x3_##_T##m1(ret, 0); \ + b.val = vget_##_T##m1x3_##_T##m1(ret, 1); \ + c.val = vget_##_T##m1x3_##_T##m1(ret, 2); \ +}\ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec##x##num& a, v_##_Tpvec##x##num& b, \ + v_##_Tpvec##x##num& c, v_##_Tpvec##x##num& d) \ +{ \ + v##_Tpvec##m1x4_t ret = vlseg4e_v_##_T##m1x4(ptr, num); \ + a.val = vget_##_T##m1x4_##_T##m1(ret, 0); \ + b.val = vget_##_T##m1x4_##_T##m1(ret, 1); \ + c.val = vget_##_T##m1x4_##_T##m1(ret, 2); \ + d.val = vget_##_T##m1x4_##_T##m1(ret, 3); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec##x##num& a, const v_##_Tpvec##x##num& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + v##_Tpvec##m1x2_t ret = vundefined_##_T##m1x2(); \ + ret = vset_##_T##m1x2(ret, 0, a.val); \ + ret = vset_##_T##m1x2(ret, 1, b.val); \ + vsseg2e_v_##_T##m1x2(ptr, ret, num); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec##x##num& a, const v_##_Tpvec##x##num& b, \ + const v_##_Tpvec##x##num& c, hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + v##_Tpvec##m1x3_t ret = vundefined_##_T##m1x3(); \ + ret = vset_##_T##m1x3(ret, 0, a.val); \ + ret = vset_##_T##m1x3(ret, 1, b.val); \ + ret = vset_##_T##m1x3(ret, 2, c.val); \ + vsseg3e_v_##_T##m1x3(ptr, ret, num); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec##x##num& a, const v_##_Tpvec##x##num& b, \ + const v_##_Tpvec##x##num& c, const v_##_Tpvec##x##num& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED ) \ +{ \ + v##_Tpvec##m1x4_t ret = vundefined_##_T##m1x4(); \ + ret = vset_##_T##m1x4(ret, 0, a.val); \ + ret = vset_##_T##m1x4(ret, 1, b.val); \ + ret = vset_##_T##m1x4(ret, 2, c.val); \ + ret = vset_##_T##m1x4(ret, 3, d.val); \ + vsseg4e_v_##_T##m1x4(ptr, ret, num); \ +} +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED_(float32, float, 4, f32) +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED_(float64, double, 2, f64) + +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED_(uint64, unsigned long, 2, u64) +OPENCV_HAL_IMPL_RISCVV_INTERLEAVED_(int64, long, 2, i64) + +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ + return v_float32x4(vfcvt_f_x_v_f32m1(a.val, 4)); +} + +#if CV_SIMD128_64F +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ + vfloat64m2_t _val = vundefined_f64m2(); + _val = vset_f64m2(_val, 0, a.val); + vfloat32m1_t aval = vfncvt_f_f_v_f32m1(_val, 2); + return v_float32x4(aval); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ + vfloat64m2_t _val = vundefined_f64m2(); + _val = vset_f64m2(_val, 0, a.val); + _val = vset_f64m2(_val, 1, b.val); + vfloat32m1_t aval = vfncvt_f_f_v_f32m1(_val, 4); + return v_float32x4(aval); +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ + vfloat32m1_t val = vfcvt_f_x_v_f32m1(a.val, 4); + vfloat64m2_t _val = vfwcvt_f_f_v_f64m2(val, 4); + return v_float64x2(vget_f64m2_f64m1(_val, 0)); +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + vfloat32m1_t val = vfcvt_f_x_v_f32m1(a.val, 4); + vfloat64m2_t _val = vfwcvt_f_f_v_f64m2(val, 4); + return v_float64x2(vget_f64m2_f64m1(_val, 1)); +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + vfloat64m2_t _val = vfwcvt_f_f_v_f64m2(a.val, 4); + return v_float64x2(vget_f64m2_f64m1(_val, 0)); +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + vfloat64m2_t _val = vfwcvt_f_f_v_f64m2(a.val, 4); + return v_float64x2(vget_f64m2_f64m1(_val, 1)); +} + +inline v_float64x2 v_cvt_f64(const v_int64x2& a) +{ + return v_float64x2(vfcvt_f_x_v_f64m1(a.val, 2)); +} + +#endif +inline v_int8x16 v_interleave_pairs(const v_int8x16& vec) +{ + vuint64m1_t m0 = {0x0705060403010200, 0x0F0D0E0C0B090A08}; + return v_int8x16(vrgather_vv_i8m1(vec.val, (vuint8m1_t)m0, 16)); +} +inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) +{ + return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); +} + +inline v_int8x16 v_interleave_quads(const v_int8x16& vec) +{ + vuint64m1_t m0 = {0x0703060205010400, 0x0F0B0E0A0D090C08}; + return v_int8x16(vrgather_vv_i8m1(vec.val, (vuint8m1_t)m0, 16)); +} +inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) +{ + return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); +} + +inline v_int16x8 v_interleave_pairs(const v_int16x8& vec) +{ + vuint64m1_t m0 = {0x0706030205040100, 0x0F0E0B0A0D0C0908}; + return v_int16x8((vint16m1_t)vrgather_vv_u8m1((vuint8m1_t)vec.val, (vuint8m1_t)m0, 16)); +} +inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } +inline v_int16x8 v_interleave_quads(const v_int16x8& vec) +{ + vuint64m1_t m0 = {0x0B0A030209080100, 0x0F0E07060D0C0504}; + return v_int16x8((vint16m1_t)vrgather_vv_u8m1((vuint8m1_t)(vec.val), (vuint8m1_t)m0, 16)); +} +inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_interleave_pairs(const v_int32x4& vec) +{ + vuint64m1_t m0 = {0x0B0A090803020100, 0x0F0E0D0C07060504}; + return v_int32x4((vint32m1_t)vrgather_vv_u8m1((vuint8m1_t)(vec.val), (vuint8m1_t)m0, 16)); +} +inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_int8x16 v_pack_triplets(const v_int8x16& vec) +{ + vuint64m1_t m0 = {0x0908060504020100, 0xFFFFFFFF0E0D0C0A}; + return v_int8x16((vint8m1_t)vrgather_vv_u8m1((vuint8m1_t)(vec.val), (vuint8m1_t)m0, 16)); +} +inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_pack_triplets(const v_int16x8& vec) +{ + vuint64m1_t m0 = {0x0908050403020100, 0xFFFFFFFF0D0C0B0A}; + return v_int16x8((vint16m1_t)vrgather_vv_u8m1((vuint8m1_t)(vec.val), (vuint8m1_t)m0, 16)); +} +inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_pack_triplets(const v_int32x4& vec) { return vec; } +inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) { return vec; } +inline v_float32x4 v_pack_triplets(const v_float32x4& vec) { return vec; } + +#if CV_SIMD128_64F +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b) +{ return v_cvt_f64(v_dotprod(a, b)); } +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, + const v_float64x2& c) +{ return v_dotprod_expand(a, b) + c; } +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b) +{ + vint64m2_t v1 = vwmul_vv_i64m2(a.val, b.val, 4); + vfloat64m1_t res = vfcvt_f_x_v_f64m1(vadd_vv_i64m1(vget_i64m2_i64m1(v1, 0), vget_i64m2_i64m1(v1, 1), 2), 2); + return v_float64x2(res); +} +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ v_float64x2 res = v_dotprod_expand_fast(a, b); + return res + c; } +#endif +////// FP16 support /////// +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + vfloat16m1_t v = vle_v_f16m1((__fp16*)ptr, 4); + vfloat32m2_t v32 = vfwcvt_f_f_v_f32m2(v, 4); + return v_float32x4(vget_f32m2_f32m1(v32, 0)); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + vfloat32m2_t v32 = vundefined_f32m2(); + v32 = vset_f32m2(v32, 0, v.val); + vfloat16m1_t hv = vfncvt_f_f_v_f16m1(v32, 4); + vse_v_f16m1((__fp16*)ptr, hv, 4); +} + + +inline void v_cleanup() {} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} +#endif diff --git a/3rdparty/include/opencv2/core/hal/intrin_wasm.hpp b/3rdparty/include/opencv2/core/hal/intrin_wasm.hpp index 22c4a34e52..b4178af8b7 100644 --- a/3rdparty/include/opencv2/core/hal/intrin_wasm.hpp +++ b/3rdparty/include/opencv2/core/hal/intrin_wasm.hpp @@ -257,221 +257,20 @@ struct v_float64x2 v128_t val; }; -namespace fallback +namespace { - -template struct v_reg -{ - typedef _Tp lane_type; - enum { nlanes = n }; - - explicit v_reg(const _Tp* ptr) { for( int i = 0; i < n; i++ ) s[i] = ptr[i]; } - - v_reg(_Tp s0, _Tp s1) { s[0] = s0; s[1] = s1; } - - v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3) { s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; } - - v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3, - _Tp s4, _Tp s5, _Tp s6, _Tp s7) - { - s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; - s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7; - } - - v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3, - _Tp s4, _Tp s5, _Tp s6, _Tp s7, - _Tp s8, _Tp s9, _Tp s10, _Tp s11, - _Tp s12, _Tp s13, _Tp s14, _Tp s15) - { - s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; - s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7; - s[8] = s8; s[9] = s9; s[10] = s10; s[11] = s11; - s[12] = s12; s[13] = s13; s[14] = s14; s[15] = s15; - } - - v_reg() {} - - v_reg(const v_reg<_Tp, n> & r) - { - for( int i = 0; i < n; i++ ) - s[i] = r.s[i]; - } - - _Tp get0() const { return s[0]; } - - _Tp get(const int i) const { return s[i]; } - v_reg<_Tp, n> high() const - { - v_reg<_Tp, n> c; - int i; - for( i = 0; i < n/2; i++ ) - { - c.s[i] = s[i+(n/2)]; - c.s[i+(n/2)] = 0; - } - return c; - } - - static v_reg<_Tp, n> zero() - { - v_reg<_Tp, n> c; - for( int i = 0; i < n; i++ ) - c.s[i] = (_Tp)0; - return c; - } - - static v_reg<_Tp, n> all(_Tp s) - { - v_reg<_Tp, n> c; - for( int i = 0; i < n; i++ ) - c.s[i] = s; - return c; - } - - template v_reg<_Tp2, n2> reinterpret_as() const - { - size_t bytes = std::min(sizeof(_Tp2)*n2, sizeof(_Tp)*n); - v_reg<_Tp2, n2> c; - std::memcpy(&c.s[0], &s[0], bytes); - return c; - } - - v_reg(const cv::v_uint8x16& v) { wasm_v128_store(&s, v.val); } - v_reg(const cv::v_int8x16& v) { wasm_v128_store(&s, v.val); } - v_reg(const cv::v_uint16x8& v) { wasm_v128_store(&s, v.val); } - v_reg(const cv::v_int16x8& v) { wasm_v128_store(&s, v.val); } - v_reg(const cv::v_uint32x4& v) { wasm_v128_store(&s, v.val); } - v_reg(const cv::v_int32x4& v) { wasm_v128_store(&s, v.val); } - v_reg(const cv::v_float32x4& v) { wasm_v128_store(&s, v.val); } - v_reg(const cv::v_float64x2& v) { wasm_v128_store(&s, v.val); } - v_reg(const cv::v_uint64x2& v) { wasm_v128_store(&s, v.val); } - v_reg(const cv::v_int64x2& v) { wasm_v128_store(&s, v.val); } - - operator cv::v_uint8x16() const { return cv::v_uint8x16(wasm_v128_load(&s)); } - operator cv::v_int8x16() const { return cv::v_int8x16(wasm_v128_load(&s)); } - operator cv::v_uint16x8() const { return cv::v_uint16x8(wasm_v128_load(&s)); } - operator cv::v_int16x8() const { return cv::v_int16x8(wasm_v128_load(&s)); } - operator cv::v_uint32x4() const { return cv::v_uint32x4(wasm_v128_load(&s)); } - operator cv::v_int32x4() const { return cv::v_int32x4(wasm_v128_load(&s)); } - operator cv::v_float32x4() const { return cv::v_float32x4(wasm_v128_load(&s)); } - operator cv::v_float64x2() const { return cv::v_float64x2(wasm_v128_load(&s)); } - operator cv::v_uint64x2() const { return cv::v_uint64x2(wasm_v128_load(&s)); } - operator cv::v_int64x2() const { return cv::v_int64x2(wasm_v128_load(&s)); } - - _Tp s[n]; -}; - -typedef v_reg v_uint8x16; -typedef v_reg v_int8x16; -typedef v_reg v_uint16x8; -typedef v_reg v_int16x8; -typedef v_reg v_uint32x4; -typedef v_reg v_int32x4; -typedef v_reg v_float32x4; -typedef v_reg v_float64x2; -typedef v_reg v_uint64x2; -typedef v_reg v_int64x2; - -#define OPENCV_HAL_IMPL_BIN_OP(bin_op) \ -template inline v_reg<_Tp, n> \ - operator bin_op (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ -{ \ - v_reg<_Tp, n> c; \ - for( int i = 0; i < n; i++ ) \ - c.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \ - return c; \ -} \ -template inline v_reg<_Tp, n>& \ - operator bin_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ -{ \ - for( int i = 0; i < n; i++ ) \ - a.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \ - return a; \ -} - -OPENCV_HAL_IMPL_BIN_OP(+) -OPENCV_HAL_IMPL_BIN_OP(-) -OPENCV_HAL_IMPL_BIN_OP(*) -OPENCV_HAL_IMPL_BIN_OP(/) - -#define OPENCV_HAL_IMPL_BIT_OP(bit_op) \ -template inline v_reg<_Tp, n> operator bit_op \ - (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ -{ \ - v_reg<_Tp, n> c; \ - typedef typename V_TypeTraits<_Tp>::int_type itype; \ - for( int i = 0; i < n; i++ ) \ - c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \ - V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \ - return c; \ -} \ -template inline v_reg<_Tp, n>& operator \ - bit_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ -{ \ - typedef typename V_TypeTraits<_Tp>::int_type itype; \ - for( int i = 0; i < n; i++ ) \ - a.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \ - V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \ - return a; \ -} - -OPENCV_HAL_IMPL_BIT_OP(&) -OPENCV_HAL_IMPL_BIT_OP(|) -OPENCV_HAL_IMPL_BIT_OP(^) - -template inline v_reg<_Tp, n> operator ~ (const v_reg<_Tp, n>& a) -{ - v_reg<_Tp, n> c; - for( int i = 0; i < n; i++ ) - { - c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int(~V_TypeTraits<_Tp>::reinterpret_int(a.s[i])); - } - return c; -} - -#define OPENCV_HAL_IMPL_MATH_FUNC(func, cfunc, _Tp2) \ -template inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a) \ -{ \ - v_reg<_Tp2, n> c; \ - for( int i = 0; i < n; i++ ) \ - c.s[i] = cfunc(a.s[i]); \ - return c; \ -} - -OPENCV_HAL_IMPL_MATH_FUNC(v_sqrt, std::sqrt, _Tp) -OPENCV_HAL_IMPL_MATH_FUNC(v_sin, std::sin, _Tp) -OPENCV_HAL_IMPL_MATH_FUNC(v_cos, std::cos, _Tp) -OPENCV_HAL_IMPL_MATH_FUNC(v_exp, std::exp, _Tp) -OPENCV_HAL_IMPL_MATH_FUNC(v_log, std::log, _Tp) -OPENCV_HAL_IMPL_MATH_FUNC(v_abs, (typename V_TypeTraits<_Tp>::abs_type)std::abs, - typename V_TypeTraits<_Tp>::abs_type) -OPENCV_HAL_IMPL_MATH_FUNC(v_round, cvRound, int) -OPENCV_HAL_IMPL_MATH_FUNC(v_floor, cvFloor, int) -OPENCV_HAL_IMPL_MATH_FUNC(v_ceil, cvCeil, int) -OPENCV_HAL_IMPL_MATH_FUNC(v_trunc, int, int) - -#define OPENCV_HAL_IMPL_MINMAX_FUNC(func, cfunc) \ -template inline v_reg<_Tp, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ -{ \ - v_reg<_Tp, n> c; \ - for( int i = 0; i < n; i++ ) \ - c.s[i] = cfunc(a.s[i], b.s[i]); \ - return c; \ -} - -#define OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(func, cfunc) \ -template inline _Tp func(const v_reg<_Tp, n>& a) \ -{ \ - _Tp c = a.s[0]; \ - for( int i = 1; i < n; i++ ) \ - c = cfunc(c, a.s[i]); \ - return c; \ -} - -OPENCV_HAL_IMPL_MINMAX_FUNC(v_min, std::min) -OPENCV_HAL_IMPL_MINMAX_FUNC(v_max, std::max) -OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_min, std::min) -OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_max, std::max) +#define OPENCV_HAL_IMPL_REINTERPRET_INT(ft, tt) \ +inline tt reinterpret_int(ft x) { union { ft l; tt i; } v; v.l = x; return v.i; } +OPENCV_HAL_IMPL_REINTERPRET_INT(uchar, schar) +OPENCV_HAL_IMPL_REINTERPRET_INT(schar, schar) +OPENCV_HAL_IMPL_REINTERPRET_INT(ushort, short) +OPENCV_HAL_IMPL_REINTERPRET_INT(short, short) +OPENCV_HAL_IMPL_REINTERPRET_INT(unsigned, int) +OPENCV_HAL_IMPL_REINTERPRET_INT(int, int) +OPENCV_HAL_IMPL_REINTERPRET_INT(float, int) +OPENCV_HAL_IMPL_REINTERPRET_INT(uint64, int64) +OPENCV_HAL_IMPL_REINTERPRET_INT(int64, int64) +OPENCV_HAL_IMPL_REINTERPRET_INT(double, int64) static const unsigned char popCountTable[] = { @@ -492,1184 +291,7 @@ static const unsigned char popCountTable[] = 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, }; - -template -inline v_reg::abs_type, n> v_popcount(const v_reg<_Tp, n>& a) -{ - v_reg::abs_type, n> b = v_reg::abs_type, n>::zero(); - for (int i = 0; i < (int)(n*sizeof(_Tp)); i++) - b.s[i/sizeof(_Tp)] += popCountTable[v_reinterpret_as_u8(a).s[i]]; - return b; -} - -template -inline void v_minmax( const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, - v_reg<_Tp, n>& minval, v_reg<_Tp, n>& maxval ) -{ - for( int i = 0; i < n; i++ ) - { - minval.s[i] = std::min(a.s[i], b.s[i]); - maxval.s[i] = std::max(a.s[i], b.s[i]); - } -} - -#define OPENCV_HAL_IMPL_CMP_OP(cmp_op) \ -template \ -inline v_reg<_Tp, n> operator cmp_op(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ -{ \ - typedef typename V_TypeTraits<_Tp>::int_type itype; \ - v_reg<_Tp, n> c; \ - for( int i = 0; i < n; i++ ) \ - c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)-(int)(a.s[i] cmp_op b.s[i])); \ - return c; \ -} - -OPENCV_HAL_IMPL_CMP_OP(<) -OPENCV_HAL_IMPL_CMP_OP(>) -OPENCV_HAL_IMPL_CMP_OP(<=) -OPENCV_HAL_IMPL_CMP_OP(>=) -OPENCV_HAL_IMPL_CMP_OP(==) -OPENCV_HAL_IMPL_CMP_OP(!=) - -template -inline v_reg v_not_nan(const v_reg& a) -{ - typedef typename V_TypeTraits::int_type itype; - v_reg c; - for (int i = 0; i < n; i++) - c.s[i] = V_TypeTraits::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i])); - return c; -} -template -inline v_reg v_not_nan(const v_reg& a) -{ - typedef typename V_TypeTraits::int_type itype; - v_reg c; - for (int i = 0; i < n; i++) - c.s[i] = V_TypeTraits::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i])); - return c; -} - -#define OPENCV_HAL_IMPL_ARITHM_OP(func, bin_op, cast_op, _Tp2) \ -template \ -inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ -{ \ - typedef _Tp2 rtype; \ - v_reg c; \ - for( int i = 0; i < n; i++ ) \ - c.s[i] = cast_op(a.s[i] bin_op b.s[i]); \ - return c; \ -} - -OPENCV_HAL_IMPL_ARITHM_OP(v_add_wrap, +, (_Tp), _Tp) -OPENCV_HAL_IMPL_ARITHM_OP(v_sub_wrap, -, (_Tp), _Tp) -OPENCV_HAL_IMPL_ARITHM_OP(v_mul_wrap, *, (_Tp), _Tp) - -template inline T _absdiff(T a, T b) -{ - return a > b ? a - b : b - a; -} - -template -inline v_reg::abs_type, n> v_absdiff(const v_reg<_Tp, n>& a, const v_reg<_Tp, n> & b) -{ - typedef typename V_TypeTraits<_Tp>::abs_type rtype; - v_reg c; - const rtype mask = (rtype)(std::numeric_limits<_Tp>::is_signed ? (1 << (sizeof(rtype)*8 - 1)) : 0); - for( int i = 0; i < n; i++ ) - { - rtype ua = a.s[i] ^ mask; - rtype ub = b.s[i] ^ mask; - c.s[i] = _absdiff(ua, ub); - } - return c; -} - -inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) -{ - v_float32x4 c; - for( int i = 0; i < c.nlanes; i++ ) - c.s[i] = _absdiff(a.s[i], b.s[i]); - return c; -} - -inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b) -{ - v_float64x2 c; - for( int i = 0; i < c.nlanes; i++ ) - c.s[i] = _absdiff(a.s[i], b.s[i]); - return c; -} - -template -inline v_reg<_Tp, n> v_absdiffs(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - v_reg<_Tp, n> c; - for( int i = 0; i < n; i++) - c.s[i] = saturate_cast<_Tp>(std::abs(a.s[i] - b.s[i])); - return c; -} - -template -inline v_reg<_Tp, n> v_invsqrt(const v_reg<_Tp, n>& a) -{ - v_reg<_Tp, n> c; - for( int i = 0; i < n; i++ ) - c.s[i] = 1.f/std::sqrt(a.s[i]); - return c; -} - -template -inline v_reg<_Tp, n> v_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - v_reg<_Tp, n> c; - for( int i = 0; i < n; i++ ) - c.s[i] = std::sqrt(a.s[i]*a.s[i] + b.s[i]*b.s[i]); - return c; -} - -template -inline v_reg<_Tp, n> v_sqr_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - v_reg<_Tp, n> c; - for( int i = 0; i < n; i++ ) - c.s[i] = a.s[i]*a.s[i] + b.s[i]*b.s[i]; - return c; -} - -template -inline v_reg<_Tp, n> v_fma(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, - const v_reg<_Tp, n>& c) -{ - v_reg<_Tp, n> d; - for( int i = 0; i < n; i++ ) - d.s[i] = a.s[i]*b.s[i] + c.s[i]; - return d; -} - -template -inline v_reg<_Tp, n> v_muladd(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, - const v_reg<_Tp, n>& c) -{ - return v_fma(a, b, c); -} - -template inline v_reg::w_type, n/2> - v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - typedef typename V_TypeTraits<_Tp>::w_type w_type; - v_reg c; - for( int i = 0; i < (n/2); i++ ) - c.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1]; - return c; -} - -template inline v_reg::w_type, n/2> - v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, const v_reg::w_type, n / 2>& c) -{ - typedef typename V_TypeTraits<_Tp>::w_type w_type; - v_reg s; - for( int i = 0; i < (n/2); i++ ) - s.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1] + c.s[i]; - return s; -} - -template inline v_reg::q_type, n/4> - v_dotprod_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - typedef typename V_TypeTraits<_Tp>::q_type q_type; - v_reg s; - for( int i = 0; i < (n/4); i++ ) - s.s[i] = (q_type)a.s[i*4 ]*b.s[i*4 ] + (q_type)a.s[i*4 + 1]*b.s[i*4 + 1] + - (q_type)a.s[i*4 + 2]*b.s[i*4 + 2] + (q_type)a.s[i*4 + 3]*b.s[i*4 + 3]; - return s; -} - -template inline v_reg::q_type, n/4> - v_dotprod_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, - const v_reg::q_type, n / 4>& c) -{ - typedef typename V_TypeTraits<_Tp>::q_type q_type; - v_reg s; - for( int i = 0; i < (n/4); i++ ) - s.s[i] = (q_type)a.s[i*4 ]*b.s[i*4 ] + (q_type)a.s[i*4 + 1]*b.s[i*4 + 1] + - (q_type)a.s[i*4 + 2]*b.s[i*4 + 2] + (q_type)a.s[i*4 + 3]*b.s[i*4 + 3] + c.s[i]; - return s; -} - -template inline void v_mul_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, - v_reg::w_type, n/2>& c, - v_reg::w_type, n/2>& d) -{ - typedef typename V_TypeTraits<_Tp>::w_type w_type; - for( int i = 0; i < (n/2); i++ ) - { - c.s[i] = (w_type)a.s[i]*b.s[i]; - d.s[i] = (w_type)a.s[i+(n/2)]*b.s[i+(n/2)]; - } -} - -template inline v_reg<_Tp, n> v_mul_hi(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - typedef typename V_TypeTraits<_Tp>::w_type w_type; - v_reg<_Tp, n> c; - for (int i = 0; i < n; i++) - c.s[i] = (_Tp)(((w_type)a.s[i] * b.s[i]) >> sizeof(_Tp)*8); - return c; -} - -template inline void v_hsum(const v_reg<_Tp, n>& a, - v_reg::w_type, n/2>& c) -{ - typedef typename V_TypeTraits<_Tp>::w_type w_type; - for( int i = 0; i < (n/2); i++ ) - { - c.s[i] = (w_type)a.s[i*2] + a.s[i*2+1]; - } -} - -#define OPENCV_HAL_IMPL_SHIFT_OP(shift_op) \ -template inline v_reg<_Tp, n> operator shift_op(const v_reg<_Tp, n>& a, int imm) \ -{ \ - v_reg<_Tp, n> c; \ - for( int i = 0; i < n; i++ ) \ - c.s[i] = (_Tp)(a.s[i] shift_op imm); \ - return c; \ -} - -OPENCV_HAL_IMPL_SHIFT_OP(<< ) -OPENCV_HAL_IMPL_SHIFT_OP(>> ) - -#define OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(suffix,opA,opB) \ -template inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a) \ -{ \ - v_reg<_Tp, n> b; \ - for (int i = 0; i < n; i++) \ - { \ - int sIndex = i opA imm; \ - if (0 <= sIndex && sIndex < n) \ - { \ - b.s[i] = a.s[sIndex]; \ - } \ - else \ - { \ - b.s[i] = 0; \ - } \ - } \ - return b; \ -} \ -template inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ -{ \ - v_reg<_Tp, n> c; \ - for (int i = 0; i < n; i++) \ - { \ - int aIndex = i opA imm; \ - int bIndex = i opA imm opB n; \ - if (0 <= bIndex && bIndex < n) \ - { \ - c.s[i] = b.s[bIndex]; \ - } \ - else if (0 <= aIndex && aIndex < n) \ - { \ - c.s[i] = a.s[aIndex]; \ - } \ - else \ - { \ - c.s[i] = 0; \ - } \ - } \ - return c; \ -} - -OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(left, -, +) -OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(right, +, -) - -template inline typename V_TypeTraits<_Tp>::sum_type v_reduce_sum(const v_reg<_Tp, n>& a) -{ - typename V_TypeTraits<_Tp>::sum_type c = a.s[0]; - for( int i = 1; i < n; i++ ) - c += a.s[i]; - return c; -} - -inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, - const v_float32x4& c, const v_float32x4& d) -{ - v_float32x4 r; - r.s[0] = a.s[0] + a.s[1] + a.s[2] + a.s[3]; - r.s[1] = b.s[0] + b.s[1] + b.s[2] + b.s[3]; - r.s[2] = c.s[0] + c.s[1] + c.s[2] + c.s[3]; - r.s[3] = d.s[0] + d.s[1] + d.s[2] + d.s[3]; - return r; -} - -template inline typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type v_reduce_sad(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type c = _absdiff(a.s[0], b.s[0]); - for (int i = 1; i < n; i++) - c += _absdiff(a.s[i], b.s[i]); - return c; -} - -template inline int v_signmask(const v_reg<_Tp, n>& a) -{ - int mask = 0; - for( int i = 0; i < n; i++ ) - mask |= (V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0) << i; - return mask; -} - -template inline bool v_check_all(const v_reg<_Tp, n>& a) -{ - for( int i = 0; i < n; i++ ) - if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) >= 0 ) - return false; - return true; -} - -template inline bool v_check_any(const v_reg<_Tp, n>& a) -{ - for( int i = 0; i < n; i++ ) - if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0 ) - return true; - return false; -} - -template inline v_reg<_Tp, n> v_select(const v_reg<_Tp, n>& mask, - const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - typedef V_TypeTraits<_Tp> Traits; - typedef typename Traits::int_type int_type; - v_reg<_Tp, n> c; - for( int i = 0; i < n; i++ ) - { - int_type m = Traits::reinterpret_int(mask.s[i]); - CV_DbgAssert(m == 0 || m == (~(int_type)0)); // restrict mask values: 0 or 0xff/0xffff/etc - c.s[i] = m ? a.s[i] : b.s[i]; - } - return c; -} - -template inline void v_expand(const v_reg<_Tp, n>& a, - v_reg::w_type, n/2>& b0, - v_reg::w_type, n/2>& b1) -{ - for( int i = 0; i < (n/2); i++ ) - { - b0.s[i] = a.s[i]; - b1.s[i] = a.s[i+(n/2)]; - } -} - -template -inline v_reg::w_type, n/2> -v_expand_low(const v_reg<_Tp, n>& a) -{ - v_reg::w_type, n/2> b; - for( int i = 0; i < (n/2); i++ ) - b.s[i] = a.s[i]; - return b; -} - -template -inline v_reg::w_type, n/2> -v_expand_high(const v_reg<_Tp, n>& a) -{ - v_reg::w_type, n/2> b; - for( int i = 0; i < (n/2); i++ ) - b.s[i] = a.s[i+(n/2)]; - return b; -} - -template inline v_reg::int_type, n> - v_reinterpret_as_int(const v_reg<_Tp, n>& a) -{ - v_reg::int_type, n> c; - for( int i = 0; i < n; i++ ) - c.s[i] = V_TypeTraits<_Tp>::reinterpret_int(a.s[i]); - return c; -} - -template inline v_reg::uint_type, n> - v_reinterpret_as_uint(const v_reg<_Tp, n>& a) -{ - v_reg::uint_type, n> c; - for( int i = 0; i < n; i++ ) - c.s[i] = V_TypeTraits<_Tp>::reinterpret_uint(a.s[i]); - return c; -} - -template inline void v_zip( const v_reg<_Tp, n>& a0, const v_reg<_Tp, n>& a1, - v_reg<_Tp, n>& b0, v_reg<_Tp, n>& b1 ) -{ - int i; - for( i = 0; i < n/2; i++ ) - { - b0.s[i*2] = a0.s[i]; - b0.s[i*2+1] = a1.s[i]; - } - for( ; i < n; i++ ) - { - b1.s[i*2-n] = a0.s[i]; - b1.s[i*2-n+1] = a1.s[i]; - } -} - -template -inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load(const _Tp* ptr) -{ - return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); -} - -template -inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_aligned(const _Tp* ptr) -{ - return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); -} - -template -inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_low(const _Tp* ptr) -{ - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; - for( int i = 0; i < c.nlanes/2; i++ ) - { - c.s[i] = ptr[i]; - } - return c; -} - -template -inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_halves(const _Tp* loptr, const _Tp* hiptr) -{ - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; - for( int i = 0; i < c.nlanes/2; i++ ) - { - c.s[i] = loptr[i]; - c.s[i+c.nlanes/2] = hiptr[i]; - } - return c; -} - -template -inline v_reg::w_type, V_TypeTraits<_Tp>::nlanes128 / 2> -v_load_expand(const _Tp* ptr) -{ - typedef typename V_TypeTraits<_Tp>::w_type w_type; - v_reg::nlanes128> c; - for( int i = 0; i < c.nlanes; i++ ) - { - c.s[i] = ptr[i]; - } - return c; -} - -template -inline v_reg::q_type, V_TypeTraits<_Tp>::nlanes128 / 4> -v_load_expand_q(const _Tp* ptr) -{ - typedef typename V_TypeTraits<_Tp>::q_type q_type; - v_reg::nlanes128> c; - for( int i = 0; i < c.nlanes; i++ ) - { - c.s[i] = ptr[i]; - } - return c; -} - -template inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, - v_reg<_Tp, n>& b) -{ - int i, i2; - for( i = i2 = 0; i < n; i++, i2 += 2 ) - { - a.s[i] = ptr[i2]; - b.s[i] = ptr[i2+1]; - } -} - -template inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, - v_reg<_Tp, n>& b, v_reg<_Tp, n>& c) -{ - int i, i3; - for( i = i3 = 0; i < n; i++, i3 += 3 ) - { - a.s[i] = ptr[i3]; - b.s[i] = ptr[i3+1]; - c.s[i] = ptr[i3+2]; - } -} - -template -inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, - v_reg<_Tp, n>& b, v_reg<_Tp, n>& c, - v_reg<_Tp, n>& d) -{ - int i, i4; - for( i = i4 = 0; i < n; i++, i4 += 4 ) - { - a.s[i] = ptr[i4]; - b.s[i] = ptr[i4+1]; - c.s[i] = ptr[i4+2]; - d.s[i] = ptr[i4+3]; - } -} - -template -inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, - const v_reg<_Tp, n>& b, - hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) -{ - int i, i2; - for( i = i2 = 0; i < n; i++, i2 += 2 ) - { - ptr[i2] = a.s[i]; - ptr[i2+1] = b.s[i]; - } -} - -template -inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, - const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c, - hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) -{ - int i, i3; - for( i = i3 = 0; i < n; i++, i3 += 3 ) - { - ptr[i3] = a.s[i]; - ptr[i3+1] = b.s[i]; - ptr[i3+2] = c.s[i]; - } -} - -template inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, - const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c, - const v_reg<_Tp, n>& d, - hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) -{ - int i, i4; - for( i = i4 = 0; i < n; i++, i4 += 4 ) - { - ptr[i4] = a.s[i]; - ptr[i4+1] = b.s[i]; - ptr[i4+2] = c.s[i]; - ptr[i4+3] = d.s[i]; - } -} - -template -inline void v_store(_Tp* ptr, const v_reg<_Tp, n>& a, hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) -{ - for( int i = 0; i < n; i++ ) - ptr[i] = a.s[i]; -} - -template -inline void v_store_low(_Tp* ptr, const v_reg<_Tp, n>& a) -{ - for( int i = 0; i < (n/2); i++ ) - ptr[i] = a.s[i]; -} - -template -inline void v_store_high(_Tp* ptr, const v_reg<_Tp, n>& a) -{ - for( int i = 0; i < (n/2); i++ ) - ptr[i] = a.s[i+(n/2)]; -} - -template -inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a) -{ - for( int i = 0; i < n; i++ ) - ptr[i] = a.s[i]; -} - -template -inline void v_store_aligned_nocache(_Tp* ptr, const v_reg<_Tp, n>& a) -{ - for( int i = 0; i < n; i++ ) - ptr[i] = a.s[i]; -} - -template -inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a, hal::StoreMode /*mode*/) -{ - for( int i = 0; i < n; i++ ) - ptr[i] = a.s[i]; -} - -template -inline v_reg<_Tp, n> v_combine_low(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - v_reg<_Tp, n> c; - for( int i = 0; i < (n/2); i++ ) - { - c.s[i] = a.s[i]; - c.s[i+(n/2)] = b.s[i]; - } - return c; -} - -template -inline v_reg<_Tp, n> v_combine_high(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - v_reg<_Tp, n> c; - for( int i = 0; i < (n/2); i++ ) - { - c.s[i] = a.s[i+(n/2)]; - c.s[i+(n/2)] = b.s[i+(n/2)]; - } - return c; -} - -template -inline void v_recombine(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, - v_reg<_Tp, n>& low, v_reg<_Tp, n>& high) -{ - for( int i = 0; i < (n/2); i++ ) - { - low.s[i] = a.s[i]; - low.s[i+(n/2)] = b.s[i]; - high.s[i] = a.s[i+(n/2)]; - high.s[i+(n/2)] = b.s[i+(n/2)]; - } -} - -template -inline v_reg<_Tp, n> v_extract(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - v_reg<_Tp, n> r; - const int shift = n - s; - int i = 0; - for (; i < shift; ++i) - r.s[i] = a.s[i+s]; - for (; i < n; ++i) - r.s[i] = b.s[i-shift]; - return r; -} - -template inline v_reg v_round(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = cvRound(a.s[i]); - return c; -} - -template inline v_reg v_round(const v_reg& a, const v_reg& b) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - { - c.s[i] = cvRound(a.s[i]); - c.s[i+n] = cvRound(b.s[i]); - } - return c; -} - -template inline v_reg v_floor(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = cvFloor(a.s[i]); - return c; -} - -template inline v_reg v_ceil(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = cvCeil(a.s[i]); - return c; -} - -template inline v_reg v_trunc(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = (int)(a.s[i]); - return c; -} - -template inline v_reg v_round(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - { - c.s[i] = cvRound(a.s[i]); - c.s[i+n] = 0; - } - return c; -} - -template inline v_reg v_floor(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - { - c.s[i] = cvFloor(a.s[i]); - c.s[i+n] = 0; - } - return c; -} - -template inline v_reg v_ceil(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - { - c.s[i] = cvCeil(a.s[i]); - c.s[i+n] = 0; - } - return c; -} - -template inline v_reg v_trunc(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - { - c.s[i] = (int)(a.s[i]); - c.s[i+n] = 0; - } - return c; -} - -template inline v_reg v_cvt_f32(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = (float)a.s[i]; - return c; -} - -template inline v_reg v_cvt_f32(const v_reg& a) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - { - c.s[i] = (float)a.s[i]; - c.s[i+n] = 0; - } - return c; -} - -template inline v_reg v_cvt_f32(const v_reg& a, const v_reg& b) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - { - c.s[i] = (float)a.s[i]; - c.s[i+n] = (float)b.s[i]; - } - return c; -} - -inline v_float64x2 v_cvt_f64(const v_int32x4& a) -{ - v_float64x2 c; - for( int i = 0; i < 2; i++ ) - c.s[i] = (double)a.s[i]; - return c; -} - -inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) -{ - v_float64x2 c; - for( int i = 0; i < 2; i++ ) - c.s[i] = (double)a.s[i+2]; - return c; -} - -inline v_float64x2 v_cvt_f64(const v_float32x4& a) -{ - v_float64x2 c; - for( int i = 0; i < 2; i++ ) - c.s[i] = (double)a.s[i]; - return c; -} - -inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) -{ - v_float64x2 c; - for( int i = 0; i < 2; i++ ) - c.s[i] = (double)a.s[i+2]; - return c; -} - -inline v_float64x2 v_cvt_f64(const v_int64x2& a) -{ - v_float64x2 c; - for( int i = 0; i < 2; i++ ) - c.s[i] = (double)a.s[i]; - return c; -} - -template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut(const _Tp* tab, const int* idx) -{ - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; - for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) - c.s[i] = tab[idx[i]]; - return c; -} -template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_pairs(const _Tp* tab, const int* idx) -{ - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; - for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) - c.s[i] = tab[idx[i / 2] + i % 2]; - return c; -} -template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_quads(const _Tp* tab, const int* idx) -{ - v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; - for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) - c.s[i] = tab[idx[i / 4] + i % 4]; - return c; -} - -template inline v_reg v_lut(const int* tab, const v_reg& idx) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = tab[idx.s[i]]; - return c; -} - -template inline v_reg v_lut(const unsigned* tab, const v_reg& idx) -{ - v_reg c; - for (int i = 0; i < n; i++) - c.s[i] = tab[idx.s[i]]; - return c; -} - -template inline v_reg v_lut(const float* tab, const v_reg& idx) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = tab[idx.s[i]]; - return c; -} - -template inline v_reg v_lut(const double* tab, const v_reg& idx) -{ - v_reg c; - for( int i = 0; i < n; i++ ) - c.s[i] = tab[idx.s[i]]; - return c; -} - -template inline void v_lut_deinterleave(const float* tab, const v_reg& idx, - v_reg& x, v_reg& y) -{ - for( int i = 0; i < n; i++ ) - { - int j = idx.s[i]; - x.s[i] = tab[j]; - y.s[i] = tab[j+1]; - } -} - -template inline void v_lut_deinterleave(const double* tab, const v_reg& idx, - v_reg& x, v_reg& y) -{ - for( int i = 0; i < n; i++ ) - { - int j = idx.s[i]; - x.s[i] = tab[j]; - y.s[i] = tab[j+1]; - } -} - -template inline v_reg<_Tp, n> v_interleave_pairs(const v_reg<_Tp, n>& vec) -{ - v_reg<_Tp, n> c; - for (int i = 0; i < n/4; i++) - { - c.s[4*i ] = vec.s[4*i ]; - c.s[4*i+1] = vec.s[4*i+2]; - c.s[4*i+2] = vec.s[4*i+1]; - c.s[4*i+3] = vec.s[4*i+3]; - } - return c; -} - -template inline v_reg<_Tp, n> v_interleave_quads(const v_reg<_Tp, n>& vec) -{ - v_reg<_Tp, n> c; - for (int i = 0; i < n/8; i++) - { - c.s[8*i ] = vec.s[8*i ]; - c.s[8*i+1] = vec.s[8*i+4]; - c.s[8*i+2] = vec.s[8*i+1]; - c.s[8*i+3] = vec.s[8*i+5]; - c.s[8*i+4] = vec.s[8*i+2]; - c.s[8*i+5] = vec.s[8*i+6]; - c.s[8*i+6] = vec.s[8*i+3]; - c.s[8*i+7] = vec.s[8*i+7]; - } - return c; -} - -template inline v_reg<_Tp, n> v_pack_triplets(const v_reg<_Tp, n>& vec) -{ - v_reg<_Tp, n> c; - for (int i = 0; i < n/4; i++) - { - c.s[3*i ] = vec.s[4*i ]; - c.s[3*i+1] = vec.s[4*i+1]; - c.s[3*i+2] = vec.s[4*i+2]; - } - return c; -} - -template -inline void v_transpose4x4( v_reg<_Tp, 4>& a0, const v_reg<_Tp, 4>& a1, - const v_reg<_Tp, 4>& a2, const v_reg<_Tp, 4>& a3, - v_reg<_Tp, 4>& b0, v_reg<_Tp, 4>& b1, - v_reg<_Tp, 4>& b2, v_reg<_Tp, 4>& b3 ) -{ - b0 = v_reg<_Tp, 4>(a0.s[0], a1.s[0], a2.s[0], a3.s[0]); - b1 = v_reg<_Tp, 4>(a0.s[1], a1.s[1], a2.s[1], a3.s[1]); - b2 = v_reg<_Tp, 4>(a0.s[2], a1.s[2], a2.s[2], a3.s[2]); - b3 = v_reg<_Tp, 4>(a0.s[3], a1.s[3], a2.s[3], a3.s[3]); -} - -#define OPENCV_HAL_IMPL_C_INIT_ZERO(_Tpvec, _Tp, suffix) \ -inline _Tpvec v_setzero_##suffix() { return _Tpvec::zero(); } - -OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint8x16, uchar, u8) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_int8x16, schar, s8) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint16x8, ushort, u16) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_int16x8, short, s16) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint32x4, unsigned, u32) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_int32x4, int, s32) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_float32x4, float, f32) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_float64x2, double, f64) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint64x2, uint64, u64) -OPENCV_HAL_IMPL_C_INIT_ZERO(v_int64x2, int64, s64) - -#define OPENCV_HAL_IMPL_C_INIT_VAL(_Tpvec, _Tp, suffix) \ -inline _Tpvec v_setall_##suffix(_Tp val) { return _Tpvec::all(val); } - -OPENCV_HAL_IMPL_C_INIT_VAL(v_int8x16, schar, s8) -OPENCV_HAL_IMPL_C_INIT_VAL(v_uint16x8, ushort, u16) -OPENCV_HAL_IMPL_C_INIT_VAL(v_int16x8, short, s16) -OPENCV_HAL_IMPL_C_INIT_VAL(v_uint32x4, unsigned, u32) -OPENCV_HAL_IMPL_C_INIT_VAL(v_int32x4, int, s32) -OPENCV_HAL_IMPL_C_INIT_VAL(v_float32x4, float, f32) -OPENCV_HAL_IMPL_C_INIT_VAL(v_float64x2, double, f64) -OPENCV_HAL_IMPL_C_INIT_VAL(v_uint64x2, uint64, u64) -OPENCV_HAL_IMPL_C_INIT_VAL(v_int64x2, int64, s64) - -#define OPENCV_HAL_IMPL_C_REINTERPRET(_Tpvec, _Tp, suffix) \ -template inline _Tpvec \ - v_reinterpret_as_##suffix(const v_reg<_Tp0, n0>& a) \ -{ return a.template reinterpret_as<_Tp, _Tpvec::nlanes>(); } - -OPENCV_HAL_IMPL_C_REINTERPRET(v_uint8x16, uchar, u8) -OPENCV_HAL_IMPL_C_REINTERPRET(v_int8x16, schar, s8) -OPENCV_HAL_IMPL_C_REINTERPRET(v_uint16x8, ushort, u16) -OPENCV_HAL_IMPL_C_REINTERPRET(v_int16x8, short, s16) -OPENCV_HAL_IMPL_C_REINTERPRET(v_uint32x4, unsigned, u32) -OPENCV_HAL_IMPL_C_REINTERPRET(v_int32x4, int, s32) -OPENCV_HAL_IMPL_C_REINTERPRET(v_float32x4, float, f32) -OPENCV_HAL_IMPL_C_REINTERPRET(v_float64x2, double, f64) -OPENCV_HAL_IMPL_C_REINTERPRET(v_uint64x2, uint64, u64) -OPENCV_HAL_IMPL_C_REINTERPRET(v_int64x2, int64, s64) - -#define OPENCV_HAL_IMPL_C_SHIFTL(_Tpvec, _Tp) \ -template inline _Tpvec v_shl(const _Tpvec& a) \ -{ return a << n; } - -OPENCV_HAL_IMPL_C_SHIFTL(v_uint16x8, ushort) -OPENCV_HAL_IMPL_C_SHIFTL(v_int16x8, short) -OPENCV_HAL_IMPL_C_SHIFTL(v_uint32x4, unsigned) -OPENCV_HAL_IMPL_C_SHIFTL(v_int32x4, int) -OPENCV_HAL_IMPL_C_SHIFTL(v_uint64x2, uint64) -OPENCV_HAL_IMPL_C_SHIFTL(v_int64x2, int64) - -#define OPENCV_HAL_IMPL_C_SHIFTR(_Tpvec, _Tp) \ -template inline _Tpvec v_shr(const _Tpvec& a) \ -{ return a >> n; } - -OPENCV_HAL_IMPL_C_SHIFTR(v_uint16x8, ushort) -OPENCV_HAL_IMPL_C_SHIFTR(v_int16x8, short) -OPENCV_HAL_IMPL_C_SHIFTR(v_uint32x4, unsigned) -OPENCV_HAL_IMPL_C_SHIFTR(v_int32x4, int) -OPENCV_HAL_IMPL_C_SHIFTR(v_uint64x2, uint64) -OPENCV_HAL_IMPL_C_SHIFTR(v_int64x2, int64) - -#define OPENCV_HAL_IMPL_C_RSHIFTR(_Tpvec, _Tp) \ -template inline _Tpvec v_rshr(const _Tpvec& a) \ -{ \ - _Tpvec c; \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ - c.s[i] = (_Tp)((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ - return c; \ -} - -OPENCV_HAL_IMPL_C_RSHIFTR(v_uint16x8, ushort) -OPENCV_HAL_IMPL_C_RSHIFTR(v_int16x8, short) -OPENCV_HAL_IMPL_C_RSHIFTR(v_uint32x4, unsigned) -OPENCV_HAL_IMPL_C_RSHIFTR(v_int32x4, int) -OPENCV_HAL_IMPL_C_RSHIFTR(v_uint64x2, uint64) -OPENCV_HAL_IMPL_C_RSHIFTR(v_int64x2, int64) - -#define OPENCV_HAL_IMPL_C_PACK(_Tpvec, _Tpnvec, _Tpn, pack_suffix, cast) \ -inline _Tpnvec v_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ -{ \ - _Tpnvec c; \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ - { \ - c.s[i] = cast<_Tpn>(a.s[i]); \ - c.s[i+_Tpvec::nlanes] = cast<_Tpn>(b.s[i]); \ - } \ - return c; \ -} - -OPENCV_HAL_IMPL_C_PACK(v_uint16x8, v_uint8x16, uchar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_int8x16, schar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_uint32x4, v_uint16x8, ushort, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_int16x8, short, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_uint64x2, v_uint32x4, unsigned, pack, static_cast) -OPENCV_HAL_IMPL_C_PACK(v_int64x2, v_int32x4, int, pack, static_cast) -OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_uint8x16, uchar, pack_u, saturate_cast) -OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_uint16x8, ushort, pack_u, saturate_cast) - -#define OPENCV_HAL_IMPL_C_RSHR_PACK(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ -template inline _Tpnvec v_rshr_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ -{ \ - _Tpnvec c; \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ - { \ - c.s[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ - c.s[i+_Tpvec::nlanes] = cast<_Tpn>((b.s[i] + ((_Tp)1 << (n - 1))) >> n); \ - } \ - return c; \ -} - -OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_int16x8, short, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int64x2, int64, v_int32x4, int, pack, static_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) - -#define OPENCV_HAL_IMPL_C_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ -inline void v_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ -{ \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ - ptr[i] = cast<_Tpn>(a.s[i]); \ -} - -OPENCV_HAL_IMPL_C_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) - -#define OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ -template inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ -{ \ - for( int i = 0; i < _Tpvec::nlanes; i++ ) \ - ptr[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ -} - -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) - -template -inline void _pack_b(_Tpm* mptr, const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) -{ - for (int i = 0; i < n; ++i) - { - mptr[i] = (_Tpm)a.s[i]; - mptr[i + n] = (_Tpm)b.s[i]; - } -} - -inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) -{ - v_uint8x16 mask; - _pack_b(mask.s, a, b); - return mask; -} - -inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, - const v_uint32x4& c, const v_uint32x4& d) -{ - v_uint8x16 mask; - _pack_b(mask.s, a, b); - _pack_b(mask.s + 8, c, d); - return mask; -} - -inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, - const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, - const v_uint64x2& g, const v_uint64x2& h) -{ - v_uint8x16 mask; - _pack_b(mask.s, a, b); - _pack_b(mask.s + 4, c, d); - _pack_b(mask.s + 8, e, f); - _pack_b(mask.s + 12, g, h); - return mask; -} - -inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, - const v_float32x4& m1, const v_float32x4& m2, - const v_float32x4& m3) -{ - return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + v.s[3]*m3.s[0], - v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + v.s[3]*m3.s[1], - v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + v.s[3]*m3.s[2], - v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + v.s[3]*m3.s[3]); -} - -inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, - const v_float32x4& m1, const v_float32x4& m2, - const v_float32x4& m3) -{ - return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + m3.s[0], - v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + m3.s[1], - v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + m3.s[2], - v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + m3.s[3]); -} - -inline v_reg::nlanes128> -v_load_expand(const float16_t* ptr) -{ - v_reg::nlanes128> v; - for( int i = 0; i < v.nlanes; i++ ) - { - v.s[i] = ptr[i]; - } - return v; -} - -inline void -v_pack_store(float16_t* ptr, const v_reg::nlanes128>& v) -{ - for( int i = 0; i < v.nlanes; i++ ) - { - ptr[i] = float16_t(v.s[i]); - } -} - -inline void v_cleanup() {} -} // namespace fallback +} // namespace static v128_t wasm_unpacklo_i8x16(v128_t a, v128_t b) { return wasm_v8x16_shuffle(a, b, 0,16,1,17,2,18,3,19,4,20,5,21,6,22,7,23); @@ -2554,14 +1176,6 @@ inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ return _Tpvec(intrin(a.val, b.val)); \ } -#define OPENCV_HAL_IMPL_WASM_BIN_FUNC_FALLBACK(_Tpvec, func, intrin) \ -inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ -{ \ - fallback::_Tpvec a_(a); \ - fallback::_Tpvec b_(b); \ - return _Tpvec(fallback::func(a_, b_)); \ -} - OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_float32x4, v_min, wasm_f32x4_min) OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_float32x4, v_max, wasm_f32x4_max) OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_float64x2, v_min, wasm_f64x2_min) @@ -2652,10 +1266,27 @@ OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_uint8x16, v_sub_wrap, wasm_i8x16_sub) OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_int8x16, v_sub_wrap, wasm_i8x16_sub) OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_uint16x8, v_sub_wrap, wasm_i16x8_sub) OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_int16x8, v_sub_wrap, wasm_i16x8_sub) -#if (__EMSCRIPTEN_major__ * 1000000 + __EMSCRIPTEN_minor__ * 1000 + __EMSCRIPTEN_tiny__) >= (2000000) +#if (__EMSCRIPTEN_major__ * 1000000 + __EMSCRIPTEN_minor__ * 1000 + __EMSCRIPTEN_tiny__) >= (1039012) // details: https://github.com/opencv/opencv/issues/18097 ( https://github.com/emscripten-core/emscripten/issues/12018 ) -OPENCV_HAL_IMPL_WASM_BIN_FUNC_FALLBACK(v_uint8x16, v_mul_wrap, wasm_i8x16_mul) -OPENCV_HAL_IMPL_WASM_BIN_FUNC_FALLBACK(v_int8x16, v_mul_wrap, wasm_i8x16_mul) +// 1.39.12: https://github.com/emscripten-core/emscripten/commit/cd801d0f110facfd694212a3c8b2ed2ffcd630e2 +inline v_uint8x16 v_mul_wrap(const v_uint8x16& a, const v_uint8x16& b) +{ + uchar a_[16], b_[16]; + wasm_v128_store(a_, a.val); + wasm_v128_store(b_, b.val); + for (int i = 0; i < 16; i++) + a_[i] = (uchar)(a_[i] * b_[i]); + return v_uint8x16(wasm_v128_load(a_)); +} +inline v_int8x16 v_mul_wrap(const v_int8x16& a, const v_int8x16& b) +{ + schar a_[16], b_[16]; + wasm_v128_store(a_, a.val); + wasm_v128_store(b_, b.val); + for (int i = 0; i < 16; i++) + a_[i] = (schar)(a_[i] * b_[i]); + return v_int8x16(wasm_v128_load(a_)); +} #else OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_uint8x16, v_mul_wrap, wasm_i8x16_mul) OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_int8x16, v_mul_wrap, wasm_i8x16_mul) @@ -2919,13 +1550,17 @@ inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode /*mode*/) \ } \ inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ { \ - fallback::_Tpvec a_(a); \ - fallback::v_store_low(ptr, a_); \ + _Tpvec::lane_type a_[_Tpvec::nlanes]; \ + wasm_v128_store(a_, a.val); \ + for (int i = 0; i < (_Tpvec::nlanes / 2); i++) \ + ptr[i] = a_[i]; \ } \ inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ { \ - fallback::_Tpvec a_(a); \ - fallback::v_store_high(ptr, a_); \ + _Tpvec::lane_type a_[_Tpvec::nlanes]; \ + wasm_v128_store(a_, a.val); \ + for (int i = 0; i < (_Tpvec::nlanes / 2); i++) \ + ptr[i] = a_[i + (_Tpvec::nlanes / 2)]; \ } OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_uint8x16, uchar) @@ -2991,8 +1626,12 @@ OPENCV_HAL_IMPL_WASM_REDUCE_OP_4_SUM(v_float32x4, float, v128_t, f32x4, f32x4) #define OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(_Tpvec, scalartype) \ inline scalartype v_reduce_sum(const _Tpvec& a) \ { \ - fallback::_Tpvec a_(a); \ - return fallback::v_reduce_sum(a_); \ + _Tpvec::lane_type a_[_Tpvec::nlanes]; \ + wasm_v128_store(a_, a.val); \ + scalartype c = a_[0]; \ + for (int i = 1; i < _Tpvec::nlanes; i++) \ + c += a_[i]; \ + return c; \ } OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(v_uint8x16, unsigned) @@ -3116,8 +1755,11 @@ inline v_uint32x4 v_popcount(const v_uint32x4& a) } inline v_uint64x2 v_popcount(const v_uint64x2& a) { - fallback::v_uint64x2 a_(a); - return fallback::v_popcount(a_); + uint64 a_[2], b_[2] = { 0 }; + wasm_v128_store(a_, a.val); + for (int i = 0; i < 16; i++) + b_[i / 8] += popCountTable[((uint8_t*)a_)[i]]; + return v_uint64x2(wasm_v128_load(b_)); } inline v_uint8x16 v_popcount(const v_int8x16& a) { return v_popcount(v_reinterpret_as_u8(a)); } @@ -3131,8 +1773,12 @@ inline v_uint64x2 v_popcount(const v_int64x2& a) #define OPENCV_HAL_IMPL_WASM_CHECK_SIGNS(_Tpvec, suffix, scalarType) \ inline int v_signmask(const _Tpvec& a) \ { \ - fallback::_Tpvec a_(a); \ - return fallback::v_signmask(a_); \ + _Tpvec::lane_type a_[_Tpvec::nlanes]; \ + wasm_v128_store(a_, a.val); \ + int mask = 0; \ + for (int i = 0; i < _Tpvec::nlanes; i++) \ + mask |= (reinterpret_int(a_[i]) < 0) << i; \ + return mask; \ } \ inline bool v_check_all(const _Tpvec& a) \ { return wasm_i8x16_all_true(wasm_##suffix##_lt(a.val, wasm_##suffix##_splat(0))); } \ @@ -3287,22 +1933,35 @@ inline v_int32x4 v_ceil(const v_float32x4& a) inline v_int32x4 v_trunc(const v_float32x4& a) { return v_int32x4(wasm_i32x4_trunc_saturate_f32x4(a.val)); } -#define OPENCV_HAL_IMPL_WASM_MATH_FUNC(func, cfunc, _Tpvec, _Tpnvec, _Tp, _Tpn) \ -inline _Tpnvec func(const _Tpvec& a) \ +#define OPENCV_HAL_IMPL_WASM_MATH_FUNC(func, cfunc) \ +inline v_int32x4 func(const v_float64x2& a) \ { \ - fallback::_Tpvec a_(a); \ - return fallback::func(a_); \ + double a_[2]; \ + wasm_v128_store(a_, a.val); \ + int c_[4]; \ + c_[0] = cfunc(a_[0]); \ + c_[1] = cfunc(a_[1]); \ + c_[2] = 0; \ + c_[3] = 0; \ + return v_int32x4(wasm_v128_load(c_)); \ } -OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_round, cvRound, v_float64x2, v_int32x4, double, int) -OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_floor, cvFloor, v_float64x2, v_int32x4, double, int) -OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_ceil, cvCeil, v_float64x2, v_int32x4, double, int) -OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_trunc, int, v_float64x2, v_int32x4, double, int) +OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_round, cvRound) +OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_floor, cvFloor) +OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_ceil, cvCeil) +OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_trunc, int) inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) { - fallback::v_float64x2 a_(a), b_(b); - return fallback::v_round(a_, b_); + double a_[2], b_[2]; + wasm_v128_store(a_, a.val); + wasm_v128_store(b_, b.val); + int c_[4]; + c_[0] = cvRound(a_[0]); + c_[1] = cvRound(a_[1]); + c_[2] = cvRound(b_[0]); + c_[3] = cvRound(b_[1]); + return v_int32x4(wasm_v128_load(c_)); } #define OPENCV_HAL_IMPL_WASM_TRANSPOSE4x4(_Tpvec, suffix) \ @@ -3796,14 +2455,27 @@ inline v_float32x4 v_cvt_f32(const v_int32x4& a) inline v_float32x4 v_cvt_f32(const v_float64x2& a) { - fallback::v_float64x2 a_(a); - return fallback::v_cvt_f32(a_); + double a_[2]; + wasm_v128_store(a_, a.val); + float c_[4]; + c_[0] = (float)(a_[0]); + c_[1] = (float)(a_[1]); + c_[2] = 0; + c_[3] = 0; + return v_float32x4(wasm_v128_load(c_)); } inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) { - fallback::v_float64x2 a_(a), b_(b); - return fallback::v_cvt_f32(a_, b_); + double a_[2], b_[2]; + wasm_v128_store(a_, a.val); + wasm_v128_store(b_, b.val); + float c_[4]; + c_[0] = (float)(a_[0]); + c_[1] = (float)(a_[1]); + c_[2] = (float)(b_[0]); + c_[3] = (float)(b_[1]); + return v_float32x4(wasm_v128_load(c_)); } inline v_float64x2 v_cvt_f64(const v_int32x4& a) @@ -3812,8 +2484,12 @@ inline v_float64x2 v_cvt_f64(const v_int32x4& a) v128_t p = v128_cvti32x4_i64x2(a.val); return v_float64x2(wasm_f64x2_convert_i64x2(p)); #else - fallback::v_int32x4 a_(a); - return fallback::v_cvt_f64(a_); + int a_[4]; + wasm_v128_store(a_, a.val); + double c_[2]; + c_[0] = (double)(a_[0]); + c_[1] = (double)(a_[1]); + return v_float64x2(wasm_v128_load(c_)); #endif } @@ -3823,21 +2499,33 @@ inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) v128_t p = v128_cvti32x4_i64x2_high(a.val); return v_float64x2(wasm_f64x2_convert_i64x2(p)); #else - fallback::v_int32x4 a_(a); - return fallback::v_cvt_f64_high(a_); + int a_[4]; + wasm_v128_store(a_, a.val); + double c_[2]; + c_[0] = (double)(a_[2]); + c_[1] = (double)(a_[3]); + return v_float64x2(wasm_v128_load(c_)); #endif } inline v_float64x2 v_cvt_f64(const v_float32x4& a) { - fallback::v_float32x4 a_(a); - return fallback::v_cvt_f64(a_); + float a_[4]; + wasm_v128_store(a_, a.val); + double c_[2]; + c_[0] = (double)(a_[0]); + c_[1] = (double)(a_[1]); + return v_float64x2(wasm_v128_load(c_)); } inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) { - fallback::v_float32x4 a_(a); - return fallback::v_cvt_f64_high(a_); + float a_[4]; + wasm_v128_store(a_, a.val); + double c_[2]; + c_[0] = (double)(a_[2]); + c_[1] = (double)(a_[3]); + return v_float64x2(wasm_v128_load(c_)); } inline v_float64x2 v_cvt_f64(const v_int64x2& a) @@ -3845,8 +2533,12 @@ inline v_float64x2 v_cvt_f64(const v_int64x2& a) #ifdef __wasm_unimplemented_simd128__ return v_float64x2(wasm_f64x2_convert_i64x2(a.val)); #else - fallback::v_int64x2 a_(a); - return fallback::v_cvt_f64(a_); + int64 a_[2]; + wasm_v128_store(a_, a.val); + double c_[2]; + c_[0] = (double)(a_[0]); + c_[1] = (double)(a_[1]); + return v_float64x2(wasm_v128_load(c_)); #endif } @@ -4063,13 +2755,20 @@ inline v_float32x4 v_broadcast_element(const v_float32x4& a) inline v_float32x4 v_load_expand(const float16_t* ptr) { - return fallback::v_load_expand(ptr); + float a[4]; + for (int i = 0; i < 4; i++) + a[i] = ptr[i]; + return v_float32x4(wasm_v128_load(a)); } inline void v_pack_store(float16_t* ptr, const v_float32x4& v) { - fallback::v_float32x4 v_(v); - fallback::v_pack_store(ptr, v_); + double v_[4]; + wasm_v128_store(v_, v.val); + ptr[0] = float16_t(v_[0]); + ptr[1] = float16_t(v_[1]); + ptr[2] = float16_t(v_[2]); + ptr[3] = float16_t(v_[3]); } inline void v_cleanup() {} diff --git a/3rdparty/include/opencv2/core/ippasync.hpp b/3rdparty/include/opencv2/core/ippasync.hpp deleted file mode 100644 index c35d8d81a1..0000000000 --- a/3rdparty/include/opencv2/core/ippasync.hpp +++ /dev/null @@ -1,195 +0,0 @@ -/*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-2015, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Copyright (C) 2013, OpenCV Foundation, all rights reserved. -// Copyright (C) 2015, Itseez 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_CORE_IPPASYNC_HPP -#define OPENCV_CORE_IPPASYNC_HPP - -#ifdef HAVE_IPP_A // this file will be removed in OpenCV 4.0 - -#include "opencv2/core.hpp" -#include -#include - -namespace cv -{ - -namespace hpp -{ - -/** @addtogroup core_ipp -This section describes conversion between OpenCV and [Intel® IPP Asynchronous -C/C++](http://software.intel.com/en-us/intel-ipp-preview) library. [Getting Started -Guide](http://registrationcenter.intel.com/irc_nas/3727/ipp_async_get_started.htm) help you to -install the library, configure header and library build paths. - */ -//! @{ - - //! convert OpenCV data type to hppDataType - inline int toHppType(const int cvType) - { - int depth = CV_MAT_DEPTH(cvType); - int hppType = depth == CV_8U ? HPP_DATA_TYPE_8U : - depth == CV_16U ? HPP_DATA_TYPE_16U : - depth == CV_16S ? HPP_DATA_TYPE_16S : - depth == CV_32S ? HPP_DATA_TYPE_32S : - depth == CV_32F ? HPP_DATA_TYPE_32F : - depth == CV_64F ? HPP_DATA_TYPE_64F : -1; - CV_Assert( hppType >= 0 ); - return hppType; - } - - //! convert hppDataType to OpenCV data type - inline int toCvType(const int hppType) - { - int cvType = hppType == HPP_DATA_TYPE_8U ? CV_8U : - hppType == HPP_DATA_TYPE_16U ? CV_16U : - hppType == HPP_DATA_TYPE_16S ? CV_16S : - hppType == HPP_DATA_TYPE_32S ? CV_32S : - hppType == HPP_DATA_TYPE_32F ? CV_32F : - hppType == HPP_DATA_TYPE_64F ? CV_64F : -1; - CV_Assert( cvType >= 0 ); - return cvType; - } - - /** @brief Convert hppiMatrix to Mat. - - This function allocates and initializes new matrix (if needed) that has the same size and type as - input matrix. Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F. - @param src input hppiMatrix. - @param dst output matrix. - @param accel accelerator instance (see hpp::getHpp for the list of acceleration framework types). - @param cn number of channels. - */ - inline void copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn) - { - hppDataType type; - hpp32u width, height; - hppStatus sts; - - if (src == NULL) - return dst.release(); - - sts = hppiInquireMatrix(src, &type, &width, &height); - - CV_Assert( sts == HPP_STATUS_NO_ERROR); - - int matType = CV_MAKETYPE(toCvType(type), cn); - - CV_Assert(width%cn == 0); - - width /= cn; - - dst.create((int)height, (int)width, (int)matType); - - size_t newSize = (size_t)(height*(hpp32u)(dst.step)); - - sts = hppiGetMatrixData(accel,src,(hpp32u)(dst.step),dst.data,&newSize); - - CV_Assert( sts == HPP_STATUS_NO_ERROR); - } - - /** @brief Create Mat from hppiMatrix. - - This function allocates and initializes the Mat that has the same size and type as input matrix. - Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F. - @param src input hppiMatrix. - @param accel accelerator instance (see hpp::getHpp for the list of acceleration framework types). - @param cn number of channels. - @sa howToUseIPPAconversion, hpp::copyHppToMat, hpp::getHpp. - */ - inline Mat getMat(hppiMatrix* src, hppAccel accel, int cn) - { - Mat dst; - copyHppToMat(src, dst, accel, cn); - return dst; - } - - /** @brief Create hppiMatrix from Mat. - - This function allocates and initializes the hppiMatrix that has the same size and type as input - matrix, returns the hppiMatrix*. - - If you want to use zero-copy for GPU you should to have 4KB aligned matrix data. See details - [hppiCreateSharedMatrix](http://software.intel.com/ru-ru/node/501697). - - Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F. - - @note The hppiMatrix pointer to the image buffer in system memory refers to the src.data. Control - the lifetime of the matrix and don't change its data, if there is no special need. - @param src input matrix. - @param accel accelerator instance. Supports type: - - **HPP_ACCEL_TYPE_CPU** - accelerated by optimized CPU instructions. - - **HPP_ACCEL_TYPE_GPU** - accelerated by GPU programmable units or fixed-function - accelerators. - - **HPP_ACCEL_TYPE_ANY** - any acceleration or no acceleration available. - @sa howToUseIPPAconversion, hpp::getMat - */ - inline hppiMatrix* getHpp(const Mat& src, hppAccel accel) - { - int htype = toHppType(src.type()); - int cn = src.channels(); - - CV_Assert(src.data); - hppAccelType accelType = hppQueryAccelType(accel); - - if (accelType!=HPP_ACCEL_TYPE_CPU) - { - hpp32u pitch, size; - hppQueryMatrixAllocParams(accel, src.cols*cn, src.rows, htype, &pitch, &size); - if (pitch!=0 && size!=0) - if ((int)(src.data)%4096==0 && pitch==(hpp32u)(src.step)) - { - return hppiCreateSharedMatrix(htype, src.cols*cn, src.rows, src.data, pitch, size); - } - } - - return hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));; - } - -//! @} -}} - -#endif - -#endif diff --git a/3rdparty/include/opencv2/core/mat.hpp b/3rdparty/include/opencv2/core/mat.hpp index 98f451cf71..6768be7683 100644 --- a/3rdparty/include/opencv2/core/mat.hpp +++ b/3rdparty/include/opencv2/core/mat.hpp @@ -53,9 +53,7 @@ #include "opencv2/core/bufferpool.hpp" -#ifdef CV_CXX11 #include -#endif namespace cv { @@ -63,8 +61,10 @@ namespace cv //! @addtogroup core_basic //! @{ -enum { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, +enum AccessFlag { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, ACCESS_RW=3<<24, ACCESS_MASK=ACCESS_RW, ACCESS_FAST=1<<26 }; +CV_ENUM_FLAGS(AccessFlag) +__CV_ENUM_FLAGS_BITWISE_AND(AccessFlag, int, AccessFlag) CV__DEBUG_NS_BEGIN @@ -158,7 +158,7 @@ Custom type is wrapped as Mat-compatible `CV_8UC` values (N = sizeof(T), N <= class CV_EXPORTS _InputArray { public: - enum { + enum KindFlag { KIND_SHIFT = 16, FIXED_TYPE = 0x8000 << KIND_SHIFT, FIXED_SIZE = 0x4000 << KIND_SHIFT, @@ -170,7 +170,9 @@ public: STD_VECTOR = 3 << KIND_SHIFT, STD_VECTOR_VECTOR = 4 << KIND_SHIFT, STD_VECTOR_MAT = 5 << KIND_SHIFT, - EXPR = 6 << KIND_SHIFT, //!< removed +#if OPENCV_ABI_COMPATIBILITY < 500 + EXPR = 6 << KIND_SHIFT, //!< removed: https://github.com/opencv/opencv/pull/17046 +#endif OPENGL_BUFFER = 7 << KIND_SHIFT, CUDA_HOST_MEM = 8 << KIND_SHIFT, CUDA_GPU_MAT = 9 << KIND_SHIFT, @@ -178,7 +180,9 @@ public: STD_VECTOR_UMAT =11 << KIND_SHIFT, STD_BOOL_VECTOR =12 << KIND_SHIFT, STD_VECTOR_CUDA_GPU_MAT = 13 << KIND_SHIFT, - STD_ARRAY =14 << KIND_SHIFT, +#if OPENCV_ABI_COMPATIBILITY < 500 + STD_ARRAY =14 << KIND_SHIFT, //!< removed: https://github.com/opencv/opencv/issues/18897 +#endif STD_ARRAY_MAT =15 << KIND_SHIFT }; @@ -191,7 +195,7 @@ public: template _InputArray(const std::vector<_Tp>& vec); _InputArray(const std::vector& vec); template _InputArray(const std::vector >& vec); - _InputArray(const std::vector >&); + _InputArray(const std::vector >&) = delete; // not supported template _InputArray(const std::vector >& vec); template _InputArray(const _Tp* vec, int n); template _InputArray(const Matx<_Tp, m, n>& matx); @@ -204,15 +208,11 @@ public: _InputArray(const UMat& um); _InputArray(const std::vector& umv); -#ifdef CV_CXX_STD_ARRAY template _InputArray(const std::array<_Tp, _Nm>& arr); template _InputArray(const std::array& arr); -#endif template static _InputArray rawIn(const std::vector<_Tp>& vec); -#ifdef CV_CXX_STD_ARRAY template static _InputArray rawIn(const std::array<_Tp, _Nm>& arr); -#endif Mat getMat(int idx=-1) const; Mat getMat_(int idx=-1) const; @@ -227,7 +227,7 @@ public: void* getObj() const; Size getSz() const; - int kind() const; + _InputArray::KindFlag kind() const; int dims(int i=-1) const; int cols(int i=-1) const; int rows(int i=-1) const; @@ -263,7 +263,8 @@ protected: void init(int _flags, const void* _obj); void init(int _flags, const void* _obj, Size _sz); }; - +CV_ENUM_FLAGS(_InputArray::KindFlag) +__CV_ENUM_FLAGS_BITWISE_AND(_InputArray::KindFlag, int, _InputArray::KindFlag) /** @brief This type is very similar to InputArray except that it is used for input/output and output function parameters. @@ -293,7 +294,7 @@ generators: class CV_EXPORTS _OutputArray : public _InputArray { public: - enum + enum DepthMask { DEPTH_MASK_8U = 1 << CV_8U, DEPTH_MASK_8S = 1 << CV_8S, @@ -302,8 +303,10 @@ public: DEPTH_MASK_32S = 1 << CV_32S, DEPTH_MASK_32F = 1 << CV_32F, DEPTH_MASK_64F = 1 << CV_64F, + DEPTH_MASK_16F = 1 << CV_16F, DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1, DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S, + DEPTH_MASK_ALL_16F = (DEPTH_MASK_16F<<1)-1, DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F }; @@ -317,9 +320,9 @@ public: _OutputArray(cuda::HostMem& cuda_mem); template _OutputArray(cudev::GpuMat_<_Tp>& m); template _OutputArray(std::vector<_Tp>& vec); - _OutputArray(std::vector& vec); + _OutputArray(std::vector& vec) = delete; // not supported template _OutputArray(std::vector >& vec); - _OutputArray(std::vector >&); + _OutputArray(std::vector >&) = delete; // not supported template _OutputArray(std::vector >& vec); template _OutputArray(Mat_<_Tp>& m); template _OutputArray(_Tp* vec, int n); @@ -343,17 +346,13 @@ public: _OutputArray(const UMat& m); _OutputArray(const std::vector& vec); -#ifdef CV_CXX_STD_ARRAY template _OutputArray(std::array<_Tp, _Nm>& arr); template _OutputArray(const std::array<_Tp, _Nm>& arr); template _OutputArray(std::array& arr); template _OutputArray(const std::array& arr); -#endif template static _OutputArray rawOut(std::vector<_Tp>& vec); -#ifdef CV_CXX_STD_ARRAY template static _OutputArray rawOut(std::array<_Tp, _Nm>& arr); -#endif bool fixedSize() const; bool fixedType() const; @@ -364,9 +363,9 @@ public: std::vector& getGpuMatVecRef() const; ogl::Buffer& getOGlBufferRef() const; cuda::HostMem& getHostMemRef() const; - void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; - void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; - void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; + void create(Size sz, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; void createSameSize(const _InputArray& arr, int mtype) const; void release() const; void clear() const; @@ -395,7 +394,7 @@ public: _InputOutputArray(cuda::HostMem& cuda_mem); template _InputOutputArray(cudev::GpuMat_<_Tp>& m); template _InputOutputArray(std::vector<_Tp>& vec); - _InputOutputArray(std::vector& vec); + _InputOutputArray(std::vector& vec) = delete; // not supported template _InputOutputArray(std::vector >& vec); template _InputOutputArray(std::vector >& vec); template _InputOutputArray(Mat_<_Tp>& m); @@ -420,17 +419,13 @@ public: _InputOutputArray(const UMat& m); _InputOutputArray(const std::vector& vec); -#ifdef CV_CXX_STD_ARRAY template _InputOutputArray(std::array<_Tp, _Nm>& arr); template _InputOutputArray(const std::array<_Tp, _Nm>& arr); template _InputOutputArray(std::array& arr); template _InputOutputArray(const std::array& arr); -#endif template static _InputOutputArray rawInOut(std::vector<_Tp>& vec); -#ifdef CV_CXX_STD_ARRAY template _InputOutputArray rawInOut(std::array<_Tp, _Nm>& arr); -#endif }; @@ -482,10 +477,10 @@ public: // uchar*& datastart, uchar*& data, size_t* step) = 0; //virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0; virtual UMatData* allocate(int dims, const int* sizes, int type, - void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const = 0; - virtual bool allocate(UMatData* data, int accessflags, UMatUsageFlags usageFlags) const = 0; + void* data, size_t* step, AccessFlag flags, UMatUsageFlags usageFlags) const = 0; + virtual bool allocate(UMatData* data, AccessFlag accessflags, UMatUsageFlags usageFlags) const = 0; virtual void deallocate(UMatData* data) const = 0; - virtual void map(UMatData* data, int accessflags) const; + virtual void map(UMatData* data, AccessFlag accessflags) const; virtual void unmap(UMatData* data) const; virtual void download(UMatData* data, void* dst, int dims, const size_t sz[], const size_t srcofs[], const size_t srcstep[], @@ -538,7 +533,7 @@ protected: // it should be explicitly initialized using init(). struct CV_EXPORTS UMatData { - enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2, + enum MemoryFlag { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2, DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24, USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64, ASYNC_CLEANUP=128 @@ -568,35 +563,37 @@ struct CV_EXPORTS UMatData uchar* origdata; size_t size; - int flags; + UMatData::MemoryFlag flags; void* handle; void* userdata; int allocatorFlags_; int mapcount; UMatData* originalUMatData; + std::shared_ptr allocatorContext; }; +CV_ENUM_FLAGS(UMatData::MemoryFlag) struct CV_EXPORTS MatSize { - explicit MatSize(int* _p); - int dims() const; + explicit MatSize(int* _p) CV_NOEXCEPT; + int dims() const CV_NOEXCEPT; Size operator()() const; const int& operator[](int i) const; int& operator[](int i); - operator const int*() const; // TODO OpenCV 4.0: drop this - bool operator == (const MatSize& sz) const; - bool operator != (const MatSize& sz) const; + operator const int*() const CV_NOEXCEPT; // TODO OpenCV 4.0: drop this + bool operator == (const MatSize& sz) const CV_NOEXCEPT; + bool operator != (const MatSize& sz) const CV_NOEXCEPT; int* p; }; struct CV_EXPORTS MatStep { - MatStep(); - explicit MatStep(size_t s); - const size_t& operator[](int i) const; - size_t& operator[](int i); + MatStep() CV_NOEXCEPT; + explicit MatStep(size_t s) CV_NOEXCEPT; + const size_t& operator[](int i) const CV_NOEXCEPT; + size_t& operator[](int i) CV_NOEXCEPT; operator size_t() const; MatStep& operator = (size_t s); @@ -625,12 +622,11 @@ Note that `M.step[i] >= M.step[i+1]` (in fact, `M.step[i] >= M.step[i+1]*M.size[ that 2-dimensional matrices are stored row-by-row, 3-dimensional matrices are stored plane-by-plane, and so on. M.step[M.dims-1] is minimal and always equal to the element size M.elemSize() . -So, the data layout in Mat is fully compatible with CvMat, IplImage, and CvMatND types from OpenCV -1.x. It is also compatible with the majority of dense array types from the standard toolkits and -SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, that is, with any -array that uses *steps* (or *strides*) to compute the position of a pixel. Due to this -compatibility, it is possible to make a Mat header for user-allocated data and process it in-place -using OpenCV functions. +So, the data layout in Mat is compatible with the majority of dense array types from the standard +toolkits and SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, +that is, with any array that uses *steps* (or *strides*) to compute the position of a pixel. +Due to this compatibility, it is possible to make a Mat header for user-allocated data and process +it in-place using OpenCV functions. There are many different ways to create a Mat object. The most popular options are listed below: @@ -720,10 +716,6 @@ sub-matrices. Mat M = Mat(3, 3, CV_64F, m).inv(); @endcode . - Partial yet very common cases of this *user-allocated data* case are conversions from CvMat and - IplImage to Mat. For this purpose, there is function cv::cvarrToMat taking pointers to CvMat or - IplImage and the optional flag indicating whether to copy the data or not. - @snippet samples/cpp/image.cpp iplimage - Use MATLAB-style array initializers, zeros(), ones(), eye(), for example: @code @@ -815,7 +807,7 @@ public: The constructed matrix can further be assigned to another matrix or matrix expression or can be allocated with Mat::create . In the former case, the old content is de-referenced. */ - Mat(); + Mat() CV_NOEXCEPT; /** @overload @param rows Number of rows in a 2D array. @@ -1022,7 +1014,6 @@ public: */ template explicit Mat(const std::vector<_Tp>& vec, bool copyData=false); -#ifdef CV_CXX11 /** @overload */ template::value>::type> @@ -1031,13 +1022,10 @@ public: /** @overload */ template explicit Mat(const std::initializer_list sizes, const std::initializer_list<_Tp> list); -#endif -#ifdef CV_CXX_STD_ARRAY /** @overload */ template explicit Mat(const std::array<_Tp, _Nm>& arr, bool copyData=false); -#endif /** @overload */ @@ -1085,7 +1073,7 @@ public: Mat& operator = (const MatExpr& expr); //! retrieve UMat from Mat - UMat getUMat(int accessFlags, UMatUsageFlags usageFlags = USAGE_DEFAULT) const; + UMat getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags = USAGE_DEFAULT) const; /** @brief Creates a matrix header for the specified matrix row. @@ -1661,20 +1649,11 @@ public: */ Mat operator()(const std::vector& ranges) const; - // //! converts header to CvMat; no data is copied - // operator CvMat() const; - // //! converts header to CvMatND; no data is copied - // operator CvMatND() const; - // //! converts header to IplImage; no data is copied - // operator IplImage() const; - template operator std::vector<_Tp>() const; template operator Vec<_Tp, n>() const; template operator Matx<_Tp, m, n>() const; -#ifdef CV_CXX_STD_ARRAY template operator std::array<_Tp, _Nm>() const; -#endif /** @brief Reports whether the matrix is continuous or not. @@ -2032,6 +2011,11 @@ public: template MatIterator_<_Tp> begin(); template MatConstIterator_<_Tp> begin() const; + /** @brief Same as begin() but for inverse traversal + */ + template std::reverse_iterator> rbegin(); + template std::reverse_iterator> rbegin() const; + /** @brief Returns the matrix iterator and sets it to the after-last matrix element. The methods return the matrix read-only or read-write iterators, set to the point following the last @@ -2040,6 +2024,12 @@ public: template MatIterator_<_Tp> end(); template MatConstIterator_<_Tp> end() const; + /** @brief Same as end() but for inverse traversal + */ + template std::reverse_iterator< MatIterator_<_Tp>> rend(); + template std::reverse_iterator< MatConstIterator_<_Tp>> rend() const; + + /** @brief Runs the given functor over all matrix elements in parallel. The operation passed as argument has to be a function pointer, a function object or a lambda(C++11). @@ -2098,10 +2088,8 @@ public: /** @overload */ template void forEach(const Functor& operation) const; -#ifdef CV_CXX_MOVE_SEMANTICS Mat(Mat&& m); Mat& operator = (Mat&& m); -#endif enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 }; @@ -2216,7 +2204,7 @@ public: typedef MatConstIterator_<_Tp> const_iterator; //! default constructor - Mat_(); + Mat_() CV_NOEXCEPT; //! equivalent to Mat(_rows, _cols, DataType<_Tp>::type) Mat_(int _rows, int _cols); //! constructor that sets each matrix element to specified value @@ -2255,14 +2243,10 @@ public: explicit Mat_(const Point3_::channel_type>& pt, bool copyData=true); explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer); -#ifdef CV_CXX11 Mat_(std::initializer_list<_Tp> values); explicit Mat_(const std::initializer_list sizes, const std::initializer_list<_Tp> values); -#endif -#ifdef CV_CXX_STD_ARRAY template explicit Mat_(const std::array<_Tp, _Nm>& arr, bool copyData=false); -#endif Mat_& operator = (const Mat& m); Mat_& operator = (const Mat_& m); @@ -2277,6 +2261,12 @@ public: const_iterator begin() const; const_iterator end() const; + //reverse iterators + std::reverse_iterator rbegin(); + std::reverse_iterator rend(); + std::reverse_iterator rbegin() const; + std::reverse_iterator rend() const; + //! template methods for for operation over all matrix elements. // the operations take care of skipping gaps in the end of rows (if any) template void forEach(const Functor& operation); @@ -2360,17 +2350,14 @@ public: //! conversion to vector. operator std::vector<_Tp>() const; -#ifdef CV_CXX_STD_ARRAY //! conversion to array. template operator std::array<_Tp, _Nm>() const; -#endif //! conversion to Vec template operator Vec::channel_type, n>() const; //! conversion to Matx template operator Matx::channel_type, m, n>() const; -#ifdef CV_CXX_MOVE_SEMANTICS Mat_(Mat_&& m); Mat_& operator = (Mat_&& m); @@ -2378,7 +2365,6 @@ public: Mat_& operator = (Mat&& m); Mat_(MatExpr&& e); -#endif }; typedef Mat_ Mat1b; @@ -2416,7 +2402,7 @@ class CV_EXPORTS UMat { public: //! default constructor - UMat(UMatUsageFlags usageFlags = USAGE_DEFAULT); + UMat(UMatUsageFlags usageFlags = USAGE_DEFAULT) CV_NOEXCEPT; //! constructs 2D matrix of the specified size and type // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.) UMat(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); @@ -2447,7 +2433,7 @@ public: //! assignment operators UMat& operator = (const UMat& m); - Mat getMat(int flags) const; + Mat getMat(AccessFlag flags) const; //! returns a new matrix header for the specified row UMat row(int y) const; @@ -2465,7 +2451,8 @@ public: //! <0 - a diagonal from the lower half) UMat diag(int d=0) const; //! constructs a square diagonal matrix which main diagonal is vector "d" - static UMat diag(const UMat& d); + static UMat diag(const UMat& d, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); + static UMat diag(const UMat& d) { return diag(d, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload //! returns deep copy of the matrix, i.e. the data is copied UMat clone() const CV_NODISCARD; @@ -2499,14 +2486,22 @@ public: double dot(InputArray m) const; //! Matlab-style matrix initialization - static UMat zeros(int rows, int cols, int type); - static UMat zeros(Size size, int type); - static UMat zeros(int ndims, const int* sz, int type); - static UMat ones(int rows, int cols, int type); - static UMat ones(Size size, int type); - static UMat ones(int ndims, const int* sz, int type); - static UMat eye(int rows, int cols, int type); - static UMat eye(Size size, int type); + static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); + static UMat zeros(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); + static UMat zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); + static UMat zeros(int rows, int cols, int type) { return zeros(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload + static UMat zeros(Size size, int type) { return zeros(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload + static UMat zeros(int ndims, const int* sz, int type) { return zeros(ndims, sz, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload + static UMat ones(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); + static UMat ones(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); + static UMat ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); + static UMat ones(int rows, int cols, int type) { return ones(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload + static UMat ones(Size size, int type) { return ones(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload + static UMat ones(int ndims, const int* sz, int type) { return ones(ndims, sz, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload + static UMat eye(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); + static UMat eye(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/); + static UMat eye(int rows, int cols, int type) { return eye(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload + static UMat eye(Size size, int type) { return eye(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload //! allocates new matrix data unless the matrix already has specified size and type. // previous data is unreferenced if needed. @@ -2566,16 +2561,14 @@ public: //! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const; -#ifdef CV_CXX_MOVE_SEMANTICS UMat(UMat&& m); UMat& operator = (UMat&& m); -#endif /*! Returns the OpenCL buffer handle on which UMat operates on. The UMat instance should be kept alive during the use of the handle to prevent the buffer to be returned to the OpenCV buffer pool. */ - void* handle(int accessFlags) const; + void* handle(AccessFlag accessFlags) const; void ndoffset(size_t* ofs) const; enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; @@ -2588,27 +2581,38 @@ public: - number of channels */ int flags; + //! the matrix dimensionality, >= 2 int dims; - //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions - int rows, cols; + + //! number of rows in the matrix; -1 when the matrix has more than 2 dimensions + int rows; + + //! number of columns in the matrix; -1 when the matrix has more than 2 dimensions + int cols; //! custom allocator MatAllocator* allocator; - UMatUsageFlags usageFlags; // usage flags for allocator + + //! usage flags for allocator; recommend do not set directly, instead set during construct/create/getUMat + UMatUsageFlags usageFlags; + //! and the standard allocator static MatAllocator* getStdAllocator(); //! internal use method: updates the continuity flag void updateContinuityFlag(); - // black-box container of UMat data + //! black-box container of UMat data UMatData* u; - // offset of the submatrix (or 0) + //! offset of the submatrix (or 0) size_t offset; + //! dimensional size of the matrix; accessible in various formats MatSize size; + + //! number of bytes each matrix element/row/plane/dimension occupies MatStep step; protected: diff --git a/3rdparty/include/opencv2/core/mat.inl.hpp b/3rdparty/include/opencv2/core/mat.inl.hpp index b6ffd81795..886b82c6a0 100644 --- a/3rdparty/include/opencv2/core/mat.inl.hpp +++ b/3rdparty/include/opencv2/core/mat.inl.hpp @@ -98,7 +98,7 @@ inline void* _InputArray::getObj() const { return obj; } inline int _InputArray::getFlags() const { return flags; } inline Size _InputArray::getSz() const { return sz; } -inline _InputArray::_InputArray() { init(NONE, 0); } +inline _InputArray::_InputArray() { init(0 + NONE, 0); } inline _InputArray::_InputArray(int _flags, void* _obj) { init(_flags, _obj); } inline _InputArray::_InputArray(const Mat& m) { init(MAT+ACCESS_READ, &m); } inline _InputArray::_InputArray(const std::vector& vec) { init(STD_VECTOR_MAT+ACCESS_READ, &vec); } @@ -109,15 +109,13 @@ template inline _InputArray::_InputArray(const std::vector<_Tp>& vec) { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _InputArray::_InputArray(const std::array<_Tp, _Nm>& arr) -{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); } template inline _InputArray::_InputArray(const std::array& arr) { init(STD_ARRAY_MAT + ACCESS_READ, arr.data(), Size(1, _Nm)); } -#endif inline _InputArray::_InputArray(const std::vector& vec) @@ -127,10 +125,6 @@ template inline _InputArray::_InputArray(const std::vector >& vec) { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } -inline -_InputArray::_InputArray(const std::vector >&) -{ CV_Error(Error::StsUnsupportedFormat, "std::vector > is not supported!\n"); } - template inline _InputArray::_InputArray(const std::vector >& vec) { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_READ, &vec); } @@ -171,17 +165,15 @@ _InputArray _InputArray::rawIn(const std::vector<_Tp>& vec) return v; } -#ifdef CV_CXX_STD_ARRAY template inline _InputArray _InputArray::rawIn(const std::array<_Tp, _Nm>& arr) { _InputArray v; - v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ; + v.flags = FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ; v.obj = (void*)arr.data(); v.sz = Size(1, _Nm); return v; } -#endif inline _InputArray::~_InputArray() {} @@ -199,45 +191,35 @@ inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::S inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; } inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR || kind() == _InputArray::STD_BOOL_VECTOR || - kind() == _InputArray::STD_ARRAY; } + (kind() == _InputArray::MATX && (sz.width <= 1 || sz.height <= 1)); } inline bool _InputArray::isGpuMat() const { return kind() == _InputArray::CUDA_GPU_MAT; } inline bool _InputArray::isGpuMatVector() const { return kind() == _InputArray::STD_VECTOR_CUDA_GPU_MAT; } //////////////////////////////////////////////////////////////////////////////////////// -inline _OutputArray::_OutputArray() { init(ACCESS_WRITE, 0); } -inline _OutputArray::_OutputArray(int _flags, void* _obj) { init(_flags|ACCESS_WRITE, _obj); } +inline _OutputArray::_OutputArray() { init(NONE + ACCESS_WRITE, 0); } +inline _OutputArray::_OutputArray(int _flags, void* _obj) { init(_flags + ACCESS_WRITE, _obj); } inline _OutputArray::_OutputArray(Mat& m) { init(MAT+ACCESS_WRITE, &m); } -inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_MAT+ACCESS_WRITE, &vec); } -inline _OutputArray::_OutputArray(UMat& m) { init(UMAT+ACCESS_WRITE, &m); } -inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_UMAT+ACCESS_WRITE, &vec); } +inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_MAT + ACCESS_WRITE, &vec); } +inline _OutputArray::_OutputArray(UMat& m) { init(UMAT + ACCESS_WRITE, &m); } +inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_UMAT + ACCESS_WRITE, &vec); } template inline _OutputArray::_OutputArray(std::vector<_Tp>& vec) { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr) -{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } template inline _OutputArray::_OutputArray(std::array& arr) { init(STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } -#endif - -inline -_OutputArray::_OutputArray(std::vector&) -{ CV_Error(Error::StsUnsupportedFormat, "std::vector cannot be an output array\n"); } template inline _OutputArray::_OutputArray(std::vector >& vec) { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } -inline -_OutputArray::_OutputArray(std::vector >&) -{ CV_Error(Error::StsUnsupportedFormat, "std::vector > cannot be an output array\n"); } - template inline _OutputArray::_OutputArray(std::vector >& vec) { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } @@ -258,15 +240,13 @@ template inline _OutputArray::_OutputArray(const std::vector<_Tp>& vec) { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr) -{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } template inline _OutputArray::_OutputArray(const std::array& arr) { init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } -#endif template inline _OutputArray::_OutputArray(const std::vector >& vec) @@ -331,22 +311,20 @@ _OutputArray _OutputArray::rawOut(std::vector<_Tp>& vec) return v; } -#ifdef CV_CXX_STD_ARRAY template inline _OutputArray _OutputArray::rawOut(std::array<_Tp, _Nm>& arr) { _OutputArray v; - v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE; + v.flags = FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE; v.obj = (void*)arr.data(); v.sz = Size(1, _Nm); return v; } -#endif /////////////////////////////////////////////////////////////////////////////////////////// -inline _InputOutputArray::_InputOutputArray() { init(ACCESS_RW, 0); } -inline _InputOutputArray::_InputOutputArray(int _flags, void* _obj) { init(_flags|ACCESS_RW, _obj); } +inline _InputOutputArray::_InputOutputArray() { init(0+ACCESS_RW, 0); } +inline _InputOutputArray::_InputOutputArray(int _flags, void* _obj) { init(_flags+ACCESS_RW, _obj); } inline _InputOutputArray::_InputOutputArray(Mat& m) { init(MAT+ACCESS_RW, &m); } inline _InputOutputArray::_InputOutputArray(std::vector& vec) { init(STD_VECTOR_MAT+ACCESS_RW, &vec); } inline _InputOutputArray::_InputOutputArray(UMat& m) { init(UMAT+ACCESS_RW, &m); } @@ -356,18 +334,13 @@ template inline _InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec) { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr) -{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } template inline _InputOutputArray::_InputOutputArray(std::array& arr) { init(STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } -#endif - -inline _InputOutputArray::_InputOutputArray(std::vector&) -{ CV_Error(Error::StsUnsupportedFormat, "std::vector cannot be an input/output array\n"); } template inline _InputOutputArray::_InputOutputArray(std::vector >& vec) @@ -393,15 +366,13 @@ template inline _InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec) { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr) -{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } template inline _InputOutputArray::_InputOutputArray(const std::array& arr) { init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } -#endif template inline _InputOutputArray::_InputOutputArray(const std::vector >& vec) @@ -468,17 +439,15 @@ _InputOutputArray _InputOutputArray::rawInOut(std::vector<_Tp>& vec) return v; } -#ifdef CV_CXX_STD_ARRAY template inline _InputOutputArray _InputOutputArray::rawInOut(std::array<_Tp, _Nm>& arr) { _InputOutputArray v; - v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW; + v.flags = FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW; v.obj = (void*)arr.data(); v.sz = Size(1, _Nm); return v; } -#endif template static inline _InputArray rawIn(_Tp& v) { return _InputArray::rawIn(v); } @@ -491,7 +460,7 @@ CV__DEBUG_NS_END template inline Mat::Mat(const std::vector<_Tp>& vec, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if(vec.empty()) @@ -506,7 +475,6 @@ Mat::Mat(const std::vector<_Tp>& vec, bool copyData) Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); } -#ifdef CV_CXX11 template inline Mat::Mat(const std::initializer_list<_Tp> list) : Mat() @@ -526,12 +494,10 @@ Mat::Mat(const std::initializer_list sizes, const std::initializer_list<_Tp CV_Assert(size_total == list.size()); Mat((int)sizes.size(), (int*)sizes.begin(), traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this); } -#endif -#ifdef CV_CXX_STD_ARRAY template inline Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()), + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()), cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if(arr.empty()) @@ -545,11 +511,10 @@ Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) else Mat((int)arr.size(), 1, traits::Type<_Tp>::value, (uchar*)arr.data()).copyTo(*this); } -#endif template inline Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0), + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if( !copyData ) @@ -565,7 +530,7 @@ Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) template inline Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0), + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if( !copyData ) @@ -581,7 +546,7 @@ Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) template inline Mat::Mat(const Point_<_Tp>& pt, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0), + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if( !copyData ) @@ -600,7 +565,7 @@ Mat::Mat(const Point_<_Tp>& pt, bool copyData) template inline Mat::Mat(const Point3_<_Tp>& pt, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0), + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if( !copyData ) @@ -620,7 +585,7 @@ Mat::Mat(const Point3_<_Tp>& pt, bool copyData) template inline Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0), + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), allocator(0), u(0), size(&rows) { *this = commaInitializer.operator Mat_<_Tp>(); @@ -898,6 +863,33 @@ const _Tp* Mat::ptr(const int* idx) const return (const _Tp*)p; } +template inline +uchar* Mat::ptr(const Vec& idx) +{ + return Mat::ptr(idx.val); +} + +template inline +const uchar* Mat::ptr(const Vec& idx) const +{ + return Mat::ptr(idx.val); +} + +template inline +_Tp* Mat::ptr(const Vec& idx) +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return Mat::ptr<_Tp>(idx.val); +} + +template inline +const _Tp* Mat::ptr(const Vec& idx) const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return Mat::ptr<_Tp>(idx.val); +} + + template inline _Tp& Mat::at(int i0, int i1) { @@ -1023,6 +1015,17 @@ MatConstIterator_<_Tp> Mat::begin() const return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this); } +template inline +std::reverse_iterator> Mat::rbegin() const +{ + if (empty()) + return std::reverse_iterator>(); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + MatConstIterator_<_Tp> it((const Mat_<_Tp>*)this); + it += total(); + return std::reverse_iterator> (it); +} + template inline MatConstIterator_<_Tp> Mat::end() const { @@ -1034,6 +1037,15 @@ MatConstIterator_<_Tp> Mat::end() const return it; } +template inline +std::reverse_iterator> Mat::rend() const +{ + if (empty()) + return std::reverse_iterator>(); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return std::reverse_iterator>((const Mat_<_Tp>*)this); +} + template inline MatIterator_<_Tp> Mat::begin() { @@ -1043,6 +1055,17 @@ MatIterator_<_Tp> Mat::begin() return MatIterator_<_Tp>((Mat_<_Tp>*)this); } +template inline +std::reverse_iterator> Mat::rbegin() +{ + if (empty()) + return std::reverse_iterator>(); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + MatIterator_<_Tp> it((Mat_<_Tp>*)this); + it += total(); + return std::reverse_iterator>(it); +} + template inline MatIterator_<_Tp> Mat::end() { @@ -1054,6 +1077,15 @@ MatIterator_<_Tp> Mat::end() return it; } +template inline +std::reverse_iterator> Mat::rend() +{ + if (empty()) + return std::reverse_iterator>(); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return std::reverse_iterator>(MatIterator_<_Tp>((Mat_<_Tp>*)this)); +} + template inline void Mat::forEach(const Functor& operation) { this->forEach_impl<_Tp>(operation); @@ -1073,7 +1105,6 @@ Mat::operator std::vector<_Tp>() const return v; } -#ifdef CV_CXX_STD_ARRAY template inline Mat::operator std::array<_Tp, _Nm>() const { @@ -1081,7 +1112,6 @@ Mat::operator std::array<_Tp, _Nm>() const copyTo(v); return v; } -#endif template inline Mat::operator Vec<_Tp, n>() const @@ -1149,80 +1179,15 @@ void Mat::push_back(const std::vector<_Tp>& v) push_back(Mat(v)); } -#ifdef CV_CXX_MOVE_SEMANTICS - -inline -Mat::Mat(Mat&& m) - : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), - datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), - u(m.u), size(&rows) -{ - if (m.dims <= 2) // move new step/size info - { - step[0] = m.step[0]; - step[1] = m.step[1]; - } - else - { - CV_DbgAssert(m.step.p != m.step.buf); - step.p = m.step.p; - size.p = m.size.p; - m.step.p = m.step.buf; - m.size.p = &m.rows; - } - m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; - m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; - m.allocator = NULL; - m.u = NULL; -} - -inline -Mat& Mat::operator = (Mat&& m) -{ - if (this == &m) - return *this; - - release(); - flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; data = m.data; - datastart = m.datastart; dataend = m.dataend; datalimit = m.datalimit; allocator = m.allocator; - u = m.u; - if (step.p != step.buf) // release self step/size - { - fastFree(step.p); - step.p = step.buf; - size.p = &rows; - } - if (m.dims <= 2) // move new step/size info - { - step[0] = m.step[0]; - step[1] = m.step[1]; - } - else - { - CV_DbgAssert(m.step.p != m.step.buf); - step.p = m.step.p; - size.p = m.size.p; - m.step.p = m.step.buf; - m.size.p = &m.rows; - } - m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; - m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; - m.allocator = NULL; - m.u = NULL; - return *this; -} - -#endif - ///////////////////////////// MatSize //////////////////////////// inline -MatSize::MatSize(int* _p) +MatSize::MatSize(int* _p) CV_NOEXCEPT : p(_p) {} inline -int MatSize::dims() const +int MatSize::dims() const CV_NOEXCEPT { return (p - 1)[0]; } @@ -1255,13 +1220,13 @@ int& MatSize::operator[](int i) } inline -MatSize::operator const int*() const +MatSize::operator const int*() const CV_NOEXCEPT { return p; } inline -bool MatSize::operator != (const MatSize& sz) const +bool MatSize::operator != (const MatSize& sz) const CV_NOEXCEPT { return !(*this == sz); } @@ -1271,25 +1236,25 @@ bool MatSize::operator != (const MatSize& sz) const ///////////////////////////// MatStep //////////////////////////// inline -MatStep::MatStep() +MatStep::MatStep() CV_NOEXCEPT { p = buf; p[0] = p[1] = 0; } inline -MatStep::MatStep(size_t s) +MatStep::MatStep(size_t s) CV_NOEXCEPT { p = buf; p[0] = s; p[1] = 0; } inline -const size_t& MatStep::operator[](int i) const +const size_t& MatStep::operator[](int i) const CV_NOEXCEPT { return p[i]; } inline -size_t& MatStep::operator[](int i) +size_t& MatStep::operator[](int i) CV_NOEXCEPT { return p[i]; } @@ -1312,10 +1277,10 @@ inline MatStep& MatStep::operator = (size_t s) ////////////////////////////// Mat_<_Tp> //////////////////////////// template inline -Mat_<_Tp>::Mat_() +Mat_<_Tp>::Mat_() CV_NOEXCEPT : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; } template inline @@ -1372,7 +1337,7 @@ template inline Mat_<_Tp>::Mat_(const Mat& m) : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; *this = m; } @@ -1442,7 +1407,6 @@ Mat_<_Tp>::Mat_(const std::vector<_Tp>& vec, bool copyData) : Mat(vec, copyData) {} -#ifdef CV_CXX11 template inline Mat_<_Tp>::Mat_(std::initializer_list<_Tp> list) : Mat(list) @@ -1452,14 +1416,11 @@ template inline Mat_<_Tp>::Mat_(const std::initializer_list sizes, std::initializer_list<_Tp> list) : Mat(sizes, list) {} -#endif -#ifdef CV_CXX_STD_ARRAY template template inline Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData) : Mat(arr, copyData) {} -#endif template inline Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m) @@ -1520,7 +1481,7 @@ template inline void Mat_<_Tp>::release() { Mat::release(); - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; } template inline @@ -1750,7 +1711,6 @@ Mat_<_Tp>::operator std::vector<_Tp>() const return v; } -#ifdef CV_CXX_STD_ARRAY template template inline Mat_<_Tp>::operator std::array<_Tp, _Nm>() const { @@ -1758,7 +1718,6 @@ Mat_<_Tp>::operator std::array<_Tp, _Nm>() const copyTo(a); return a; } -#endif template template inline Mat_<_Tp>::operator Vec::channel_type, n>() const @@ -1794,24 +1753,48 @@ MatConstIterator_<_Tp> Mat_<_Tp>::begin() const return Mat::begin<_Tp>(); } +template inline +std::reverse_iterator> Mat_<_Tp>::rbegin() const +{ + return Mat::rbegin<_Tp>(); +} + template inline MatConstIterator_<_Tp> Mat_<_Tp>::end() const { return Mat::end<_Tp>(); } +template inline +std::reverse_iterator> Mat_<_Tp>::rend() const +{ + return Mat::rend<_Tp>(); +} + template inline MatIterator_<_Tp> Mat_<_Tp>::begin() { return Mat::begin<_Tp>(); } +template inline +std::reverse_iterator> Mat_<_Tp>::rbegin() +{ + return Mat::rbegin<_Tp>(); +} + template inline MatIterator_<_Tp> Mat_<_Tp>::end() { return Mat::end<_Tp>(); } +template inline +std::reverse_iterator> Mat_<_Tp>::rend() +{ + return Mat::rend<_Tp>(); +} + template template inline void Mat_<_Tp>::forEach(const Functor& operation) { Mat::forEach<_Tp, Functor>(operation); @@ -1822,8 +1805,6 @@ void Mat_<_Tp>::forEach(const Functor& operation) const { Mat::forEach<_Tp, Functor>(operation); } -#ifdef CV_CXX_MOVE_SEMANTICS - template inline Mat_<_Tp>::Mat_(Mat_&& m) : Mat(std::move(m)) @@ -1841,7 +1822,7 @@ template inline Mat_<_Tp>::Mat_(Mat&& m) : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; *this = std::move(m); } @@ -1872,11 +1853,10 @@ template inline Mat_<_Tp>::Mat_(MatExpr&& e) : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; *this = Mat(e); } -#endif ///////////////////////////// SparseMat ///////////////////////////// @@ -2110,7 +2090,7 @@ SparseMatConstIterator_<_Tp> SparseMat::end() const template inline SparseMat_<_Tp>::SparseMat_() { - flags = MAGIC_VAL | traits::Type<_Tp>::value; + flags = MAGIC_VAL + traits::Type<_Tp>::value; } template inline @@ -3268,7 +3248,7 @@ const Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b) template inline UMat::UMat(const std::vector<_Tp>& vec, bool copyData) -: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), +: flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) { if(vec.empty()) @@ -3392,70 +3372,6 @@ size_t UMat::step1(int i) const return step.p[i] / elemSize1(); } -#ifdef CV_CXX_MOVE_SEMANTICS - -inline -UMat::UMat(UMat&& m) -: flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), - usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows) -{ - if (m.dims <= 2) // move new step/size info - { - step[0] = m.step[0]; - step[1] = m.step[1]; - } - else - { - CV_DbgAssert(m.step.p != m.step.buf); - step.p = m.step.p; - size.p = m.size.p; - m.step.p = m.step.buf; - m.size.p = &m.rows; - } - m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; - m.allocator = NULL; - m.u = NULL; - m.offset = 0; -} - -inline -UMat& UMat::operator = (UMat&& m) -{ - if (this == &m) - return *this; - release(); - flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; - allocator = m.allocator; usageFlags = m.usageFlags; - u = m.u; - offset = m.offset; - if (step.p != step.buf) // release self step/size - { - fastFree(step.p); - step.p = step.buf; - size.p = &rows; - } - if (m.dims <= 2) // move new step/size info - { - step[0] = m.step[0]; - step[1] = m.step[1]; - } - else - { - CV_DbgAssert(m.step.p != m.step.buf); - step.p = m.step.p; - size.p = m.size.p; - m.step.p = m.step.buf; - m.size.p = &m.rows; - } - m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; - m.allocator = NULL; - m.u = NULL; - m.offset = 0; - return *this; -} - -#endif - inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; } inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; } diff --git a/3rdparty/include/opencv2/core/matx.hpp b/3rdparty/include/opencv2/core/matx.hpp index 733f675192..45d8a97f34 100644 --- a/3rdparty/include/opencv2/core/matx.hpp +++ b/3rdparty/include/opencv2/core/matx.hpp @@ -53,9 +53,7 @@ #include "opencv2/core/traits.hpp" #include "opencv2/core/saturate.hpp" -#ifdef CV_CXX11 #include -#endif namespace cv { @@ -142,9 +140,7 @@ public: _Tp v12, _Tp v13, _Tp v14, _Tp v15); //!< 1x16, 4x4 or 16x1 matrix explicit Matx(const _Tp* vals); //!< initialize from a plain array -#ifdef CV_CXX11 Matx(std::initializer_list<_Tp>); //!< initialize from an initializer list -#endif static Matx all(_Tp alpha); static Matx zeros(); @@ -371,9 +367,7 @@ public: Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13); //!< 14-element vector constructor explicit Vec(const _Tp* values); -#ifdef CV_CXX11 Vec(std::initializer_list<_Tp>); -#endif Vec(const Vec<_Tp, cn>& v); @@ -679,7 +673,6 @@ Matx<_Tp, m, n>::Matx(const _Tp* values) for( int i = 0; i < channels; i++ ) val[i] = values[i]; } -#ifdef CV_CXX11 template inline Matx<_Tp, m, n>::Matx(std::initializer_list<_Tp> list) { @@ -690,7 +683,6 @@ Matx<_Tp, m, n>::Matx(std::initializer_list<_Tp> list) val[i++] = elem; } } -#endif template inline Matx<_Tp, m, n> Matx<_Tp, m, n>::all(_Tp alpha) @@ -1033,11 +1025,9 @@ template inline Vec<_Tp, cn>::Vec(const _Tp* values) : Matx<_Tp, cn, 1>(values) {} -#ifdef CV_CXX11 template inline Vec<_Tp, cn>::Vec(std::initializer_list<_Tp> list) : Matx<_Tp, cn, 1>(list) {} -#endif template inline Vec<_Tp, cn>::Vec(const Vec<_Tp, cn>& m) diff --git a/3rdparty/include/opencv2/core/ocl.hpp b/3rdparty/include/opencv2/core/ocl.hpp index ca46cdc38a..f9cc9e019a 100644 --- a/3rdparty/include/opencv2/core/ocl.hpp +++ b/3rdparty/include/opencv2/core/ocl.hpp @@ -43,6 +43,8 @@ #define OPENCV_OPENCL_HPP #include "opencv2/core.hpp" +#include +#include namespace cv { namespace ocl { @@ -70,10 +72,12 @@ class CV_EXPORTS Image2D; class CV_EXPORTS_W_SIMPLE Device { public: - CV_WRAP Device(); + CV_WRAP Device() CV_NOEXCEPT; explicit Device(void* d); Device(const Device& d); Device& operator = (const Device& d); + Device(Device&& d) CV_NOEXCEPT; + Device& operator = (Device&& d) CV_NOEXCEPT; CV_WRAP ~Device(); void set(void* d); @@ -229,8 +233,15 @@ public: CV_WRAP static const Device& getDefault(); -protected: + /** + * @param d OpenCL handle (cl_device_id). clRetainDevice() is called on success. + */ + static Device fromHandle(void* d); + struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } + inline bool empty() const { return !p; } +protected: Impl* p; }; @@ -238,48 +249,98 @@ protected: class CV_EXPORTS Context { public: - Context(); - explicit Context(int dtype); + Context() CV_NOEXCEPT; + explicit Context(int dtype); //!< @deprecated ~Context(); Context(const Context& c); - Context& operator = (const Context& c); + Context& operator= (const Context& c); + Context(Context&& c) CV_NOEXCEPT; + Context& operator = (Context&& c) CV_NOEXCEPT; + /** @deprecated */ bool create(); + /** @deprecated */ bool create(int dtype); + size_t ndevices() const; - const Device& device(size_t idx) const; + Device& device(size_t idx) const; Program getProg(const ProgramSource& prog, const String& buildopt, String& errmsg); void unloadProg(Program& prog); + + /** Get thread-local OpenCL context (initialize if necessary) */ +#if 0 // OpenCV 5.0 + static Context& getDefault(); +#else static Context& getDefault(bool initialize = true); +#endif + + /** @returns cl_context value */ void* ptr() const; - friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); + /** + * @brief Get OpenCL context property specified on context creation + * @param propertyId Property id (CL_CONTEXT_* as defined in cl_context_properties type) + * @returns Property value if property was specified on clCreateContext, or NULL if context created without the property + */ + void* getOpenCLContextProperty(int propertyId) const; bool useSVM() const; void setUseSVM(bool enabled); + /** + * @param context OpenCL handle (cl_context). clRetainContext() is called on success + */ + static Context fromHandle(void* context); + static Context fromDevice(const ocl::Device& device); + static Context create(const std::string& configuration); + + void release(); + + class CV_EXPORTS UserContext { + public: + virtual ~UserContext(); + }; + template + inline void setUserContext(const std::shared_ptr& userContext) { + setUserContext(typeid(T), userContext); + } + template + inline std::shared_ptr getUserContext() { + return std::dynamic_pointer_cast(getUserContext(typeid(T))); + } + void setUserContext(std::type_index typeId, const std::shared_ptr& userContext); + std::shared_ptr getUserContext(std::type_index typeId); + struct Impl; inline Impl* getImpl() const { return (Impl*)p; } + inline bool empty() const { return !p; } +// TODO OpenCV 5.0 //protected: Impl* p; }; +/** @deprecated */ class CV_EXPORTS Platform { public: - Platform(); + Platform() CV_NOEXCEPT; ~Platform(); Platform(const Platform& p); Platform& operator = (const Platform& p); + Platform(Platform&& p) CV_NOEXCEPT; + Platform& operator = (Platform&& p) CV_NOEXCEPT; void* ptr() const; + + /** @deprecated */ static Platform& getDefault(); - friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); -protected: struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } + inline bool empty() const { return !p; } +protected: Impl* p; }; @@ -319,16 +380,19 @@ CV_EXPORTS void convertFromBuffer(void* cl_mem_buffer, size_t step, int rows, in CV_EXPORTS void convertFromImage(void* cl_mem_image, UMat& dst); // TODO Move to internal header +/// @deprecated void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); class CV_EXPORTS Queue { public: - Queue(); + Queue() CV_NOEXCEPT; explicit Queue(const Context& c, const Device& d=Device()); ~Queue(); Queue(const Queue& q); Queue& operator = (const Queue& q); + Queue(Queue&& q) CV_NOEXCEPT; + Queue& operator = (Queue&& q) CV_NOEXCEPT; bool create(const Context& c=Context(), const Device& d=Device()); void finish(); @@ -340,6 +404,7 @@ public: struct Impl; friend struct Impl; inline Impl* getImpl() const { return p; } + inline bool empty() const { return !p; } protected: Impl* p; }; @@ -350,7 +415,7 @@ class CV_EXPORTS KernelArg public: enum { LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8, PTR_ONLY = 16, NO_SIZE=256 }; KernelArg(int _flags, UMat* _m, int wscale=1, int iwscale=1, const void* _obj=0, size_t _sz=0); - KernelArg(); + KernelArg() CV_NOEXCEPT; static KernelArg Local(size_t localMemSize) { return KernelArg(LOCAL, 0, 1, 1, 0, localMemSize); } @@ -387,13 +452,15 @@ public: class CV_EXPORTS Kernel { public: - Kernel(); + Kernel() CV_NOEXCEPT; Kernel(const char* kname, const Program& prog); Kernel(const char* kname, const ProgramSource& prog, const String& buildopts = String(), String* errmsg=0); ~Kernel(); Kernel(const Kernel& k); Kernel& operator = (const Kernel& k); + Kernel(Kernel&& k) CV_NOEXCEPT; + Kernel& operator = (Kernel&& k) CV_NOEXCEPT; bool empty() const; bool create(const char* kname, const Program& prog); @@ -407,161 +474,28 @@ public: template int set(int i, const _Tp& value) { return set(i, &value, sizeof(value)); } - template - Kernel& args(const _Tp0& a0) - { - set(0, a0); return *this; - } - template - Kernel& args(const _Tp0& a0, const _Tp1& a1) - { - int i = set(0, a0); set(i, a1); return *this; - } +protected: + template inline + int set_args_(int i, const _Tp0& a0) { return set(i, a0); } + template inline + int set_args_(int i, const _Tp0& a0, const _Tps&... rest_args) { i = set(i, a0); return set_args_(i, rest_args...); } +public: + /** @brief Setup OpenCL Kernel arguments. + Avoid direct using of set(i, ...) methods. + @code + bool ok = kernel + .args( + srcUMat, dstUMat, + (float)some_float_param + ).run(ndims, globalSize, localSize); + if (!ok) return false; + @endcode + */ + template inline + Kernel& args(const _Tps&... kernel_args) { set_args_(0, kernel_args...); return *this; } - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2) - { - int i = set(0, a0); i = set(i, a1); set(i, a2); return *this; - } - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, - const _Tp3& a3, const _Tp4& a4) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); - i = set(i, a3); set(i, a4); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, - const _Tp3& a3, const _Tp4& a4, const _Tp5& a5) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); - i = set(i, a3); i = set(i, a4); set(i, a5); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); - i = set(i, a4); i = set(i, a5); set(i, a6); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); - i = set(i, a4); i = set(i, a5); i = set(i, a6); set(i, a7); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, - const _Tp8& a8) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); - i = set(i, a5); i = set(i, a6); i = set(i, a7); set(i, a8); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, - const _Tp8& a8, const _Tp9& a9) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); - i = set(i, a6); i = set(i, a7); i = set(i, a8); set(i, a9); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, - const _Tp8& a8, const _Tp9& a9, const _Tp10& a10) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); - i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); set(i, a10); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, - const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); - i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); set(i, a11); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, - const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, - const _Tp12& a12) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); - i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); - set(i, a12); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, - const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, - const _Tp12& a12, const _Tp13& a13) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); - i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); - i = set(i, a12); set(i, a13); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, - const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, - const _Tp12& a12, const _Tp13& a13, const _Tp14& a14) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); - i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); - i = set(i, a12); i = set(i, a13); set(i, a14); return *this; - } - - template - Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3, - const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7, - const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11, - const _Tp12& a12, const _Tp13& a13, const _Tp14& a14, const _Tp15& a15) - { - int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5); - i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); - i = set(i, a12); i = set(i, a13); i = set(i, a14); set(i, a15); return *this; - } /** @brief Run the OpenCL kernel. @param dims the work problem dimensions. It is the length of globalsize and localsize. It can be either 1, 2 or 3. @param globalsize work items for each dimension. It is not the final globalsize passed to @@ -597,12 +531,13 @@ protected: class CV_EXPORTS Program { public: - Program(); + Program() CV_NOEXCEPT; Program(const ProgramSource& src, const String& buildflags, String& errmsg); Program(const Program& prog); - Program& operator = (const Program& prog); + Program(Program&& prog) CV_NOEXCEPT; + Program& operator = (Program&& prog) CV_NOEXCEPT; ~Program(); bool create(const ProgramSource& src, @@ -623,6 +558,7 @@ public: struct Impl; friend struct Impl; inline Impl* getImpl() const { return (Impl*)p; } + inline bool empty() const { return !p; } protected: Impl* p; public: @@ -642,13 +578,15 @@ class CV_EXPORTS ProgramSource public: typedef uint64 hash_t; // deprecated - ProgramSource(); + ProgramSource() CV_NOEXCEPT; explicit ProgramSource(const String& module, const String& name, const String& codeStr, const String& codeHash); explicit ProgramSource(const String& prog); // deprecated explicit ProgramSource(const char* prog); // deprecated ~ProgramSource(); ProgramSource(const ProgramSource& prog); ProgramSource& operator = (const ProgramSource& prog); + ProgramSource(ProgramSource&& prog) CV_NOEXCEPT; + ProgramSource& operator = (ProgramSource&& prog) CV_NOEXCEPT; const String& source() const; // deprecated hash_t hash() const; // deprecated @@ -704,6 +642,7 @@ public: struct Impl; friend struct Impl; inline Impl* getImpl() const { return (Impl*)p; } + inline bool empty() const { return !p; } protected: Impl* p; }; @@ -711,12 +650,17 @@ protected: class CV_EXPORTS PlatformInfo { public: - PlatformInfo(); + PlatformInfo() CV_NOEXCEPT; + /** + * @param id pointer cl_platform_id (cl_platform_id*) + */ explicit PlatformInfo(void* id); ~PlatformInfo(); PlatformInfo(const PlatformInfo& i); PlatformInfo& operator =(const PlatformInfo& i); + PlatformInfo(PlatformInfo&& i) CV_NOEXCEPT; + PlatformInfo& operator = (PlatformInfo&& i) CV_NOEXCEPT; String name() const; String vendor() const; @@ -729,8 +673,9 @@ public: int deviceNumber() const; void getDevice(Device& device, int d) const; -protected: struct Impl; + bool empty() const { return !p; } +protected: Impl* p; }; @@ -776,7 +721,7 @@ CV_EXPORTS void buildOptionsAddMatrixDescription(String& buildOptions, const Str class CV_EXPORTS Image2D { public: - Image2D(); + Image2D() CV_NOEXCEPT; /** @param src UMat object from which to get image properties and data @@ -789,6 +734,8 @@ public: ~Image2D(); Image2D & operator = (const Image2D & i); + Image2D(Image2D &&) CV_NOEXCEPT; + Image2D &operator=(Image2D &&) CV_NOEXCEPT; /** Indicates if creating an aliased image should succeed. Depends on the underlying platform and the dimensions of the UMat. @@ -827,6 +774,108 @@ private: CV_EXPORTS MatAllocator* getOpenCLAllocator(); +class CV_EXPORTS_W OpenCLExecutionContext +{ +public: + OpenCLExecutionContext() = default; + ~OpenCLExecutionContext() = default; + + OpenCLExecutionContext(const OpenCLExecutionContext&) = default; + OpenCLExecutionContext(OpenCLExecutionContext&&) = default; + + OpenCLExecutionContext& operator=(const OpenCLExecutionContext&) = default; + OpenCLExecutionContext& operator=(OpenCLExecutionContext&&) = default; + + /** Get associated ocl::Context */ + Context& getContext() const; + /** Get the single default associated ocl::Device */ + Device& getDevice() const; + /** Get the single ocl::Queue that is associated with the ocl::Context and + * the single default ocl::Device + */ + Queue& getQueue() const; + + bool useOpenCL() const; + void setUseOpenCL(bool flag); + + /** Get OpenCL execution context of current thread. + * + * Initialize OpenCL execution context if it is empty + * - create new + * - reuse context of the main thread (threadID = 0) + */ + static OpenCLExecutionContext& getCurrent(); + + /** Get OpenCL execution context of current thread (can be empty) */ + static OpenCLExecutionContext& getCurrentRef(); + + /** Bind this OpenCL execution context to current thread. + * + * Context can't be empty. + * + * @note clFinish is not called for queue of previous execution context + */ + void bind() const; + + /** Creates new execution context with same OpenCV context and device + * + * @param q OpenCL queue + */ + OpenCLExecutionContext cloneWithNewQueue(const ocl::Queue& q) const; + /** @overload */ + OpenCLExecutionContext cloneWithNewQueue() const; + + /** @brief Creates OpenCL execution context + * OpenCV will check if available OpenCL platform has platformName name, then assign context to + * OpenCV and call `clRetainContext` function. The deviceID device will be used as target device and + * new command queue will be created. + * + * @note Lifetime of passed handles is transferred to OpenCV wrappers on success + * + * @param platformName name of OpenCL platform to attach, this string is used to check if platform is available to OpenCV at runtime + * @param platformID ID of platform attached context was created for (cl_platform_id) + * @param context OpenCL context to be attached to OpenCV (cl_context) + * @param deviceID OpenCL device (cl_device_id) + */ + static OpenCLExecutionContext create(const std::string& platformName, void* platformID, void* context, void* deviceID); + + /** @brief Creates OpenCL execution context + * + * @param context non-empty OpenCL context + * @param device non-empty OpenCL device (must be a part of context) + * @param queue non-empty OpenCL queue for provided context and device + */ + static OpenCLExecutionContext create(const Context& context, const Device& device, const ocl::Queue& queue); + /** @overload */ + static OpenCLExecutionContext create(const Context& context, const Device& device); + + struct Impl; + inline bool empty() const { return !p; } + void release(); +protected: + std::shared_ptr p; +}; + +class OpenCLExecutionContextScope +{ + OpenCLExecutionContext ctx_; +public: + inline OpenCLExecutionContextScope(const OpenCLExecutionContext& ctx) + { + CV_Assert(!ctx.empty()); + ctx_ = OpenCLExecutionContext::getCurrentRef(); + ctx.bind(); + } + + inline ~OpenCLExecutionContextScope() + { + if (!ctx_.empty()) + { + ctx_.bind(); + } + } +}; + #ifdef __OPENCV_BUILD namespace internal { diff --git a/3rdparty/include/opencv2/core/opencl/ocl_defs.hpp b/3rdparty/include/opencv2/core/opencl/ocl_defs.hpp index 605a65f8d8..14df750fc7 100644 --- a/3rdparty/include/opencv2/core/opencl/ocl_defs.hpp +++ b/3rdparty/include/opencv2/core/opencl/ocl_defs.hpp @@ -59,11 +59,18 @@ static inline bool isOpenCLActivated() { return false; } } #else #define CV_OCL_RUN_(condition, func, ...) \ +try \ +{ \ if (cv::ocl::isOpenCLActivated() && (condition) && func) \ { \ CV_IMPL_ADD(CV_IMPL_OCL); \ return __VA_ARGS__; \ - } + } \ +} \ +catch (const cv::Exception& e) \ +{ \ + CV_UNUSED(e); /* TODO: Add some logging here */ \ +} #endif #else diff --git a/3rdparty/include/opencv2/core/opencl/opencl_info.hpp b/3rdparty/include/opencv2/core/opencl/opencl_info.hpp index 5e5c846ad0..3ead76e5c4 100644 --- a/3rdparty/include/opencv2/core/opencl/opencl_info.hpp +++ b/3rdparty/include/opencv2/core/opencl/opencl_info.hpp @@ -144,6 +144,10 @@ static void dumpOpenCLInformation() DUMP_MESSAGE_STDOUT(" Double support = " << doubleSupportStr); DUMP_CONFIG_PROPERTY("cv_ocl_current_haveDoubleSupport", device.doubleFPConfig() > 0); + const char* halfSupportStr = device.halfFPConfig() > 0 ? "Yes" : "No"; + DUMP_MESSAGE_STDOUT(" Half support = " << halfSupportStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_haveHalfSupport", device.halfFPConfig() > 0); + const char* isUnifiedMemoryStr = device.hostUnifiedMemory() ? "Yes" : "No"; DUMP_MESSAGE_STDOUT(" Host unified memory = " << isUnifiedMemoryStr); DUMP_CONFIG_PROPERTY("cv_ocl_current_hostUnifiedMemory", device.hostUnifiedMemory()); @@ -191,6 +195,9 @@ static void dumpOpenCLInformation() DUMP_MESSAGE_STDOUT(" Preferred vector width double = " << device.preferredVectorWidthDouble()); DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthDouble", device.preferredVectorWidthDouble()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width half = " << device.preferredVectorWidthHalf()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthHalf", device.preferredVectorWidthHalf()); } catch (...) { diff --git a/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp b/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp deleted file mode 100644 index 65c8493524..0000000000 --- a/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp +++ /dev/null @@ -1,714 +0,0 @@ -// -// AUTOGENERATED, DO NOT EDIT -// -#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP -#error "Invalid usage" -#endif - -// generated by parser_clamdblas.py -#define clAmdBlasAddScratchImage clAmdBlasAddScratchImage_ -#define clAmdBlasCaxpy clAmdBlasCaxpy_ -#define clAmdBlasCcopy clAmdBlasCcopy_ -#define clAmdBlasCdotc clAmdBlasCdotc_ -#define clAmdBlasCdotu clAmdBlasCdotu_ -#define clAmdBlasCgbmv clAmdBlasCgbmv_ -#define clAmdBlasCgemm clAmdBlasCgemm_ -#define clAmdBlasCgemmEx clAmdBlasCgemmEx_ -#define clAmdBlasCgemv clAmdBlasCgemv_ -#define clAmdBlasCgemvEx clAmdBlasCgemvEx_ -#define clAmdBlasCgerc clAmdBlasCgerc_ -#define clAmdBlasCgeru clAmdBlasCgeru_ -#define clAmdBlasChbmv clAmdBlasChbmv_ -#define clAmdBlasChemm clAmdBlasChemm_ -#define clAmdBlasChemv clAmdBlasChemv_ -#define clAmdBlasCher clAmdBlasCher_ -#define clAmdBlasCher2 clAmdBlasCher2_ -#define clAmdBlasCher2k clAmdBlasCher2k_ -#define clAmdBlasCherk clAmdBlasCherk_ -#define clAmdBlasChpmv clAmdBlasChpmv_ -#define clAmdBlasChpr clAmdBlasChpr_ -#define clAmdBlasChpr2 clAmdBlasChpr2_ -#define clAmdBlasCrotg clAmdBlasCrotg_ -#define clAmdBlasCscal clAmdBlasCscal_ -#define clAmdBlasCsrot clAmdBlasCsrot_ -#define clAmdBlasCsscal clAmdBlasCsscal_ -#define clAmdBlasCswap clAmdBlasCswap_ -#define clAmdBlasCsymm clAmdBlasCsymm_ -#define clAmdBlasCsyr2k clAmdBlasCsyr2k_ -#define clAmdBlasCsyr2kEx clAmdBlasCsyr2kEx_ -#define clAmdBlasCsyrk clAmdBlasCsyrk_ -#define clAmdBlasCsyrkEx clAmdBlasCsyrkEx_ -#define clAmdBlasCtbmv clAmdBlasCtbmv_ -#define clAmdBlasCtbsv clAmdBlasCtbsv_ -#define clAmdBlasCtpmv clAmdBlasCtpmv_ -#define clAmdBlasCtpsv clAmdBlasCtpsv_ -#define clAmdBlasCtrmm clAmdBlasCtrmm_ -#define clAmdBlasCtrmmEx clAmdBlasCtrmmEx_ -#define clAmdBlasCtrmv clAmdBlasCtrmv_ -#define clAmdBlasCtrsm clAmdBlasCtrsm_ -#define clAmdBlasCtrsmEx clAmdBlasCtrsmEx_ -#define clAmdBlasCtrsv clAmdBlasCtrsv_ -#define clAmdBlasDasum clAmdBlasDasum_ -#define clAmdBlasDaxpy clAmdBlasDaxpy_ -#define clAmdBlasDcopy clAmdBlasDcopy_ -#define clAmdBlasDdot clAmdBlasDdot_ -#define clAmdBlasDgbmv clAmdBlasDgbmv_ -#define clAmdBlasDgemm clAmdBlasDgemm_ -#define clAmdBlasDgemmEx clAmdBlasDgemmEx_ -#define clAmdBlasDgemv clAmdBlasDgemv_ -#define clAmdBlasDgemvEx clAmdBlasDgemvEx_ -#define clAmdBlasDger clAmdBlasDger_ -#define clAmdBlasDnrm2 clAmdBlasDnrm2_ -#define clAmdBlasDrot clAmdBlasDrot_ -#define clAmdBlasDrotg clAmdBlasDrotg_ -#define clAmdBlasDrotm clAmdBlasDrotm_ -#define clAmdBlasDrotmg clAmdBlasDrotmg_ -#define clAmdBlasDsbmv clAmdBlasDsbmv_ -#define clAmdBlasDscal clAmdBlasDscal_ -#define clAmdBlasDspmv clAmdBlasDspmv_ -#define clAmdBlasDspr clAmdBlasDspr_ -#define clAmdBlasDspr2 clAmdBlasDspr2_ -#define clAmdBlasDswap clAmdBlasDswap_ -#define clAmdBlasDsymm clAmdBlasDsymm_ -#define clAmdBlasDsymv clAmdBlasDsymv_ -#define clAmdBlasDsymvEx clAmdBlasDsymvEx_ -#define clAmdBlasDsyr clAmdBlasDsyr_ -#define clAmdBlasDsyr2 clAmdBlasDsyr2_ -#define clAmdBlasDsyr2k clAmdBlasDsyr2k_ -#define clAmdBlasDsyr2kEx clAmdBlasDsyr2kEx_ -#define clAmdBlasDsyrk clAmdBlasDsyrk_ -#define clAmdBlasDsyrkEx clAmdBlasDsyrkEx_ -#define clAmdBlasDtbmv clAmdBlasDtbmv_ -#define clAmdBlasDtbsv clAmdBlasDtbsv_ -#define clAmdBlasDtpmv clAmdBlasDtpmv_ -#define clAmdBlasDtpsv clAmdBlasDtpsv_ -#define clAmdBlasDtrmm clAmdBlasDtrmm_ -#define clAmdBlasDtrmmEx clAmdBlasDtrmmEx_ -#define clAmdBlasDtrmv clAmdBlasDtrmv_ -#define clAmdBlasDtrsm clAmdBlasDtrsm_ -#define clAmdBlasDtrsmEx clAmdBlasDtrsmEx_ -#define clAmdBlasDtrsv clAmdBlasDtrsv_ -#define clAmdBlasDzasum clAmdBlasDzasum_ -#define clAmdBlasDznrm2 clAmdBlasDznrm2_ -#define clAmdBlasGetVersion clAmdBlasGetVersion_ -#define clAmdBlasRemoveScratchImage clAmdBlasRemoveScratchImage_ -#define clAmdBlasSasum clAmdBlasSasum_ -#define clAmdBlasSaxpy clAmdBlasSaxpy_ -#define clAmdBlasScasum clAmdBlasScasum_ -#define clAmdBlasScnrm2 clAmdBlasScnrm2_ -#define clAmdBlasScopy clAmdBlasScopy_ -#define clAmdBlasSdot clAmdBlasSdot_ -#define clAmdBlasSetup clAmdBlasSetup_ -#define clAmdBlasSgbmv clAmdBlasSgbmv_ -#define clAmdBlasSgemm clAmdBlasSgemm_ -#define clAmdBlasSgemmEx clAmdBlasSgemmEx_ -#define clAmdBlasSgemv clAmdBlasSgemv_ -#define clAmdBlasSgemvEx clAmdBlasSgemvEx_ -#define clAmdBlasSger clAmdBlasSger_ -#define clAmdBlasSnrm2 clAmdBlasSnrm2_ -#define clAmdBlasSrot clAmdBlasSrot_ -#define clAmdBlasSrotg clAmdBlasSrotg_ -#define clAmdBlasSrotm clAmdBlasSrotm_ -#define clAmdBlasSrotmg clAmdBlasSrotmg_ -#define clAmdBlasSsbmv clAmdBlasSsbmv_ -#define clAmdBlasSscal clAmdBlasSscal_ -#define clAmdBlasSspmv clAmdBlasSspmv_ -#define clAmdBlasSspr clAmdBlasSspr_ -#define clAmdBlasSspr2 clAmdBlasSspr2_ -#define clAmdBlasSswap clAmdBlasSswap_ -#define clAmdBlasSsymm clAmdBlasSsymm_ -#define clAmdBlasSsymv clAmdBlasSsymv_ -#define clAmdBlasSsymvEx clAmdBlasSsymvEx_ -#define clAmdBlasSsyr clAmdBlasSsyr_ -#define clAmdBlasSsyr2 clAmdBlasSsyr2_ -#define clAmdBlasSsyr2k clAmdBlasSsyr2k_ -#define clAmdBlasSsyr2kEx clAmdBlasSsyr2kEx_ -#define clAmdBlasSsyrk clAmdBlasSsyrk_ -#define clAmdBlasSsyrkEx clAmdBlasSsyrkEx_ -#define clAmdBlasStbmv clAmdBlasStbmv_ -#define clAmdBlasStbsv clAmdBlasStbsv_ -#define clAmdBlasStpmv clAmdBlasStpmv_ -#define clAmdBlasStpsv clAmdBlasStpsv_ -#define clAmdBlasStrmm clAmdBlasStrmm_ -#define clAmdBlasStrmmEx clAmdBlasStrmmEx_ -#define clAmdBlasStrmv clAmdBlasStrmv_ -#define clAmdBlasStrsm clAmdBlasStrsm_ -#define clAmdBlasStrsmEx clAmdBlasStrsmEx_ -#define clAmdBlasStrsv clAmdBlasStrsv_ -#define clAmdBlasTeardown clAmdBlasTeardown_ -#define clAmdBlasZaxpy clAmdBlasZaxpy_ -#define clAmdBlasZcopy clAmdBlasZcopy_ -#define clAmdBlasZdotc clAmdBlasZdotc_ -#define clAmdBlasZdotu clAmdBlasZdotu_ -#define clAmdBlasZdrot clAmdBlasZdrot_ -#define clAmdBlasZdscal clAmdBlasZdscal_ -#define clAmdBlasZgbmv clAmdBlasZgbmv_ -#define clAmdBlasZgemm clAmdBlasZgemm_ -#define clAmdBlasZgemmEx clAmdBlasZgemmEx_ -#define clAmdBlasZgemv clAmdBlasZgemv_ -#define clAmdBlasZgemvEx clAmdBlasZgemvEx_ -#define clAmdBlasZgerc clAmdBlasZgerc_ -#define clAmdBlasZgeru clAmdBlasZgeru_ -#define clAmdBlasZhbmv clAmdBlasZhbmv_ -#define clAmdBlasZhemm clAmdBlasZhemm_ -#define clAmdBlasZhemv clAmdBlasZhemv_ -#define clAmdBlasZher clAmdBlasZher_ -#define clAmdBlasZher2 clAmdBlasZher2_ -#define clAmdBlasZher2k clAmdBlasZher2k_ -#define clAmdBlasZherk clAmdBlasZherk_ -#define clAmdBlasZhpmv clAmdBlasZhpmv_ -#define clAmdBlasZhpr clAmdBlasZhpr_ -#define clAmdBlasZhpr2 clAmdBlasZhpr2_ -#define clAmdBlasZrotg clAmdBlasZrotg_ -#define clAmdBlasZscal clAmdBlasZscal_ -#define clAmdBlasZswap clAmdBlasZswap_ -#define clAmdBlasZsymm clAmdBlasZsymm_ -#define clAmdBlasZsyr2k clAmdBlasZsyr2k_ -#define clAmdBlasZsyr2kEx clAmdBlasZsyr2kEx_ -#define clAmdBlasZsyrk clAmdBlasZsyrk_ -#define clAmdBlasZsyrkEx clAmdBlasZsyrkEx_ -#define clAmdBlasZtbmv clAmdBlasZtbmv_ -#define clAmdBlasZtbsv clAmdBlasZtbsv_ -#define clAmdBlasZtpmv clAmdBlasZtpmv_ -#define clAmdBlasZtpsv clAmdBlasZtpsv_ -#define clAmdBlasZtrmm clAmdBlasZtrmm_ -#define clAmdBlasZtrmmEx clAmdBlasZtrmmEx_ -#define clAmdBlasZtrmv clAmdBlasZtrmv_ -#define clAmdBlasZtrsm clAmdBlasZtrsm_ -#define clAmdBlasZtrsmEx clAmdBlasZtrsmEx_ -#define clAmdBlasZtrsv clAmdBlasZtrsv_ -#define clAmdBlasiCamax clAmdBlasiCamax_ -#define clAmdBlasiDamax clAmdBlasiDamax_ -#define clAmdBlasiSamax clAmdBlasiSamax_ -#define clAmdBlasiZamax clAmdBlasiZamax_ - -#include - -// generated by parser_clamdblas.py -#undef clAmdBlasAddScratchImage -//#define clAmdBlasAddScratchImage clAmdBlasAddScratchImage_pfn -#undef clAmdBlasCaxpy -//#define clAmdBlasCaxpy clAmdBlasCaxpy_pfn -#undef clAmdBlasCcopy -//#define clAmdBlasCcopy clAmdBlasCcopy_pfn -#undef clAmdBlasCdotc -//#define clAmdBlasCdotc clAmdBlasCdotc_pfn -#undef clAmdBlasCdotu -//#define clAmdBlasCdotu clAmdBlasCdotu_pfn -#undef clAmdBlasCgbmv -//#define clAmdBlasCgbmv clAmdBlasCgbmv_pfn -#undef clAmdBlasCgemm -//#define clAmdBlasCgemm clAmdBlasCgemm_pfn -#undef clAmdBlasCgemmEx -#define clAmdBlasCgemmEx clAmdBlasCgemmEx_pfn -#undef clAmdBlasCgemv -//#define clAmdBlasCgemv clAmdBlasCgemv_pfn -#undef clAmdBlasCgemvEx -//#define clAmdBlasCgemvEx clAmdBlasCgemvEx_pfn -#undef clAmdBlasCgerc -//#define clAmdBlasCgerc clAmdBlasCgerc_pfn -#undef clAmdBlasCgeru -//#define clAmdBlasCgeru clAmdBlasCgeru_pfn -#undef clAmdBlasChbmv -//#define clAmdBlasChbmv clAmdBlasChbmv_pfn -#undef clAmdBlasChemm -//#define clAmdBlasChemm clAmdBlasChemm_pfn -#undef clAmdBlasChemv -//#define clAmdBlasChemv clAmdBlasChemv_pfn -#undef clAmdBlasCher -//#define clAmdBlasCher clAmdBlasCher_pfn -#undef clAmdBlasCher2 -//#define clAmdBlasCher2 clAmdBlasCher2_pfn -#undef clAmdBlasCher2k -//#define clAmdBlasCher2k clAmdBlasCher2k_pfn -#undef clAmdBlasCherk -//#define clAmdBlasCherk clAmdBlasCherk_pfn -#undef clAmdBlasChpmv -//#define clAmdBlasChpmv clAmdBlasChpmv_pfn -#undef clAmdBlasChpr -//#define clAmdBlasChpr clAmdBlasChpr_pfn -#undef clAmdBlasChpr2 -//#define clAmdBlasChpr2 clAmdBlasChpr2_pfn -#undef clAmdBlasCrotg -//#define clAmdBlasCrotg clAmdBlasCrotg_pfn -#undef clAmdBlasCscal -//#define clAmdBlasCscal clAmdBlasCscal_pfn -#undef clAmdBlasCsrot -//#define clAmdBlasCsrot clAmdBlasCsrot_pfn -#undef clAmdBlasCsscal -//#define clAmdBlasCsscal clAmdBlasCsscal_pfn -#undef clAmdBlasCswap -//#define clAmdBlasCswap clAmdBlasCswap_pfn -#undef clAmdBlasCsymm -//#define clAmdBlasCsymm clAmdBlasCsymm_pfn -#undef clAmdBlasCsyr2k -//#define clAmdBlasCsyr2k clAmdBlasCsyr2k_pfn -#undef clAmdBlasCsyr2kEx -//#define clAmdBlasCsyr2kEx clAmdBlasCsyr2kEx_pfn -#undef clAmdBlasCsyrk -//#define clAmdBlasCsyrk clAmdBlasCsyrk_pfn -#undef clAmdBlasCsyrkEx -//#define clAmdBlasCsyrkEx clAmdBlasCsyrkEx_pfn -#undef clAmdBlasCtbmv -//#define clAmdBlasCtbmv clAmdBlasCtbmv_pfn -#undef clAmdBlasCtbsv -//#define clAmdBlasCtbsv clAmdBlasCtbsv_pfn -#undef clAmdBlasCtpmv -//#define clAmdBlasCtpmv clAmdBlasCtpmv_pfn -#undef clAmdBlasCtpsv -//#define clAmdBlasCtpsv clAmdBlasCtpsv_pfn -#undef clAmdBlasCtrmm -//#define clAmdBlasCtrmm clAmdBlasCtrmm_pfn -#undef clAmdBlasCtrmmEx -//#define clAmdBlasCtrmmEx clAmdBlasCtrmmEx_pfn -#undef clAmdBlasCtrmv -//#define clAmdBlasCtrmv clAmdBlasCtrmv_pfn -#undef clAmdBlasCtrsm -//#define clAmdBlasCtrsm clAmdBlasCtrsm_pfn -#undef clAmdBlasCtrsmEx -//#define clAmdBlasCtrsmEx clAmdBlasCtrsmEx_pfn -#undef clAmdBlasCtrsv -//#define clAmdBlasCtrsv clAmdBlasCtrsv_pfn -#undef clAmdBlasDasum -//#define clAmdBlasDasum clAmdBlasDasum_pfn -#undef clAmdBlasDaxpy -//#define clAmdBlasDaxpy clAmdBlasDaxpy_pfn -#undef clAmdBlasDcopy -//#define clAmdBlasDcopy clAmdBlasDcopy_pfn -#undef clAmdBlasDdot -//#define clAmdBlasDdot clAmdBlasDdot_pfn -#undef clAmdBlasDgbmv -//#define clAmdBlasDgbmv clAmdBlasDgbmv_pfn -#undef clAmdBlasDgemm -//#define clAmdBlasDgemm clAmdBlasDgemm_pfn -#undef clAmdBlasDgemmEx -#define clAmdBlasDgemmEx clAmdBlasDgemmEx_pfn -#undef clAmdBlasDgemv -//#define clAmdBlasDgemv clAmdBlasDgemv_pfn -#undef clAmdBlasDgemvEx -//#define clAmdBlasDgemvEx clAmdBlasDgemvEx_pfn -#undef clAmdBlasDger -//#define clAmdBlasDger clAmdBlasDger_pfn -#undef clAmdBlasDnrm2 -//#define clAmdBlasDnrm2 clAmdBlasDnrm2_pfn -#undef clAmdBlasDrot -//#define clAmdBlasDrot clAmdBlasDrot_pfn -#undef clAmdBlasDrotg -//#define clAmdBlasDrotg clAmdBlasDrotg_pfn -#undef clAmdBlasDrotm -//#define clAmdBlasDrotm clAmdBlasDrotm_pfn -#undef clAmdBlasDrotmg -//#define clAmdBlasDrotmg clAmdBlasDrotmg_pfn -#undef clAmdBlasDsbmv -//#define clAmdBlasDsbmv clAmdBlasDsbmv_pfn -#undef clAmdBlasDscal -//#define clAmdBlasDscal clAmdBlasDscal_pfn -#undef clAmdBlasDspmv -//#define clAmdBlasDspmv clAmdBlasDspmv_pfn -#undef clAmdBlasDspr -//#define clAmdBlasDspr clAmdBlasDspr_pfn -#undef clAmdBlasDspr2 -//#define clAmdBlasDspr2 clAmdBlasDspr2_pfn -#undef clAmdBlasDswap -//#define clAmdBlasDswap clAmdBlasDswap_pfn -#undef clAmdBlasDsymm -//#define clAmdBlasDsymm clAmdBlasDsymm_pfn -#undef clAmdBlasDsymv -//#define clAmdBlasDsymv clAmdBlasDsymv_pfn -#undef clAmdBlasDsymvEx -//#define clAmdBlasDsymvEx clAmdBlasDsymvEx_pfn -#undef clAmdBlasDsyr -//#define clAmdBlasDsyr clAmdBlasDsyr_pfn -#undef clAmdBlasDsyr2 -//#define clAmdBlasDsyr2 clAmdBlasDsyr2_pfn -#undef clAmdBlasDsyr2k -//#define clAmdBlasDsyr2k clAmdBlasDsyr2k_pfn -#undef clAmdBlasDsyr2kEx -//#define clAmdBlasDsyr2kEx clAmdBlasDsyr2kEx_pfn -#undef clAmdBlasDsyrk -//#define clAmdBlasDsyrk clAmdBlasDsyrk_pfn -#undef clAmdBlasDsyrkEx -//#define clAmdBlasDsyrkEx clAmdBlasDsyrkEx_pfn -#undef clAmdBlasDtbmv -//#define clAmdBlasDtbmv clAmdBlasDtbmv_pfn -#undef clAmdBlasDtbsv -//#define clAmdBlasDtbsv clAmdBlasDtbsv_pfn -#undef clAmdBlasDtpmv -//#define clAmdBlasDtpmv clAmdBlasDtpmv_pfn -#undef clAmdBlasDtpsv -//#define clAmdBlasDtpsv clAmdBlasDtpsv_pfn -#undef clAmdBlasDtrmm -//#define clAmdBlasDtrmm clAmdBlasDtrmm_pfn -#undef clAmdBlasDtrmmEx -//#define clAmdBlasDtrmmEx clAmdBlasDtrmmEx_pfn -#undef clAmdBlasDtrmv -//#define clAmdBlasDtrmv clAmdBlasDtrmv_pfn -#undef clAmdBlasDtrsm -//#define clAmdBlasDtrsm clAmdBlasDtrsm_pfn -#undef clAmdBlasDtrsmEx -//#define clAmdBlasDtrsmEx clAmdBlasDtrsmEx_pfn -#undef clAmdBlasDtrsv -//#define clAmdBlasDtrsv clAmdBlasDtrsv_pfn -#undef clAmdBlasDzasum -//#define clAmdBlasDzasum clAmdBlasDzasum_pfn -#undef clAmdBlasDznrm2 -//#define clAmdBlasDznrm2 clAmdBlasDznrm2_pfn -#undef clAmdBlasGetVersion -//#define clAmdBlasGetVersion clAmdBlasGetVersion_pfn -#undef clAmdBlasRemoveScratchImage -//#define clAmdBlasRemoveScratchImage clAmdBlasRemoveScratchImage_pfn -#undef clAmdBlasSasum -//#define clAmdBlasSasum clAmdBlasSasum_pfn -#undef clAmdBlasSaxpy -//#define clAmdBlasSaxpy clAmdBlasSaxpy_pfn -#undef clAmdBlasScasum -//#define clAmdBlasScasum clAmdBlasScasum_pfn -#undef clAmdBlasScnrm2 -//#define clAmdBlasScnrm2 clAmdBlasScnrm2_pfn -#undef clAmdBlasScopy -//#define clAmdBlasScopy clAmdBlasScopy_pfn -#undef clAmdBlasSdot -//#define clAmdBlasSdot clAmdBlasSdot_pfn -#undef clAmdBlasSetup -#define clAmdBlasSetup clAmdBlasSetup_pfn -#undef clAmdBlasSgbmv -//#define clAmdBlasSgbmv clAmdBlasSgbmv_pfn -#undef clAmdBlasSgemm -//#define clAmdBlasSgemm clAmdBlasSgemm_pfn -#undef clAmdBlasSgemmEx -#define clAmdBlasSgemmEx clAmdBlasSgemmEx_pfn -#undef clAmdBlasSgemv -//#define clAmdBlasSgemv clAmdBlasSgemv_pfn -#undef clAmdBlasSgemvEx -//#define clAmdBlasSgemvEx clAmdBlasSgemvEx_pfn -#undef clAmdBlasSger -//#define clAmdBlasSger clAmdBlasSger_pfn -#undef clAmdBlasSnrm2 -//#define clAmdBlasSnrm2 clAmdBlasSnrm2_pfn -#undef clAmdBlasSrot -//#define clAmdBlasSrot clAmdBlasSrot_pfn -#undef clAmdBlasSrotg -//#define clAmdBlasSrotg clAmdBlasSrotg_pfn -#undef clAmdBlasSrotm -//#define clAmdBlasSrotm clAmdBlasSrotm_pfn -#undef clAmdBlasSrotmg -//#define clAmdBlasSrotmg clAmdBlasSrotmg_pfn -#undef clAmdBlasSsbmv -//#define clAmdBlasSsbmv clAmdBlasSsbmv_pfn -#undef clAmdBlasSscal -//#define clAmdBlasSscal clAmdBlasSscal_pfn -#undef clAmdBlasSspmv -//#define clAmdBlasSspmv clAmdBlasSspmv_pfn -#undef clAmdBlasSspr -//#define clAmdBlasSspr clAmdBlasSspr_pfn -#undef clAmdBlasSspr2 -//#define clAmdBlasSspr2 clAmdBlasSspr2_pfn -#undef clAmdBlasSswap -//#define clAmdBlasSswap clAmdBlasSswap_pfn -#undef clAmdBlasSsymm -//#define clAmdBlasSsymm clAmdBlasSsymm_pfn -#undef clAmdBlasSsymv -//#define clAmdBlasSsymv clAmdBlasSsymv_pfn -#undef clAmdBlasSsymvEx -//#define clAmdBlasSsymvEx clAmdBlasSsymvEx_pfn -#undef clAmdBlasSsyr -//#define clAmdBlasSsyr clAmdBlasSsyr_pfn -#undef clAmdBlasSsyr2 -//#define clAmdBlasSsyr2 clAmdBlasSsyr2_pfn -#undef clAmdBlasSsyr2k -//#define clAmdBlasSsyr2k clAmdBlasSsyr2k_pfn -#undef clAmdBlasSsyr2kEx -//#define clAmdBlasSsyr2kEx clAmdBlasSsyr2kEx_pfn -#undef clAmdBlasSsyrk -//#define clAmdBlasSsyrk clAmdBlasSsyrk_pfn -#undef clAmdBlasSsyrkEx -//#define clAmdBlasSsyrkEx clAmdBlasSsyrkEx_pfn -#undef clAmdBlasStbmv -//#define clAmdBlasStbmv clAmdBlasStbmv_pfn -#undef clAmdBlasStbsv -//#define clAmdBlasStbsv clAmdBlasStbsv_pfn -#undef clAmdBlasStpmv -//#define clAmdBlasStpmv clAmdBlasStpmv_pfn -#undef clAmdBlasStpsv -//#define clAmdBlasStpsv clAmdBlasStpsv_pfn -#undef clAmdBlasStrmm -//#define clAmdBlasStrmm clAmdBlasStrmm_pfn -#undef clAmdBlasStrmmEx -//#define clAmdBlasStrmmEx clAmdBlasStrmmEx_pfn -#undef clAmdBlasStrmv -//#define clAmdBlasStrmv clAmdBlasStrmv_pfn -#undef clAmdBlasStrsm -//#define clAmdBlasStrsm clAmdBlasStrsm_pfn -#undef clAmdBlasStrsmEx -//#define clAmdBlasStrsmEx clAmdBlasStrsmEx_pfn -#undef clAmdBlasStrsv -//#define clAmdBlasStrsv clAmdBlasStrsv_pfn -#undef clAmdBlasTeardown -#define clAmdBlasTeardown clAmdBlasTeardown_pfn -#undef clAmdBlasZaxpy -//#define clAmdBlasZaxpy clAmdBlasZaxpy_pfn -#undef clAmdBlasZcopy -//#define clAmdBlasZcopy clAmdBlasZcopy_pfn -#undef clAmdBlasZdotc -//#define clAmdBlasZdotc clAmdBlasZdotc_pfn -#undef clAmdBlasZdotu -//#define clAmdBlasZdotu clAmdBlasZdotu_pfn -#undef clAmdBlasZdrot -//#define clAmdBlasZdrot clAmdBlasZdrot_pfn -#undef clAmdBlasZdscal -//#define clAmdBlasZdscal clAmdBlasZdscal_pfn -#undef clAmdBlasZgbmv -//#define clAmdBlasZgbmv clAmdBlasZgbmv_pfn -#undef clAmdBlasZgemm -//#define clAmdBlasZgemm clAmdBlasZgemm_pfn -#undef clAmdBlasZgemmEx -#define clAmdBlasZgemmEx clAmdBlasZgemmEx_pfn -#undef clAmdBlasZgemv -//#define clAmdBlasZgemv clAmdBlasZgemv_pfn -#undef clAmdBlasZgemvEx -//#define clAmdBlasZgemvEx clAmdBlasZgemvEx_pfn -#undef clAmdBlasZgerc -//#define clAmdBlasZgerc clAmdBlasZgerc_pfn -#undef clAmdBlasZgeru -//#define clAmdBlasZgeru clAmdBlasZgeru_pfn -#undef clAmdBlasZhbmv -//#define clAmdBlasZhbmv clAmdBlasZhbmv_pfn -#undef clAmdBlasZhemm -//#define clAmdBlasZhemm clAmdBlasZhemm_pfn -#undef clAmdBlasZhemv -//#define clAmdBlasZhemv clAmdBlasZhemv_pfn -#undef clAmdBlasZher -//#define clAmdBlasZher clAmdBlasZher_pfn -#undef clAmdBlasZher2 -//#define clAmdBlasZher2 clAmdBlasZher2_pfn -#undef clAmdBlasZher2k -//#define clAmdBlasZher2k clAmdBlasZher2k_pfn -#undef clAmdBlasZherk -//#define clAmdBlasZherk clAmdBlasZherk_pfn -#undef clAmdBlasZhpmv -//#define clAmdBlasZhpmv clAmdBlasZhpmv_pfn -#undef clAmdBlasZhpr -//#define clAmdBlasZhpr clAmdBlasZhpr_pfn -#undef clAmdBlasZhpr2 -//#define clAmdBlasZhpr2 clAmdBlasZhpr2_pfn -#undef clAmdBlasZrotg -//#define clAmdBlasZrotg clAmdBlasZrotg_pfn -#undef clAmdBlasZscal -//#define clAmdBlasZscal clAmdBlasZscal_pfn -#undef clAmdBlasZswap -//#define clAmdBlasZswap clAmdBlasZswap_pfn -#undef clAmdBlasZsymm -//#define clAmdBlasZsymm clAmdBlasZsymm_pfn -#undef clAmdBlasZsyr2k -//#define clAmdBlasZsyr2k clAmdBlasZsyr2k_pfn -#undef clAmdBlasZsyr2kEx -//#define clAmdBlasZsyr2kEx clAmdBlasZsyr2kEx_pfn -#undef clAmdBlasZsyrk -//#define clAmdBlasZsyrk clAmdBlasZsyrk_pfn -#undef clAmdBlasZsyrkEx -//#define clAmdBlasZsyrkEx clAmdBlasZsyrkEx_pfn -#undef clAmdBlasZtbmv -//#define clAmdBlasZtbmv clAmdBlasZtbmv_pfn -#undef clAmdBlasZtbsv -//#define clAmdBlasZtbsv clAmdBlasZtbsv_pfn -#undef clAmdBlasZtpmv -//#define clAmdBlasZtpmv clAmdBlasZtpmv_pfn -#undef clAmdBlasZtpsv -//#define clAmdBlasZtpsv clAmdBlasZtpsv_pfn -#undef clAmdBlasZtrmm -//#define clAmdBlasZtrmm clAmdBlasZtrmm_pfn -#undef clAmdBlasZtrmmEx -//#define clAmdBlasZtrmmEx clAmdBlasZtrmmEx_pfn -#undef clAmdBlasZtrmv -//#define clAmdBlasZtrmv clAmdBlasZtrmv_pfn -#undef clAmdBlasZtrsm -//#define clAmdBlasZtrsm clAmdBlasZtrsm_pfn -#undef clAmdBlasZtrsmEx -//#define clAmdBlasZtrsmEx clAmdBlasZtrsmEx_pfn -#undef clAmdBlasZtrsv -//#define clAmdBlasZtrsv clAmdBlasZtrsv_pfn -#undef clAmdBlasiCamax -//#define clAmdBlasiCamax clAmdBlasiCamax_pfn -#undef clAmdBlasiDamax -//#define clAmdBlasiDamax clAmdBlasiDamax_pfn -#undef clAmdBlasiSamax -//#define clAmdBlasiSamax clAmdBlasiSamax_pfn -#undef clAmdBlasiZamax -//#define clAmdBlasiZamax clAmdBlasiZamax_pfn - -// generated by parser_clamdblas.py -//extern CL_RUNTIME_EXPORT cl_ulong (*clAmdBlasAddScratchImage)(cl_context context, size_t width, size_t height, clAmdBlasStatus* status); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCaxpy)(size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCdotc)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCdotu)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, FloatComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, FloatComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, FloatComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgerc)(clAmdBlasOrder order, size_t M, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgeru)(clAmdBlasOrder order, size_t M, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChemm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChemv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, FloatComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, FloatComplex beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCher)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCher2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCher2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCherk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, float alpha, const cl_mem A, size_t offa, size_t lda, float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float2 alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChpr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChpr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCrotg)(cl_mem CA, size_t offCA, cl_mem CB, size_t offCB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCscal)(size_t N, cl_float2 alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_float C, cl_float S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsscal)(size_t N, cl_float alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, FloatComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t lda, FloatComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDaxpy)(size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDdot)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_double beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDger)(clAmdBlasOrder order, size_t M, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_double C, cl_double S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrotg)(cl_mem DA, size_t offDA, cl_mem DB, size_t offDB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrotm)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, const cl_mem DPARAM, size_t offDparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrotmg)(cl_mem DD1, size_t offDD1, cl_mem DD2, size_t offDD2, cl_mem DX1, size_t offDX1, const cl_mem DY1, size_t offDY1, cl_mem DPARAM, size_t offDparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDscal)(size_t N, cl_double alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDspmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDspr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDspr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsymv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsymvEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_double beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t lda, cl_double beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDzasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDznrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasGetVersion)(cl_uint* major, cl_uint* minor, cl_uint* patch); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasRemoveScratchImage)(cl_ulong imageID); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSaxpy)(size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasScasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasScnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasScopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSdot)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSetup)(); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_float beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSger)(clAmdBlasOrder order, size_t M, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_float C, cl_float S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrotg)(cl_mem SA, size_t offSA, cl_mem SB, size_t offSB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrotm)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, const cl_mem SPARAM, size_t offSparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrotmg)(cl_mem SD1, size_t offSD1, cl_mem SD2, size_t offSD2, cl_mem SX1, size_t offSX1, const cl_mem SY1, size_t offSY1, cl_mem SPARAM, size_t offSparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSscal)(size_t N, cl_float alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSspmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSspr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSspr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsymv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsymvEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_float beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t lda, cl_float beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -extern CL_RUNTIME_EXPORT void (*clAmdBlasTeardown)(); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZaxpy)(size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdotc)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdotu)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_double C, cl_double S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdscal)(size_t N, cl_double alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, DoubleComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, DoubleComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, DoubleComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgerc)(clAmdBlasOrder order, size_t M, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgeru)(clAmdBlasOrder order, size_t M, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhemm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhemv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, DoubleComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, DoubleComplex beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZher)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZher2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZher2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZherk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, double alpha, const cl_mem A, size_t offa, size_t lda, double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double2 alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhpr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhpr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZrotg)(cl_mem CA, size_t offCA, cl_mem CB, size_t offCB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZscal)(size_t N, cl_double2 alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, DoubleComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t lda, DoubleComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiCamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiDamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiSamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); -//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiZamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); diff --git a/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp b/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp deleted file mode 100644 index 1457d7eb8d..0000000000 --- a/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp +++ /dev/null @@ -1,142 +0,0 @@ -// -// AUTOGENERATED, DO NOT EDIT -// -#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP -#error "Invalid usage" -#endif - -// generated by parser_clamdfft.py -#define clAmdFftBakePlan clAmdFftBakePlan_ -#define clAmdFftCopyPlan clAmdFftCopyPlan_ -#define clAmdFftCreateDefaultPlan clAmdFftCreateDefaultPlan_ -#define clAmdFftDestroyPlan clAmdFftDestroyPlan_ -#define clAmdFftEnqueueTransform clAmdFftEnqueueTransform_ -#define clAmdFftGetLayout clAmdFftGetLayout_ -#define clAmdFftGetPlanBatchSize clAmdFftGetPlanBatchSize_ -#define clAmdFftGetPlanContext clAmdFftGetPlanContext_ -#define clAmdFftGetPlanDim clAmdFftGetPlanDim_ -#define clAmdFftGetPlanDistance clAmdFftGetPlanDistance_ -#define clAmdFftGetPlanInStride clAmdFftGetPlanInStride_ -#define clAmdFftGetPlanLength clAmdFftGetPlanLength_ -#define clAmdFftGetPlanOutStride clAmdFftGetPlanOutStride_ -#define clAmdFftGetPlanPrecision clAmdFftGetPlanPrecision_ -#define clAmdFftGetPlanScale clAmdFftGetPlanScale_ -#define clAmdFftGetPlanTransposeResult clAmdFftGetPlanTransposeResult_ -#define clAmdFftGetResultLocation clAmdFftGetResultLocation_ -#define clAmdFftGetTmpBufSize clAmdFftGetTmpBufSize_ -#define clAmdFftGetVersion clAmdFftGetVersion_ -#define clAmdFftSetLayout clAmdFftSetLayout_ -#define clAmdFftSetPlanBatchSize clAmdFftSetPlanBatchSize_ -#define clAmdFftSetPlanDim clAmdFftSetPlanDim_ -#define clAmdFftSetPlanDistance clAmdFftSetPlanDistance_ -#define clAmdFftSetPlanInStride clAmdFftSetPlanInStride_ -#define clAmdFftSetPlanLength clAmdFftSetPlanLength_ -#define clAmdFftSetPlanOutStride clAmdFftSetPlanOutStride_ -#define clAmdFftSetPlanPrecision clAmdFftSetPlanPrecision_ -#define clAmdFftSetPlanScale clAmdFftSetPlanScale_ -#define clAmdFftSetPlanTransposeResult clAmdFftSetPlanTransposeResult_ -#define clAmdFftSetResultLocation clAmdFftSetResultLocation_ -#define clAmdFftSetup clAmdFftSetup_ -#define clAmdFftTeardown clAmdFftTeardown_ - -#include - -// generated by parser_clamdfft.py -#undef clAmdFftBakePlan -#define clAmdFftBakePlan clAmdFftBakePlan_pfn -#undef clAmdFftCopyPlan -//#define clAmdFftCopyPlan clAmdFftCopyPlan_pfn -#undef clAmdFftCreateDefaultPlan -#define clAmdFftCreateDefaultPlan clAmdFftCreateDefaultPlan_pfn -#undef clAmdFftDestroyPlan -#define clAmdFftDestroyPlan clAmdFftDestroyPlan_pfn -#undef clAmdFftEnqueueTransform -#define clAmdFftEnqueueTransform clAmdFftEnqueueTransform_pfn -#undef clAmdFftGetLayout -//#define clAmdFftGetLayout clAmdFftGetLayout_pfn -#undef clAmdFftGetPlanBatchSize -//#define clAmdFftGetPlanBatchSize clAmdFftGetPlanBatchSize_pfn -#undef clAmdFftGetPlanContext -//#define clAmdFftGetPlanContext clAmdFftGetPlanContext_pfn -#undef clAmdFftGetPlanDim -//#define clAmdFftGetPlanDim clAmdFftGetPlanDim_pfn -#undef clAmdFftGetPlanDistance -//#define clAmdFftGetPlanDistance clAmdFftGetPlanDistance_pfn -#undef clAmdFftGetPlanInStride -//#define clAmdFftGetPlanInStride clAmdFftGetPlanInStride_pfn -#undef clAmdFftGetPlanLength -//#define clAmdFftGetPlanLength clAmdFftGetPlanLength_pfn -#undef clAmdFftGetPlanOutStride -//#define clAmdFftGetPlanOutStride clAmdFftGetPlanOutStride_pfn -#undef clAmdFftGetPlanPrecision -//#define clAmdFftGetPlanPrecision clAmdFftGetPlanPrecision_pfn -#undef clAmdFftGetPlanScale -//#define clAmdFftGetPlanScale clAmdFftGetPlanScale_pfn -#undef clAmdFftGetPlanTransposeResult -//#define clAmdFftGetPlanTransposeResult clAmdFftGetPlanTransposeResult_pfn -#undef clAmdFftGetResultLocation -//#define clAmdFftGetResultLocation clAmdFftGetResultLocation_pfn -#undef clAmdFftGetTmpBufSize -#define clAmdFftGetTmpBufSize clAmdFftGetTmpBufSize_pfn -#undef clAmdFftGetVersion -#define clAmdFftGetVersion clAmdFftGetVersion_pfn -#undef clAmdFftSetLayout -#define clAmdFftSetLayout clAmdFftSetLayout_pfn -#undef clAmdFftSetPlanBatchSize -#define clAmdFftSetPlanBatchSize clAmdFftSetPlanBatchSize_pfn -#undef clAmdFftSetPlanDim -//#define clAmdFftSetPlanDim clAmdFftSetPlanDim_pfn -#undef clAmdFftSetPlanDistance -#define clAmdFftSetPlanDistance clAmdFftSetPlanDistance_pfn -#undef clAmdFftSetPlanInStride -#define clAmdFftSetPlanInStride clAmdFftSetPlanInStride_pfn -#undef clAmdFftSetPlanLength -//#define clAmdFftSetPlanLength clAmdFftSetPlanLength_pfn -#undef clAmdFftSetPlanOutStride -#define clAmdFftSetPlanOutStride clAmdFftSetPlanOutStride_pfn -#undef clAmdFftSetPlanPrecision -#define clAmdFftSetPlanPrecision clAmdFftSetPlanPrecision_pfn -#undef clAmdFftSetPlanScale -#define clAmdFftSetPlanScale clAmdFftSetPlanScale_pfn -#undef clAmdFftSetPlanTransposeResult -//#define clAmdFftSetPlanTransposeResult clAmdFftSetPlanTransposeResult_pfn -#undef clAmdFftSetResultLocation -#define clAmdFftSetResultLocation clAmdFftSetResultLocation_pfn -#undef clAmdFftSetup -#define clAmdFftSetup clAmdFftSetup_pfn -#undef clAmdFftTeardown -#define clAmdFftTeardown clAmdFftTeardown_pfn - -// generated by parser_clamdfft.py -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftBakePlan)(clAmdFftPlanHandle plHandle, cl_uint numQueues, cl_command_queue* commQueueFFT, void (CL_CALLBACK* pfn_notify) (clAmdFftPlanHandle plHandle, void* user_data), void* user_data); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftCopyPlan)(clAmdFftPlanHandle* out_plHandle, cl_context new_context, clAmdFftPlanHandle in_plHandle); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftCreateDefaultPlan)(clAmdFftPlanHandle* plHandle, cl_context context, const clAmdFftDim dim, const size_t* clLengths); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftDestroyPlan)(clAmdFftPlanHandle* plHandle); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftEnqueueTransform)(clAmdFftPlanHandle plHandle, clAmdFftDirection dir, cl_uint numQueuesAndEvents, cl_command_queue* commQueues, cl_uint numWaitEvents, const cl_event* waitEvents, cl_event* outEvents, cl_mem* inputBuffers, cl_mem* outputBuffers, cl_mem tmpBuffer); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetLayout)(const clAmdFftPlanHandle plHandle, clAmdFftLayout* iLayout, clAmdFftLayout* oLayout); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanBatchSize)(const clAmdFftPlanHandle plHandle, size_t* batchSize); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanContext)(const clAmdFftPlanHandle plHandle, cl_context* context); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanDim)(const clAmdFftPlanHandle plHandle, clAmdFftDim* dim, cl_uint* size); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanDistance)(const clAmdFftPlanHandle plHandle, size_t* iDist, size_t* oDist); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanInStride)(const clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanLength)(const clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clLengths); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanOutStride)(const clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanPrecision)(const clAmdFftPlanHandle plHandle, clAmdFftPrecision* precision); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanScale)(const clAmdFftPlanHandle plHandle, clAmdFftDirection dir, cl_float* scale); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanTransposeResult)(const clAmdFftPlanHandle plHandle, clAmdFftResultTransposed* transposed); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetResultLocation)(const clAmdFftPlanHandle plHandle, clAmdFftResultLocation* placeness); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetTmpBufSize)(const clAmdFftPlanHandle plHandle, size_t* buffersize); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetVersion)(cl_uint* major, cl_uint* minor, cl_uint* patch); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetLayout)(clAmdFftPlanHandle plHandle, clAmdFftLayout iLayout, clAmdFftLayout oLayout); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanBatchSize)(clAmdFftPlanHandle plHandle, size_t batchSize); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanDim)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanDistance)(clAmdFftPlanHandle plHandle, size_t iDist, size_t oDist); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanInStride)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanLength)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim, const size_t* clLengths); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanOutStride)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanPrecision)(clAmdFftPlanHandle plHandle, clAmdFftPrecision precision); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanScale)(clAmdFftPlanHandle plHandle, clAmdFftDirection dir, cl_float scale); -//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanTransposeResult)(clAmdFftPlanHandle plHandle, clAmdFftResultTransposed transposed); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetResultLocation)(clAmdFftPlanHandle plHandle, clAmdFftResultLocation placeness); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetup)(const clAmdFftSetupData* setupData); -extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftTeardown)(); diff --git a/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clblas.hpp b/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clblas.hpp new file mode 100644 index 0000000000..2749927bea --- /dev/null +++ b/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clblas.hpp @@ -0,0 +1,602 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP +#error "Invalid usage" +#endif + +// generated by parser_clblas.py +#define clblasCaxpy clblasCaxpy_ +#define clblasCcopy clblasCcopy_ +#define clblasCdotc clblasCdotc_ +#define clblasCdotu clblasCdotu_ +#define clblasCgbmv clblasCgbmv_ +#define clblasCgemm clblasCgemm_ +#define clblasCgemv clblasCgemv_ +#define clblasCgerc clblasCgerc_ +#define clblasCgeru clblasCgeru_ +#define clblasChbmv clblasChbmv_ +#define clblasChemm clblasChemm_ +#define clblasChemv clblasChemv_ +#define clblasCher clblasCher_ +#define clblasCher2 clblasCher2_ +#define clblasCher2k clblasCher2k_ +#define clblasCherk clblasCherk_ +#define clblasChpmv clblasChpmv_ +#define clblasChpr clblasChpr_ +#define clblasChpr2 clblasChpr2_ +#define clblasCrotg clblasCrotg_ +#define clblasCscal clblasCscal_ +#define clblasCsrot clblasCsrot_ +#define clblasCsscal clblasCsscal_ +#define clblasCswap clblasCswap_ +#define clblasCsymm clblasCsymm_ +#define clblasCsyr2k clblasCsyr2k_ +#define clblasCsyrk clblasCsyrk_ +#define clblasCtbmv clblasCtbmv_ +#define clblasCtbsv clblasCtbsv_ +#define clblasCtpmv clblasCtpmv_ +#define clblasCtpsv clblasCtpsv_ +#define clblasCtrmm clblasCtrmm_ +#define clblasCtrmv clblasCtrmv_ +#define clblasCtrsm clblasCtrsm_ +#define clblasCtrsv clblasCtrsv_ +#define clblasDasum clblasDasum_ +#define clblasDaxpy clblasDaxpy_ +#define clblasDcopy clblasDcopy_ +#define clblasDdot clblasDdot_ +#define clblasDgbmv clblasDgbmv_ +#define clblasDgemm clblasDgemm_ +#define clblasDgemv clblasDgemv_ +#define clblasDger clblasDger_ +#define clblasDnrm2 clblasDnrm2_ +#define clblasDrot clblasDrot_ +#define clblasDrotg clblasDrotg_ +#define clblasDrotm clblasDrotm_ +#define clblasDrotmg clblasDrotmg_ +#define clblasDsbmv clblasDsbmv_ +#define clblasDscal clblasDscal_ +#define clblasDspmv clblasDspmv_ +#define clblasDspr clblasDspr_ +#define clblasDspr2 clblasDspr2_ +#define clblasDswap clblasDswap_ +#define clblasDsymm clblasDsymm_ +#define clblasDsymv clblasDsymv_ +#define clblasDsyr clblasDsyr_ +#define clblasDsyr2 clblasDsyr2_ +#define clblasDsyr2k clblasDsyr2k_ +#define clblasDsyrk clblasDsyrk_ +#define clblasDtbmv clblasDtbmv_ +#define clblasDtbsv clblasDtbsv_ +#define clblasDtpmv clblasDtpmv_ +#define clblasDtpsv clblasDtpsv_ +#define clblasDtrmm clblasDtrmm_ +#define clblasDtrmv clblasDtrmv_ +#define clblasDtrsm clblasDtrsm_ +#define clblasDtrsv clblasDtrsv_ +#define clblasDzasum clblasDzasum_ +#define clblasDznrm2 clblasDznrm2_ +#define clblasGetVersion clblasGetVersion_ +#define clblasSasum clblasSasum_ +#define clblasSaxpy clblasSaxpy_ +#define clblasScasum clblasScasum_ +#define clblasScnrm2 clblasScnrm2_ +#define clblasScopy clblasScopy_ +#define clblasSdot clblasSdot_ +#define clblasSetup clblasSetup_ +#define clblasSgbmv clblasSgbmv_ +#define clblasSgemm clblasSgemm_ +#define clblasSgemv clblasSgemv_ +#define clblasSger clblasSger_ +#define clblasSnrm2 clblasSnrm2_ +#define clblasSrot clblasSrot_ +#define clblasSrotg clblasSrotg_ +#define clblasSrotm clblasSrotm_ +#define clblasSrotmg clblasSrotmg_ +#define clblasSsbmv clblasSsbmv_ +#define clblasSscal clblasSscal_ +#define clblasSspmv clblasSspmv_ +#define clblasSspr clblasSspr_ +#define clblasSspr2 clblasSspr2_ +#define clblasSswap clblasSswap_ +#define clblasSsymm clblasSsymm_ +#define clblasSsymv clblasSsymv_ +#define clblasSsyr clblasSsyr_ +#define clblasSsyr2 clblasSsyr2_ +#define clblasSsyr2k clblasSsyr2k_ +#define clblasSsyrk clblasSsyrk_ +#define clblasStbmv clblasStbmv_ +#define clblasStbsv clblasStbsv_ +#define clblasStpmv clblasStpmv_ +#define clblasStpsv clblasStpsv_ +#define clblasStrmm clblasStrmm_ +#define clblasStrmv clblasStrmv_ +#define clblasStrsm clblasStrsm_ +#define clblasStrsv clblasStrsv_ +#define clblasTeardown clblasTeardown_ +#define clblasZaxpy clblasZaxpy_ +#define clblasZcopy clblasZcopy_ +#define clblasZdotc clblasZdotc_ +#define clblasZdotu clblasZdotu_ +#define clblasZdrot clblasZdrot_ +#define clblasZdscal clblasZdscal_ +#define clblasZgbmv clblasZgbmv_ +#define clblasZgemm clblasZgemm_ +#define clblasZgemv clblasZgemv_ +#define clblasZgerc clblasZgerc_ +#define clblasZgeru clblasZgeru_ +#define clblasZhbmv clblasZhbmv_ +#define clblasZhemm clblasZhemm_ +#define clblasZhemv clblasZhemv_ +#define clblasZher clblasZher_ +#define clblasZher2 clblasZher2_ +#define clblasZher2k clblasZher2k_ +#define clblasZherk clblasZherk_ +#define clblasZhpmv clblasZhpmv_ +#define clblasZhpr clblasZhpr_ +#define clblasZhpr2 clblasZhpr2_ +#define clblasZrotg clblasZrotg_ +#define clblasZscal clblasZscal_ +#define clblasZswap clblasZswap_ +#define clblasZsymm clblasZsymm_ +#define clblasZsyr2k clblasZsyr2k_ +#define clblasZsyrk clblasZsyrk_ +#define clblasZtbmv clblasZtbmv_ +#define clblasZtbsv clblasZtbsv_ +#define clblasZtpmv clblasZtpmv_ +#define clblasZtpsv clblasZtpsv_ +#define clblasZtrmm clblasZtrmm_ +#define clblasZtrmv clblasZtrmv_ +#define clblasZtrsm clblasZtrsm_ +#define clblasZtrsv clblasZtrsv_ +#define clblasiCamax clblasiCamax_ +#define clblasiDamax clblasiDamax_ +#define clblasiSamax clblasiSamax_ +#define clblasiZamax clblasiZamax_ + +#include + +// generated by parser_clblas.py +#undef clblasCaxpy +//#define clblasCaxpy clblasCaxpy_pfn +#undef clblasCcopy +//#define clblasCcopy clblasCcopy_pfn +#undef clblasCdotc +//#define clblasCdotc clblasCdotc_pfn +#undef clblasCdotu +//#define clblasCdotu clblasCdotu_pfn +#undef clblasCgbmv +//#define clblasCgbmv clblasCgbmv_pfn +#undef clblasCgemm +#define clblasCgemm clblasCgemm_pfn +#undef clblasCgemv +//#define clblasCgemv clblasCgemv_pfn +#undef clblasCgerc +//#define clblasCgerc clblasCgerc_pfn +#undef clblasCgeru +//#define clblasCgeru clblasCgeru_pfn +#undef clblasChbmv +//#define clblasChbmv clblasChbmv_pfn +#undef clblasChemm +//#define clblasChemm clblasChemm_pfn +#undef clblasChemv +//#define clblasChemv clblasChemv_pfn +#undef clblasCher +//#define clblasCher clblasCher_pfn +#undef clblasCher2 +//#define clblasCher2 clblasCher2_pfn +#undef clblasCher2k +//#define clblasCher2k clblasCher2k_pfn +#undef clblasCherk +//#define clblasCherk clblasCherk_pfn +#undef clblasChpmv +//#define clblasChpmv clblasChpmv_pfn +#undef clblasChpr +//#define clblasChpr clblasChpr_pfn +#undef clblasChpr2 +//#define clblasChpr2 clblasChpr2_pfn +#undef clblasCrotg +//#define clblasCrotg clblasCrotg_pfn +#undef clblasCscal +//#define clblasCscal clblasCscal_pfn +#undef clblasCsrot +//#define clblasCsrot clblasCsrot_pfn +#undef clblasCsscal +//#define clblasCsscal clblasCsscal_pfn +#undef clblasCswap +//#define clblasCswap clblasCswap_pfn +#undef clblasCsymm +//#define clblasCsymm clblasCsymm_pfn +#undef clblasCsyr2k +//#define clblasCsyr2k clblasCsyr2k_pfn +#undef clblasCsyrk +//#define clblasCsyrk clblasCsyrk_pfn +#undef clblasCtbmv +//#define clblasCtbmv clblasCtbmv_pfn +#undef clblasCtbsv +//#define clblasCtbsv clblasCtbsv_pfn +#undef clblasCtpmv +//#define clblasCtpmv clblasCtpmv_pfn +#undef clblasCtpsv +//#define clblasCtpsv clblasCtpsv_pfn +#undef clblasCtrmm +//#define clblasCtrmm clblasCtrmm_pfn +#undef clblasCtrmv +//#define clblasCtrmv clblasCtrmv_pfn +#undef clblasCtrsm +//#define clblasCtrsm clblasCtrsm_pfn +#undef clblasCtrsv +//#define clblasCtrsv clblasCtrsv_pfn +#undef clblasDasum +//#define clblasDasum clblasDasum_pfn +#undef clblasDaxpy +//#define clblasDaxpy clblasDaxpy_pfn +#undef clblasDcopy +//#define clblasDcopy clblasDcopy_pfn +#undef clblasDdot +//#define clblasDdot clblasDdot_pfn +#undef clblasDgbmv +//#define clblasDgbmv clblasDgbmv_pfn +#undef clblasDgemm +#define clblasDgemm clblasDgemm_pfn +#undef clblasDgemv +//#define clblasDgemv clblasDgemv_pfn +#undef clblasDger +//#define clblasDger clblasDger_pfn +#undef clblasDnrm2 +//#define clblasDnrm2 clblasDnrm2_pfn +#undef clblasDrot +//#define clblasDrot clblasDrot_pfn +#undef clblasDrotg +//#define clblasDrotg clblasDrotg_pfn +#undef clblasDrotm +//#define clblasDrotm clblasDrotm_pfn +#undef clblasDrotmg +//#define clblasDrotmg clblasDrotmg_pfn +#undef clblasDsbmv +//#define clblasDsbmv clblasDsbmv_pfn +#undef clblasDscal +//#define clblasDscal clblasDscal_pfn +#undef clblasDspmv +//#define clblasDspmv clblasDspmv_pfn +#undef clblasDspr +//#define clblasDspr clblasDspr_pfn +#undef clblasDspr2 +//#define clblasDspr2 clblasDspr2_pfn +#undef clblasDswap +//#define clblasDswap clblasDswap_pfn +#undef clblasDsymm +//#define clblasDsymm clblasDsymm_pfn +#undef clblasDsymv +//#define clblasDsymv clblasDsymv_pfn +#undef clblasDsyr +//#define clblasDsyr clblasDsyr_pfn +#undef clblasDsyr2 +//#define clblasDsyr2 clblasDsyr2_pfn +#undef clblasDsyr2k +//#define clblasDsyr2k clblasDsyr2k_pfn +#undef clblasDsyrk +//#define clblasDsyrk clblasDsyrk_pfn +#undef clblasDtbmv +//#define clblasDtbmv clblasDtbmv_pfn +#undef clblasDtbsv +//#define clblasDtbsv clblasDtbsv_pfn +#undef clblasDtpmv +//#define clblasDtpmv clblasDtpmv_pfn +#undef clblasDtpsv +//#define clblasDtpsv clblasDtpsv_pfn +#undef clblasDtrmm +//#define clblasDtrmm clblasDtrmm_pfn +#undef clblasDtrmv +//#define clblasDtrmv clblasDtrmv_pfn +#undef clblasDtrsm +//#define clblasDtrsm clblasDtrsm_pfn +#undef clblasDtrsv +//#define clblasDtrsv clblasDtrsv_pfn +#undef clblasDzasum +//#define clblasDzasum clblasDzasum_pfn +#undef clblasDznrm2 +//#define clblasDznrm2 clblasDznrm2_pfn +#undef clblasGetVersion +//#define clblasGetVersion clblasGetVersion_pfn +#undef clblasSasum +//#define clblasSasum clblasSasum_pfn +#undef clblasSaxpy +//#define clblasSaxpy clblasSaxpy_pfn +#undef clblasScasum +//#define clblasScasum clblasScasum_pfn +#undef clblasScnrm2 +//#define clblasScnrm2 clblasScnrm2_pfn +#undef clblasScopy +//#define clblasScopy clblasScopy_pfn +#undef clblasSdot +//#define clblasSdot clblasSdot_pfn +#undef clblasSetup +#define clblasSetup clblasSetup_pfn +#undef clblasSgbmv +//#define clblasSgbmv clblasSgbmv_pfn +#undef clblasSgemm +#define clblasSgemm clblasSgemm_pfn +#undef clblasSgemv +//#define clblasSgemv clblasSgemv_pfn +#undef clblasSger +//#define clblasSger clblasSger_pfn +#undef clblasSnrm2 +//#define clblasSnrm2 clblasSnrm2_pfn +#undef clblasSrot +//#define clblasSrot clblasSrot_pfn +#undef clblasSrotg +//#define clblasSrotg clblasSrotg_pfn +#undef clblasSrotm +//#define clblasSrotm clblasSrotm_pfn +#undef clblasSrotmg +//#define clblasSrotmg clblasSrotmg_pfn +#undef clblasSsbmv +//#define clblasSsbmv clblasSsbmv_pfn +#undef clblasSscal +//#define clblasSscal clblasSscal_pfn +#undef clblasSspmv +//#define clblasSspmv clblasSspmv_pfn +#undef clblasSspr +//#define clblasSspr clblasSspr_pfn +#undef clblasSspr2 +//#define clblasSspr2 clblasSspr2_pfn +#undef clblasSswap +//#define clblasSswap clblasSswap_pfn +#undef clblasSsymm +//#define clblasSsymm clblasSsymm_pfn +#undef clblasSsymv +//#define clblasSsymv clblasSsymv_pfn +#undef clblasSsyr +//#define clblasSsyr clblasSsyr_pfn +#undef clblasSsyr2 +//#define clblasSsyr2 clblasSsyr2_pfn +#undef clblasSsyr2k +//#define clblasSsyr2k clblasSsyr2k_pfn +#undef clblasSsyrk +//#define clblasSsyrk clblasSsyrk_pfn +#undef clblasStbmv +//#define clblasStbmv clblasStbmv_pfn +#undef clblasStbsv +//#define clblasStbsv clblasStbsv_pfn +#undef clblasStpmv +//#define clblasStpmv clblasStpmv_pfn +#undef clblasStpsv +//#define clblasStpsv clblasStpsv_pfn +#undef clblasStrmm +//#define clblasStrmm clblasStrmm_pfn +#undef clblasStrmv +//#define clblasStrmv clblasStrmv_pfn +#undef clblasStrsm +//#define clblasStrsm clblasStrsm_pfn +#undef clblasStrsv +//#define clblasStrsv clblasStrsv_pfn +#undef clblasTeardown +#define clblasTeardown clblasTeardown_pfn +#undef clblasZaxpy +//#define clblasZaxpy clblasZaxpy_pfn +#undef clblasZcopy +//#define clblasZcopy clblasZcopy_pfn +#undef clblasZdotc +//#define clblasZdotc clblasZdotc_pfn +#undef clblasZdotu +//#define clblasZdotu clblasZdotu_pfn +#undef clblasZdrot +//#define clblasZdrot clblasZdrot_pfn +#undef clblasZdscal +//#define clblasZdscal clblasZdscal_pfn +#undef clblasZgbmv +//#define clblasZgbmv clblasZgbmv_pfn +#undef clblasZgemm +#define clblasZgemm clblasZgemm_pfn +#undef clblasZgemv +//#define clblasZgemv clblasZgemv_pfn +#undef clblasZgerc +//#define clblasZgerc clblasZgerc_pfn +#undef clblasZgeru +//#define clblasZgeru clblasZgeru_pfn +#undef clblasZhbmv +//#define clblasZhbmv clblasZhbmv_pfn +#undef clblasZhemm +//#define clblasZhemm clblasZhemm_pfn +#undef clblasZhemv +//#define clblasZhemv clblasZhemv_pfn +#undef clblasZher +//#define clblasZher clblasZher_pfn +#undef clblasZher2 +//#define clblasZher2 clblasZher2_pfn +#undef clblasZher2k +//#define clblasZher2k clblasZher2k_pfn +#undef clblasZherk +//#define clblasZherk clblasZherk_pfn +#undef clblasZhpmv +//#define clblasZhpmv clblasZhpmv_pfn +#undef clblasZhpr +//#define clblasZhpr clblasZhpr_pfn +#undef clblasZhpr2 +//#define clblasZhpr2 clblasZhpr2_pfn +#undef clblasZrotg +//#define clblasZrotg clblasZrotg_pfn +#undef clblasZscal +//#define clblasZscal clblasZscal_pfn +#undef clblasZswap +//#define clblasZswap clblasZswap_pfn +#undef clblasZsymm +//#define clblasZsymm clblasZsymm_pfn +#undef clblasZsyr2k +//#define clblasZsyr2k clblasZsyr2k_pfn +#undef clblasZsyrk +//#define clblasZsyrk clblasZsyrk_pfn +#undef clblasZtbmv +//#define clblasZtbmv clblasZtbmv_pfn +#undef clblasZtbsv +//#define clblasZtbsv clblasZtbsv_pfn +#undef clblasZtpmv +//#define clblasZtpmv clblasZtpmv_pfn +#undef clblasZtpsv +//#define clblasZtpsv clblasZtpsv_pfn +#undef clblasZtrmm +//#define clblasZtrmm clblasZtrmm_pfn +#undef clblasZtrmv +//#define clblasZtrmv clblasZtrmv_pfn +#undef clblasZtrsm +//#define clblasZtrsm clblasZtrsm_pfn +#undef clblasZtrsv +//#define clblasZtrsv clblasZtrsv_pfn +#undef clblasiCamax +//#define clblasiCamax clblasiCamax_pfn +#undef clblasiDamax +//#define clblasiDamax clblasiDamax_pfn +#undef clblasiSamax +//#define clblasiSamax clblasiSamax_pfn +#undef clblasiZamax +//#define clblasiZamax clblasiZamax_pfn + +// generated by parser_clblas.py +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCaxpy)(size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCdotc)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCdotu)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCgbmv)(clblasOrder order, clblasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clblasStatus (*clblasCgemm)(clblasOrder order, clblasTranspose transA, clblasTranspose transB, size_t M, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCgemv)(clblasOrder order, clblasTranspose transA, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, FloatComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCgerc)(clblasOrder order, size_t M, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCgeru)(clblasOrder order, size_t M, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasChbmv)(clblasOrder order, clblasUplo uplo, size_t N, size_t K, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasChemm)(clblasOrder order, clblasSide side, clblasUplo uplo, size_t M, size_t N, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasChemv)(clblasOrder order, clblasUplo uplo, size_t N, FloatComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, FloatComplex beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCher)(clblasOrder order, clblasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCher2)(clblasOrder order, clblasUplo uplo, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCher2k)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCherk)(clblasOrder order, clblasUplo uplo, clblasTranspose transA, size_t N, size_t K, float alpha, const cl_mem A, size_t offa, size_t lda, float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasChpmv)(clblasOrder order, clblasUplo uplo, size_t N, cl_float2 alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasChpr)(clblasOrder order, clblasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasChpr2)(clblasOrder order, clblasUplo uplo, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCrotg)(cl_mem CA, size_t offCA, cl_mem CB, size_t offCB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCscal)(size_t N, cl_float2 alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCsrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_float C, cl_float S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCsscal)(size_t N, cl_float alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCsymm)(clblasOrder order, clblasSide side, clblasUplo uplo, size_t M, size_t N, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCsyr2k)(clblasOrder order, clblasUplo uplo, clblasTranspose transAB, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCsyrk)(clblasOrder order, clblasUplo uplo, clblasTranspose transA, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCtbmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCtbsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCtpmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCtpsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCtrmm)(clblasOrder order, clblasSide side, clblasUplo uplo, clblasTranspose transA, clblasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCtrmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCtrsm)(clblasOrder order, clblasSide side, clblasUplo uplo, clblasTranspose transA, clblasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasCtrsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDaxpy)(size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDdot)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDgbmv)(clblasOrder order, clblasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clblasStatus (*clblasDgemm)(clblasOrder order, clblasTranspose transA, clblasTranspose transB, size_t M, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDgemv)(clblasOrder order, clblasTranspose transA, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDger)(clblasOrder order, size_t M, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_double C, cl_double S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDrotg)(cl_mem DA, size_t offDA, cl_mem DB, size_t offDB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDrotm)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, const cl_mem DPARAM, size_t offDparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDrotmg)(cl_mem DD1, size_t offDD1, cl_mem DD2, size_t offDD2, cl_mem DX1, size_t offDX1, const cl_mem DY1, size_t offDY1, cl_mem DPARAM, size_t offDparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDsbmv)(clblasOrder order, clblasUplo uplo, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDscal)(size_t N, cl_double alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDspmv)(clblasOrder order, clblasUplo uplo, size_t N, cl_double alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDspr)(clblasOrder order, clblasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDspr2)(clblasOrder order, clblasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDsymm)(clblasOrder order, clblasSide side, clblasUplo uplo, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDsymv)(clblasOrder order, clblasUplo uplo, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDsyr)(clblasOrder order, clblasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDsyr2)(clblasOrder order, clblasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDsyr2k)(clblasOrder order, clblasUplo uplo, clblasTranspose transAB, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDsyrk)(clblasOrder order, clblasUplo uplo, clblasTranspose transA, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDtbmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDtbsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDtpmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDtpsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDtrmm)(clblasOrder order, clblasSide side, clblasUplo uplo, clblasTranspose transA, clblasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDtrmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDtrsm)(clblasOrder order, clblasSide side, clblasUplo uplo, clblasTranspose transA, clblasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDtrsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDzasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasDznrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasGetVersion)(cl_uint* major, cl_uint* minor, cl_uint* patch); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSaxpy)(size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasScasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasScnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasScopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSdot)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clblasStatus (*clblasSetup)(); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSgbmv)(clblasOrder order, clblasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clblasStatus (*clblasSgemm)(clblasOrder order, clblasTranspose transA, clblasTranspose transB, size_t M, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSgemv)(clblasOrder order, clblasTranspose transA, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSger)(clblasOrder order, size_t M, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_float C, cl_float S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSrotg)(cl_mem SA, size_t offSA, cl_mem SB, size_t offSB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSrotm)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, const cl_mem SPARAM, size_t offSparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSrotmg)(cl_mem SD1, size_t offSD1, cl_mem SD2, size_t offSD2, cl_mem SX1, size_t offSX1, const cl_mem SY1, size_t offSY1, cl_mem SPARAM, size_t offSparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSsbmv)(clblasOrder order, clblasUplo uplo, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSscal)(size_t N, cl_float alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSspmv)(clblasOrder order, clblasUplo uplo, size_t N, cl_float alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSspr)(clblasOrder order, clblasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSspr2)(clblasOrder order, clblasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSsymm)(clblasOrder order, clblasSide side, clblasUplo uplo, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSsymv)(clblasOrder order, clblasUplo uplo, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSsyr)(clblasOrder order, clblasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSsyr2)(clblasOrder order, clblasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSsyr2k)(clblasOrder order, clblasUplo uplo, clblasTranspose transAB, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasSsyrk)(clblasOrder order, clblasUplo uplo, clblasTranspose transA, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasStbmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasStbsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasStpmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasStpsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasStrmm)(clblasOrder order, clblasSide side, clblasUplo uplo, clblasTranspose transA, clblasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasStrmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasStrsm)(clblasOrder order, clblasSide side, clblasUplo uplo, clblasTranspose transA, clblasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasStrsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT void (*clblasTeardown)(); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZaxpy)(size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZdotc)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZdotu)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZdrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_double C, cl_double S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZdscal)(size_t N, cl_double alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZgbmv)(clblasOrder order, clblasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clblasStatus (*clblasZgemm)(clblasOrder order, clblasTranspose transA, clblasTranspose transB, size_t M, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZgemv)(clblasOrder order, clblasTranspose transA, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, DoubleComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZgerc)(clblasOrder order, size_t M, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZgeru)(clblasOrder order, size_t M, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZhbmv)(clblasOrder order, clblasUplo uplo, size_t N, size_t K, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZhemm)(clblasOrder order, clblasSide side, clblasUplo uplo, size_t M, size_t N, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZhemv)(clblasOrder order, clblasUplo uplo, size_t N, DoubleComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, DoubleComplex beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZher)(clblasOrder order, clblasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZher2)(clblasOrder order, clblasUplo uplo, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZher2k)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZherk)(clblasOrder order, clblasUplo uplo, clblasTranspose transA, size_t N, size_t K, double alpha, const cl_mem A, size_t offa, size_t lda, double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZhpmv)(clblasOrder order, clblasUplo uplo, size_t N, cl_double2 alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZhpr)(clblasOrder order, clblasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZhpr2)(clblasOrder order, clblasUplo uplo, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZrotg)(cl_mem CA, size_t offCA, cl_mem CB, size_t offCB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZscal)(size_t N, cl_double2 alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZsymm)(clblasOrder order, clblasSide side, clblasUplo uplo, size_t M, size_t N, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZsyr2k)(clblasOrder order, clblasUplo uplo, clblasTranspose transAB, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZsyrk)(clblasOrder order, clblasUplo uplo, clblasTranspose transA, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZtbmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZtbsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZtpmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZtpsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZtrmm)(clblasOrder order, clblasSide side, clblasUplo uplo, clblasTranspose transA, clblasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZtrmv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZtrsm)(clblasOrder order, clblasSide side, clblasUplo uplo, clblasTranspose transA, clblasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasZtrsv)(clblasOrder order, clblasUplo uplo, clblasTranspose trans, clblasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasiCamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasiDamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasiSamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clblasStatus (*clblasiZamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); diff --git a/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clfft.hpp b/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clfft.hpp new file mode 100644 index 0000000000..dff3b406a6 --- /dev/null +++ b/3rdparty/include/opencv2/core/opencl/runtime/autogenerated/opencl_clfft.hpp @@ -0,0 +1,146 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP +#error "Invalid usage" +#endif + +// generated by parser_clfft.py +#define clfftBakePlan clfftBakePlan_ +#define clfftCopyPlan clfftCopyPlan_ +#define clfftCreateDefaultPlan clfftCreateDefaultPlan_ +#define clfftDestroyPlan clfftDestroyPlan_ +#define clfftEnqueueTransform clfftEnqueueTransform_ +#define clfftGetLayout clfftGetLayout_ +#define clfftGetPlanBatchSize clfftGetPlanBatchSize_ +#define clfftGetPlanContext clfftGetPlanContext_ +#define clfftGetPlanDim clfftGetPlanDim_ +#define clfftGetPlanDistance clfftGetPlanDistance_ +#define clfftGetPlanInStride clfftGetPlanInStride_ +#define clfftGetPlanLength clfftGetPlanLength_ +#define clfftGetPlanOutStride clfftGetPlanOutStride_ +#define clfftGetPlanPrecision clfftGetPlanPrecision_ +#define clfftGetPlanScale clfftGetPlanScale_ +#define clfftGetPlanTransposeResult clfftGetPlanTransposeResult_ +#define clfftGetResultLocation clfftGetResultLocation_ +#define clfftGetTmpBufSize clfftGetTmpBufSize_ +#define clfftGetVersion clfftGetVersion_ +#define clfftSetLayout clfftSetLayout_ +#define clfftSetPlanBatchSize clfftSetPlanBatchSize_ +#define clfftSetPlanCallback clfftSetPlanCallback_ +#define clfftSetPlanDim clfftSetPlanDim_ +#define clfftSetPlanDistance clfftSetPlanDistance_ +#define clfftSetPlanInStride clfftSetPlanInStride_ +#define clfftSetPlanLength clfftSetPlanLength_ +#define clfftSetPlanOutStride clfftSetPlanOutStride_ +#define clfftSetPlanPrecision clfftSetPlanPrecision_ +#define clfftSetPlanScale clfftSetPlanScale_ +#define clfftSetPlanTransposeResult clfftSetPlanTransposeResult_ +#define clfftSetResultLocation clfftSetResultLocation_ +#define clfftSetup clfftSetup_ +#define clfftTeardown clfftTeardown_ + +#include + +// generated by parser_clfft.py +#undef clfftBakePlan +#define clfftBakePlan clfftBakePlan_pfn +#undef clfftCopyPlan +//#define clfftCopyPlan clfftCopyPlan_pfn +#undef clfftCreateDefaultPlan +#define clfftCreateDefaultPlan clfftCreateDefaultPlan_pfn +#undef clfftDestroyPlan +#define clfftDestroyPlan clfftDestroyPlan_pfn +#undef clfftEnqueueTransform +#define clfftEnqueueTransform clfftEnqueueTransform_pfn +#undef clfftGetLayout +//#define clfftGetLayout clfftGetLayout_pfn +#undef clfftGetPlanBatchSize +//#define clfftGetPlanBatchSize clfftGetPlanBatchSize_pfn +#undef clfftGetPlanContext +//#define clfftGetPlanContext clfftGetPlanContext_pfn +#undef clfftGetPlanDim +//#define clfftGetPlanDim clfftGetPlanDim_pfn +#undef clfftGetPlanDistance +//#define clfftGetPlanDistance clfftGetPlanDistance_pfn +#undef clfftGetPlanInStride +//#define clfftGetPlanInStride clfftGetPlanInStride_pfn +#undef clfftGetPlanLength +//#define clfftGetPlanLength clfftGetPlanLength_pfn +#undef clfftGetPlanOutStride +//#define clfftGetPlanOutStride clfftGetPlanOutStride_pfn +#undef clfftGetPlanPrecision +//#define clfftGetPlanPrecision clfftGetPlanPrecision_pfn +#undef clfftGetPlanScale +//#define clfftGetPlanScale clfftGetPlanScale_pfn +#undef clfftGetPlanTransposeResult +//#define clfftGetPlanTransposeResult clfftGetPlanTransposeResult_pfn +#undef clfftGetResultLocation +//#define clfftGetResultLocation clfftGetResultLocation_pfn +#undef clfftGetTmpBufSize +#define clfftGetTmpBufSize clfftGetTmpBufSize_pfn +#undef clfftGetVersion +#define clfftGetVersion clfftGetVersion_pfn +#undef clfftSetLayout +#define clfftSetLayout clfftSetLayout_pfn +#undef clfftSetPlanBatchSize +#define clfftSetPlanBatchSize clfftSetPlanBatchSize_pfn +#undef clfftSetPlanCallback +//#define clfftSetPlanCallback clfftSetPlanCallback_pfn +#undef clfftSetPlanDim +//#define clfftSetPlanDim clfftSetPlanDim_pfn +#undef clfftSetPlanDistance +#define clfftSetPlanDistance clfftSetPlanDistance_pfn +#undef clfftSetPlanInStride +#define clfftSetPlanInStride clfftSetPlanInStride_pfn +#undef clfftSetPlanLength +//#define clfftSetPlanLength clfftSetPlanLength_pfn +#undef clfftSetPlanOutStride +#define clfftSetPlanOutStride clfftSetPlanOutStride_pfn +#undef clfftSetPlanPrecision +#define clfftSetPlanPrecision clfftSetPlanPrecision_pfn +#undef clfftSetPlanScale +#define clfftSetPlanScale clfftSetPlanScale_pfn +#undef clfftSetPlanTransposeResult +//#define clfftSetPlanTransposeResult clfftSetPlanTransposeResult_pfn +#undef clfftSetResultLocation +#define clfftSetResultLocation clfftSetResultLocation_pfn +#undef clfftSetup +#define clfftSetup clfftSetup_pfn +#undef clfftTeardown +#define clfftTeardown clfftTeardown_pfn + +// generated by parser_clfft.py +extern CL_RUNTIME_EXPORT clfftStatus (*clfftBakePlan)(clfftPlanHandle plHandle, cl_uint numQueues, cl_command_queue* commQueueFFT, void (CL_CALLBACK* pfn_notify) (clfftPlanHandle plHandle, void* user_data), void* user_data); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftCopyPlan)(clfftPlanHandle* out_plHandle, cl_context new_context, clfftPlanHandle in_plHandle); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftCreateDefaultPlan)(clfftPlanHandle* plHandle, cl_context context, const clfftDim dim, const size_t* clLengths); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftDestroyPlan)(clfftPlanHandle* plHandle); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftEnqueueTransform)(clfftPlanHandle plHandle, clfftDirection dir, cl_uint numQueuesAndEvents, cl_command_queue* commQueues, cl_uint numWaitEvents, const cl_event* waitEvents, cl_event* outEvents, cl_mem* inputBuffers, cl_mem* outputBuffers, cl_mem tmpBuffer); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetLayout)(const clfftPlanHandle plHandle, clfftLayout* iLayout, clfftLayout* oLayout); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanBatchSize)(const clfftPlanHandle plHandle, size_t* batchSize); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanContext)(const clfftPlanHandle plHandle, cl_context* context); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanDim)(const clfftPlanHandle plHandle, clfftDim* dim, cl_uint* size); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanDistance)(const clfftPlanHandle plHandle, size_t* iDist, size_t* oDist); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanInStride)(const clfftPlanHandle plHandle, const clfftDim dim, size_t* clStrides); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanLength)(const clfftPlanHandle plHandle, const clfftDim dim, size_t* clLengths); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanOutStride)(const clfftPlanHandle plHandle, const clfftDim dim, size_t* clStrides); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanPrecision)(const clfftPlanHandle plHandle, clfftPrecision* precision); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanScale)(const clfftPlanHandle plHandle, clfftDirection dir, cl_float* scale); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetPlanTransposeResult)(const clfftPlanHandle plHandle, clfftResultTransposed* transposed); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetResultLocation)(const clfftPlanHandle plHandle, clfftResultLocation* placeness); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetTmpBufSize)(const clfftPlanHandle plHandle, size_t* buffersize); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftGetVersion)(cl_uint* major, cl_uint* minor, cl_uint* patch); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetLayout)(clfftPlanHandle plHandle, clfftLayout iLayout, clfftLayout oLayout); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanBatchSize)(clfftPlanHandle plHandle, size_t batchSize); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanCallback)(clfftPlanHandle plHandle, const char* funcName, const char* funcString, int localMemSize, clfftCallbackType callbackType, cl_mem* userdata, int numUserdataBuffers); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanDim)(clfftPlanHandle plHandle, const clfftDim dim); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanDistance)(clfftPlanHandle plHandle, size_t iDist, size_t oDist); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanInStride)(clfftPlanHandle plHandle, const clfftDim dim, size_t* clStrides); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanLength)(clfftPlanHandle plHandle, const clfftDim dim, const size_t* clLengths); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanOutStride)(clfftPlanHandle plHandle, const clfftDim dim, size_t* clStrides); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanPrecision)(clfftPlanHandle plHandle, clfftPrecision precision); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanScale)(clfftPlanHandle plHandle, clfftDirection dir, cl_float scale); +//extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetPlanTransposeResult)(clfftPlanHandle plHandle, clfftResultTransposed transposed); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetResultLocation)(clfftPlanHandle plHandle, clfftResultLocation placeness); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftSetup)(const clfftSetupData* setupData); +extern CL_RUNTIME_EXPORT clfftStatus (*clfftTeardown)(); diff --git a/3rdparty/include/opencv2/core/opencl/runtime/opencl_clamdblas.hpp b/3rdparty/include/opencv2/core/opencl/runtime/opencl_clblas.hpp similarity index 98% rename from 3rdparty/include/opencv2/core/opencl/runtime/opencl_clamdblas.hpp rename to 3rdparty/include/opencv2/core/opencl/runtime/opencl_clblas.hpp index 2ad8ac0b5d..ccddf8f76c 100644 --- a/3rdparty/include/opencv2/core/opencl/runtime/opencl_clamdblas.hpp +++ b/3rdparty/include/opencv2/core/opencl/runtime/opencl_clblas.hpp @@ -46,7 +46,7 @@ #include "opencl_core.hpp" -#include "autogenerated/opencl_clamdblas.hpp" +#include "autogenerated/opencl_clblas.hpp" #endif // HAVE_CLAMDBLAS diff --git a/3rdparty/include/opencv2/core/opencl/runtime/opencl_clamdfft.hpp b/3rdparty/include/opencv2/core/opencl/runtime/opencl_clfft.hpp similarity index 98% rename from 3rdparty/include/opencv2/core/opencl/runtime/opencl_clamdfft.hpp rename to 3rdparty/include/opencv2/core/opencl/runtime/opencl_clfft.hpp index a328f722fc..7f4af5e60b 100644 --- a/3rdparty/include/opencv2/core/opencl/runtime/opencl_clamdfft.hpp +++ b/3rdparty/include/opencv2/core/opencl/runtime/opencl_clfft.hpp @@ -46,7 +46,7 @@ #include "opencl_core.hpp" -#include "autogenerated/opencl_clamdfft.hpp" +#include "autogenerated/opencl_clfft.hpp" #endif // HAVE_CLAMDFFT diff --git a/3rdparty/include/opencv2/core/opengl.hpp b/3rdparty/include/opencv2/core/opengl.hpp index a6288bebe8..a311ce2525 100644 --- a/3rdparty/include/opencv2/core/opengl.hpp +++ b/3rdparty/include/opencv2/core/opengl.hpp @@ -548,7 +548,7 @@ calling unmapGLBuffer() function. @param accessFlags - data access flags (ACCESS_READ|ACCESS_WRITE). @return Returns UMat object */ -CV_EXPORTS UMat mapGLBuffer(const Buffer& buffer, int accessFlags = ACCESS_READ|ACCESS_WRITE); +CV_EXPORTS UMat mapGLBuffer(const Buffer& buffer, AccessFlag accessFlags = ACCESS_READ | ACCESS_WRITE); /** @brief Unmaps Buffer object (releases UMat, previously mapped from Buffer). diff --git a/3rdparty/include/opencv2/core/operations.hpp b/3rdparty/include/opencv2/core/operations.hpp index ef1808a8a1..bde28c49b2 100644 --- a/3rdparty/include/opencv2/core/operations.hpp +++ b/3rdparty/include/opencv2/core/operations.hpp @@ -51,6 +51,16 @@ #include +#if defined(__GNUC__) || defined(__clang__) // at least GCC 3.1+, clang 3.5+ +# if defined(__MINGW_PRINTF_FORMAT) // https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. +# define CV_FORMAT_PRINTF(string_idx, first_to_check) __attribute__ ((format (__MINGW_PRINTF_FORMAT, string_idx, first_to_check))) +# else +# define CV_FORMAT_PRINTF(string_idx, first_to_check) __attribute__ ((format (printf, string_idx, first_to_check))) +# endif +#else +# define CV_FORMAT_PRINTF(A, B) +#endif + //! @cond IGNORED namespace cv @@ -405,13 +415,24 @@ template static inline _Tp randu() The function acts like sprintf but forms and returns an STL string. It can be used to form an error message in the Exception constructor. @param fmt printf-compatible formatting specifiers. + +**Note**: +|Type|Specifier| +|-|-| +|`const char*`|`%s`| +|`char`|`%c`| +|`float` / `double`|`%f`,`%g`| +|`int`, `long`, `long long`|`%d`, `%ld`, ``%lld`| +|`unsigned`, `unsigned long`, `unsigned long long`|`%u`, `%lu`, `%llu`| +|`uint64` -> `uintmax_t`, `int64` -> `intmax_t`|`%ju`, `%jd`| +|`size_t`|`%zu`| */ -CV_EXPORTS String format( const char* fmt, ... ); +CV_EXPORTS String format( const char* fmt, ... ) CV_FORMAT_PRINTF(1, 2); ///////////////////////////////// Formatted output of cv::Mat ///////////////////////////////// static inline -Ptr format(InputArray mtx, int fmt) +Ptr format(InputArray mtx, Formatter::FormatType fmt) { return Formatter::get(fmt)->format(mtx.getMat()); } diff --git a/3rdparty/include/opencv2/core/optim.hpp b/3rdparty/include/opencv2/core/optim.hpp index 5a0940037d..f61a2b9407 100644 --- a/3rdparty/include/opencv2/core/optim.hpp +++ b/3rdparty/include/opencv2/core/optim.hpp @@ -293,7 +293,7 @@ and the remaining to \f$A\f$. It should contain 32- or 64-bit floating point num formulation above. It will contain 64-bit floating point numbers. @return One of cv::SolveLPResult */ -CV_EXPORTS_W int solveLP(const Mat& Func, const Mat& Constr, Mat& z); +CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z); //! @} diff --git a/3rdparty/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp b/3rdparty/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp new file mode 100644 index 0000000000..b172cac34d --- /dev/null +++ b/3rdparty/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp @@ -0,0 +1,72 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_PARALLEL_FOR_OPENMP_HPP +#define OPENCV_CORE_PARALLEL_FOR_OPENMP_HPP + +#include "opencv2/core/parallel/parallel_backend.hpp" + +#if !defined(_OPENMP) && !defined(OPENCV_SKIP_OPENMP_PRESENSE_CHECK) +#error "This file must be compiled with enabled OpenMP" +#endif + +#include + +namespace cv { namespace parallel { namespace openmp { + +/** OpenMP parallel_for API implementation + * + * @sa setParallelForBackend + * @ingroup core_parallel_backend + */ +class ParallelForBackend : public ParallelForAPI +{ +protected: + int numThreads; + int numThreadsMax; +public: + ParallelForBackend() + { + numThreads = 0; + numThreadsMax = omp_get_max_threads(); + } + + virtual ~ParallelForBackend() {} + + virtual void parallel_for(int tasks, FN_parallel_for_body_cb_t body_callback, void* callback_data) CV_OVERRIDE + { +#pragma omp parallel for schedule(dynamic) num_threads(numThreads > 0 ? numThreads : numThreadsMax) + for (int i = 0; i < tasks; ++i) + body_callback(i, i + 1, callback_data); + } + + virtual int getThreadNum() const CV_OVERRIDE + { + return omp_get_thread_num(); + } + + virtual int getNumThreads() const CV_OVERRIDE + { + return numThreads > 0 + ? numThreads + : numThreadsMax; + } + + virtual int setNumThreads(int nThreads) CV_OVERRIDE + { + int oldNumThreads = numThreads; + numThreads = nThreads; + // nothing needed as numThreads is used in #pragma omp parallel for directly + return oldNumThreads; + } + + const char* getName() const CV_OVERRIDE + { + return "openmp"; + } +}; + +}}} // namespace + +#endif // OPENCV_CORE_PARALLEL_FOR_OPENMP_HPP diff --git a/3rdparty/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp b/3rdparty/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp new file mode 100644 index 0000000000..264def5f50 --- /dev/null +++ b/3rdparty/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp @@ -0,0 +1,153 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_PARALLEL_FOR_TBB_HPP +#define OPENCV_CORE_PARALLEL_FOR_TBB_HPP + +#include "opencv2/core/parallel/parallel_backend.hpp" +#include + +#ifndef TBB_SUPPRESS_DEPRECATED_MESSAGES // supress warning +#define TBB_SUPPRESS_DEPRECATED_MESSAGES 1 +#endif +#include "tbb/tbb.h" +#if !defined(TBB_INTERFACE_VERSION) +#error "Unknows/unsupported TBB version" +#endif + +#if TBB_INTERFACE_VERSION >= 8000 +#include "tbb/task_arena.h" +#endif + +namespace cv { namespace parallel { namespace tbb { + +using namespace ::tbb; + +#if TBB_INTERFACE_VERSION >= 8000 +static tbb::task_arena& getArena() +{ + static tbb::task_arena tbbArena(tbb::task_arena::automatic); + return tbbArena; +} +#else +static tbb::task_scheduler_init& getScheduler() +{ + static tbb::task_scheduler_init tbbScheduler(tbb::task_scheduler_init::deferred); + return tbbScheduler; +} +#endif + +/** OpenMP parallel_for API implementation + * + * @sa setParallelForBackend + * @ingroup core_parallel_backend + */ +class ParallelForBackend : public ParallelForAPI +{ +protected: + int numThreads; + int numThreadsMax; +public: + ParallelForBackend() + { + CV_LOG_INFO(NULL, "Initializing TBB parallel backend: TBB_INTERFACE_VERSION=" << TBB_INTERFACE_VERSION); + numThreads = 0; +#if TBB_INTERFACE_VERSION >= 8000 + (void)getArena(); +#else + (void)getScheduler(); +#endif + } + + virtual ~ParallelForBackend() {} + + class CallbackProxy + { + const FN_parallel_for_body_cb_t& callback; + void* const callback_data; + const int tasks; + public: + inline CallbackProxy(int tasks_, FN_parallel_for_body_cb_t& callback_, void* callback_data_) + : callback(callback_), callback_data(callback_data_), tasks(tasks_) + { + // nothing + } + + void operator()(const tbb::blocked_range& range) const + { + this->callback(range.begin(), range.end(), callback_data); + } + + void operator()() const + { + tbb::parallel_for(tbb::blocked_range(0, tasks), *this); + } + }; + + virtual void parallel_for(int tasks, FN_parallel_for_body_cb_t body_callback, void* callback_data) CV_OVERRIDE + { + CallbackProxy task(tasks, body_callback, callback_data); +#if TBB_INTERFACE_VERSION >= 8000 + getArena().execute(task); +#else + task(); +#endif + } + + virtual int getThreadNum() const CV_OVERRIDE + { +#if TBB_INTERFACE_VERSION >= 9100 + return tbb::this_task_arena::current_thread_index(); +#elif TBB_INTERFACE_VERSION >= 8000 + return tbb::task_arena::current_thread_index(); +#else + return 0; +#endif + } + + virtual int getNumThreads() const CV_OVERRIDE + { +#if TBB_INTERFACE_VERSION >= 9100 + return getArena().max_concurrency(); +#elif TBB_INTERFACE_VERSION >= 8000 + return numThreads > 0 + ? numThreads + : tbb::task_scheduler_init::default_num_threads(); +#else + return getScheduler().is_active() + ? numThreads + : tbb::task_scheduler_init::default_num_threads(); +#endif + } + + virtual int setNumThreads(int nThreads) CV_OVERRIDE + { + int oldNumThreads = numThreads; + numThreads = nThreads; + +#if TBB_INTERFACE_VERSION >= 8000 + auto& tbbArena = getArena(); + if (tbbArena.is_active()) + tbbArena.terminate(); + if (numThreads > 0) + tbbArena.initialize(numThreads); +#else + auto& tbbScheduler = getScheduler(); + if (tbbScheduler.is_active()) + tbbScheduler.terminate(); + if (numThreads > 0) + tbbScheduler.initialize(numThreads); +#endif + return oldNumThreads; + } + + const char* getName() const CV_OVERRIDE + { + return "tbb"; + } +}; + +}}} // namespace + +#endif // OPENCV_CORE_PARALLEL_FOR_TBB_HPP diff --git a/3rdparty/include/opencv2/core/parallel/parallel_backend.hpp b/3rdparty/include/opencv2/core/parallel/parallel_backend.hpp new file mode 100644 index 0000000000..c3e8333c1c --- /dev/null +++ b/3rdparty/include/opencv2/core/parallel/parallel_backend.hpp @@ -0,0 +1,90 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_PARALLEL_BACKEND_HPP +#define OPENCV_CORE_PARALLEL_BACKEND_HPP + +#include "opencv2/core/cvdef.h" +#include + +namespace cv { namespace parallel { +#ifndef CV_API_CALL +#define CV_API_CALL +#endif + +/** @addtogroup core_parallel_backend + * @{ + * API below is provided to resolve problem of CPU resource over-subscription by multiple thread pools from different multi-threading frameworks. + * This is common problem for cases when OpenCV compiled threading framework is different from the Users Applications framework. + * + * Applications can replace OpenCV `parallel_for()` backend with own implementation (to reuse Application's thread pool). + * + * + * ### Backend API usage examples + * + * #### Intel TBB + * + * - include header with simple implementation of TBB backend: + * @snippet parallel_backend/example-tbb.cpp tbb_include + * - execute backend replacement code: + * @snippet parallel_backend/example-tbb.cpp tbb_backend + * - configuration of compiler/linker options is responsibility of Application's scripts + * + * #### OpenMP + * + * - include header with simple implementation of OpenMP backend: + * @snippet parallel_backend/example-openmp.cpp openmp_include + * - execute backend replacement code: + * @snippet parallel_backend/example-openmp.cpp openmp_backend + * - Configuration of compiler/linker options is responsibility of Application's scripts + * + * + * ### Plugins support + * + * Runtime configuration options: + * - change backend priority: `OPENCV_PARALLEL_PRIORITY_=9999` + * - disable backend: `OPENCV_PARALLEL_PRIORITY_=0` + * - specify list of backends with high priority (>100000): `OPENCV_PARALLEL_PRIORITY_LIST=TBB,OPENMP`. Unknown backends are registered as new plugins. + * + */ + +/** Interface for parallel_for backends implementations + * + * @sa setParallelForBackend + */ +class CV_EXPORTS ParallelForAPI +{ +public: + virtual ~ParallelForAPI(); + + typedef void (CV_API_CALL *FN_parallel_for_body_cb_t)(int start, int end, void* data); + + virtual void parallel_for(int tasks, FN_parallel_for_body_cb_t body_callback, void* callback_data) = 0; + + virtual int getThreadNum() const = 0; + + virtual int getNumThreads() const = 0; + + virtual int setNumThreads(int nThreads) = 0; + + virtual const char* getName() const = 0; +}; + +/** @brief Replace OpenCV parallel_for backend + * + * Application can replace OpenCV `parallel_for()` backend with own implementation. + * + * @note This call is not thread-safe. Consider calling this function from the `main()` before any other OpenCV processing functions (and without any other created threads). + */ +CV_EXPORTS void setParallelForBackend(const std::shared_ptr& api, bool propagateNumThreads = true); + +/** @brief Change OpenCV parallel_for backend + * + * @note This call is not thread-safe. Consider calling this function from the `main()` before any other OpenCV processing functions (and without any other created threads). + */ +CV_EXPORTS_W bool setParallelForBackend(const std::string& backendName, bool propagateNumThreads = true); + +//! @} +}} // namespace +#endif // OPENCV_CORE_PARALLEL_BACKEND_HPP diff --git a/3rdparty/include/opencv2/core/persistence.hpp b/3rdparty/include/opencv2/core/persistence.hpp index e3026e3c9f..276f640323 100644 --- a/3rdparty/include/opencv2/core/persistence.hpp +++ b/3rdparty/include/opencv2/core/persistence.hpp @@ -94,10 +94,6 @@ The same functions can read and write data in both formats; the particular forma the extension of the opened file, ".xml" for XML files, ".yml" or ".yaml" for YAML and ".json" for JSON. */ -typedef struct CvFileStorage CvFileStorage; -typedef struct CvFileNode CvFileNode; -typedef struct CvMat CvMat; -typedef struct CvMatND CvMatND; //! @} core_c @@ -128,7 +124,7 @@ streams. Here is an example: @code - #include "opencv2/opencv.hpp" + #include "opencv2/core.hpp" #include using namespace cv; @@ -314,7 +310,7 @@ public: WRITE = 1, //!< value, open the file for writing APPEND = 2, //!< value, open the file for appending MEMORY = 4, //!< flag, read data from source or write data to the internal buffer (which is - //!< returned by FileStorage::release) + //!< returned by FileStorage::release) FORMAT_MASK = (7<<3), //!< mask for format flags FORMAT_AUTO = 0, //!< flag, auto format FORMAT_XML = (1<<3), //!< flag, XML format @@ -324,7 +320,7 @@ public: BASE64 = 64, //!< flag, write rawdata in Base64 by default. (consider using WRITE_BASE64) WRITE_BASE64 = BASE64 | WRITE, //!< flag, enable both WRITE and BASE64 }; - enum + enum State { UNDEFINED = 0, VALUE_EXPECTED = 1, @@ -334,109 +330,81 @@ public: /** @brief The constructors. - The full constructor opens the file. Alternatively you can use the default constructor and then - call FileStorage::open. + The full constructor opens the file. Alternatively you can use the default constructor and then + call FileStorage::open. */ CV_WRAP FileStorage(); /** @overload - @copydoc open() - */ + @copydoc open() + */ CV_WRAP FileStorage(const String& filename, int flags, const String& encoding=String()); - /** @overload */ - FileStorage(CvFileStorage* fs, bool owning=true); - //! the destructor. calls release() virtual ~FileStorage(); /** @brief Opens a file. - See description of parameters in FileStorage::FileStorage. The method calls FileStorage::release - before opening the file. - @param filename Name of the file to open or the text string to read the data from. - Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON - respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both - FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify - the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. - You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to - FileStorage::BASE64 flag. - @param flags Mode of operation. One of FileStorage::Mode - @param encoding Encoding of the file. Note that UTF-16 XML encoding is not supported currently and - you should use 8-bit encoding instead of it. + See description of parameters in FileStorage::FileStorage. The method calls FileStorage::release + before opening the file. + @param filename Name of the file to open or the text string to read the data from. + Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON + respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both + FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify + the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. + You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to + FileStorage::BASE64 flag. + @param flags Mode of operation. One of FileStorage::Mode + @param encoding Encoding of the file. Note that UTF-16 XML encoding is not supported currently and + you should use 8-bit encoding instead of it. */ CV_WRAP virtual bool open(const String& filename, int flags, const String& encoding=String()); /** @brief Checks whether the file is opened. - @returns true if the object is associated with the current file and false otherwise. It is a - good practice to call this method after you tried to open a file. + @returns true if the object is associated with the current file and false otherwise. It is a + good practice to call this method after you tried to open a file. */ CV_WRAP virtual bool isOpened() const; /** @brief Closes the file and releases all the memory buffers. - Call this method after all I/O operations with the storage are finished. + Call this method after all I/O operations with the storage are finished. */ CV_WRAP virtual void release(); /** @brief Closes the file and releases all the memory buffers. - Call this method after all I/O operations with the storage are finished. If the storage was - opened for writing data and FileStorage::WRITE was specified + Call this method after all I/O operations with the storage are finished. If the storage was + opened for writing data and FileStorage::WRITE was specified */ CV_WRAP virtual String releaseAndGetString(); /** @brief Returns the first element of the top-level mapping. - @returns The first element of the top-level mapping. + @returns The first element of the top-level mapping. */ CV_WRAP FileNode getFirstTopLevelNode() const; /** @brief Returns the top-level mapping - @param streamidx Zero-based index of the stream. In most cases there is only one stream in the file. - However, YAML supports multiple streams and so there can be several. - @returns The top-level mapping. + @param streamidx Zero-based index of the stream. In most cases there is only one stream in the file. + However, YAML supports multiple streams and so there can be several. + @returns The top-level mapping. */ CV_WRAP FileNode root(int streamidx=0) const; /** @brief Returns the specified element of the top-level mapping. - @param nodename Name of the file node. - @returns Node with the given name. + @param nodename Name of the file node. + @returns Node with the given name. */ FileNode operator[](const String& nodename) const; /** @overload */ CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; - /** @brief Returns the obsolete C FileStorage structure. - @returns Pointer to the underlying C FileStorage structure - */ - CvFileStorage* operator *() { return fs.get(); } - - /** @overload */ - const CvFileStorage* operator *() const { return fs.get(); } - - /** @brief Writes multiple numbers. - - Writes one or more numbers of the specified format to the currently written structure. Usually it is - more convenient to use operator `<<` instead of this method. - @param fmt Specification of each array element, see @ref format_spec "format specification" - @param vec Pointer to the written array. - @param len Number of the uchar elements to write. - */ - void writeRaw( const String& fmt, const uchar* vec, size_t len ); - - /** @brief Writes the registered C structure (CvMat, CvMatND, CvSeq). - @param name Name of the written object. - @param obj Pointer to the object. - @see cvWrite for details. - */ - void writeObj( const String& name, const void* obj ); - /** * @brief Simplified writing API to use with bindings. - * @param name Name of the written object - * @param val Value of the written object + * @param name Name of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string. + * @param val Value of the written object. */ CV_WRAP void write(const String& name, int val); /// @overload @@ -444,22 +412,35 @@ public: /// @overload CV_WRAP void write(const String& name, const String& val); /// @overload - CV_WRAP void write(const String& name, InputArray val); + CV_WRAP void write(const String& name, const Mat& val); + /// @overload + CV_WRAP void write(const String& name, const std::vector& val); + + /** @brief Writes multiple numbers. + + Writes one or more numbers of the specified format to the currently written structure. Usually it is + more convenient to use operator `<<` instead of this method. + @param fmt Specification of each array element, see @ref format_spec "format specification" + @param vec Pointer to the written array. + @param len Number of the uchar elements to write. + */ + void writeRaw( const String& fmt, const void* vec, size_t len ); /** @brief Writes a comment. - The function writes a comment into file storage. The comments are skipped when the storage is read. - @param comment The written comment, single-line or multi-line - @param append If true, the function tries to put the comment at the end of current line. - Else if the comment is multi-line, or if it does not fit at the end of the current - line, the comment starts a new line. + The function writes a comment into file storage. The comments are skipped when the storage is read. + @param comment The written comment, single-line or multi-line + @param append If true, the function tries to put the comment at the end of current line. + Else if the comment is multi-line, or if it does not fit at the end of the current + line, the comment starts a new line. */ CV_WRAP void writeComment(const String& comment, bool append = false); /** @brief Starts to write a nested structure (sequence or a mapping). - @param name name of the structure (if it's a member of parent mapping, otherwise it should be empty + @param name name of the structure. When writing to sequences (a.k.a. "arrays"), pass an empty string. @param flags type of the structure (FileNode::MAP or FileNode::SEQ (both with optional FileNode::FLOW)). - @param typeName usually an empty string + @param typeName optional name of the type you store. The effect of setting this depends on the storage format. + I.e. if the format has a specification for storing type information, this parameter is used. */ CV_WRAP void startWriteStruct(const String& name, int flags, const String& typeName=String()); @@ -478,13 +459,12 @@ public: */ CV_WRAP int getFormat() const; - Ptr fs; //!< the underlying C FileStorage structure - String elname; //!< the currently written element - std::vector structs; //!< the stack of written structures - int state; //!< the writer state -}; + int state; + std::string elname; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvFileStorage* obj) const; + class Impl; + Ptr p; +}; /** @brief File Storage Node class. @@ -502,7 +482,7 @@ class CV_EXPORTS_W_SIMPLE FileNode { public: //! type of the file storage node - enum Type + enum { NONE = 0, //!< empty node INT = 1, //!< an integer @@ -510,58 +490,62 @@ public: FLOAT = REAL, //!< synonym or REAL STR = 3, //!< text string in UTF-8 encoding STRING = STR, //!< synonym for STR - REF = 4, //!< integer of size size_t. Typically used for storing complex dynamic structures where some elements reference the others - SEQ = 5, //!< sequence - MAP = 6, //!< mapping + SEQ = 4, //!< sequence + MAP = 5, //!< mapping TYPE_MASK = 7, + FLOW = 8, //!< compact representation of a sequence or mapping. Used only by YAML writer - USER = 16, //!< a registered object (e.g. a matrix) - EMPTY = 32, //!< empty structure (sequence or mapping) - NAMED = 64 //!< the node has a name (i.e. it is element of a mapping) + UNIFORM = 8, //!< if set, means that all the collection elements are numbers of the same type (real's or int's). + //!< UNIFORM is used only when reading FileStorage; FLOW is used only when writing. So they share the same bit + EMPTY = 16, //!< empty structure (sequence or mapping) + NAMED = 32 //!< the node has a name (i.e. it is element of a mapping). }; /** @brief The constructors. - These constructors are used to create a default file node, construct it from obsolete structures or - from the another file node. + These constructors are used to create a default file node, construct it from obsolete structures or + from the another file node. */ CV_WRAP FileNode(); /** @overload - @param fs Pointer to the obsolete file storage structure. - @param node File node to be used as initialization for the created file node. - */ - FileNode(const CvFileStorage* fs, const CvFileNode* node); + @param fs Pointer to the file storage structure. + @param blockIdx Index of the memory block where the file node is stored + @param ofs Offset in bytes from the beginning of the serialized storage + + @deprecated + */ + FileNode(const FileStorage* fs, size_t blockIdx, size_t ofs); /** @overload - @param node File node to be used as initialization for the created file node. - */ + @param node File node to be used as initialization for the created file node. + */ FileNode(const FileNode& node); FileNode& operator=(const FileNode& node); /** @brief Returns element of a mapping node or a sequence node. - @param nodename Name of an element in the mapping node. - @returns Returns the element with the given identifier. + @param nodename Name of an element in the mapping node. + @returns Returns the element with the given identifier. */ FileNode operator[](const String& nodename) const; /** @overload - @param nodename Name of an element in the mapping node. - */ + @param nodename Name of an element in the mapping node. + */ CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; /** @overload - @param i Index of an element in the sequence node. - */ + @param i Index of an element in the sequence node. + */ CV_WRAP_AS(at) FileNode operator[](int i) const; /** @brief Returns keys of a mapping node. - @returns Keys of a mapping node. + @returns Keys of a mapping node. */ CV_WRAP std::vector keys() const; /** @brief Returns type of the node. - @returns Type of the node. See FileNode::Type + @returns Type of the node. See FileNode::Type */ CV_WRAP int type() const; @@ -582,9 +566,11 @@ public: //! returns true if the node has a name CV_WRAP bool isNamed() const; //! returns the node name or an empty string if the node is nameless - CV_WRAP String name() const; + CV_WRAP std::string name() const; //! returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise. CV_WRAP size_t size() const; + //! returns raw size of the FileNode in bytes + CV_WRAP size_t rawSize() const; //! returns the node content as an integer. If the node stores floating-point number, it is rounded. operator int() const; //! returns the node content as float @@ -592,13 +578,16 @@ public: //! returns the node content as double operator double() const; //! returns the node content as text string - operator String() const; - operator std::string() const; + inline operator std::string() const { return this->string(); } - //! returns pointer to the underlying file node - CvFileNode* operator *(); - //! returns pointer to the underlying file node - const CvFileNode* operator* () const; + static bool isMap(int flags); + static bool isSeq(int flags); + static bool isCollection(int flags); + static bool isEmptyCollection(int flags); + static bool isFlow(int flags); + + uchar* ptr(); + const uchar* ptr() const; //! returns iterator pointing to the first node element FileNodeIterator begin() const; @@ -613,70 +602,70 @@ public: @param len Number of bytes to read (buffer size limit). If it is greater than number of remaining elements then all of them will be read. */ - void readRaw( const String& fmt, uchar* vec, size_t len ) const; + void readRaw( const String& fmt, void* vec, size_t len ) const; - //! reads the registered object and returns pointer to it - void* readObj() const; + /** Internal method used when reading FileStorage. + Sets the type (int, real or string) and value of the previously created node. + */ + void setValue( int type, const void* value, int len=-1 ); //! Simplified reading API to use with bindings. CV_WRAP double real() const; //! Simplified reading API to use with bindings. - CV_WRAP String string() const; + CV_WRAP std::string string() const; //! Simplified reading API to use with bindings. CV_WRAP Mat mat() const; - // do not use wrapper pointer classes for better efficiency - const CvFileStorage* fs; - const CvFileNode* node; + //protected: + FileNode(FileStorage::Impl* fs, size_t blockIdx, size_t ofs); + + FileStorage::Impl* fs; + size_t blockIdx; + size_t ofs; }; /** @brief used to iterate through sequences and mappings. -A standard STL notation, with node.begin(), node.end() denoting the beginning and the end of a -sequence, stored in node. See the data reading sample in the beginning of the section. + A standard STL notation, with node.begin(), node.end() denoting the beginning and the end of a + sequence, stored in node. See the data reading sample in the beginning of the section. */ class CV_EXPORTS FileNodeIterator { public: /** @brief The constructors. - These constructors are used to create a default iterator, set it to specific element in a file node - or construct it from another iterator. + These constructors are used to create a default iterator, set it to specific element in a file node + or construct it from another iterator. */ FileNodeIterator(); /** @overload - @param fs File storage for the iterator. - @param node File node for the iterator. - @param ofs Index of the element in the node. The created iterator will point to this element. - */ - FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0); + @param node File node - the collection to iterate over; + it can be a scalar (equivalent to 1-element collection) or "none" (equivalent to empty collection). + @param seekEnd - true if iterator needs to be set after the last element of the node; + that is: + * node.begin() => FileNodeIterator(node, false) + * node.end() => FileNodeIterator(node, true) + */ + FileNodeIterator(const FileNode& node, bool seekEnd); /** @overload - @param it Iterator to be used as initialization for the created iterator. - */ + @param it Iterator to be used as initialization for the created iterator. + */ FileNodeIterator(const FileNodeIterator& it); FileNodeIterator& operator=(const FileNodeIterator& it); //! returns the currently observed element FileNode operator *() const; - //! accesses the currently observed element methods - FileNode operator ->() const; //! moves iterator to the next node FileNodeIterator& operator ++ (); //! moves iterator to the next node FileNodeIterator operator ++ (int); - //! moves iterator to the previous node - FileNodeIterator& operator -- (); - //! moves iterator to the previous node - FileNodeIterator operator -- (int); //! moves iterator forward by the specified offset (possibly negative) FileNodeIterator& operator += (int ofs); - //! moves iterator backward by the specified offset (possibly negative) - FileNodeIterator& operator -= (int ofs); /** @brief Reads node elements to the buffer with the specified format. @@ -685,27 +674,22 @@ public: @param vec Pointer to the destination array. @param len Number of bytes to read (buffer size limit). If it is greater than number of remaining elements then all of them will be read. - */ - FileNodeIterator& readRaw( const String& fmt, uchar* vec, + FileNodeIterator& readRaw( const String& fmt, void* vec, size_t len=(size_t)INT_MAX ); - struct SeqReader - { - int header_size; - void* seq; /* sequence, beign read; CvSeq */ - void* block; /* current block; CvSeqBlock */ - schar* ptr; /* pointer to element be read next */ - schar* block_min; /* pointer to the beginning of block */ - schar* block_max; /* pointer to the end of block */ - int delta_index;/* = seq->first->start_index */ - schar* prev_elem; /* pointer to previous element */ - }; + //! returns the number of remaining (not read yet) elements + size_t remaining() const; - const CvFileStorage* fs; - const CvFileNode* container; - SeqReader reader; - size_t remaining; + bool equalTo(const FileNodeIterator& it) const; + +protected: + FileStorage::Impl* fs; + size_t blockIdx; + size_t ofs; + size_t blockSize; + size_t nodeNElems; + size_t idx; }; //! @} core_xml @@ -739,7 +723,6 @@ CV_EXPORTS void writeScalar( FileStorage& fs, const String& value ); CV_EXPORTS void read(const FileNode& node, int& value, int default_value); CV_EXPORTS void read(const FileNode& node, float& value, float default_value); CV_EXPORTS void read(const FileNode& node, double& value, double default_value); -CV_EXPORTS void read(const FileNode& node, String& value, const String& default_value); CV_EXPORTS void read(const FileNode& node, std::string& value, const std::string& default_value); CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() ); CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() ); @@ -788,6 +771,17 @@ template static inline void read(const FileNode& node, Vec value = temp.size() != cn ? default_value : Vec<_Tp, cn>(&temp[0]); } +template static inline void read(const FileNode& node, Matx<_Tp, m, n>& value, const Matx<_Tp, m, n>& default_matx = Matx<_Tp, m, n>()) +{ + Mat temp; + read(node, temp); // read as a Mat class + + if (temp.empty()) + value = default_matx; + else + value = Matx<_Tp, m, n>(temp); +} + template static inline void read(const FileNode& node, Scalar_<_Tp>& value, const Scalar_<_Tp>& default_value) { std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; @@ -856,7 +850,7 @@ namespace internal VecReaderProxy( FileNodeIterator* _it ) : it(_it) {} void operator()(std::vector<_Tp>& vec, size_t count) const { - count = std::min(count, it->remaining); + count = std::min(count, it->remaining()); vec.resize(count); for (size_t i = 0; i < count; i++, ++(*it)) read(**it, vec[i], _Tp()); @@ -871,14 +865,14 @@ namespace internal VecReaderProxy( FileNodeIterator* _it ) : it(_it) {} void operator()(std::vector<_Tp>& vec, size_t count) const { - size_t remaining = it->remaining; + size_t remaining = it->remaining(); size_t cn = DataType<_Tp>::channels; int _fmt = traits::SafeFmt<_Tp>::fmt; CV_Assert((_fmt >> 8) < 9); char fmt[] = { (char)((_fmt >> 8)+'1'), (char)_fmt, '\0' }; CV_Assert((remaining % cn) == 0); size_t remaining1 = remaining / cn; - count = count < remaining1 ? count : remaining1; + count = count > remaining1 ? remaining1 : count; vec.resize(count); it->readRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, count*sizeof(_Tp)); } @@ -968,6 +962,12 @@ void write(FileStorage& fs, const Vec<_Tp, cn>& v ) write(fs, v.val[i]); } +template static inline +void write(FileStorage& fs, const Matx<_Tp, m, n>& x ) +{ + write(fs, Mat(x)); // write as a Mat class +} + template static inline void write(FileStorage& fs, const Scalar_<_Tp>& s ) { @@ -1033,6 +1033,12 @@ void write(FileStorage& fs, const String& name, const Vec<_Tp, cn>& v ) write(fs, v); } +template static inline +void write(FileStorage& fs, const String& name, const Matx<_Tp, m, n>& x ) +{ + write(fs, name, Mat(x)); // write as a Mat class +} + template static inline void write(FileStorage& fs, const String& name, const Scalar_<_Tp>& s ) { @@ -1070,6 +1076,12 @@ void write(FileStorage& fs, const String& name, const DMatch& m) write(fs, m.distance); } +template::value >::type* = nullptr> +static inline void write( FileStorage& fs, const String& name, const _Tp& val ) +{ + write(fs, name, static_cast(val)); +} + template static inline void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec ) { @@ -1158,10 +1170,18 @@ void read( FileNodeIterator& it, std::vector<_Tp>& vec, size_t maxCount = (size_ r(vec, maxCount); } +template::value >::type* = nullptr> +static inline void read(const FileNode& node, _Tp& value, const _Tp& default_value = static_cast<_Tp>(0)) +{ + int temp; + read(node, temp, static_cast(default_value)); + value = static_cast<_Tp>(temp); +} + template static inline void read( const FileNode& node, std::vector<_Tp>& vec, const std::vector<_Tp>& default_value = std::vector<_Tp>() ) { - if(!node.node) + if(node.empty()) vec = default_value; else { @@ -1173,7 +1193,7 @@ void read( const FileNode& node, std::vector<_Tp>& vec, const std::vector<_Tp>& static inline void read( const FileNode& node, std::vector& vec, const std::vector& default_value ) { - if(!node.node) + if(node.empty()) vec = default_value; else read(node, vec); @@ -1182,7 +1202,7 @@ void read( const FileNode& node, std::vector& vec, const std::vector& vec, const std::vector& default_value ) { - if(!node.node) + if(node.empty()) vec = default_value; else read(node, vec); @@ -1308,76 +1328,23 @@ void operator >> (const FileNode& n, DMatch& m) //! @relates cv::FileNodeIterator //! @{ -static inline -bool operator == (const FileNodeIterator& it1, const FileNodeIterator& it2) -{ - return it1.fs == it2.fs && it1.container == it2.container && - it1.reader.ptr == it2.reader.ptr && it1.remaining == it2.remaining; -} - -static inline -bool operator != (const FileNodeIterator& it1, const FileNodeIterator& it2) -{ - return !(it1 == it2); -} +CV_EXPORTS bool operator == (const FileNodeIterator& it1, const FileNodeIterator& it2); +CV_EXPORTS bool operator != (const FileNodeIterator& it1, const FileNodeIterator& it2); static inline ptrdiff_t operator - (const FileNodeIterator& it1, const FileNodeIterator& it2) { - return it2.remaining - it1.remaining; + return it2.remaining() - it1.remaining(); } static inline bool operator < (const FileNodeIterator& it1, const FileNodeIterator& it2) { - return it1.remaining > it2.remaining; + return it1.remaining() > it2.remaining(); } //! @} FileNodeIterator -//! @cond IGNORED - -inline FileNode FileStorage::getFirstTopLevelNode() const { FileNode r = root(); FileNodeIterator it = r.begin(); return it != r.end() ? *it : FileNode(); } -inline FileNode::FileNode() : fs(0), node(0) {} -inline FileNode::FileNode(const CvFileStorage* _fs, const CvFileNode* _node) : fs(_fs), node(_node) {} -inline FileNode::FileNode(const FileNode& _node) : fs(_node.fs), node(_node.node) {} -inline FileNode& FileNode::operator=(const FileNode& _node) { fs = _node.fs; node = _node.node; return *this; } -inline bool FileNode::empty() const { return node == 0; } -inline bool FileNode::isNone() const { return type() == NONE; } -inline bool FileNode::isSeq() const { return type() == SEQ; } -inline bool FileNode::isMap() const { return type() == MAP; } -inline bool FileNode::isInt() const { return type() == INT; } -inline bool FileNode::isReal() const { return type() == REAL; } -inline bool FileNode::isString() const { return type() == STR; } -inline CvFileNode* FileNode::operator *() { return (CvFileNode*)node; } -inline const CvFileNode* FileNode::operator* () const { return node; } -inline FileNode::operator int() const { int value; read(*this, value, 0); return value; } -inline FileNode::operator float() const { float value; read(*this, value, 0.f); return value; } -inline FileNode::operator double() const { double value; read(*this, value, 0.); return value; } -inline FileNode::operator String() const { String value; read(*this, value, value); return value; } -inline double FileNode::real() const { return double(*this); } -inline String FileNode::string() const { return String(*this); } -inline Mat FileNode::mat() const { Mat value; read(*this, value, value); return value; } -inline FileNodeIterator FileNode::begin() const { return FileNodeIterator(fs, node); } -inline FileNodeIterator FileNode::end() const { return FileNodeIterator(fs, node, size()); } -inline void FileNode::readRaw( const String& fmt, uchar* vec, size_t len ) const { begin().readRaw( fmt, vec, len ); } -inline FileNode FileNodeIterator::operator *() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); } -inline FileNode FileNodeIterator::operator ->() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); } -inline String::String(const FileNode& fn): cstr_(0), len_(0) { read(fn, *this, *this); } - -//! @endcond - - -CV_EXPORTS void cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt); - -CV_EXPORTS void cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len); - -CV_EXPORTS void cvEndWriteRawData_Base64(::CvFileStorage * fs); - -CV_EXPORTS void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat); - -CV_EXPORTS void cvWriteMatND_Base64(::CvFileStorage* fs, const char* name, const ::CvMatND* mat); - } // cv #endif // OPENCV_CORE_PERSISTENCE_HPP diff --git a/3rdparty/include/opencv2/core/ptr.inl.hpp b/3rdparty/include/opencv2/core/ptr.inl.hpp deleted file mode 100644 index 466f6342ec..0000000000 --- a/3rdparty/include/opencv2/core/ptr.inl.hpp +++ /dev/null @@ -1,379 +0,0 @@ -/*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) 2013, NVIDIA Corporation, 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 copyright holders 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_CORE_PTR_INL_HPP -#define OPENCV_CORE_PTR_INL_HPP - -#include - -//! @cond IGNORED - -namespace cv { - -template -void DefaultDeleter::operator () (Y* p) const -{ - delete p; -} - -namespace detail -{ - -struct PtrOwner -{ - PtrOwner() : refCount(1) - {} - - void incRef() - { - CV_XADD(&refCount, 1); - } - - void decRef() - { - if (CV_XADD(&refCount, -1) == 1) deleteSelf(); - } - -protected: - /* This doesn't really need to be virtual, since PtrOwner is never deleted - directly, but it doesn't hurt and it helps avoid warnings. */ - virtual ~PtrOwner() - {} - - virtual void deleteSelf() = 0; - -private: - unsigned int refCount; - - // noncopyable - PtrOwner(const PtrOwner&); - PtrOwner& operator = (const PtrOwner&); -}; - -template -struct PtrOwnerImpl CV_FINAL : PtrOwner -{ - PtrOwnerImpl(Y* p, D d) : owned(p), deleter(d) - {} - - void deleteSelf() CV_OVERRIDE - { - deleter(owned); - delete this; - } - -private: - Y* owned; - D deleter; -}; - - -} - -template -Ptr::Ptr() : owner(NULL), stored(NULL) -{} - -template -template -Ptr::Ptr(Y* p) - : owner(p - ? new detail::PtrOwnerImpl >(p, DefaultDeleter()) - : NULL), - stored(p) -{} - -template -template -Ptr::Ptr(Y* p, D d) - : owner(p - ? new detail::PtrOwnerImpl(p, d) - : NULL), - stored(p) -{} - -template -Ptr::Ptr(const Ptr& o) : owner(o.owner), stored(o.stored) -{ - if (owner) owner->incRef(); -} - -template -template -Ptr::Ptr(const Ptr& o) : owner(o.owner), stored(o.stored) -{ - if (owner) owner->incRef(); -} - -template -template -Ptr::Ptr(const Ptr& o, T* p) : owner(o.owner), stored(p) -{ - if (owner) owner->incRef(); -} - -template -Ptr::~Ptr() -{ - release(); -} - -template -Ptr& Ptr::operator = (const Ptr& o) -{ - Ptr(o).swap(*this); - return *this; -} - -template -template -Ptr& Ptr::operator = (const Ptr& o) -{ - Ptr(o).swap(*this); - return *this; -} - -template -void Ptr::release() -{ - if (owner) owner->decRef(); - owner = NULL; - stored = NULL; -} - -template -template -void Ptr::reset(Y* p) -{ - Ptr(p).swap(*this); -} - -template -template -void Ptr::reset(Y* p, D d) -{ - Ptr(p, d).swap(*this); -} - -template -void Ptr::swap(Ptr& o) -{ - std::swap(owner, o.owner); - std::swap(stored, o.stored); -} - -template -T* Ptr::get() const -{ - return stored; -} - -template -typename detail::RefOrVoid::type Ptr::operator * () const -{ - return *stored; -} - -template -T* Ptr::operator -> () const -{ - return stored; -} - -template -Ptr::operator T* () const -{ - return stored; -} - - -template -bool Ptr::empty() const -{ - return !stored; -} - -template -template -Ptr Ptr::staticCast() const -{ - return Ptr(*this, static_cast(stored)); -} - -template -template -Ptr Ptr::constCast() const -{ - return Ptr(*this, const_cast(stored)); -} - -template -template -Ptr Ptr::dynamicCast() const -{ - return Ptr(*this, dynamic_cast(stored)); -} - -#ifdef CV_CXX_MOVE_SEMANTICS - -template -Ptr::Ptr(Ptr&& o) : owner(o.owner), stored(o.stored) -{ - o.owner = NULL; - o.stored = NULL; -} - -template -Ptr& Ptr::operator = (Ptr&& o) -{ - if (this == &o) - return *this; - - release(); - owner = o.owner; - stored = o.stored; - o.owner = NULL; - o.stored = NULL; - return *this; -} - -#endif - - -template -void swap(Ptr& ptr1, Ptr& ptr2){ - ptr1.swap(ptr2); -} - -template -bool operator == (const Ptr& ptr1, const Ptr& ptr2) -{ - return ptr1.get() == ptr2.get(); -} - -template -bool operator != (const Ptr& ptr1, const Ptr& ptr2) -{ - return ptr1.get() != ptr2.get(); -} - -template -Ptr makePtr() -{ - return Ptr(new T()); -} - -template -Ptr makePtr(const A1& a1) -{ - return Ptr(new T(a1)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2) -{ - return Ptr(new T(a1, a2)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3) -{ - return Ptr(new T(a1, a2, a3)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4) -{ - return Ptr(new T(a1, a2, a3, a4)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) -{ - return Ptr(new T(a1, a2, a3, a4, a5)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) -{ - return Ptr(new T(a1, a2, a3, a4, a5, a6)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) -{ - return Ptr(new T(a1, a2, a3, a4, a5, a6, a7)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) -{ - return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) -{ - return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) -{ - return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11) -{ - return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)); -} - -template -Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11, const A12& a12) -{ - return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)); -} -} // namespace cv - -//! @endcond - -#endif // OPENCV_CORE_PTR_INL_HPP diff --git a/3rdparty/include/opencv2/core/quaternion.hpp b/3rdparty/include/opencv2/core/quaternion.hpp new file mode 100644 index 0000000000..8c21501e3f --- /dev/null +++ b/3rdparty/include/opencv2/core/quaternion.hpp @@ -0,0 +1,1696 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved. +// Third party copyrights are property of their respective owners. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Author: Liangqian Kong +// Longbu Wang +#ifndef OPENCV_CORE_QUATERNION_HPP +#define OPENCV_CORE_QUATERNION_HPP + +#include +#include +#include +namespace cv +{ +//! @addtogroup core +//! @{ + +//! Unit quaternion flag +enum QuatAssumeType +{ + /** + * This flag is specified by default. + * If this flag is specified, the input quaternions are assumed to be not unit quaternions. + * It can guarantee the correctness of the calculations, + * although the calculation speed will be slower than the flag QUAT_ASSUME_UNIT. + */ + QUAT_ASSUME_NOT_UNIT, + /** + * If this flag is specified, the input quaternions are assumed to be unit quaternions which + * will save some computations. However, if this flag is specified without unit quaternion, + * the program correctness of the result will not be guaranteed. + */ + QUAT_ASSUME_UNIT +}; + +class QuatEnum +{ +public: + /** @brief Enum of Euler angles type. + * + * Without considering the possibility of using two different convertions for the definition of the rotation axes , + * there exists twelve possible sequences of rotation axes, divided into two groups: + * - Proper Euler angles (Z-X-Z, X-Y-X, Y-Z-Y, Z-Y-Z, X-Z-X, Y-X-Y) + * - Tait–Bryan angles (X-Y-Z, Y-Z-X, Z-X-Y, X-Z-Y, Z-Y-X, Y-X-Z). + * + * The three elemental rotations may be [extrinsic](https://en.wikipedia.org/wiki/Euler_angles#Definition_by_extrinsic_rotations) + * (rotations about the axes *xyz* of the original coordinate system, which is assumed to remain motionless), + * or [intrinsic](https://en.wikipedia.org/wiki/Euler_angles#Definition_by_intrinsic_rotations)(rotations about the axes of the rotating coordinate system *XYZ*, solidary with the moving body, which changes its orientation after each elemental rotation). + * + * + * Extrinsic and intrinsic rotations are relevant. + * + * The definition of the Euler angles is as following, + * - \f$\theta_1 \f$ represents the first rotation angle, + * - \f$\theta_2 \f$ represents the second rotation angle, + * - \f$\theta_3 \f$ represents the third rotation angle. + * + * For intrinsic rotations in the order of X-Y-Z, the rotation matrix R can be calculated by:\f[R =X(\theta_1) Y(\theta_2) Z(\theta_3) \f] + * For extrinsic rotations in the order of X-Y-Z, the rotation matrix R can be calculated by:\f[R =Z({\theta_3}) Y({\theta_2}) X({\theta_1})\f] + * where + * \f[X({\theta})={\begin{bmatrix}1&0&0\\0&\cos {\theta_1} &-\sin {\theta_1} \\0&\sin {\theta_1} &\cos {\theta_1} \\\end{bmatrix}}, + * Y({\theta})={\begin{bmatrix}\cos \theta_{2}&0&\sin \theta_{2}\\0&1 &0 \\\ -sin \theta_2& 0&\cos \theta_{2} \\\end{bmatrix}}, + * Z({\theta})={\begin{bmatrix}\cos\theta_{3} &-\sin \theta_3&0\\\sin \theta_3 &\cos \theta_3 &0\\0&0&1\\\end{bmatrix}}. + * \f] + * + * The function is designed according to this set of conventions: + * - [Right handed](https://en.wikipedia.org/wiki/Right_hand_rule) reference frames are adopted, and the [right hand rule](https://en.wikipedia.org/wiki/Right_hand_rule) is used to determine the sign of angles. + * - Each matrix is meant to represent an [active rotation](https://en.wikipedia.org/wiki/Active_and_passive_transformation) (the composing and composed matrices + * are supposed to act on the coordinates of vectors defined in the initial fixed reference frame and give as a result the coordinates of a rotated vector defined in the same reference frame). + * - For \f$\theta_1\f$ and \f$\theta_3\f$, the valid range is (−π, π]. + * + * For \f$\theta_2\f$, the valid range is [−π/2, π/2] or [0, π]. + * + * For Tait–Bryan angles, the valid range of \f$\theta_2\f$ is [−π/2, π/2]. When transforming a quaternion to Euler angles, the solution of Euler angles is unique in condition of \f$ \theta_2 \in (−π/2, π/2)\f$ . + * If \f$\theta_2 = −π/2 \f$ or \f$ \theta_2 = π/2\f$, there are infinite solutions. The common name for this situation is gimbal lock. + * For Proper Euler angles,the valid range of \f$\theta_2\f$ is in [0, π]. The solutions of Euler angles are unique in condition of \f$ \theta_2 \in (0, π)\f$ . If \f$\theta_2 =0 \f$ or \f$\theta_2 =π \f$, + * there are infinite solutions and gimbal lock will occur. + */ + enum EulerAnglesType + { + INT_XYZ, ///< Intrinsic rotations with the Euler angles type X-Y-Z + INT_XZY, ///< Intrinsic rotations with the Euler angles type X-Z-Y + INT_YXZ, ///< Intrinsic rotations with the Euler angles type Y-X-Z + INT_YZX, ///< Intrinsic rotations with the Euler angles type Y-Z-X + INT_ZXY, ///< Intrinsic rotations with the Euler angles type Z-X-Y + INT_ZYX, ///< Intrinsic rotations with the Euler angles type Z-Y-X + INT_XYX, ///< Intrinsic rotations with the Euler angles type X-Y-X + INT_XZX, ///< Intrinsic rotations with the Euler angles type X-Z-X + INT_YXY, ///< Intrinsic rotations with the Euler angles type Y-X-Y + INT_YZY, ///< Intrinsic rotations with the Euler angles type Y-Z-Y + INT_ZXZ, ///< Intrinsic rotations with the Euler angles type Z-X-Z + INT_ZYZ, ///< Intrinsic rotations with the Euler angles type Z-Y-Z + + EXT_XYZ, ///< Extrinsic rotations with the Euler angles type X-Y-Z + EXT_XZY, ///< Extrinsic rotations with the Euler angles type X-Z-Y + EXT_YXZ, ///< Extrinsic rotations with the Euler angles type Y-X-Z + EXT_YZX, ///< Extrinsic rotations with the Euler angles type Y-Z-X + EXT_ZXY, ///< Extrinsic rotations with the Euler angles type Z-X-Y + EXT_ZYX, ///< Extrinsic rotations with the Euler angles type Z-Y-X + EXT_XYX, ///< Extrinsic rotations with the Euler angles type X-Y-X + EXT_XZX, ///< Extrinsic rotations with the Euler angles type X-Z-X + EXT_YXY, ///< Extrinsic rotations with the Euler angles type Y-X-Y + EXT_YZY, ///< Extrinsic rotations with the Euler angles type Y-Z-Y + EXT_ZXZ, ///< Extrinsic rotations with the Euler angles type Z-X-Z + EXT_ZYZ, ///< Extrinsic rotations with the Euler angles type Z-Y-Z + #ifndef CV_DOXYGEN + EULER_ANGLES_MAX_VALUE + #endif + }; + +}; + +template class Quat; +template std::ostream& operator<<(std::ostream&, const Quat<_Tp>&); + +/** + * Quaternion is a number system that extends the complex numbers. It can be expressed as a + * rotation in three-dimensional space. + * A quaternion is generally represented in the form: + * \f[q = w + x\boldsymbol{i} + y\boldsymbol{j} + z\boldsymbol{k}\f] + * \f[q = [w, x, y, z]\f] + * \f[q = [w, \boldsymbol{v}] \f] + * \f[q = ||q||[\cos\psi, u_x\sin\psi,u_y\sin\psi, u_z\sin\psi].\f] + * \f[q = ||q||[\cos\psi, \boldsymbol{u}\sin\psi]\f] + * where \f$\psi = \frac{\theta}{2}\f$, \f$\theta\f$ represents rotation angle, + * \f$\boldsymbol{u} = [u_x, u_y, u_z]\f$ represents normalized rotation axis, + * and \f$||q||\f$ represents the norm of \f$q\f$. + * + * A unit quaternion is usually represents rotation, which has the form: + * \f[q = [\cos\psi, u_x\sin\psi,u_y\sin\psi, u_z\sin\psi].\f] + * + * To create a quaternion representing the rotation around the axis \f$\boldsymbol{u}\f$ + * with angle \f$\theta\f$, you can use + * ``` + * using namespace cv; + * double angle = CV_PI; + * Vec3d axis = {0, 0, 1}; + * Quatd q = Quatd::createFromAngleAxis(angle, axis); + * ``` + * + * You can simply use four same type number to create a quaternion + * ``` + * Quatd q(1, 2, 3, 4); + * ``` + * Or use a Vec4d or Vec4f vector. + * ``` + * Vec4d vec{1, 2, 3, 4}; + * Quatd q(vec); + * ``` + * + * ``` + * Vec4f vec{1, 2, 3, 4}; + * Quatf q(vec); + * ``` + * + * If you already have a 3x3 rotation matrix R, then you can use + * ``` + * Quatd q = Quatd::createFromRotMat(R); + * ``` + * + * If you already have a rotation vector rvec which has the form of `angle * axis`, then you can use + * ``` + * Quatd q = Quatd::createFromRvec(rvec); + * ``` + * + * To extract the rotation matrix from quaternion, see toRotMat3x3() + * + * To extract the Vec4d or Vec4f, see toVec() + * + * To extract the rotation vector, see toRotVec() + * + * If there are two quaternions \f$q_0, q_1\f$ are needed to interpolate, you can use nlerp(), slerp() or spline() + * ``` + * Quatd::nlerp(q0, q1, t) + * + * Quatd::slerp(q0, q1, t) + * + * Quatd::spline(q0, q0, q1, q1, t) + * ``` + * spline can smoothly connect rotations of multiple quaternions + * + * Three ways to get an element in Quaternion + * ``` + * Quatf q(1,2,3,4); + * std::cout << q.w << std::endl; // w=1, x=2, y=3, z=4 + * std::cout << q[0] << std::endl; // q[0]=1, q[1]=2, q[2]=3, q[3]=4 + * std::cout << q.at(0) << std::endl; + * ``` + */ +template +class Quat +{ + static_assert(std::is_floating_point<_Tp>::value, "Quaternion only make sense with type of float or double"); + using value_type = _Tp; +public: + static constexpr _Tp CV_QUAT_EPS = (_Tp)1.e-6; + static constexpr _Tp CV_QUAT_CONVERT_THRESHOLD = (_Tp)1.e-6; + + Quat(); + + /** + * @brief From Vec4d or Vec4f. + */ + explicit Quat(const Vec<_Tp, 4> &coeff); + + /** + * @brief from four numbers. + */ + Quat(_Tp w, _Tp x, _Tp y, _Tp z); + + /** + * @brief from an angle, axis. Axis will be normalized in this function. And + * it generates + * \f[q = [\cos\psi, u_x\sin\psi,u_y\sin\psi, u_z\sin\psi].\f] + * where \f$\psi = \frac{\theta}{2}\f$, \f$\theta\f$ is the rotation angle. + */ + static Quat<_Tp> createFromAngleAxis(const _Tp angle, const Vec<_Tp, 3> &axis); + + /** + * @brief from a 3x3 rotation matrix. + */ + static Quat<_Tp> createFromRotMat(InputArray R); + + /** + * @brief from a rotation vector + * \f$r\f$ has the form \f$\theta \cdot \boldsymbol{u}\f$, where \f$\theta\f$ + * represents rotation angle and \f$\boldsymbol{u}\f$ represents normalized rotation axis. + * + * Angle and axis could be easily derived as: + * \f[ + * \begin{equation} + * \begin{split} + * \psi &= ||r||\\ + * \boldsymbol{u} &= \frac{r}{\theta} + * \end{split} + * \end{equation} + * \f] + * Then a quaternion can be calculated by + * \f[q = [\cos\psi, \boldsymbol{u}\sin\psi]\f] + * where \f$\psi = \theta / 2 \f$ + */ + static Quat<_Tp> createFromRvec(InputArray rvec); + + /** + * @brief + * from Euler angles + * + * A quaternion can be generated from Euler angles by combining the quaternion representations of the Euler rotations. + * + * For example, if we use intrinsic rotations in the order of X-Y-Z,\f$\theta_1 \f$ is rotation around the X-axis, \f$\theta_2 \f$ is rotation around the Y-axis, + * \f$\theta_3 \f$ is rotation around the Z-axis. The final quaternion q can be calculated by + * + * \f[ {q} = q_{X, \theta_1} q_{Y, \theta_2} q_{Z, \theta_3}\f] + * where \f$ q_{X, \theta_1} \f$ is created from @ref createFromXRot, \f$ q_{Y, \theta_2} \f$ is created from @ref createFromYRot, + * \f$ q_{Z, \theta_3} \f$ is created from @ref createFromZRot. + * @param angles the Euler angles in a vector of length 3 + * @param eulerAnglesType the convertion Euler angles type + */ + static Quat<_Tp> createFromEulerAngles(const Vec<_Tp, 3> &angles, QuatEnum::EulerAnglesType eulerAnglesType); + + /** + * @brief get a quaternion from a rotation about the Y-axis by \f$\theta\f$ . + * \f[q = \cos(\theta/2)+0 i+ sin(\theta/2) j +0k \f] + */ + static Quat<_Tp> createFromYRot(const _Tp theta); + + /** + * @brief get a quaternion from a rotation about the X-axis by \f$\theta\f$ . + * \f[q = \cos(\theta/2)+sin(\theta/2) i +0 j +0 k \f] + */ + static Quat<_Tp> createFromXRot(const _Tp theta); + + /** + * @brief get a quaternion from a rotation about the Z-axis by \f$\theta\f$. + * \f[q = \cos(\theta/2)+0 i +0 j +sin(\theta/2) k \f] + */ + static Quat<_Tp> createFromZRot(const _Tp theta); + + /** + * @brief a way to get element. + * @param index over a range [0, 3]. + * + * A quaternion q + * + * q.at(0) is equivalent to q.w, + * + * q.at(1) is equivalent to q.x, + * + * q.at(2) is equivalent to q.y, + * + * q.at(3) is equivalent to q.z. + */ + _Tp at(size_t index) const; + + /** + * @brief return the conjugate of this quaternion. + * \f[q.conjugate() = (w, -x, -y, -z).\f] + */ + Quat<_Tp> conjugate() const; + + /** + * + * @brief return the value of exponential value. + * \f[\exp(q) = e^w (\cos||\boldsymbol{v}||+ \frac{v}{||\boldsymbol{v}||})\sin||\boldsymbol{v}||\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param q a quaternion. + * + * For example: + * ``` + * Quatd q{1,2,3,4}; + * cout << exp(q) << endl; + * ``` + */ + template + friend Quat exp(const Quat &q); + + /** + * @brief return the value of exponential value. + * \f[\exp(q) = e^w (\cos||\boldsymbol{v}||+ \frac{v}{||\boldsymbol{v}||}\sin||\boldsymbol{v}||)\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * + * For example + * ``` + * Quatd q{1,2,3,4}; + * cout << q.exp() << endl; + * ``` + */ + Quat<_Tp> exp() const; + + /** + * @brief return the value of logarithm function. + * \f[\ln(q) = \ln||q|| + \frac{\boldsymbol{v}}{||\boldsymbol{v}||}\arccos\frac{w}{||q||}.\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param q a quaternion. + * @param assumeUnit if QUAT_ASSUME_UNIT, q assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatd q1{1,2,3,4}; + * cout << log(q1) << endl; + * ``` + */ + template + friend Quat log(const Quat &q, QuatAssumeType assumeUnit); + + /** + * @brief return the value of logarithm function. + * \f[\ln(q) = \ln||q|| + \frac{\boldsymbol{v}}{||\boldsymbol{v}||}\arccos\frac{w}{||q||}\f]. + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param assumeUnit if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.log(); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * Quatd q1(1,2,3,4); + * q1.normalize().log(assumeUnit); + * ``` + */ + Quat<_Tp> log(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return the value of power function with index \f$x\f$. + * \f[q^x = ||q||(cos(x\theta) + \boldsymbol{u}sin(x\theta))).\f] + * @param q a quaternion. + * @param x index of exponentiation. + * @param assumeUnit if QUAT_ASSUME_UNIT, quaternion q assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * power(q, 2.0); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * double angle = CV_PI; + * Vec3d axis{0, 0, 1}; + * Quatd q1 = Quatd::createFromAngleAxis(angle, axis); //generate a unit quat by axis and angle + * power(q1, 2.0, assumeUnit);//This assumeUnit means q1 is a unit quaternion. + * ``` + * @note the type of the index should be the same as the quaternion. + */ + template + friend Quat power(const Quat &q, const T x, QuatAssumeType assumeUnit); + + /** + * @brief return the value of power function with index \f$x\f$. + * \f[q^x = ||q||(\cos(x\theta) + \boldsymbol{u}\sin(x\theta))).\f] + * @param x index of exponentiation. + * @param assumeUnit if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.power(2.0); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * double angle = CV_PI; + * Vec3d axis{0, 0, 1}; + * Quatd q1 = Quatd::createFromAngleAxis(angle, axis); //generate a unit quat by axis and angle + * q1.power(2.0, assumeUnit); //This assumeUnt means q1 is a unit quaternion + * ``` + */ + Quat<_Tp> power(const _Tp x, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return \f$\sqrt{q}\f$. + * @param q a quaternion. + * @param assumeUnit if QUAT_ASSUME_UNIT, quaternion q assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatf q(1,2,3,4); + * sqrt(q); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * q = {1,0,0,0}; + * sqrt(q, assumeUnit); //This assumeUnit means q is a unit quaternion. + * ``` + */ + template + friend Quat sqrt(const Quat &q, QuatAssumeType assumeUnit); + + /** + * @brief return \f$\sqrt{q}\f$. + * @param assumeUnit if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatf q(1,2,3,4); + * q.sqrt(); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * q = {1,0,0,0}; + * q.sqrt(assumeUnit); //This assumeUnit means q is a unit quaternion + * ``` + */ + Quat<_Tp> sqrt(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return the value of power function with quaternion \f$q\f$. + * \f[p^q = e^{q\ln(p)}.\f] + * @param p base quaternion of power function. + * @param q index quaternion of power function. + * @param assumeUnit if QUAT_ASSUME_UNIT, quaternion \f$p\f$ assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatd p(1,2,3,4); + * Quatd q(5,6,7,8); + * power(p, q); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * p = p.normalize(); + * power(p, q, assumeUnit); //This assumeUnit means p is a unit quaternion + * ``` + */ + template + friend Quat power(const Quat &p, const Quat &q, QuatAssumeType assumeUnit); + + /** + * @brief return the value of power function with quaternion \f$q\f$. + * \f[p^q = e^{q\ln(p)}.\f] + * @param q index quaternion of power function. + * @param assumeUnit if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatd p(1,2,3,4); + * Quatd q(5,6,7,8); + * p.power(q); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * p = p.normalize(); + * p.power(q, assumeUnit); //This assumeUnit means p is a unit quaternion + * ``` + */ + Quat<_Tp> power(const Quat<_Tp> &q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return the crossProduct between \f$p = (a, b, c, d) = (a, \boldsymbol{u})\f$ and \f$q = (w, x, y, z) = (w, \boldsymbol{v})\f$. + * \f[p \times q = \frac{pq- qp}{2}\f] + * \f[p \times q = \boldsymbol{u} \times \boldsymbol{v}\f] + * \f[p \times q = (cz-dy)i + (dx-bz)j + (by-xc)k \f] + * + * For example + * ``` + * Quatd q{1,2,3,4}; + * Quatd p{5,6,7,8}; + * crossProduct(p, q); + * ``` + */ + template + friend Quat crossProduct(const Quat &p, const Quat &q); + + /** + * @brief return the crossProduct between \f$p = (a, b, c, d) = (a, \boldsymbol{u})\f$ and \f$q = (w, x, y, z) = (w, \boldsymbol{v})\f$. + * \f[p \times q = \frac{pq- qp}{2}.\f] + * \f[p \times q = \boldsymbol{u} \times \boldsymbol{v}.\f] + * \f[p \times q = (cz-dy)i + (dx-bz)j + (by-xc)k. \f] + * + * For example + * ``` + * Quatd q{1,2,3,4}; + * Quatd p{5,6,7,8}; + * p.crossProduct(q) + * ``` + */ + Quat<_Tp> crossProduct(const Quat<_Tp> &q) const; + + /** + * @brief return the norm of quaternion. + * \f[||q|| = \sqrt{w^2 + x^2 + y^2 + z^2}.\f] + */ + _Tp norm() const; + + /** + * @brief return a normalized \f$p\f$. + * \f[p = \frac{q}{||q||}\f] + * where \f$p\f$ satisfies \f$(p.x)^2 + (p.y)^2 + (p.z)^2 + (p.w)^2 = 1.\f$ + */ + Quat<_Tp> normalize() const; + + /** + * @brief return \f$q^{-1}\f$ which is an inverse of \f$q\f$ + * which satisfies \f$q * q^{-1} = 1\f$. + * @param q a quaternion. + * @param assumeUnit if QUAT_ASSUME_UNIT, quaternion q assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * inv(q); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * q = q.normalize(); + * inv(q, assumeUnit);//This assumeUnit means p is a unit quaternion + * ``` + */ + template + friend Quat inv(const Quat &q, QuatAssumeType assumeUnit); + + /** + * @brief return \f$q^{-1}\f$ which is an inverse of \f$q\f$ + * satisfying \f$q * q^{-1} = 1\f$. + * @param assumeUnit if QUAT_ASSUME_UNIT, quaternion q assume to be a unit quaternion and this function will save some computations. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.inv(); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * q = q.normalize(); + * q.inv(assumeUnit); //assumeUnit means p is a unit quaternion + * ``` + */ + Quat<_Tp> inv(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return sinh value of quaternion q, sinh could be calculated as: + * \f[\sinh(p) = \sin(w)\cos(||\boldsymbol{v}||) + \cosh(w)\frac{v}{||\boldsymbol{v}||}\sin||\boldsymbol{v}||\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * sinh(q); + * ``` + */ + template + friend Quat sinh(const Quat &q); + + /** + * @brief return sinh value of this quaternion, sinh could be calculated as: + * \f$\sinh(p) = \sin(w)\cos(||\boldsymbol{v}||) + \cosh(w)\frac{v}{||\boldsymbol{v}||}\sin||\boldsymbol{v}||\f$ + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.sinh(); + * ``` + */ + Quat<_Tp> sinh() const; + + /** + * @brief return cosh value of quaternion q, cosh could be calculated as: + * \f[\cosh(p) = \cosh(w) * \cos(||\boldsymbol{v}||) + \sinh(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sin(||\boldsymbol{v}||)\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * cosh(q); + * ``` + */ + template + friend Quat cosh(const Quat &q); + + /** + * @brief return cosh value of this quaternion, cosh could be calculated as: + * \f[\cosh(p) = \cosh(w) * \cos(||\boldsymbol{v}||) + \sinh(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}sin(||\boldsymbol{v}||)\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.cosh(); + * ``` + */ + Quat<_Tp> cosh() const; + + /** + * @brief return tanh value of quaternion q, tanh could be calculated as: + * \f[ \tanh(q) = \frac{\sinh(q)}{\cosh(q)}.\f] + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * tanh(q); + * ``` + * @sa sinh, cosh + */ + template + friend Quat tanh(const Quat &q); + + /** + * @brief return tanh value of this quaternion, tanh could be calculated as: + * \f[ \tanh(q) = \frac{\sinh(q)}{\cosh(q)}.\f] + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.tanh(); + * ``` + * @sa sinh, cosh + */ + Quat<_Tp> tanh() const; + + /** + * @brief return tanh value of quaternion q, sin could be calculated as: + * \f[\sin(p) = \sin(w) * \cosh(||\boldsymbol{v}||) + \cos(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sinh(||\boldsymbol{v}||)\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * sin(q); + * ``` + */ + template + friend Quat sin(const Quat &q); + + /** + * @brief return sin value of this quaternion, sin could be calculated as: + * \f[\sin(p) = \sin(w) * \cosh(||\boldsymbol{v}||) + \cos(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sinh(||\boldsymbol{v}||)\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.sin(); + * ``` + */ + Quat<_Tp> sin() const; + + /** + * @brief return sin value of quaternion q, cos could be calculated as: + * \f[\cos(p) = \cos(w) * \cosh(||\boldsymbol{v}||) - \sin(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sinh(||\boldsymbol{v}||)\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * cos(q); + * ``` + */ + template + friend Quat cos(const Quat &q); + + /** + * @brief return cos value of this quaternion, cos could be calculated as: + * \f[\cos(p) = \cos(w) * \cosh(||\boldsymbol{v}||) - \sin(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sinh(||\boldsymbol{v}||)\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.cos(); + * ``` + */ + Quat<_Tp> cos() const; + + /** + * @brief return tan value of quaternion q, tan could be calculated as: + * \f[\tan(q) = \frac{\sin(q)}{\cos(q)}.\f] + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * tan(q); + * ``` + */ + template + friend Quat tan(const Quat &q); + + /** + * @brief return tan value of this quaternion, tan could be calculated as: + * \f[\tan(q) = \frac{\sin(q)}{\cos(q)}.\f] + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.tan(); + * ``` + */ + Quat<_Tp> tan() const; + + /** + * @brief return arcsin value of quaternion q, arcsin could be calculated as: + * \f[\arcsin(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arcsinh(q\frac{\boldsymbol{v}}{||\boldsymbol{v}||})\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * asin(q); + * ``` + */ + template + friend Quat asin(const Quat &q); + + /** + * @brief return arcsin value of this quaternion, arcsin could be calculated as: + * \f[\arcsin(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arcsinh(q\frac{\boldsymbol{v}}{||\boldsymbol{v}||})\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.asin(); + * ``` + */ + Quat<_Tp> asin() const; + + /** + * @brief return arccos value of quaternion q, arccos could be calculated as: + * \f[\arccos(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arccosh(q)\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * acos(q); + * ``` + */ + template + friend Quat acos(const Quat &q); + + /** + * @brief return arccos value of this quaternion, arccos could be calculated as: + * \f[\arccos(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arccosh(q)\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.acos(); + * ``` + */ + Quat<_Tp> acos() const; + + /** + * @brief return arctan value of quaternion q, arctan could be calculated as: + * \f[\arctan(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arctanh(q\frac{\boldsymbol{v}}{||\boldsymbol{v}||})\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * atan(q); + * ``` + */ + template + friend Quat atan(const Quat &q); + + /** + * @brief return arctan value of this quaternion, arctan could be calculated as: + * \f[\arctan(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arctanh(q\frac{\boldsymbol{v}}{||\boldsymbol{v}||})\f] + * where \f$\boldsymbol{v} = [x, y, z].\f$ + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.atan(); + * ``` + */ + Quat<_Tp> atan() const; + + /** + * @brief return arcsinh value of quaternion q, arcsinh could be calculated as: + * \f[arcsinh(q) = \ln(q + \sqrt{q^2 + 1})\f]. + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * asinh(q); + * ``` + */ + template + friend Quat asinh(const Quat &q); + + /** + * @brief return arcsinh value of this quaternion, arcsinh could be calculated as: + * \f[arcsinh(q) = \ln(q + \sqrt{q^2 + 1})\f]. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.asinh(); + * ``` + */ + Quat<_Tp> asinh() const; + + /** + * @brief return arccosh value of quaternion q, arccosh could be calculated as: + * \f[arccosh(q) = \ln(q + \sqrt{q^2 - 1})\f]. + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * acosh(q); + * ``` + */ + template + friend Quat acosh(const Quat &q); + + /** + * @brief return arccosh value of this quaternion, arccosh could be calculated as: + * \f[arcosh(q) = \ln(q + \sqrt{q^2 - 1})\f]. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.acosh(); + * ``` + */ + Quat<_Tp> acosh() const; + + /** + * @brief return arctanh value of quaternion q, arctanh could be calculated as: + * \f[arctanh(q) = \frac{\ln(q + 1) - \ln(1 - q)}{2}\f]. + * @param q a quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * atanh(q); + * ``` + */ + template + friend Quat atanh(const Quat &q); + + /** + * @brief return arctanh value of this quaternion, arctanh could be calculated as: + * \f[arcsinh(q) = \frac{\ln(q + 1) - \ln(1 - q)}{2}\f]. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.atanh(); + * ``` + */ + Quat<_Tp> atanh() const; + + /** + * @brief return true if this quaternion is a unit quaternion. + * @param eps tolerance scope of normalization. The eps could be defined as + * + * \f[eps = |1 - dotValue|\f] where \f[dotValue = (this.w^2 + this.x^2 + this,y^2 + this.z^2).\f] + * And this function will consider it is normalized when the dotValue over a range \f$[1-eps, 1+eps]\f$. + */ + bool isNormal(_Tp eps=CV_QUAT_EPS) const; + + /** + * @brief to throw an error if this quaternion is not a unit quaternion. + * @param eps tolerance scope of normalization. + * @sa isNormal + */ + void assertNormal(_Tp eps=CV_QUAT_EPS) const; + + /** + * @brief transform a quaternion to a 3x3 rotation matrix. + * @param assumeUnit if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and + * this function will save some computations. Otherwise, this function will normalize this + * quaternion at first then do the transformation. + * + * @note Matrix A which is to be rotated should have the form + * \f[\begin{bmatrix} + * x_0& x_1& x_2&...&x_n\\ + * y_0& y_1& y_2&...&y_n\\ + * z_0& z_1& z_2&...&z_n + * \end{bmatrix}\f] + * where the same subscript represents a point. The shape of A assume to be [3, n] + * The points matrix A can be rotated by toRotMat3x3() * A. + * The result has 3 rows and n columns too. + + * For example + * ``` + * double angle = CV_PI; + * Vec3d axis{0,0,1}; + * Quatd q_unit = Quatd::createFromAngleAxis(angle, axis); //quaternion could also be get by interpolation by two or more quaternions. + * + * //assume there is two points (1,0,0) and (1,0,1) to be rotated + * Mat pointsA = (Mat_(2, 3) << 1,0,0,1,0,1); + * //change the shape + * pointsA = pointsA.t(); + * // rotate 180 degrees around the z axis + * Mat new_point = q_unit.toRotMat3x3() * pointsA; + * // print two points + * cout << new_point << endl; + * ``` + */ + Matx<_Tp, 3, 3> toRotMat3x3(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief transform a quaternion to a 4x4 rotation matrix. + * @param assumeUnit if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and + * this function will save some computations. Otherwise, this function will normalize this + * quaternion at first then do the transformation. + * + * The operations is similar as toRotMat3x3 + * except that the points matrix should have the form + * \f[\begin{bmatrix} + * x_0& x_1& x_2&...&x_n\\ + * y_0& y_1& y_2&...&y_n\\ + * z_0& z_1& z_2&...&z_n\\ + * 0&0&0&...&0 + * \end{bmatrix}\f] + * + * @sa toRotMat3x3 + */ + + Matx<_Tp, 4, 4> toRotMat4x4(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief transform the this quaternion to a Vec. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.toVec(); + * ``` + */ + Vec<_Tp, 4> toVec() const; + + /** + * @brief transform this quaternion to a Rotation vector. + * @param assumeUnit if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and + * this function will save some computations. + * Rotation vector rVec is defined as: + * \f[ rVec = [\theta v_x, \theta v_y, \theta v_z]\f] + * where \f$\theta\f$ represents rotation angle, and \f$\boldsymbol{v}\f$ represents the normalized rotation axis. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.toRotVec(); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * q.normalize().toRotVec(assumeUnit); //answer is same as q.toRotVec(). + * ``` + */ + Vec<_Tp, 3> toRotVec(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief get the angle of quaternion, it returns the rotation angle. + * @param assumeUnit if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and + * this function will save some computations. + * \f[\psi = 2 *arccos(\frac{w}{||q||})\f] + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.getAngle(); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * q.normalize().getAngle(assumeUnit);//same as q.getAngle(). + * ``` + * @note It always return the value between \f$[0, 2\pi]\f$. + */ + _Tp getAngle(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief get the axis of quaternion, it returns a vector of length 3. + * @param assumeUnit if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and + * this function will save some computations. + * + * the unit axis \f$\boldsymbol{u}\f$ is defined by + * \f[\begin{equation} + * \begin{split} + * \boldsymbol{v} + * &= \boldsymbol{u} ||\boldsymbol{v}||\\ + * &= \boldsymbol{u}||q||sin(\frac{\theta}{2}) + * \end{split} + * \end{equation}\f] + * where \f$v=[x, y ,z]\f$ and \f$\theta\f$ represents rotation angle. + * + * + * For example + * ``` + * Quatd q(1,2,3,4); + * q.getAxis(); + * + * QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT; + * q.normalize().getAxis(assumeUnit);//same as q.getAxis() + * ``` + */ + Vec<_Tp, 3> getAxis(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const; + + /** + * @brief return the dot between quaternion \f$q\f$ and this quaternion. + * + * dot(p, q) is a good metric of how close the quaternions are. + * Indeed, consider the unit quaternion difference \f$p^{-1} * q\f$, its real part is dot(p, q). + * At the same time its real part is equal to \f$\cos(\beta/2)\f$ where \f$\beta\f$ is + * an angle of rotation between p and q, i.e., + * Therefore, the closer dot(p, q) to 1, + * the smaller rotation between them. + * \f[p \cdot q = p.w \cdot q.w + p.x \cdot q.x + p.y \cdot q.y + p.z \cdot q.z\f] + * @param q the other quaternion. + * + * For example + * ``` + * Quatd q(1,2,3,4); + * Quatd p(5,6,7,8); + * p.dot(q); + * ``` + */ + _Tp dot(Quat<_Tp> q) const; + + /** + * @brief To calculate the interpolation from \f$q_0\f$ to \f$q_1\f$ by Linear Interpolation(Nlerp) + * For two quaternions, this interpolation curve can be displayed as: + * \f[Lerp(q_0, q_1, t) = (1 - t)q_0 + tq_1.\f] + * Obviously, the lerp will interpolate along a straight line if we think of \f$q_0\f$ and \f$q_1\f$ as a vector + * in a two-dimensional space. When \f$t = 0\f$, it returns \f$q_0\f$ and when \f$t= 1\f$, it returns \f$q_1\f$. + * \f$t\f$ should to be ranged in \f$[0, 1]\f$ normally. + * @param q0 a quaternion used in linear interpolation. + * @param q1 a quaternion used in linear interpolation. + * @param t percent of vector \f$\overrightarrow{q_0q_1}\f$ over a range [0, 1]. + * @note it returns a non-unit quaternion. + */ + static Quat<_Tp> lerp(const Quat<_Tp> &q0, const Quat &q1, const _Tp t); + + /** + * @brief To calculate the interpolation from \f$q_0\f$ to \f$q_1\f$ by Normalized Linear Interpolation(Nlerp). + * it returns a normalized quaternion of Linear Interpolation(Lerp). + * \f[ Nlerp(q_0, q_1, t) = \frac{(1 - t)q_0 + tq_1}{||(1 - t)q_0 + tq_1||}.\f] + * The interpolation will always choose the shortest path but the constant speed is not guaranteed. + * @param q0 a quaternion used in normalized linear interpolation. + * @param q1 a quaternion used in normalized linear interpolation. + * @param t percent of vector \f$\overrightarrow{q_0q_1}\f$ over a range [0, 1]. + * @param assumeUnit if QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternion. Otherwise, all inputs + quaternion will be normalized inside the function. + * @sa lerp + */ + static Quat<_Tp> nlerp(const Quat<_Tp> &q0, const Quat &q1, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + + /** + @brief To calculate the interpolation between \f$q_0\f$ and \f$q_1\f$ by Spherical Linear + Interpolation(Slerp), which can be defined as: + \f[ Slerp(q_0, q_1, t) = \frac{\sin((1-t)\theta)}{\sin(\theta)}q_0 + \frac{\sin(t\theta)}{\sin(\theta)}q_1\f] + where \f$\theta\f$ can be calculated as: + \f[\theta=cos^{-1}(q_0\cdot q_1)\f] + resulting from the both of their norm is unit. + @param q0 a quaternion used in Slerp. + @param q1 a quaternion used in Slerp. + @param t percent of angle between \f$q_0\f$ and \f$q_1\f$ over a range [0, 1]. + @param assumeUnit if QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternions. Otherwise, all input + quaternions will be normalized inside the function. + @param directChange if QUAT_ASSUME_UNIT, the interpolation will choose the nearest path. + @note If the interpolation angle is small, the error between Nlerp and Slerp is not so large. To improve efficiency and + avoid zero division error, we use Nlerp instead of Slerp. + */ + static Quat<_Tp> slerp(const Quat<_Tp> &q0, const Quat &q1, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT, bool directChange=true); + + /** + * @brief To calculate the interpolation between \f$q_0\f$,\f$q_1\f$,\f$q_2\f$,\f$q_3\f$ by Spherical and quadrangle(Squad). This could be defined as: + * \f[Squad(q_i, s_i, s_{i+1}, q_{i+1}, t) = Slerp(Slerp(q_i, q_{i+1}, t), Slerp(s_i, s_{i+1}, t), 2t(1-t))\f] + * where + * \f[s_i = q_i\exp(-\frac{\log(q^*_iq_{i+1}) + \log(q^*_iq_{i-1})}{4})\f] + * + * The Squad expression is analogous to the \f$B\acute{e}zier\f$ curve, but involves spherical linear + * interpolation instead of simple linear interpolation. Each \f$s_i\f$ needs to be calculated by three + * quaternions. + * + * @param q0 the first quaternion. + * @param s0 the second quaternion. + * @param s1 the third quaternion. + * @param q1 thr fourth quaternion. + * @param t interpolation parameter of quadratic and linear interpolation over a range \f$[0, 1]\f$. + * @param assumeUnit if QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternion. Otherwise, all input + * quaternions will be normalized inside the function. + * @param directChange if QUAT_ASSUME_UNIT, squad will find the nearest path to interpolate. + * @sa interPoint, spline + */ + static Quat<_Tp> squad(const Quat<_Tp> &q0, const Quat<_Tp> &s0, + const Quat<_Tp> &s1, const Quat<_Tp> &q1, + const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT, + bool directChange=true); + + /** + * @brief This is the part calculation of squad. + * To calculate the intermedia quaternion \f$s_i\f$ between each three quaternion + * \f[s_i = q_i\exp(-\frac{\log(q^*_iq_{i+1}) + \log(q^*_iq_{i-1})}{4}).\f] + * @param q0 the first quaternion. + * @param q1 the second quaternion. + * @param q2 the third quaternion. + * @param assumeUnit if QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternion. Otherwise, all input + * quaternions will be normalized inside the function. + * @sa squad + */ + static Quat<_Tp> interPoint(const Quat<_Tp> &q0, const Quat<_Tp> &q1, + const Quat<_Tp> &q2, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + + /** + * @brief to calculate a quaternion which is the result of a \f$C^1\f$ continuous + * spline curve constructed by squad at the ratio t. Here, the interpolation values are + * between \f$q_1\f$ and \f$q_2\f$. \f$q_0\f$ and \f$q_2\f$ are used to ensure the \f$C^1\f$ + * continuity. if t = 0, it returns \f$q_1\f$, if t = 1, it returns \f$q_2\f$. + * @param q0 the first input quaternion to ensure \f$C^1\f$ continuity. + * @param q1 the second input quaternion. + * @param q2 the third input quaternion. + * @param q3 the fourth input quaternion the same use of \f$q1\f$. + * @param t ratio over a range [0, 1]. + * @param assumeUnit if QUAT_ASSUME_UNIT, \f$q_0, q_1, q_2, q_3\f$ assume to be unit quaternion. Otherwise, all input + * quaternions will be normalized inside the function. + * + * For example: + * + * If there are three double quaternions \f$v_0, v_1, v_2\f$ waiting to be interpolated. + * + * Interpolation between \f$v_0\f$ and \f$v_1\f$ with a ratio \f$t_0\f$ could be calculated as + * ``` + * Quatd::spline(v0, v0, v1, v2, t0); + * ``` + * Interpolation between \f$v_1\f$ and \f$v_2\f$ with a ratio \f$t_0\f$ could be calculated as + * ``` + * Quatd::spline(v0, v1, v2, v2, t0); + * ``` + * @sa squad, slerp + */ + static Quat<_Tp> spline(const Quat<_Tp> &q0, const Quat<_Tp> &q1, + const Quat<_Tp> &q2, const Quat<_Tp> &q3, + const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + + /** + * @brief Return opposite quaternion \f$-p\f$ + * which satisfies \f$p + (-p) = 0.\f$ + * + * For example + * ``` + * Quatd q{1, 2, 3, 4}; + * std::cout << -q << std::endl; // [-1, -2, -3, -4] + * ``` + */ + Quat<_Tp> operator-() const; + + /** + * @brief return true if two quaternions p and q are nearly equal, i.e. when the absolute + * value of each \f$p_i\f$ and \f$q_i\f$ is less than CV_QUAT_EPS. + */ + bool operator==(const Quat<_Tp>&) const; + + /** + * @brief Addition operator of two quaternions p and q. + * It returns a new quaternion that each value is the sum of \f$p_i\f$ and \f$q_i\f$. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * Quatd q{5, 6, 7, 8}; + * std::cout << p + q << std::endl; //[6, 8, 10, 12] + * ``` + */ + Quat<_Tp> operator+(const Quat<_Tp>&) const; + + /** + * @brief Addition assignment operator of two quaternions p and q. + * It adds right operand to the left operand and assign the result to left operand. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * Quatd q{5, 6, 7, 8}; + * p += q; // equivalent to p = p + q + * std::cout << p << std::endl; //[6, 8, 10, 12] + * + * ``` + */ + Quat<_Tp>& operator+=(const Quat<_Tp>&); + + /** + * @brief Subtraction operator of two quaternions p and q. + * It returns a new quaternion that each value is the sum of \f$p_i\f$ and \f$-q_i\f$. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * Quatd q{5, 6, 7, 8}; + * std::cout << p - q << std::endl; //[-4, -4, -4, -4] + * ``` + */ + Quat<_Tp> operator-(const Quat<_Tp>&) const; + + /** + * @brief Subtraction assignment operator of two quaternions p and q. + * It subtracts right operand from the left operand and assign the result to left operand. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * Quatd q{5, 6, 7, 8}; + * p -= q; // equivalent to p = p - q + * std::cout << p << std::endl; //[-4, -4, -4, -4] + * + * ``` + */ + Quat<_Tp>& operator-=(const Quat<_Tp>&); + + /** + * @brief Multiplication assignment operator of two quaternions q and p. + * It multiplies right operand with the left operand and assign the result to left operand. + * + * Rule of quaternion multiplication: + * \f[ + * \begin{equation} + * \begin{split} + * p * q &= [p_0, \boldsymbol{u}]*[q_0, \boldsymbol{v}]\\ + * &=[p_0q_0 - \boldsymbol{u}\cdot \boldsymbol{v}, p_0\boldsymbol{v} + q_0\boldsymbol{u}+ \boldsymbol{u}\times \boldsymbol{v}]. + * \end{split} + * \end{equation} + * \f] + * where \f$\cdot\f$ means dot product and \f$\times \f$ means cross product. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * Quatd q{5, 6, 7, 8}; + * p *= q; // equivalent to p = p * q + * std::cout << p << std::endl; //[-60, 12, 30, 24] + * ``` + */ + Quat<_Tp>& operator*=(const Quat<_Tp>&); + + /** + * @brief Multiplication assignment operator of a quaternions and a scalar. + * It multiplies right operand with the left operand and assign the result to left operand. + * + * Rule of quaternion multiplication with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p * s &= [w, x, y, z] * s\\ + * &=[w * s, x * s, y * s, z * s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * double s = 2.0; + * p *= s; // equivalent to p = p * s + * std::cout << p << std::endl; //[2.0, 4.0, 6.0, 8.0] + * ``` + * @note the type of scalar should be equal to the quaternion. + */ + Quat<_Tp>& operator*=(const _Tp s); + + /** + * @brief Multiplication operator of two quaternions q and p. + * Multiplies values on either side of the operator. + * + * Rule of quaternion multiplication: + * \f[ + * \begin{equation} + * \begin{split} + * p * q &= [p_0, \boldsymbol{u}]*[q_0, \boldsymbol{v}]\\ + * &=[p_0q_0 - \boldsymbol{u}\cdot \boldsymbol{v}, p_0\boldsymbol{v} + q_0\boldsymbol{u}+ \boldsymbol{u}\times \boldsymbol{v}]. + * \end{split} + * \end{equation} + * \f] + * where \f$\cdot\f$ means dot product and \f$\times \f$ means cross product. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * Quatd q{5, 6, 7, 8}; + * std::cout << p * q << std::endl; //[-60, 12, 30, 24] + * ``` + */ + Quat<_Tp> operator*(const Quat<_Tp>&) const; + + /** + * @brief Division operator of a quaternions and a scalar. + * It divides left operand with the right operand and assign the result to left operand. + * + * Rule of quaternion division with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p / s &= [w, x, y, z] / s\\ + * &=[w/s, x/s, y/s, z/s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * double s = 2.0; + * p /= s; // equivalent to p = p / s + * std::cout << p << std::endl; //[0.5, 1, 1.5, 2] + * ``` + * @note the type of scalar should be equal to this quaternion. + */ + Quat<_Tp> operator/(const _Tp s) const; + + /** + * @brief Division operator of two quaternions p and q. + * Divides left hand operand by right hand operand. + * + * Rule of quaternion division with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p / q &= p * q.inv()\\ + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * Quatd q{5, 6, 7, 8}; + * std::cout << p / q << std::endl; // equivalent to p * q.inv() + * ``` + */ + Quat<_Tp> operator/(const Quat<_Tp>&) const; + + /** + * @brief Division assignment operator of a quaternions and a scalar. + * It divides left operand with the right operand and assign the result to left operand. + * + * Rule of quaternion division with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p / s &= [w, x, y, z] / s\\ + * &=[w / s, x / s, y / s, z / s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * double s = 2.0;; + * p /= s; // equivalent to p = p / s + * std::cout << p << std::endl; //[0.5, 1.0, 1.5, 2.0] + * ``` + * @note the type of scalar should be equal to the quaternion. + */ + Quat<_Tp>& operator/=(const _Tp s); + + /** + * @brief Division assignment operator of two quaternions p and q; + * It divides left operand with the right operand and assign the result to left operand. + * + * Rule of quaternion division with a quaternion: + * \f[ + * \begin{equation} + * \begin{split} + * p / q&= p * q.inv()\\ + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * Quatd q{5, 6, 7, 8}; + * p /= q; // equivalent to p = p * q.inv() + * std::cout << p << std::endl; + * ``` + */ + Quat<_Tp>& operator/=(const Quat<_Tp>&); + + _Tp& operator[](std::size_t n); + + const _Tp& operator[](std::size_t n) const; + + /** + * @brief Subtraction operator of a scalar and a quaternions. + * Subtracts right hand operand from left hand operand. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * double scalar = 2.0; + * std::cout << scalar - p << std::endl; //[1.0, -2, -3, -4] + * ``` + * @note the type of scalar should be equal to the quaternion. + */ + template + friend Quat cv::operator-(const T s, const Quat&); + + /** + * @brief Subtraction operator of a quaternions and a scalar. + * Subtracts right hand operand from left hand operand. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * double scalar = 2.0; + * std::cout << p - scalar << std::endl; //[-1.0, 2, 3, 4] + * ``` + * @note the type of scalar should be equal to the quaternion. + */ + template + friend Quat cv::operator-(const Quat&, const T s); + + /** + * @brief Addition operator of a quaternions and a scalar. + * Adds right hand operand from left hand operand. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * double scalar = 2.0; + * std::cout << scalar + p << std::endl; //[3.0, 2, 3, 4] + * ``` + * @note the type of scalar should be equal to the quaternion. + */ + template + friend Quat cv::operator+(const T s, const Quat&); + + /** + * @brief Addition operator of a quaternions and a scalar. + * Adds right hand operand from left hand operand. + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * double scalar = 2.0; + * std::cout << p + scalar << std::endl; //[3.0, 2, 3, 4] + * ``` + * @note the type of scalar should be equal to the quaternion. + */ + template + friend Quat cv::operator+(const Quat&, const T s); + + /** + * @brief Multiplication operator of a scalar and a quaternions. + * It multiplies right operand with the left operand and assign the result to left operand. + * + * Rule of quaternion multiplication with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p * s &= [w, x, y, z] * s\\ + * &=[w * s, x * s, y * s, z * s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * double s = 2.0; + * std::cout << s * p << std::endl; //[2.0, 4.0, 6.0, 8.0] + * ``` + * @note the type of scalar should be equal to the quaternion. + */ + template + friend Quat cv::operator*(const T s, const Quat&); + + /** + * @brief Multiplication operator of a quaternion and a scalar. + * It multiplies right operand with the left operand and assign the result to left operand. + * + * Rule of quaternion multiplication with a scalar: + * \f[ + * \begin{equation} + * \begin{split} + * p * s &= [w, x, y, z] * s\\ + * &=[w * s, x * s, y * s, z * s]. + * \end{split} + * \end{equation} + * \f] + * + * For example + * ``` + * Quatd p{1, 2, 3, 4}; + * double s = 2.0; + * std::cout << p * s << std::endl; //[2.0, 4.0, 6.0, 8.0] + * ``` + * @note the type of scalar should be equal to the quaternion. + */ + template + friend Quat cv::operator*(const Quat&, const T s); + + template + friend std::ostream& cv::operator<<(std::ostream&, const Quat&); + + /** + * @brief Transform a quaternion q to Euler angles. + * + * + * When transforming a quaternion \f$q = w + x\boldsymbol{i} + y\boldsymbol{j} + z\boldsymbol{k}\f$ to Euler angles, rotation matrix M can be calculated by: + * \f[ \begin{aligned} {M} &={\begin{bmatrix}1-2(y^{2}+z^{2})&2(xy-zx)&2(xz+yw)\\2(xy+zw)&1-2(x^{2}+z^{2})&2(yz-xw)\\2(xz-yw)&2(yz+xw)&1-2(x^{2}+y^{2})\end{bmatrix}}\end{aligned}.\f] + * On the other hand, the rotation matrix can be obtained from Euler angles. + * Using intrinsic rotations with Euler angles type XYZ as an example, + * \f$\theta_1 \f$, \f$\theta_2 \f$, \f$\theta_3 \f$ are three angles for Euler angles, the rotation matrix R can be calculated by:\f[R =X(\theta_1)Y(\theta_2)Z(\theta_3) + * ={\begin{bmatrix}\cos\theta_{2}\cos\theta_{3}&-\cos\theta_{2}\sin\theta_{3}&\sin\theta_{2}\\\cos\theta_{1}\sin\theta_{3}+\cos\theta_{3}\sin\theta_{1}\sin\theta_{2}&\cos\theta_{1}\cos\theta_{3}-\sin\theta_{1}\sin\theta_{2}\sin\theta_{3}&-\cos\theta_{2}\sin\theta_{1}\\\sin\theta_{1}\sin\theta_{3}-\cos\theta_{1}\cos\theta_{3}\sin\theta_{2}&\cos\theta_{3}\sin\theta_{1}+\cos\theta_{1}\sin\theta_{2}\sin\theta_{3}&\cos\theta_{1}\cos_{2}\end{bmatrix}}\f] + * Rotation matrix M and R are equal. As long as \f$ s_{2} \neq 1 \f$, by comparing each element of two matrices ,the solution is\f$\begin{cases} \theta_1 = \arctan2(-m_{23},m_{33})\\\theta_2 = arcsin(m_{13}) \\\theta_3 = \arctan2(-m_{12},m_{11}) \end{cases}\f$. + * + * When \f$ s_{2}=1\f$ or \f$ s_{2}=-1\f$, the gimbal lock occurs. The function will prompt "WARNING: Gimbal Lock will occur. Euler angles is non-unique. For intrinsic rotations, we set the third angle to 0, and for external rotation, we set the first angle to 0.". + * + * When \f$ s_{2}=1\f$ , + * The rotation matrix R is \f$R = {\begin{bmatrix}0&0&1\\\sin(\theta_1+\theta_3)&\cos(\theta_1+\theta_3)&0\\-\cos(\theta_1+\theta_3)&\sin(\theta_1+\theta_3)&0\end{bmatrix}}\f$. + * + * The number of solutions is infinite with the condition \f$\begin{cases} \theta_1+\theta_3 = \arctan2(m_{21},m_{22})\\ \theta_2=\pi/2 \end{cases}\ \f$. + * + * We set \f$ \theta_3 = 0\f$, the solution is \f$\begin{cases} \theta_1=\arctan2(m_{21},m_{22})\\ \theta_2=\pi/2\\ \theta_3=0 \end{cases}\f$. + * + * When \f$ s_{2}=-1\f$, + * The rotation matrix R is \f$X_{1}Y_{2}Z_{3}={\begin{bmatrix}0&0&-1\\-\sin(\theta_1-\theta_3)&\cos(\theta_1-\theta_3)&0\\\cos(\theta_1-\theta_3)&\sin(\theta_1-\theta_3)&0\end{bmatrix}}\f$. + * + * The number of solutions is infinite with the condition \f$\begin{cases} \theta_1+\theta_3 = \arctan2(m_{32},m_{22})\\ \theta_2=\pi/2 \end{cases}\ \f$. + * + * We set \f$ \theta_3 = 0\f$, the solution is \f$ \begin{cases}\theta_1=\arctan2(m_{32},m_{22}) \\ \theta_2=-\pi/2\\ \theta_3=0\end{cases}\f$. + * + * Since \f$ sin \theta\in [-1,1] \f$ and \f$ cos \theta \in [-1,1] \f$, the unnormalized quaternion will cause computational troubles. For this reason, this function will normalize the quaternion at first and @ref QuatAssumeType is not needed. + * + * When the gimbal lock occurs, we set \f$\theta_3 = 0\f$ for intrinsic rotations or \f$\theta_1 = 0\f$ for extrinsic rotations. + * + * As a result, for every Euler angles type, we can get solution as shown in the following table. + * EulerAnglesType | Ordinary | \f$\theta_2 = π/2\f$ | \f$\theta_2 = -π/2\f$ + * ------------- | -------------| -------------| ------------- + * INT_XYZ|\f$ \theta_1 = \arctan2(-m_{23},m_{33})\\\theta_2 = \arcsin(m_{13}) \\\theta_3= \arctan2(-m_{12},m_{11}) \f$|\f$ \theta_1=\arctan2(m_{21},m_{22})\\ \theta_2=\pi/2\\ \theta_3=0 \f$|\f$ \theta_1=\arctan2(m_{32},m_{22})\\ \theta_2=-\pi/2\\ \theta_3=0 \f$ + * INT_XZY|\f$ \theta_1 = \arctan2(m_{32},m_{22})\\\theta_2 = -\arcsin(m_{12}) \\\theta_3= \arctan2(m_{13},m_{11}) \f$|\f$ \theta_1=\arctan2(m_{31},m_{33})\\ \theta_2=\pi/2\\ \theta_3=0 \f$|\f$ \theta_1=\arctan2(-m_{23},m_{33})\\ \theta_2=-\pi/2\\ \theta_3=0 \f$ + * INT_YXZ|\f$ \theta_1 = \arctan2(m_{13},m_{33})\\\theta_2 = -\arcsin(m_{23}) \\\theta_3= \arctan2(m_{21},m_{22}) \f$|\f$ \theta_1=\arctan2(m_{12},m_{11})\\ \theta_2=\pi/2\\ \theta_3=0 \f$|\f$ \theta_1=\arctan2(-m_{12},m_{11})\\ \theta_2=-\pi/2\\ \theta_3=0 \f$ + * INT_YZX|\f$ \theta_1 = \arctan2(-m_{31},m_{11})\\\theta_2 = \arcsin(m_{21}) \\\theta_3= \arctan2(-m_{23},m_{22}) \f$|\f$ \theta_1=\arctan2(m_{13},m_{33})\\ \theta_2=\pi/2\\ \theta_3=0 \f$|\f$ \theta_1=\arctan2(m_{13},m_{12})\\ \theta_2=-\pi/2\\ \theta_3=0 \f$ + * INT_ZXY|\f$ \theta_1 = \arctan2(-m_{12},m_{22})\\\theta_2 = \arcsin(m_{32}) \\\theta_3= \arctan2(-m_{31},m_{33}) \f$|\f$ \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=\pi/2\\ \theta_3=0 \f$|\f$ \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=-\pi/2\\ \theta_3=0 \f$ + * INT_ZYX|\f$ \theta_1 = \arctan2(m_{21},m_{11})\\\theta_2 = \arcsin(-m_{31}) \\\theta_3= \arctan2(m_{32},m_{33}) \f$|\f$ \theta_1=\arctan2(m_{23},m_{22})\\ \theta_2=\pi/2\\ \theta_3=0 \f$|\f$ \theta_1=\arctan2(-m_{12},m_{22})\\ \theta_2=-\pi/2\\ \theta_3=0 \f$ + * EXT_XYZ|\f$ \theta_1 = \arctan2(m_{32},m_{33})\\\theta_2 = \arcsin(-m_{31}) \\\ \theta_3 = \arctan2(m_{21},m_{11})\f$|\f$ \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{23},m_{22}) \f$|\f$ \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(-m_{12},m_{22}) \f$ + * EXT_XZY|\f$ \theta_1 = \arctan2(-m_{23},m_{22})\\\theta_2 = \arcsin(m_{21}) \\\theta_3= \arctan2(-m_{31},m_{11})\f$|\f$ \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{13},m_{33}) \f$|\f$ \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(m_{13},m_{12}) \f$ + * EXT_YXZ|\f$ \theta_1 = \arctan2(-m_{31},m_{33}) \\\theta_2 = \arcsin(m_{32}) \\\theta_3= \arctan2(-m_{12},m_{22})\f$|\f$ \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{21},m_{11}) \f$|\f$ \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(m_{21},m_{11}) \f$ + * EXT_YZX|\f$ \theta_1 = \arctan2(m_{13},m_{11})\\\theta_2 = -\arcsin(m_{12}) \\\theta_3= \arctan2(m_{32},m_{22})\f$|\f$ \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{31},m_{33}) \f$|\f$ \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(-m_{23},m_{33}) \f$ + * EXT_ZXY|\f$ \theta_1 = \arctan2(m_{21},m_{22})\\\theta_2 = -\arcsin(m_{23}) \\\theta_3= \arctan2(m_{13},m_{33})\f$|\f$ \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{12},m_{11}) \f$|\f$ \theta_1= 0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(-m_{12},m_{11}) \f$ + * EXT_ZYX|\f$ \theta_1 = \arctan2(-m_{12},m_{11})\\\theta_2 = \arcsin(m_{13}) \\\theta_3= \arctan2(-m_{23},m_{33})\f$|\f$ \theta_1=0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{21},m_{22}) \f$|\f$ \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(m_{32},m_{22}) \f$ + * + * EulerAnglesType | Ordinary | \f$\theta_2 = 0\f$ | \f$\theta_2 = π\f$ + * ------------- | -------------| -------------| ------------- + * INT_XYX| \f$ \theta_1 = \arctan2(m_{21},-m_{31})\\\theta_2 =\arccos(m_{11}) \\\theta_3 = \arctan2(m_{12},m_{13}) \f$| \f$ \theta_1=\arctan2(m_{32},m_{33})\\ \theta_2=0\\ \theta_3=0 \f$| \f$ \theta_1=\arctan2(m_{23},m_{22})\\ \theta_2=\pi\\ \theta_3=0 \f$ + * INT_XZX| \f$ \theta_1 = \arctan2(m_{31},m_{21})\\\theta_2 = \arccos(m_{11}) \\\theta_3 = \arctan2(m_{13},-m_{12}) \f$| \f$ \theta_1=\arctan2(m_{32},m_{33})\\ \theta_2=0\\ \theta_3=0 \f$| \f$ \theta_1=\arctan2(-m_{32},m_{33})\\ \theta_2=\pi\\ \theta_3=0 \f$ + * INT_YXY| \f$ \theta_1 = \arctan2(m_{12},m_{32})\\\theta_2 = \arccos(m_{22}) \\\theta_3 = \arctan2(m_{21},-m_{23}) \f$| \f$ \theta_1=\arctan2(m_{13},m_{11})\\ \theta_2=0\\ \theta_3=0 \f$| \f$ \theta_1=\arctan2(-m_{31},m_{11})\\ \theta_2=\pi\\ \theta_3=0 \f$ + * INT_YZY| \f$ \theta_1 = \arctan2(m_{32},-m_{12})\\\theta_2 = \arccos(m_{22}) \\\theta_3 =\arctan2(m_{23},m_{21}) \f$| \f$ \theta_1=\arctan2(m_{13},m_{11})\\ \theta_2=0\\ \theta_3=0 \f$| \f$ \theta_1=\arctan2(m_{13},-m_{11})\\ \theta_2=\pi\\ \theta_3=0 \f$ + * INT_ZXZ| \f$ \theta_1 = \arctan2(-m_{13},m_{23})\\\theta_2 = \arccos(m_{33}) \\\theta_3 =\arctan2(m_{31},m_{32}) \f$| \f$ \theta_1=\arctan2(m_{21},m_{22})\\ \theta_2=0\\ \theta_3=0 \f$| \f$ \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=\pi\\ \theta_3=0 \f$ + * INT_ZYZ| \f$ \theta_1 = \arctan2(m_{23},m_{13})\\\theta_2 = \arccos(m_{33}) \\\theta_3 = \arctan2(m_{32},-m_{31}) \f$| \f$ \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=0\\ \theta_3=0 \f$| \f$ \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=\pi\\ \theta_3=0 \f$ + * EXT_XYX| \f$ \theta_1 = \arctan2(m_{12},m_{13}) \\\theta_2 = \arccos(m_{11}) \\\theta_3 = \arctan2(m_{21},-m_{31})\f$| \f$ \theta_1=0\\ \theta_2=0\\ \theta_3=\arctan2(m_{32},m_{33}) \f$| \f$ \theta_1= 0\\ \theta_2=\pi\\ \theta_3= \arctan2(m_{23},m_{22}) \f$ + * EXT_XZX| \f$ \theta_1 = \arctan2(m_{13},-m_{12})\\\theta_2 = \arccos(m_{11}) \\\theta_3 = \arctan2(m_{31},m_{21})\f$| \f$ \theta_1= 0\\ \theta_2=0\\ \theta_3=\arctan2(m_{32},m_{33}) \f$| \f$ \theta_1= 0\\ \theta_2=\pi\\ \theta_3=\arctan2(-m_{32},m_{33}) \f$ + * EXT_YXY| \f$ \theta_1 = \arctan2(m_{21},-m_{23})\\\theta_2 = \arccos(m_{22}) \\\theta_3 = \arctan2(m_{12},m_{32}) \f$| \f$ \theta_1= 0\\ \theta_2=0\\ \theta_3=\arctan2(m_{13},m_{11}) \f$| \f$ \theta_1= 0\\ \theta_2=\pi\\ \theta_3=\arctan2(-m_{31},m_{11}) \f$ + * EXT_YZY| \f$ \theta_1 = \arctan2(m_{23},m_{21}) \\\theta_2 = \arccos(m_{22}) \\\theta_3 = \arctan2(m_{32},-m_{12}) \f$| \f$ \theta_1= 0\\ \theta_2=0\\ \theta_3=\arctan2(m_{13},m_{11}) \f$| \f$ \theta_1=0\\ \theta_2=\pi\\ \theta_3=\arctan2(m_{13},-m_{11}) \f$ + * EXT_ZXZ| \f$ \theta_1 = \arctan2(m_{31},m_{32}) \\\theta_2 = \arccos(m_{33}) \\\theta_3 = \arctan2(-m_{13},m_{23})\f$| \f$ \theta_1=0\\ \theta_2=0\\ \theta_3=\arctan2(m_{21},m_{22}) \f$| \f$ \theta_1= 0\\ \theta_2=\pi\\ \theta_3=\arctan2(m_{21},m_{11}) \f$ + * EXT_ZYZ| \f$ \theta_1 = \arctan2(m_{32},-m_{31})\\\theta_2 = \arccos(m_{33}) \\\theta_3 = \arctan2(m_{23},m_{13}) \f$| \f$ \theta_1=0\\ \theta_2=0\\ \theta_3=\arctan2(m_{21},m_{11}) \f$| \f$ \theta_1= 0\\ \theta_2=\pi\\ \theta_3=\arctan2(m_{21},m_{11}) \f$ + * + * @param eulerAnglesType the convertion Euler angles type + */ + + Vec<_Tp, 3> toEulerAngles(QuatEnum::EulerAnglesType eulerAnglesType); + + _Tp w, x, y, z; + +}; + +template +Quat inv(const Quat &q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + +template +Quat sinh(const Quat &q); + +template +Quat cosh(const Quat &q); + +template +Quat tanh(const Quat &q); + +template +Quat sin(const Quat &q); + +template +Quat cos(const Quat &q); + +template +Quat tan(const Quat &q); + +template +Quat asinh(const Quat &q); + +template +Quat acosh(const Quat &q); + +template +Quat atanh(const Quat &q); + +template +Quat asin(const Quat &q); + +template +Quat acos(const Quat &q); + +template +Quat atan(const Quat &q); + +template +Quat power(const Quat &q, const Quat &p, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + +template +Quat exp(const Quat &q); + +template +Quat log(const Quat &q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + +template +Quat power(const Quat& q, const T x, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + +template +Quat crossProduct(const Quat &p, const Quat &q); + +template +Quat sqrt(const Quat &q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT); + +template +Quat operator*(const T, const Quat&); + +template +Quat operator*(const Quat&, const T); + +template +std::ostream& operator<<(std::ostream&, const Quat&); + +using Quatd = Quat; +using Quatf = Quat; + +//! @} core +} + +#include "opencv2/core/quaternion.inl.hpp" + +#endif /* OPENCV_CORE_QUATERNION_HPP */ diff --git a/3rdparty/include/opencv2/core/quaternion.inl.hpp b/3rdparty/include/opencv2/core/quaternion.inl.hpp new file mode 100644 index 0000000000..3c2fce10af --- /dev/null +++ b/3rdparty/include/opencv2/core/quaternion.inl.hpp @@ -0,0 +1,1063 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2020, Huawei Technologies Co., Ltd. All rights reserved. +// Third party copyrights are property of their respective owners. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Author: Liangqian Kong +// Longbu Wang + +#ifndef OPENCV_CORE_QUATERNION_INL_HPP +#define OPENCV_CORE_QUATERNION_INL_HPP + +#ifndef OPENCV_CORE_QUATERNION_HPP +#erorr This is not a standalone header. Include quaternion.hpp instead. +#endif + +//@cond IGNORE +/////////////////////////////////////////////////////////////////////////////////////// +//Implementation +namespace cv { + +template +Quat::Quat() : w(0), x(0), y(0), z(0) {} + +template +Quat::Quat(const Vec &coeff):w(coeff[0]), x(coeff[1]), y(coeff[2]), z(coeff[3]){} + +template +Quat::Quat(const T qw, const T qx, const T qy, const T qz):w(qw), x(qx), y(qy), z(qz){} + +template +Quat Quat::createFromAngleAxis(const T angle, const Vec &axis) +{ + T w, x, y, z; + T vNorm = std::sqrt(axis.dot(axis)); + if (vNorm < CV_QUAT_EPS) + { + CV_Error(Error::StsBadArg, "this quaternion does not represent a rotation"); + } + const T angle_half = angle * 0.5; + w = std::cos(angle_half); + const T sin_v = std::sin(angle_half); + const T sin_norm = sin_v / vNorm; + x = sin_norm * axis[0]; + y = sin_norm * axis[1]; + z = sin_norm * axis[2]; + return Quat(w, x, y, z); +} + +template +Quat Quat::createFromRotMat(InputArray _R) +{ + CV_CheckTypeEQ(_R.type(), cv::traits::Type::value, ""); + if (_R.rows() != 3 || _R.cols() != 3) + { + CV_Error(Error::StsBadArg, "Cannot convert matrix to quaternion: rotation matrix should be a 3x3 matrix"); + } + Matx R; + _R.copyTo(R); + + T S, w, x, y, z; + T trace = R(0, 0) + R(1, 1) + R(2, 2); + if (trace > 0) + { + S = std::sqrt(trace + 1) * 2; + x = (R(1, 2) - R(2, 1)) / S; + y = (R(2, 0) - R(0, 2)) / S; + z = (R(0, 1) - R(1, 0)) / S; + w = -0.25 * S; + } + else if (R(0, 0) > R(1, 1) && R(0, 0) > R(2, 2)) + { + + S = std::sqrt(1.0 + R(0, 0) - R(1, 1) - R(2, 2)) * 2; + x = -0.25 * S; + y = -(R(1, 0) + R(0, 1)) / S; + z = -(R(0, 2) + R(2, 0)) / S; + w = (R(1, 2) - R(2, 1)) / S; + } + else if (R(1, 1) > R(2, 2)) + { + S = std::sqrt(1.0 - R(0, 0) + R(1, 1) - R(2, 2)) * 2; + x = (R(0, 1) + R(1, 0)) / S; + y = 0.25 * S; + z = (R(1, 2) + R(2, 1)) / S; + w = (R(0, 2) - R(2, 0)) / S; + } + else + { + S = std::sqrt(1.0 - R(0, 0) - R(1, 1) + R(2, 2)) * 2; + x = (R(0, 2) + R(2, 0)) / S; + y = (R(1, 2) + R(2, 1)) / S; + z = 0.25 * S; + w = -(R(0, 1) - R(1, 0)) / S; + } + return Quat (w, x, y, z); +} + +template +Quat Quat::createFromRvec(InputArray _rvec) +{ + if (!((_rvec.cols() == 1 && _rvec.rows() == 3) || (_rvec.cols() == 3 && _rvec.rows() == 1))) { + CV_Error(Error::StsBadArg, "Cannot convert rotation vector to quaternion: The length of rotation vector should be 3"); + } + Vec rvec; + _rvec.copyTo(rvec); + T psi = std::sqrt(rvec.dot(rvec)); + if (abs(psi) < CV_QUAT_EPS) { + return Quat (1, 0, 0, 0); + } + Vec axis = rvec / psi; + return createFromAngleAxis(psi, axis); +} + +template +inline Quat Quat::operator-() const +{ + return Quat(-w, -x, -y, -z); +} + + +template +inline bool Quat::operator==(const Quat &q) const +{ + return (abs(w - q.w) < CV_QUAT_EPS && abs(x - q.x) < CV_QUAT_EPS && abs(y - q.y) < CV_QUAT_EPS && abs(z - q.z) < CV_QUAT_EPS); +} + +template +inline Quat Quat::operator+(const Quat &q1) const +{ + return Quat(w + q1.w, x + q1.x, y + q1.y, z + q1.z); +} + +template +inline Quat operator+(const T a, const Quat& q) +{ + return Quat(q.w + a, q.x, q.y, q.z); +} + +template +inline Quat operator+(const Quat& q, const T a) +{ + return Quat(q.w + a, q.x, q.y, q.z); +} + +template +inline Quat operator-(const T a, const Quat& q) +{ + return Quat(a - q.w, -q.x, -q.y, -q.z); +} + +template +inline Quat operator-(const Quat& q, const T a) +{ + return Quat(q.w - a, q.x, q.y, q.z); +} + +template +inline Quat Quat::operator-(const Quat &q1) const +{ + return Quat(w - q1.w, x - q1.x, y - q1.y, z - q1.z); +} + +template +inline Quat& Quat::operator+=(const Quat &q1) +{ + w += q1.w; + x += q1.x; + y += q1.y; + z += q1.z; + return *this; +} + +template +inline Quat& Quat::operator-=(const Quat &q1) +{ + w -= q1.w; + x -= q1.x; + y -= q1.y; + z -= q1.z; + return *this; +} + +template +inline Quat Quat::operator*(const Quat &q1) const +{ + Vec q{w, x, y, z}; + Vec q2{q1.w, q1.x, q1.y, q1.z}; + return Quat(q * q2); +} + + +template +Quat operator*(const Quat &q1, const T a) +{ + return Quat(a * q1.w, a * q1.x, a * q1.y, a * q1.z); +} + +template +Quat operator*(const T a, const Quat &q1) +{ + return Quat(a * q1.w, a * q1.x, a * q1.y, a * q1.z); +} + +template +inline Quat& Quat::operator*=(const Quat &q1) +{ + T qw, qx, qy, qz; + qw = w * q1.w - x * q1.x - y * q1.y - z * q1.z; + qx = x * q1.w + w * q1.x + y * q1.z - z * q1.y; + qy = y * q1.w + w * q1.y + z * q1.x - x * q1.z; + qz = z * q1.w + w * q1.z + x * q1.y - y * q1.x; + w = qw; + x = qx; + y = qy; + z = qz; + return *this; +} + +template +inline Quat& Quat::operator/=(const Quat &q1) +{ + Quat q(*this * q1.inv()); + w = q.w; + x = q.x; + y = q.y; + z = q.z; + return *this; +} +template +Quat& Quat::operator*=(const T q1) +{ + w *= q1; + x *= q1; + y *= q1; + z *= q1; + return *this; +} + +template +inline Quat& Quat::operator/=(const T a) +{ + const T a_inv = 1.0 / a; + w *= a_inv; + x *= a_inv; + y *= a_inv; + z *= a_inv; + return *this; +} + +template +inline Quat Quat::operator/(const T a) const +{ + const T a_inv = 1.0 / a; + return Quat(w * a_inv, x * a_inv, y * a_inv, z * a_inv); +} + +template +inline Quat Quat::operator/(const Quat &q) const +{ + return *this * q.inv(); +} + +template +inline const T& Quat::operator[](std::size_t n) const +{ + switch (n) { + case 0: + return w; + case 1: + return x; + case 2: + return y; + case 3: + return z; + default: + CV_Error(Error::StsOutOfRange, "subscript exceeds the index range"); + } +} + +template +inline T& Quat::operator[](std::size_t n) +{ + switch (n) { + case 0: + return w; + case 1: + return x; + case 2: + return y; + case 3: + return z; + default: + CV_Error(Error::StsOutOfRange, "subscript exceeds the index range"); + } +} + +template +std::ostream & operator<<(std::ostream &os, const Quat &q) +{ + os << "Quat " << Vec{q.w, q.x, q.y, q.z}; + return os; +} + +template +inline T Quat::at(size_t index) const +{ + return (*this)[index]; +} + +template +inline Quat Quat::conjugate() const +{ + return Quat(w, -x, -y, -z); +} + +template +inline T Quat::norm() const +{ + return std::sqrt(dot(*this)); +} + +template +Quat exp(const Quat &q) +{ + return q.exp(); +} + +template +Quat Quat::exp() const +{ + Vec v{x, y, z}; + T normV = std::sqrt(v.dot(v)); + T k = normV < CV_QUAT_EPS ? 1 : std::sin(normV) / normV; + return std::exp(w) * Quat(std::cos(normV), v[0] * k, v[1] * k, v[2] * k); +} + +template +Quat log(const Quat &q, QuatAssumeType assumeUnit) +{ + return q.log(assumeUnit); +} + +template +Quat Quat::log(QuatAssumeType assumeUnit) const +{ + Vec v{x, y, z}; + T vNorm = std::sqrt(v.dot(v)); + if (assumeUnit) + { + T k = vNorm < CV_QUAT_EPS ? 1 : std::acos(w) / vNorm; + return Quat(0, v[0] * k, v[1] * k, v[2] * k); + } + T qNorm = norm(); + if (qNorm < CV_QUAT_EPS) + { + CV_Error(Error::StsBadArg, "Cannot apply this quaternion to log function: undefined"); + } + T k = vNorm < CV_QUAT_EPS ? 1 : std::acos(w / qNorm) / vNorm; + return Quat(std::log(qNorm), v[0] * k, v[1] * k, v[2] *k); +} + +template +inline Quat power(const Quat &q1, const T alpha, QuatAssumeType assumeUnit) +{ + return q1.power(alpha, assumeUnit); +} + +template +inline Quat Quat::power(const T alpha, QuatAssumeType assumeUnit) const +{ + if (x * x + y * y + z * z > CV_QUAT_EPS) + { + T angle = getAngle(assumeUnit); + Vec axis = getAxis(assumeUnit); + if (assumeUnit) + { + return createFromAngleAxis(alpha * angle, axis); + } + return std::pow(norm(), alpha) * createFromAngleAxis(alpha * angle, axis); + } + else + { + return std::pow(norm(), alpha) * Quat(w, x, y, z); + } +} + + +template +inline Quat sqrt(const Quat &q, QuatAssumeType assumeUnit) +{ + return q.sqrt(assumeUnit); +} + +template +inline Quat Quat::sqrt(QuatAssumeType assumeUnit) const +{ + return power(0.5, assumeUnit); +} + + +template +inline Quat power(const Quat &p, const Quat &q, QuatAssumeType assumeUnit) +{ + return p.power(q, assumeUnit); +} + + +template +inline Quat Quat::power(const Quat &q, QuatAssumeType assumeUnit) const +{ + return cv::exp(q * log(assumeUnit)); +} + +template +inline T Quat::dot(Quat q1) const +{ + return w * q1.w + x * q1.x + y * q1.y + z * q1.z; +} + + +template +inline Quat crossProduct(const Quat &p, const Quat &q) +{ + return p.crossProduct(q); +} + + +template +inline Quat Quat::crossProduct(const Quat &q) const +{ + return Quat (0, y * q.z - z * q.y, z * q.x - x * q.z, x * q.y - q.x * y); +} + +template +inline Quat Quat::normalize() const +{ + T normVal = norm(); + if (normVal < CV_QUAT_EPS) + { + CV_Error(Error::StsBadArg, "Cannot normalize this quaternion: the norm is too small."); + } + return Quat(w / normVal, x / normVal, y / normVal, z / normVal) ; +} + +template +inline Quat inv(const Quat &q, QuatAssumeType assumeUnit) +{ + return q.inv(assumeUnit); +} + + +template +inline Quat Quat::inv(QuatAssumeType assumeUnit) const +{ + if (assumeUnit) + { + return conjugate(); + } + T norm2 = dot(*this); + if (norm2 < CV_QUAT_EPS) + { + CV_Error(Error::StsBadArg, "This quaternion do not have inverse quaternion"); + } + return conjugate() / norm2; +} + +template +inline Quat sinh(const Quat &q) +{ + return q.sinh(); +} + + +template +inline Quat Quat::sinh() const +{ + Vec v{x, y ,z}; + T vNorm = std::sqrt(v.dot(v)); + T k = vNorm < CV_QUAT_EPS ? 1 : std::cosh(w) * std::sin(vNorm) / vNorm; + return Quat(std::sinh(w) * std::cos(vNorm), v[0] * k, v[1] * k, v[2] * k); +} + + +template +inline Quat cosh(const Quat &q) +{ + return q.cosh(); +} + + +template +inline Quat Quat::cosh() const +{ + Vec v{x, y ,z}; + T vNorm = std::sqrt(v.dot(v)); + T k = vNorm < CV_QUAT_EPS ? 1 : std::sinh(w) * std::sin(vNorm) / vNorm; + return Quat(std::cosh(w) * std::cos(vNorm), v[0] * k, v[1] * k, v[2] * k); +} + +template +inline Quat tanh(const Quat &q) +{ + return q.tanh(); +} + +template +inline Quat Quat::tanh() const +{ + return sinh() * cosh().inv(); +} + + +template +inline Quat sin(const Quat &q) +{ + return q.sin(); +} + + +template +inline Quat Quat::sin() const +{ + Vec v{x, y ,z}; + T vNorm = std::sqrt(v.dot(v)); + T k = vNorm < CV_QUAT_EPS ? 1 : std::cos(w) * std::sinh(vNorm) / vNorm; + return Quat(std::sin(w) * std::cosh(vNorm), v[0] * k, v[1] * k, v[2] * k); +} + +template +inline Quat cos(const Quat &q) +{ + return q.cos(); +} + +template +inline Quat Quat::cos() const +{ + Vec v{x, y ,z}; + T vNorm = std::sqrt(v.dot(v)); + T k = vNorm < CV_QUAT_EPS ? 1 : std::sin(w) * std::sinh(vNorm) / vNorm; + return Quat(std::cos(w) * std::cosh(vNorm), -v[0] * k, -v[1] * k, -v[2] * k); +} + +template +inline Quat tan(const Quat &q) +{ + return q.tan(); +} + +template +inline Quat Quat::tan() const +{ + return sin() * cos().inv(); +} + +template +inline Quat asinh(const Quat &q) +{ + return q.asinh(); +} + +template +inline Quat Quat::asinh() const +{ + return cv::log(*this + cv::power(*this * *this + Quat(1, 0, 0, 0), 0.5)); +} + +template +inline Quat acosh(const Quat &q) +{ + return q.acosh(); +} + +template +inline Quat Quat::acosh() const +{ + return cv::log(*this + cv::power(*this * *this - Quat(1,0,0,0), 0.5)); +} + +template +inline Quat atanh(const Quat &q) +{ + return q.atanh(); +} + +template +inline Quat Quat::atanh() const +{ + Quat ident(1, 0, 0, 0); + Quat c1 = (ident + *this).log(); + Quat c2 = (ident - *this).log(); + return 0.5 * (c1 - c2); +} + +template +inline Quat asin(const Quat &q) +{ + return q.asin(); +} + +template +inline Quat Quat::asin() const +{ + Quat v(0, x, y, z); + T vNorm = v.norm(); + T k = vNorm < CV_QUAT_EPS ? 1 : vNorm; + return -v / k * (*this * v / k).asinh(); +} + +template +inline Quat acos(const Quat &q) +{ + return q.acos(); +} + +template +inline Quat Quat::acos() const +{ + Quat v(0, x, y, z); + T vNorm = v.norm(); + T k = vNorm < CV_QUAT_EPS ? 1 : vNorm; + return -v / k * acosh(); +} + +template +inline Quat atan(const Quat &q) +{ + return q.atan(); +} + +template +inline Quat Quat::atan() const +{ + Quat v(0, x, y, z); + T vNorm = v.norm(); + T k = vNorm < CV_QUAT_EPS ? 1 : vNorm; + return -v / k * (*this * v / k).atanh(); +} + +template +inline T Quat::getAngle(QuatAssumeType assumeUnit) const +{ + if (assumeUnit) + { + return 2 * std::acos(w); + } + if (norm() < CV_QUAT_EPS) + { + CV_Error(Error::StsBadArg, "This quaternion does not represent a rotation"); + } + return 2 * std::acos(w / norm()); +} + +template +inline Vec Quat::getAxis(QuatAssumeType assumeUnit) const +{ + T angle = getAngle(assumeUnit); + const T sin_v = std::sin(angle * 0.5); + if (assumeUnit) + { + return Vec{x, y, z} / sin_v; + } + return Vec {x, y, z} / (norm() * sin_v); +} + +template +Matx Quat::toRotMat4x4(QuatAssumeType assumeUnit) const +{ + T a = w, b = x, c = y, d = z; + if (!assumeUnit) + { + Quat qTemp = normalize(); + a = qTemp.w; + b = qTemp.x; + c = qTemp.y; + d = qTemp.z; + } + Matx R{ + 1 - 2 * (c * c + d * d), 2 * (b * c - a * d) , 2 * (b * d + a * c) , 0, + 2 * (b * c + a * d) , 1 - 2 * (b * b + d * d), 2 * (c * d - a * b) , 0, + 2 * (b * d - a * c) , 2 * (c * d + a * b) , 1 - 2 * (b * b + c * c), 0, + 0 , 0 , 0 , 1, + }; + return R; +} + +template +Matx Quat::toRotMat3x3(QuatAssumeType assumeUnit) const +{ + T a = w, b = x, c = y, d = z; + if (!assumeUnit) + { + Quat qTemp = normalize(); + a = qTemp.w; + b = qTemp.x; + c = qTemp.y; + d = qTemp.z; + } + Matx R{ + 1 - 2 * (c * c + d * d), 2 * (b * c - a * d) , 2 * (b * d + a * c), + 2 * (b * c + a * d) , 1 - 2 * (b * b + d * d), 2 * (c * d - a * b), + 2 * (b * d - a * c) , 2 * (c * d + a * b) , 1 - 2 * (b * b + c * c) + }; + return R; +} + +template +Vec Quat::toRotVec(QuatAssumeType assumeUnit) const +{ + T angle = getAngle(assumeUnit); + Vec axis = getAxis(assumeUnit); + return angle * axis; +} + +template +Vec Quat::toVec() const +{ + return Vec{w, x, y, z}; +} + +template +Quat Quat::lerp(const Quat &q0, const Quat &q1, const T t) +{ + return (1 - t) * q0 + t * q1; +} + +template +Quat Quat::slerp(const Quat &q0, const Quat &q1, const T t, QuatAssumeType assumeUnit, bool directChange) +{ + Quatd v0(q0); + Quatd v1(q1); + if (!assumeUnit) + { + v0 = v0.normalize(); + v1 = v1.normalize(); + } + T cosTheta = v0.dot(v1); + constexpr T DOT_THRESHOLD = 0.995; + if (cosTheta > DOT_THRESHOLD) + { + return nlerp(v0, v1, t, QUAT_ASSUME_UNIT); + } + + if (directChange && cosTheta < 0) + { + v0 = -v0; + cosTheta = -cosTheta; + } + T sinTheta = std::sqrt(1 - cosTheta * cosTheta); + T angle = atan2(sinTheta, cosTheta); + return (std::sin((1 - t) * angle) / (sinTheta) * v0 + std::sin(t * angle) / (sinTheta) * v1).normalize(); +} + + +template +inline Quat Quat::nlerp(const Quat &q0, const Quat &q1, const T t, QuatAssumeType assumeUnit) +{ + Quat v0(q0), v1(q1); + if (v1.dot(v0) < 0) + { + v0 = -v0; + } + if (assumeUnit) + { + return ((1 - t) * v0 + t * v1).normalize(); + } + v0 = v0.normalize(); + v1 = v1.normalize(); + return ((1 - t) * v0 + t * v1).normalize(); +} + + +template +inline bool Quat::isNormal(T eps) const +{ + + double normVar = norm(); + if ((normVar > 1 - eps) && (normVar < 1 + eps)) + return true; + return false; +} + +template +inline void Quat::assertNormal(T eps) const +{ + if (!isNormal(eps)) + CV_Error(Error::StsBadArg, "Quaternion should be normalized"); +} + + +template +inline Quat Quat::squad(const Quat &q0, const Quat &q1, + const Quat &q2, const Quat &q3, + const T t, QuatAssumeType assumeUnit, + bool directChange) +{ + Quat v0(q0), v1(q1), v2(q2), v3(q3); + if (!assumeUnit) + { + v0 = v0.normalize(); + v1 = v1.normalize(); + v2 = v2.normalize(); + v3 = v3.normalize(); + } + + Quat c0 = slerp(v0, v3, t, assumeUnit, directChange); + Quat c1 = slerp(v1, v2, t, assumeUnit, directChange); + return slerp(c0, c1, 2 * t * (1 - t), assumeUnit, directChange); +} + +template +Quat Quat::interPoint(const Quat &q0, const Quat &q1, + const Quat &q2, QuatAssumeType assumeUnit) +{ + Quat v0(q0), v1(q1), v2(q2); + if (!assumeUnit) + { + v0 = v0.normalize(); + v1 = v1.normalize(); + v2 = v2.normalize(); + } + return v1 * cv::exp(-(cv::log(v1.conjugate() * v0, assumeUnit) + (cv::log(v1.conjugate() * v2, assumeUnit))) / 4); +} + +template +Quat Quat::spline(const Quat &q0, const Quat &q1, const Quat &q2, const Quat &q3, const T t, QuatAssumeType assumeUnit) +{ + Quatd v0(q0), v1(q1), v2(q2), v3(q3); + if (!assumeUnit) + { + v0 = v0.normalize(); + v1 = v1.normalize(); + v2 = v2.normalize(); + v3 = v3.normalize(); + } + T cosTheta; + std::vector> vec{v0, v1, v2, v3}; + for (size_t i = 0; i < 3; ++i) + { + cosTheta = vec[i].dot(vec[i + 1]); + if (cosTheta < 0) + { + vec[i + 1] = -vec[i + 1]; + } + } + Quat s1 = interPoint(vec[0], vec[1], vec[2], QUAT_ASSUME_UNIT); + Quat s2 = interPoint(vec[1], vec[2], vec[3], QUAT_ASSUME_UNIT); + return squad(vec[1], s1, s2, vec[2], t, assumeUnit, QUAT_ASSUME_NOT_UNIT); +} + +namespace detail { + +template static +Quat createFromAxisRot(int axis, const T theta) +{ + if (axis == 0) + return Quat::createFromXRot(theta); + if (axis == 1) + return Quat::createFromYRot(theta); + if (axis == 2) + return Quat::createFromZRot(theta); + CV_Assert(0); +} + +inline bool isIntAngleType(QuatEnum::EulerAnglesType eulerAnglesType) +{ + return eulerAnglesType < QuatEnum::EXT_XYZ; +} + +inline bool isTaitBryan(QuatEnum::EulerAnglesType eulerAnglesType) +{ + return eulerAnglesType/6 == 1 || eulerAnglesType/6 == 3; +} +} // namespace detail + +template +Quat Quat::createFromYRot(const T theta) +{ + return Quat{std::cos(theta * 0.5f), 0, std::sin(theta * 0.5f), 0}; +} + +template +Quat Quat::createFromXRot(const T theta){ + return Quat{std::cos(theta * 0.5f), std::sin(theta * 0.5f), 0, 0}; +} + +template +Quat Quat::createFromZRot(const T theta){ + return Quat{std::cos(theta * 0.5f), 0, 0, std::sin(theta * 0.5f)}; +} + + +template +Quat Quat::createFromEulerAngles(const Vec &angles, QuatEnum::EulerAnglesType eulerAnglesType) { + CV_Assert(eulerAnglesType < QuatEnum::EulerAnglesType::EULER_ANGLES_MAX_VALUE); + static const int rotationAxis[24][3] = { + {0, 1, 2}, ///< Intrinsic rotations with the Euler angles type X-Y-Z + {0, 2, 1}, ///< Intrinsic rotations with the Euler angles type X-Z-Y + {1, 0, 2}, ///< Intrinsic rotations with the Euler angles type Y-X-Z + {1, 2, 0}, ///< Intrinsic rotations with the Euler angles type Y-Z-X + {2, 0, 1}, ///< Intrinsic rotations with the Euler angles type Z-X-Y + {2, 1, 0}, ///< Intrinsic rotations with the Euler angles type Z-Y-X + {0, 1, 0}, ///< Intrinsic rotations with the Euler angles type X-Y-X + {0, 2, 0}, ///< Intrinsic rotations with the Euler angles type X-Z-X + {1, 0, 1}, ///< Intrinsic rotations with the Euler angles type Y-X-Y + {1, 2, 1}, ///< Intrinsic rotations with the Euler angles type Y-Z-Y + {2, 0, 2}, ///< Intrinsic rotations with the Euler angles type Z-X-Z + {2, 1, 2}, ///< Intrinsic rotations with the Euler angles type Z-Y-Z + {0, 1, 2}, ///< Extrinsic rotations with the Euler angles type X-Y-Z + {0, 2, 1}, ///< Extrinsic rotations with the Euler angles type X-Z-Y + {1, 0, 2}, ///< Extrinsic rotations with the Euler angles type Y-X-Z + {1, 2, 0}, ///< Extrinsic rotations with the Euler angles type Y-Z-X + {2, 0, 1}, ///< Extrinsic rotations with the Euler angles type Z-X-Y + {2, 1, 0}, ///< Extrinsic rotations with the Euler angles type Z-Y-X + {0, 1, 0}, ///< Extrinsic rotations with the Euler angles type X-Y-X + {0, 2, 0}, ///< Extrinsic rotations with the Euler angles type X-Z-X + {1, 0, 1}, ///< Extrinsic rotations with the Euler angles type Y-X-Y + {1, 2, 1}, ///< Extrinsic rotations with the Euler angles type Y-Z-Y + {2, 0, 2}, ///< Extrinsic rotations with the Euler angles type Z-X-Z + {2, 1, 2} ///< Extrinsic rotations with the Euler angles type Z-Y-Z + }; + Quat q1 = detail::createFromAxisRot(rotationAxis[eulerAnglesType][0], angles(0)); + Quat q2 = detail::createFromAxisRot(rotationAxis[eulerAnglesType][1], angles(1)); + Quat q3 = detail::createFromAxisRot(rotationAxis[eulerAnglesType][2], angles(2)); + if (detail::isIntAngleType(eulerAnglesType)) + { + return q1 * q2 * q3; + } + else // (!detail::isIntAngleType(eulerAnglesType)) + { + return q3 * q2 * q1; + } +} + +template +Vec Quat::toEulerAngles(QuatEnum::EulerAnglesType eulerAnglesType){ + CV_Assert(eulerAnglesType < QuatEnum::EulerAnglesType::EULER_ANGLES_MAX_VALUE); + Matx33d R = toRotMat3x3(); + enum { + C_ZERO, + C_PI, + C_PI_2, + N_CONSTANTS, + R_0_0 = N_CONSTANTS, R_0_1, R_0_2, + R_1_0, R_1_1, R_1_2, + R_2_0, R_2_1, R_2_2 + }; + static const T constants_[N_CONSTANTS] = { + 0, // C_ZERO + (T)CV_PI, // C_PI + (T)(CV_PI * 0.5) // C_PI_2, -C_PI_2 + }; + static const int rotationR_[24][12] = { + {+R_0_2, +R_1_0, +R_1_1, C_PI_2, +R_2_1, +R_1_1, -C_PI_2, -R_1_2, +R_2_2, +R_0_2, -R_0_1, +R_0_0}, // INT_XYZ + {+R_0_1, -R_1_2, +R_2_2, -C_PI_2, +R_2_0, +R_2_2, C_PI_2, +R_2_1, +R_1_1, -R_0_1, +R_0_2, +R_0_0}, // INT_XZY + {+R_1_2, -R_0_1, +R_0_0, -C_PI_2, +R_0_1, +R_0_0, C_PI_2, +R_0_2, +R_2_2, -R_1_2, +R_1_0, +R_1_1}, // INT_YXZ + {+R_1_0, +R_0_2, +R_2_2, C_PI_2, +R_0_2, +R_0_1, -C_PI_2, -R_2_0, +R_0_0, +R_1_0, -R_1_2, +R_1_1}, // INT_YZX + {+R_2_1, +R_1_0, +R_0_0, C_PI_2, +R_1_0, +R_0_0, -C_PI_2, -R_0_1, +R_1_1, +R_2_1, -R_2_0, +R_2_2}, // INT_ZXY + {+R_2_0, -R_0_1, +R_1_1, -C_PI_2, +R_1_2, +R_1_1, C_PI_2, +R_1_0, +R_0_0, -R_2_0, +R_2_1, +R_2_2}, // INT_ZYX + {+R_0_0, +R_2_1, +R_2_2, C_ZERO, +R_1_2, +R_1_1, C_PI, +R_1_0, -R_2_0, +R_0_0, +R_0_1, +R_0_2}, // INT_XYX + {+R_0_0, +R_2_1, +R_2_2, C_ZERO, -R_2_1, +R_2_2, C_PI, +R_2_0, +R_1_0, +R_0_0, +R_0_2, -R_0_1}, // INT_XZX + {+R_1_1, +R_0_2, +R_0_0, C_ZERO, -R_2_0, +R_0_0, C_PI, +R_0_1, +R_2_1, +R_1_1, +R_1_0, -R_1_2}, // INT_YXY + {+R_1_1, +R_0_2, +R_0_0, C_ZERO, +R_0_2, -R_0_0, C_PI, +R_2_1, -R_0_1, +R_1_1, +R_1_2, +R_1_0}, // INT_YZY + {+R_2_2, +R_1_0, +R_1_1, C_ZERO, +R_1_0, +R_0_0, C_PI, +R_0_2, -R_1_2, +R_2_2, +R_2_0, +R_2_1}, // INT_ZXZ + {+R_2_2, +R_1_0, +R_0_0, C_ZERO, +R_1_0, +R_0_0, C_PI, +R_1_2, +R_0_2, +R_2_2, +R_2_1, -R_2_0}, // INT_ZYZ + + {+R_2_0, -C_PI_2, -R_0_1, +R_1_1, C_PI_2, +R_1_2, +R_1_1, +R_2_1, +R_2_2, -R_2_0, +R_1_0, +R_0_0}, // EXT_XYZ + {+R_1_0, C_PI_2, +R_0_2, +R_2_2, -C_PI_2, +R_0_2, +R_0_1, -R_1_2, +R_1_1, +R_1_0, -R_2_0, +R_0_0}, // EXT_XZY + {+R_2_1, C_PI_2, +R_1_0, +R_0_0, -C_PI_2, +R_1_0, +R_0_0, -R_2_0, +R_2_2, +R_2_1, -R_0_1, +R_1_1}, // EXT_YXZ + {+R_0_2, -C_PI_2, -R_1_2, +R_2_2, C_PI_2, +R_2_0, +R_2_2, +R_0_2, +R_0_0, -R_0_1, +R_2_1, +R_1_1}, // EXT_YZX + {+R_1_2, -C_PI_2, -R_0_1, +R_0_0, C_PI_2, +R_0_1, +R_0_0, +R_1_0, +R_1_1, -R_1_2, +R_0_2, +R_2_2}, // EXT_ZXY + {+R_0_2, C_PI_2, +R_1_0, +R_1_1, -C_PI_2, +R_2_1, +R_1_1, -R_0_1, +R_0_0, +R_0_2, -R_1_2, +R_2_2}, // EXT_ZYX + {+R_0_0, C_ZERO, +R_2_1, +R_2_2, C_PI, +R_1_2, +R_1_1, +R_0_1, +R_0_2, +R_0_0, +R_1_0, -R_2_0}, // EXT_XYX + {+R_0_0, C_ZERO, +R_2_1, +R_2_2, C_PI, +R_2_1, +R_2_2, +R_0_2, -R_0_1, +R_0_0, +R_2_0, +R_1_0}, // EXT_XZX + {+R_1_1, C_ZERO, +R_0_2, +R_0_0, C_PI, -R_2_0, +R_0_0, +R_1_0, -R_1_2, +R_1_1, +R_0_1, +R_2_1}, // EXT_YXY + {+R_1_1, C_ZERO, +R_0_2, +R_0_0, C_PI, +R_0_2, -R_0_0, +R_1_2, +R_1_0, +R_1_1, +R_2_1, -R_0_1}, // EXT_YZY + {+R_2_2, C_ZERO, +R_1_0, +R_1_1, C_PI, +R_1_0, +R_0_0, +R_2_0, +R_2_1, +R_2_2, +R_0_2, -R_1_2}, // EXT_ZXZ + {+R_2_2, C_ZERO, +R_1_0, +R_0_0, C_PI, +R_1_0, +R_0_0, +R_2_1, -R_2_0, +R_2_2, +R_1_2, +R_0_2}, // EXT_ZYZ + }; + T rotationR[12]; + for (int i = 0; i < 12; i++) + { + int id = rotationR_[eulerAnglesType][i]; + unsigned idx = std::abs(id); + T value = 0.0f; + if (idx < N_CONSTANTS) + { + value = constants_[idx]; + } + else + { + unsigned r_idx = idx - N_CONSTANTS; + CV_DbgAssert(r_idx < 9); + value = R.val[r_idx]; + } + bool isNegative = id < 0; + if (isNegative) + value = -value; + rotationR[i] = value; + } + Vec angles; + if (detail::isIntAngleType(eulerAnglesType)) + { + if (abs(rotationR[0] - 1) < CV_QUAT_CONVERT_THRESHOLD) + { + CV_LOG_WARNING(NULL,"Gimbal Lock occurs. Euler angles are non-unique, we set the third angle to 0"); + angles = {std::atan2(rotationR[1], rotationR[2]), rotationR[3], 0}; + return angles; + } + else if(abs(rotationR[0] + 1) < CV_QUAT_CONVERT_THRESHOLD) + { + CV_LOG_WARNING(NULL,"Gimbal Lock occurs. Euler angles are non-unique, we set the third angle to 0"); + angles = {std::atan2(rotationR[4], rotationR[5]), rotationR[6], 0}; + return angles; + } + } + else // (!detail::isIntAngleType(eulerAnglesType)) + { + if (abs(rotationR[0] - 1) < CV_QUAT_CONVERT_THRESHOLD) + { + CV_LOG_WARNING(NULL,"Gimbal Lock occurs. Euler angles are non-unique, we set the first angle to 0"); + angles = {0, rotationR[1], std::atan2(rotationR[2], rotationR[3])}; + return angles; + } + else if (abs(rotationR[0] + 1) < CV_QUAT_CONVERT_THRESHOLD) + { + CV_LOG_WARNING(NULL,"Gimbal Lock occurs. Euler angles are non-unique, we set the first angle to 0"); + angles = {0, rotationR[4], std::atan2(rotationR[5], rotationR[6])}; + return angles; + } + } + + angles(0) = std::atan2(rotationR[7], rotationR[8]); + if (detail::isTaitBryan(eulerAnglesType)) + angles(1) = std::acos(rotationR[9]); + else + angles(1) = std::asin(rotationR[9]); + angles(2) = std::atan2(rotationR[10], rotationR[11]); + return angles; +} + +} // namepsace +//! @endcond + +#endif /*OPENCV_CORE_QUATERNION_INL_HPP*/ diff --git a/3rdparty/include/opencv2/core/saturate.hpp b/3rdparty/include/opencv2/core/saturate.hpp index 36d312154f..8127e3d9ef 100644 --- a/3rdparty/include/opencv2/core/saturate.hpp +++ b/3rdparty/include/opencv2/core/saturate.hpp @@ -156,6 +156,22 @@ template<> inline uint64 saturate_cast(int64 v) { return (uint64)st template<> inline int64 saturate_cast(uint64 v) { return (int64)std::min(v, (uint64)LLONG_MAX); } +/** @overload */ +template static inline _Tp saturate_cast(float16_t v) { return saturate_cast<_Tp>((float)v); } + +// in theory, we could use a LUT for 8u/8s->16f conversion, +// but with hardware support for FP32->FP16 conversion the current approach is preferable +template<> inline float16_t saturate_cast(uchar v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(schar v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(ushort v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(short v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(unsigned v){ return float16_t((float)v); } +template<> inline float16_t saturate_cast(int v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(uint64 v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(int64 v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(float v) { return float16_t(v); } +template<> inline float16_t saturate_cast(double v) { return float16_t((float)v); } + //! @} } // cv diff --git a/3rdparty/include/opencv2/core/simd_intrinsics.hpp b/3rdparty/include/opencv2/core/simd_intrinsics.hpp index 7151d36073..8fe7ee6b60 100644 --- a/3rdparty/include/opencv2/core/simd_intrinsics.hpp +++ b/3rdparty/include/opencv2/core/simd_intrinsics.hpp @@ -7,7 +7,7 @@ /** Helper header to support SIMD intrinsics (universal intrinsics) in user code. -Intrinsics documentation: https://docs.opencv.org/3.4/df/d91/group__core__hal__intrin.html +Intrinsics documentation: https://docs.opencv.org/master/df/d91/group__core__hal__intrin.html Checks of target CPU instruction set based on compiler definitions don't work well enough. @@ -40,7 +40,6 @@ Notes: #endif #include "opencv2/core/cvdef.h" -#include "opencv2/core/version.hpp" #ifdef OPENCV_SIMD_CONFIG_HEADER #include CVAUX_STR(OPENCV_SIMD_CONFIG_HEADER) diff --git a/3rdparty/include/opencv2/core/traits.hpp b/3rdparty/include/opencv2/core/traits.hpp index 6cb10f44cf..52ab083ca4 100644 --- a/3rdparty/include/opencv2/core/traits.hpp +++ b/3rdparty/include/opencv2/core/traits.hpp @@ -261,6 +261,20 @@ public: }; }; +template<> class DataType +{ +public: + typedef float16_t value_type; + typedef float work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_16F, + channels = 1, + fmt = (int)'h', + type = CV_MAKETYPE(depth, channels) + }; +}; /** @brief A helper class for cv::DataType @@ -330,6 +344,12 @@ template<> class TypeDepth typedef double value_type; }; +template<> class TypeDepth +{ + enum { depth = CV_16F }; + typedef float16_t value_type; +}; + #endif //! @} diff --git a/3rdparty/include/opencv2/core/types.hpp b/3rdparty/include/opencv2/core/types.hpp index 4d04bef90a..3f0131da8c 100644 --- a/3rdparty/include/opencv2/core/types.hpp +++ b/3rdparty/include/opencv2/core/types.hpp @@ -163,10 +163,12 @@ public: Point_(); Point_(_Tp _x, _Tp _y); Point_(const Point_& pt); + Point_(Point_&& pt) CV_NOEXCEPT; Point_(const Size_<_Tp>& sz); Point_(const Vec<_Tp, 2>& v); Point_& operator = (const Point_& pt); + Point_& operator = (Point_&& pt) CV_NOEXCEPT; //! conversion to another data type template operator Point_<_Tp2>() const; @@ -243,18 +245,16 @@ public: Point3_(); Point3_(_Tp _x, _Tp _y, _Tp _z); Point3_(const Point3_& pt); + Point3_(Point3_&& pt) CV_NOEXCEPT; explicit Point3_(const Point_<_Tp>& pt); Point3_(const Vec<_Tp, 3>& v); Point3_& operator = (const Point3_& pt); + Point3_& operator = (Point3_&& pt) CV_NOEXCEPT; //! conversion to another data type template operator Point3_<_Tp2>() const; //! conversion to cv::Vec<> -#if OPENCV_ABI_COMPATIBILITY > 300 - template operator Vec<_Tp2, 3>() const; -#else operator Vec<_Tp, 3>() const; -#endif //! dot product _Tp dot(const Point3_& pt) const; @@ -321,11 +321,15 @@ public: Size_(); Size_(_Tp _width, _Tp _height); Size_(const Size_& sz); + Size_(Size_&& sz) CV_NOEXCEPT; Size_(const Point_<_Tp>& pt); Size_& operator = (const Size_& sz); + Size_& operator = (Size_&& sz) CV_NOEXCEPT; //! the area (width*height) _Tp area() const; + //! aspect ratio (width/height) + double aspectRatio() const; //! true if empty bool empty() const; @@ -422,10 +426,12 @@ public: Rect_(); Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height); Rect_(const Rect_& r); + Rect_(Rect_&& r) CV_NOEXCEPT; Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz); Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2); Rect_& operator = ( const Rect_& r ); + Rect_& operator = ( Rect_&& r ) CV_NOEXCEPT; //! the top-left corner Point_<_Tp> tl() const; //! the bottom-right corner @@ -635,6 +641,12 @@ public: Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0); Scalar_(_Tp v0); + Scalar_(const Scalar_& s); + Scalar_(Scalar_&& s) CV_NOEXCEPT; + + Scalar_& operator=(const Scalar_& s); + Scalar_& operator=(Scalar_&& s) CV_NOEXCEPT; + template Scalar_(const Vec<_Tp2, cn>& v); @@ -702,24 +714,24 @@ public: //! the default constructor CV_WRAP KeyPoint(); /** - @param _pt x & y coordinates of the keypoint - @param _size keypoint diameter - @param _angle keypoint orientation - @param _response keypoint detector response on the keypoint (that is, strength of the keypoint) - @param _octave pyramid octave in which the keypoint has been detected - @param _class_id object id + @param pt x & y coordinates of the keypoint + @param size keypoint diameter + @param angle keypoint orientation + @param response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param octave pyramid octave in which the keypoint has been detected + @param class_id object id */ - KeyPoint(Point2f _pt, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1); + KeyPoint(Point2f pt, float size, float angle=-1, float response=0, int octave=0, int class_id=-1); /** @param x x-coordinate of the keypoint @param y y-coordinate of the keypoint - @param _size keypoint diameter - @param _angle keypoint orientation - @param _response keypoint detector response on the keypoint (that is, strength of the keypoint) - @param _octave pyramid octave in which the keypoint has been detected - @param _class_id object id + @param size keypoint diameter + @param angle keypoint orientation + @param response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param octave pyramid octave in which the keypoint has been detected + @param class_id object id */ - CV_WRAP KeyPoint(float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1); + CV_WRAP KeyPoint(float x, float y, float size, float angle=-1, float response=0, int octave=0, int class_id=-1); size_t hash() const; @@ -1156,6 +1168,10 @@ template inline Point_<_Tp>::Point_(const Point_& pt) : x(pt.x), y(pt.y) {} +template inline +Point_<_Tp>::Point_(Point_&& pt) CV_NOEXCEPT + : x(std::move(pt.x)), y(std::move(pt.y)) {} + template inline Point_<_Tp>::Point_(const Size_<_Tp>& sz) : x(sz.width), y(sz.height) {} @@ -1171,6 +1187,13 @@ Point_<_Tp>& Point_<_Tp>::operator = (const Point_& pt) return *this; } +template inline +Point_<_Tp>& Point_<_Tp>::operator = (Point_&& pt) CV_NOEXCEPT +{ + x = std::move(pt.x); y = std::move(pt.y); + return *this; +} + template template inline Point_<_Tp>::operator Point_<_Tp2>() const { @@ -1412,6 +1435,10 @@ template inline Point3_<_Tp>::Point3_(const Point3_& pt) : x(pt.x), y(pt.y), z(pt.z) {} +template inline +Point3_<_Tp>::Point3_(Point3_&& pt) CV_NOEXCEPT + : x(std::move(pt.x)), y(std::move(pt.y)), z(std::move(pt.z)) {} + template inline Point3_<_Tp>::Point3_(const Point_<_Tp>& pt) : x(pt.x), y(pt.y), z(_Tp()) {} @@ -1426,19 +1453,11 @@ Point3_<_Tp>::operator Point3_<_Tp2>() const return Point3_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(z)); } -#if OPENCV_ABI_COMPATIBILITY > 300 -template template inline -Point3_<_Tp>::operator Vec<_Tp2, 3>() const -{ - return Vec<_Tp2, 3>(x, y, z); -} -#else template inline Point3_<_Tp>::operator Vec<_Tp, 3>() const { return Vec<_Tp, 3>(x, y, z); } -#endif template inline Point3_<_Tp>& Point3_<_Tp>::operator = (const Point3_& pt) @@ -1447,6 +1466,13 @@ Point3_<_Tp>& Point3_<_Tp>::operator = (const Point3_& pt) return *this; } +template inline +Point3_<_Tp>& Point3_<_Tp>::operator = (Point3_&& pt) CV_NOEXCEPT +{ + x = std::move(pt.x); y = std::move(pt.y); z = std::move(pt.z); + return *this; +} + template inline _Tp Point3_<_Tp>::dot(const Point3_& pt) const { @@ -1663,6 +1689,10 @@ template inline Size_<_Tp>::Size_(const Size_& sz) : width(sz.width), height(sz.height) {} +template inline +Size_<_Tp>::Size_(Size_&& sz) CV_NOEXCEPT + : width(std::move(sz.width)), height(std::move(sz.height)) {} + template inline Size_<_Tp>::Size_(const Point_<_Tp>& pt) : width(pt.x), height(pt.y) {} @@ -1680,6 +1710,13 @@ Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz) return *this; } +template inline +Size_<_Tp>& Size_<_Tp>::operator = (Size_<_Tp>&& sz) CV_NOEXCEPT +{ + width = std::move(sz.width); height = std::move(sz.height); + return *this; +} + template inline _Tp Size_<_Tp>::area() const { @@ -1689,6 +1726,12 @@ _Tp Size_<_Tp>::area() const return result; } +template inline +double Size_<_Tp>::aspectRatio() const +{ + return width / static_cast(height); +} + template inline bool Size_<_Tp>::empty() const { @@ -1788,6 +1831,10 @@ template inline Rect_<_Tp>::Rect_(const Rect_<_Tp>& r) : x(r.x), y(r.y), width(r.width), height(r.height) {} +template inline +Rect_<_Tp>::Rect_(Rect_<_Tp>&& r) CV_NOEXCEPT + : x(std::move(r.x)), y(std::move(r.y)), width(std::move(r.width)), height(std::move(r.height)) {} + template inline Rect_<_Tp>::Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz) : x(org.x), y(org.y), width(sz.width), height(sz.height) {} @@ -1811,6 +1858,16 @@ Rect_<_Tp>& Rect_<_Tp>::operator = ( const Rect_<_Tp>& r ) return *this; } +template inline +Rect_<_Tp>& Rect_<_Tp>::operator = ( Rect_<_Tp>&& r ) CV_NOEXCEPT +{ + x = std::move(r.x); + y = std::move(r.y); + width = std::move(r.width); + height = std::move(r.height); + return *this; +} + template inline Point_<_Tp> Rect_<_Tp>::tl() const { @@ -2007,8 +2064,6 @@ inline RotatedRect::RotatedRect(const Point2f& _center, const Size2f& _size, float _angle) : center(_center), size(_size), angle(_angle) {} - - ///////////////////////////////// Range ///////////////////////////////// inline @@ -2108,6 +2163,36 @@ Scalar_<_Tp>::Scalar_(_Tp v0, _Tp v1, _Tp v2, _Tp v3) this->val[3] = v3; } +template inline +Scalar_<_Tp>::Scalar_(const Scalar_<_Tp>& s) : Vec<_Tp, 4>(s) { +} + +template inline +Scalar_<_Tp>::Scalar_(Scalar_<_Tp>&& s) CV_NOEXCEPT { + this->val[0] = std::move(s.val[0]); + this->val[1] = std::move(s.val[1]); + this->val[2] = std::move(s.val[2]); + this->val[3] = std::move(s.val[3]); +} + +template inline +Scalar_<_Tp>& Scalar_<_Tp>::operator=(const Scalar_<_Tp>& s) { + this->val[0] = s.val[0]; + this->val[1] = s.val[1]; + this->val[2] = s.val[2]; + this->val[3] = s.val[3]; + return *this; +} + +template inline +Scalar_<_Tp>& Scalar_<_Tp>::operator=(Scalar_<_Tp>&& s) CV_NOEXCEPT { + this->val[0] = std::move(s.val[0]); + this->val[1] = std::move(s.val[1]); + this->val[2] = std::move(s.val[2]); + this->val[3] = std::move(s.val[3]); + return *this; +} + template template inline Scalar_<_Tp>::Scalar_(const Vec<_Tp2, cn>& v) { diff --git a/3rdparty/include/opencv2/core/types_c.h b/3rdparty/include/opencv2/core/types_c.h index eddbe7d664..32f3c8c999 100644 --- a/3rdparty/include/opencv2/core/types_c.h +++ b/3rdparty/include/opencv2/core/types_c.h @@ -358,7 +358,11 @@ _IplImage needed for correct deallocation */ #if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) - _IplImage() {} + _IplImage() + { + memset(this, 0, sizeof(*this)); // valid for POD structure + nSize = sizeof(IplImage); + } _IplImage(const cv::Mat& m) { *this = cvIplImage(m); } #endif } @@ -1707,7 +1711,7 @@ typedef CvContour CvPoint2DSeq; #define CV_SEQ_ELTYPE_POINT CV_32SC2 /**< (x,y) */ #define CV_SEQ_ELTYPE_CODE CV_8UC1 /**< freeman code: 0..7 */ #define CV_SEQ_ELTYPE_GENERIC 0 -#define CV_SEQ_ELTYPE_PTR CV_USRTYPE1 +#define CV_SEQ_ELTYPE_PTR CV_MAKE_TYPE(CV_8U, 8 /*sizeof(void*)*/) #define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR /**< &(x,y) */ #define CV_SEQ_ELTYPE_INDEX CV_32SC1 /**< #(x,y) */ #define CV_SEQ_ELTYPE_GRAPH_EDGE 0 /**< &next_o, &next_d, &vtx_o, &vtx_d */ @@ -1959,6 +1963,8 @@ CvSeqReader; * Data structures for persistence (a.k.a serialization) functionality * \****************************************************************************************/ +#if 0 + /** "black box" file storage */ typedef struct CvFileStorage CvFileStorage; @@ -2111,28 +2117,7 @@ typedef struct CvTypeInfo CvCloneFunc clone; /**< creates a copy of the object */ } CvTypeInfo; - - -/**** System data types ******/ - -typedef struct CvPluginFuncInfo -{ - void** func_addr; - void* default_func_addr; - const char* func_names; - int search_modules; - int loaded_from; -} -CvPluginFuncInfo; - -typedef struct CvModuleInfo -{ - struct CvModuleInfo* next; - const char* name; - const char* version; - CvPluginFuncInfo* func_tab; -} -CvModuleInfo; +#endif /** @} */ diff --git a/3rdparty/include/opencv2/core/utility.hpp b/3rdparty/include/opencv2/core/utility.hpp index b97458d2d3..f0368027aa 100644 --- a/3rdparty/include/opencv2/core/utility.hpp +++ b/3rdparty/include/opencv2/core/utility.hpp @@ -56,8 +56,10 @@ #include "opencv2/core.hpp" #include -#ifdef CV_CXX11 #include + +#if !defined(_M_CEE) +#include // std::mutex, std::lock_guard #endif namespace cv @@ -568,6 +570,8 @@ static inline size_t getElemSize(int type) { return (size_t)CV_ELEM_SIZE(type); /////////////////////////////// Parallel Primitives ////////////////////////////////// /** @brief Base class for parallel data processors + +@ingroup core_parallel */ class CV_EXPORTS ParallelLoopBody { @@ -577,18 +581,23 @@ public: }; /** @brief Parallel data processor + +@ingroup core_parallel */ CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.); -#ifdef CV_CXX11 +//! @ingroup core_parallel class ParallelLoopBodyLambdaWrapper : public ParallelLoopBody { private: std::function m_functor; public: - ParallelLoopBodyLambdaWrapper(std::function functor) : - m_functor(functor) - { } + inline + ParallelLoopBodyLambdaWrapper(std::function functor) + : m_functor(functor) + { + // nothing + } virtual void operator() (const cv::Range& range) const CV_OVERRIDE { @@ -596,11 +605,13 @@ public: } }; -inline void parallel_for_(const Range& range, std::function functor, double nstripes=-1.) +//! @ingroup core_parallel +static inline +void parallel_for_(const Range& range, std::function functor, double nstripes=-1.) { parallel_for_(range, ParallelLoopBodyLambdaWrapper(functor), nstripes); } -#endif + /////////////////////////////// forEach method of cv::Mat //////////////////////////// template inline @@ -702,34 +713,10 @@ void Mat::forEach_impl(const Functor& operation) { /////////////////////////// Synchronization Primitives /////////////////////////////// -class CV_EXPORTS Mutex -{ -public: - Mutex(); - ~Mutex(); - Mutex(const Mutex& m); - Mutex& operator = (const Mutex& m); - - void lock(); - bool trylock(); - void unlock(); - - struct Impl; -protected: - Impl* impl; -}; - -class CV_EXPORTS AutoLock -{ -public: - AutoLock(Mutex& m) : mutex(&m) { mutex->lock(); } - ~AutoLock() { mutex->unlock(); } -protected: - Mutex* mutex; -private: - AutoLock(const AutoLock&); - AutoLock& operator = (const AutoLock&); -}; +#if !defined(_M_CEE) +typedef std::recursive_mutex Mutex; +typedef std::lock_guard AutoLock; +#endif /** @brief Designed for command line parsing @@ -949,8 +936,8 @@ public: void printErrors() const; protected: - void getByName(const String& name, bool space_delete, int type, void* dst) const; - void getByIndex(int index, bool space_delete, int type, void* dst) const; + void getByName(const String& name, bool space_delete, Param type, void* dst) const; + void getByIndex(int index, bool space_delete, Param type, void* dst) const; struct Impl; Impl* impl; @@ -1059,15 +1046,6 @@ template inline size_t AutoBuffer<_Tp, fixed_size>::size() const { return sz; } -template<> inline std::string CommandLineParser::get(int index, bool space_delete) const -{ - return get(index, space_delete); -} -template<> inline std::string CommandLineParser::get(const String& name, bool space_delete) const -{ - return get(name, space_delete); -} - //! @endcond @@ -1230,8 +1208,4 @@ CV_EXPORTS int getThreadID(); #define CV_IMPL_ADD(impl) #endif -#ifndef DISABLE_OPENCV_24_COMPATIBILITY -#include "opencv2/core/core_c.h" -#endif - #endif //OPENCV_CORE_UTILITY_H diff --git a/3rdparty/include/opencv2/core/utils/filesystem.hpp b/3rdparty/include/opencv2/core/utils/filesystem.hpp index 00b0dd1c12..a98d2202fc 100644 --- a/3rdparty/include/opencv2/core/utils/filesystem.hpp +++ b/3rdparty/include/opencv2/core/utils/filesystem.hpp @@ -26,6 +26,10 @@ CV_EXPORTS cv::String canonical(const cv::String& path); /** Join path components */ CV_EXPORTS cv::String join(const cv::String& base, const cv::String& path); +/** Get parent directory */ +CV_EXPORTS cv::String getParent(const cv::String &path); +CV_EXPORTS std::wstring getParent(const std::wstring& path); + /** * Generate a list of all files that match the globbing pattern. * diff --git a/3rdparty/include/opencv2/core/utils/logger.defines.hpp b/3rdparty/include/opencv2/core/utils/logger.defines.hpp index b2dfc41704..7d73f02b66 100644 --- a/3rdparty/include/opencv2/core/utils/logger.defines.hpp +++ b/3rdparty/include/opencv2/core/utils/logger.defines.hpp @@ -17,6 +17,26 @@ #define CV_LOG_LEVEL_DEBUG 5 //!< Debug message. Disabled in the "Release" build. #define CV_LOG_LEVEL_VERBOSE 6 //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. +namespace cv { +namespace utils { +namespace logging { + +//! Supported logging levels and their semantic +enum LogLevel { + LOG_LEVEL_SILENT = 0, //!< for using in setLogVevel() call + LOG_LEVEL_FATAL = 1, //!< Fatal (critical) error (unrecoverable internal error) + LOG_LEVEL_ERROR = 2, //!< Error message + LOG_LEVEL_WARNING = 3, //!< Warning message + LOG_LEVEL_INFO = 4, //!< Info message + LOG_LEVEL_DEBUG = 5, //!< Debug message. Disabled in the "Release" build. + LOG_LEVEL_VERBOSE = 6, //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. +#ifndef CV_DOXYGEN + ENUM_LOG_LEVEL_FORCE_INT = INT_MAX +#endif +}; + +}}} // namespace + //! @} #endif // OPENCV_LOGGER_DEFINES_HPP diff --git a/3rdparty/include/opencv2/core/utils/logger.hpp b/3rdparty/include/opencv2/core/utils/logger.hpp index 501d1404e7..accb860ada 100644 --- a/3rdparty/include/opencv2/core/utils/logger.hpp +++ b/3rdparty/include/opencv2/core/utils/logger.hpp @@ -10,6 +10,7 @@ #include // INT_MAX #include "logger.defines.hpp" +#include "logtag.hpp" namespace cv { namespace utils { @@ -18,20 +19,6 @@ namespace logging { //! @addtogroup core_logging //! @{ -//! Supported logging levels and their semantic -enum LogLevel { - LOG_LEVEL_SILENT = 0, //!< for using in setLogVevel() call - LOG_LEVEL_FATAL = 1, //!< Fatal (critical) error (unrecoverable internal error) - LOG_LEVEL_ERROR = 2, //!< Error message - LOG_LEVEL_WARNING = 3, //!< Warning message - LOG_LEVEL_INFO = 4, //!< Info message - LOG_LEVEL_DEBUG = 5, //!< Debug message. Disabled in the "Release" build. - LOG_LEVEL_VERBOSE = 6, //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. -#ifndef CV_DOXYGEN - ENUM_LOG_LEVEL_FORCE_INT = INT_MAX -#endif -}; - /** Set global logging level @return previous logging level */ @@ -39,15 +26,39 @@ CV_EXPORTS LogLevel setLogLevel(LogLevel logLevel); /** Get global logging level */ CV_EXPORTS LogLevel getLogLevel(); +CV_EXPORTS void registerLogTag(cv::utils::logging::LogTag* plogtag); + +CV_EXPORTS void setLogTagLevel(const char* tag, cv::utils::logging::LogLevel level); + +CV_EXPORTS cv::utils::logging::LogLevel getLogTagLevel(const char* tag); + namespace internal { + +/** Get global log tag */ +CV_EXPORTS cv::utils::logging::LogTag* getGlobalLogTag(); + /** Write log message */ CV_EXPORTS void writeLogMessage(LogLevel logLevel, const char* message); + +/** Write log message */ +CV_EXPORTS void writeLogMessageEx(LogLevel logLevel, const char* tag, const char* file, int line, const char* func, const char* message); + } // namespace +struct LogTagAuto + : public LogTag +{ + inline LogTagAuto(const char* _name, LogLevel _level) + : LogTag(_name, _level) + { + registerLogTag(this); + } +}; + /** * \def CV_LOG_STRIP_LEVEL * - * Define CV_LOG_STRIP_LEVEL=CV_LOG_LEVEL_[DEBUG|INFO|WARN|ERROR|FATAL|DISABLED] to compile out anything at that and before that logging level + * Define CV_LOG_STRIP_LEVEL=CV_LOG_LEVEL_[DEBUG|INFO|WARN|ERROR|FATAL|SILENT] to compile out anything at that and before that logging level */ #ifndef CV_LOG_STRIP_LEVEL # if defined NDEBUG @@ -57,22 +68,70 @@ CV_EXPORTS void writeLogMessage(LogLevel logLevel, const char* message); # endif #endif -#define CV_LOG_WITH_TAG(tag, msgLevel, extra_check0, extra_check1, msg_prefix, ...) \ +#define CV_LOGTAG_PTR_CAST(expr) static_cast(expr) + +// CV_LOGTAG_EXPAND_NAME is intended to be re-defined (undef and then define again) +// to allows logging users to use a shorter name argument when calling +// CV_LOG_WITH_TAG or its related macros such as CV_LOG_INFO. +// +// This macro is intended to modify the tag argument as a string (token), via +// preprocessor token pasting or metaprogramming techniques. A typical usage +// is to apply a prefix, such as +// ...... #define CV_LOGTAG_EXPAND_NAME(tag) cv_logtag_##tag +// +// It is permitted to re-define to a hard-coded expression, ignoring the tag. +// This would work identically like the CV_LOGTAG_FALLBACK macro. +// +// Important: When the logging macro is called with tag being NULL, a user-defined +// CV_LOGTAG_EXPAND_NAME may expand it into cv_logtag_0, cv_logtag_NULL, or +// cv_logtag_nullptr. Use with care. Also be mindful of C++ symbol redefinitions. +// +// If there is significant amount of logging code with tag being NULL, it is +// recommended to use (re-define) CV_LOGTAG_FALLBACK to inject locally a default +// tag at the beginning of a compilation unit, to minimize lines of code changes. +// +#define CV_LOGTAG_EXPAND_NAME(tag) tag + +// CV_LOGTAG_FALLBACK is intended to be re-defined (undef and then define again) +// by any other compilation units to provide a log tag when the logging statement +// does not specify one. The macro needs to expand into a C++ expression that can +// be static_cast into (cv::utils::logging::LogTag*). Null (nullptr) is permitted. +#define CV_LOGTAG_FALLBACK nullptr + +// CV_LOGTAG_GLOBAL is the tag used when a log tag is not specified in the logging +// statement nor the compilation unit. The macro needs to expand into a C++ +// expression that can be static_cast into (cv::utils::logging::LogTag*). Must be +// non-null. Do not re-define. +#define CV_LOGTAG_GLOBAL cv::utils::logging::internal::getGlobalLogTag() + +#define CV_LOG_WITH_TAG(tag, msgLevel, extra_check0, extra_check1, ...) \ for(;;) { \ extra_check0; \ - if (cv::utils::logging::getLogLevel() < msgLevel) break; \ + const auto cv_temp_msglevel = (cv::utils::logging::LogLevel)(msgLevel); \ + if (cv_temp_msglevel >= (CV_LOG_STRIP_LEVEL)) break; \ + auto cv_temp_logtagptr = CV_LOGTAG_PTR_CAST(CV_LOGTAG_EXPAND_NAME(tag)); \ + if (!cv_temp_logtagptr) cv_temp_logtagptr = CV_LOGTAG_PTR_CAST(CV_LOGTAG_FALLBACK); \ + if (!cv_temp_logtagptr) cv_temp_logtagptr = CV_LOGTAG_PTR_CAST(CV_LOGTAG_GLOBAL); \ + if (cv_temp_logtagptr && (cv_temp_msglevel > cv_temp_logtagptr->level)) break; \ extra_check1; \ - std::stringstream ss; ss msg_prefix << __VA_ARGS__; \ - cv::utils::logging::internal::writeLogMessage(msgLevel, ss.str().c_str()); \ + std::stringstream cv_temp_logstream; \ + cv_temp_logstream << __VA_ARGS__; \ + cv::utils::logging::internal::writeLogMessageEx( \ + cv_temp_msglevel, \ + (cv_temp_logtagptr ? cv_temp_logtagptr->name : nullptr), \ + __FILE__, \ + __LINE__, \ + CV_Func, \ + cv_temp_logstream.str().c_str()); \ break; \ } -#define CV_LOG_FATAL(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_FATAL, , , , __VA_ARGS__) -#define CV_LOG_ERROR(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, , , , __VA_ARGS__) -#define CV_LOG_WARNING(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, , , , __VA_ARGS__) -#define CV_LOG_INFO(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, , , , __VA_ARGS__) -#define CV_LOG_DEBUG(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, , , , __VA_ARGS__) -#define CV_LOG_VERBOSE(tag, v, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_VERBOSE, , , << "[VERB" << v << ":" << cv::utils::getThreadID() << "] ", __VA_ARGS__) +#define CV_LOG_FATAL(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_FATAL, , , __VA_ARGS__) +#define CV_LOG_ERROR(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, , , __VA_ARGS__) +#define CV_LOG_WARNING(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, , , __VA_ARGS__) +#define CV_LOG_INFO(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, , , __VA_ARGS__) +#define CV_LOG_DEBUG(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, , , __VA_ARGS__) +#define CV_LOG_VERBOSE(tag, v, ...) CV_LOG_WITH_TAG(tag, (cv::utils::logging::LOG_LEVEL_VERBOSE + (int)(v)), , , __VA_ARGS__) #if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO #undef CV_LOG_INFO @@ -105,11 +164,11 @@ CV_EXPORTS void writeLogMessage(LogLevel logLevel, const char* message); // CV_LOG_ONCE_XXX macros -#define CV_LOG_ONCE_ERROR(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, , __VA_ARGS__) -#define CV_LOG_ONCE_WARNING(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, , __VA_ARGS__) -#define CV_LOG_ONCE_INFO(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, , __VA_ARGS__) -#define CV_LOG_ONCE_DEBUG(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, , __VA_ARGS__) -#define CV_LOG_ONCE_VERBOSE(tag, v, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_VERBOSE, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, << "[VERB" << v << ":" << cv::utils::getThreadID() << "] ", __VA_ARGS__) +#define CV_LOG_ONCE_ERROR(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__) +#define CV_LOG_ONCE_WARNING(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__) +#define CV_LOG_ONCE_INFO(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__) +#define CV_LOG_ONCE_DEBUG(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__) +#define CV_LOG_ONCE_VERBOSE(tag, v, ...) CV_LOG_WITH_TAG(tag, (cv::utils::logging::LOG_LEVEL_VERBOSE + (int)(v)), CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__) #if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO #undef CV_LOG_ONCE_INFO @@ -129,12 +188,12 @@ CV_EXPORTS void writeLogMessage(LogLevel logLevel, const char* message); // CV_LOG_IF_XXX macros -#define CV_LOG_IF_FATAL(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_FATAL, , CV__LOG_IF_CHECK(logging_cond), , __VA_ARGS__) -#define CV_LOG_IF_ERROR(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, , CV__LOG_IF_CHECK(logging_cond), , __VA_ARGS__) -#define CV_LOG_IF_WARNING(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, , CV__LOG_IF_CHECK(logging_cond), , __VA_ARGS__) -#define CV_LOG_IF_INFO(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, , CV__LOG_IF_CHECK(logging_cond), , __VA_ARGS__) -#define CV_LOG_IF_DEBUG(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, , CV__LOG_IF_CHECK(logging_cond), , __VA_ARGS__) -#define CV_LOG_IF_VERBOSE(tag, v, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_VERBOSE, , CV__LOG_IF_CHECK(logging_cond), << "[VERB" << v << ":" << cv::utils::getThreadID() << "] ", __VA_ARGS__) +#define CV_LOG_IF_FATAL(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_FATAL, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__) +#define CV_LOG_IF_ERROR(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__) +#define CV_LOG_IF_WARNING(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__) +#define CV_LOG_IF_INFO(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__) +#define CV_LOG_IF_DEBUG(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__) +#define CV_LOG_IF_VERBOSE(tag, v, logging_cond, ...) CV_LOG_WITH_TAG(tag, (cv::utils::logging::LOG_LEVEL_VERBOSE + (int)(v)), , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__) #if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO #undef CV_LOG_IF_INFO diff --git a/3rdparty/include/opencv2/core/utils/logtag.hpp b/3rdparty/include/opencv2/core/utils/logtag.hpp new file mode 100644 index 0000000000..4089720767 --- /dev/null +++ b/3rdparty/include/opencv2/core/utils/logtag.hpp @@ -0,0 +1,28 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_LOGTAG_HPP +#define OPENCV_CORE_LOGTAG_HPP + +#include "opencv2/core/cvstd.hpp" +#include "logger.defines.hpp" + +namespace cv { +namespace utils { +namespace logging { + +struct LogTag +{ + const char* name; + LogLevel level; + + inline LogTag(const char* _name, LogLevel _level) + : name(_name) + , level(_level) + {} +}; + +}}} + +#endif diff --git a/3rdparty/include/opencv2/core/utils/tls.hpp b/3rdparty/include/opencv2/core/utils/tls.hpp index b5f1138593..124caebc85 100644 --- a/3rdparty/include/opencv2/core/utils/tls.hpp +++ b/3rdparty/include/opencv2/core/utils/tls.hpp @@ -5,7 +5,9 @@ #ifndef OPENCV_UTILS_TLS_HPP #define OPENCV_UTILS_TLS_HPP -#include +#ifndef OPENCV_CORE_UTILITY_H +#error "tls.hpp must be included after opencv2/core/utility.hpp or opencv2/core.hpp" +#endif namespace cv { @@ -38,11 +40,7 @@ protected: virtual void* createDataInstance() const = 0; virtual void deleteDataInstance(void* pData) const = 0; -#if OPENCV_ABI_COMPATIBILITY > 300 private: -#else -public: -#endif int key_; friend class cv::details::TlsStorage; // core/src/system.cpp @@ -52,8 +50,8 @@ public: private: // Disable copy/assign (noncopyable pattern) - TLSDataContainer(TLSDataContainer &); - TLSDataContainer& operator =(const TLSDataContainer &); + TLSDataContainer(TLSDataContainer &) = delete; + TLSDataContainer& operator =(const TLSDataContainer &) = delete; }; diff --git a/3rdparty/include/opencv2/core/va_intel.hpp b/3rdparty/include/opencv2/core/va_intel.hpp index f66547093e..b37ce75135 100644 --- a/3rdparty/include/opencv2/core/va_intel.hpp +++ b/3rdparty/include/opencv2/core/va_intel.hpp @@ -29,14 +29,11 @@ namespace cv { namespace va_intel { /** @addtogroup core_va_intel This section describes Intel VA-API/OpenCL (CL-VA) interoperability. -To enable CL-VA interoperability support, configure OpenCV using CMake with WITH_VA_INTEL=ON . Currently VA-API is -supported on Linux only. You should also install Intel Media Server Studio (MSS) to use this feature. You may -have to specify the path(s) to MSS components for cmake in environment variables: +To enable basic VA interoperability build OpenCV with libva library integration enabled: `-DWITH_VA=ON` (corresponding dev package should be installed). -- VA_INTEL_IOCL_ROOT for Intel OpenCL (default is "/opt/intel/opencl"). +To enable advanced CL-VA interoperability support on Intel HW, enable option: `-DWITH_VA_INTEL=ON` (OpenCL integration should be enabled which is the default setting). Special runtime environment should be set up in order to use this feature: correct combination of [libva](https://github.com/intel/libva), [OpenCL runtime](https://github.com/intel/compute-runtime) and [media driver](https://github.com/intel/media-driver) should be installed. -To use CL-VA interoperability you should first create VADisplay (libva), and then call initializeContextFromVA() -function to create OpenCL context and set up interoperability. +Check usage example for details: samples/va_intel/va_intel_interop.cpp */ //! @{ diff --git a/3rdparty/include/opencv2/core/version.hpp b/3rdparty/include/opencv2/core/version.hpp index 7b5bb2de28..c9f4b7ed11 100644 --- a/3rdparty/include/opencv2/core/version.hpp +++ b/3rdparty/include/opencv2/core/version.hpp @@ -5,9 +5,9 @@ #ifndef OPENCV_VERSION_HPP #define OPENCV_VERSION_HPP -#define CV_VERSION_MAJOR 3 -#define CV_VERSION_MINOR 4 -#define CV_VERSION_REVISION 13 +#define CV_VERSION_MAJOR 4 +#define CV_VERSION_MINOR 5 +#define CV_VERSION_REVISION 3 #define CV_VERSION_STATUS "" #define CVAUX_STR_EXP(__A) #__A diff --git a/3rdparty/include/opencv2/core/vsx_utils.hpp b/3rdparty/include/opencv2/core/vsx_utils.hpp index d7962517df..68863ffb36 100644 --- a/3rdparty/include/opencv2/core/vsx_utils.hpp +++ b/3rdparty/include/opencv2/core/vsx_utils.hpp @@ -497,11 +497,13 @@ VSX_IMPL_CONV_EVEN_2_4(vec_uint4, vec_double2, vec_ctu, vec_ctuo) VSX_FINLINE(rt) fnm(const rg& a, int only_truncate) \ { \ assert(only_truncate == 0); \ - CV_UNUSED(only_truncate); \ + CV_UNUSED(only_truncate); \ return fn2(a); \ } VSX_IMPL_CONV_2VARIANT(vec_int4, vec_float4, vec_cts, vec_cts) + VSX_IMPL_CONV_2VARIANT(vec_uint4, vec_float4, vec_ctu, vec_ctu) VSX_IMPL_CONV_2VARIANT(vec_float4, vec_int4, vec_ctf, vec_ctf) + VSX_IMPL_CONV_2VARIANT(vec_float4, vec_uint4, vec_ctf, vec_ctf) // define vec_cts for converting double precision to signed doubleword // which isn't compatible with xlc but its okay since Eigen only uses it for gcc VSX_IMPL_CONV_2VARIANT(vec_dword2, vec_double2, vec_cts, vec_ctsl) diff --git a/3rdparty/include/opencv2/core/wimage.hpp b/3rdparty/include/opencv2/core/wimage.hpp deleted file mode 100644 index c7b6efa06a..0000000000 --- a/3rdparty/include/opencv2/core/wimage.hpp +++ /dev/null @@ -1,603 +0,0 @@ -/*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) 2008, Google, 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 Intel Corporation or contributors 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_CORE_WIMAGE_HPP -#define OPENCV_CORE_WIMAGE_HPP - -#include "opencv2/core/core_c.h" - -#ifdef __cplusplus - -namespace cv { - -//! @addtogroup core -//! @{ - -template class WImage; -template class WImageBuffer; -template class WImageView; - -template class WImageC; -template class WImageBufferC; -template class WImageViewC; - -// Commonly used typedefs. -typedef WImage WImage_b; -typedef WImageView WImageView_b; -typedef WImageBuffer WImageBuffer_b; - -typedef WImageC WImage1_b; -typedef WImageViewC WImageView1_b; -typedef WImageBufferC WImageBuffer1_b; - -typedef WImageC WImage3_b; -typedef WImageViewC WImageView3_b; -typedef WImageBufferC WImageBuffer3_b; - -typedef WImage WImage_f; -typedef WImageView WImageView_f; -typedef WImageBuffer WImageBuffer_f; - -typedef WImageC WImage1_f; -typedef WImageViewC WImageView1_f; -typedef WImageBufferC WImageBuffer1_f; - -typedef WImageC WImage3_f; -typedef WImageViewC WImageView3_f; -typedef WImageBufferC WImageBuffer3_f; - -// There isn't a standard for signed and unsigned short so be more -// explicit in the typename for these cases. -typedef WImage WImage_16s; -typedef WImageView WImageView_16s; -typedef WImageBuffer WImageBuffer_16s; - -typedef WImageC WImage1_16s; -typedef WImageViewC WImageView1_16s; -typedef WImageBufferC WImageBuffer1_16s; - -typedef WImageC WImage3_16s; -typedef WImageViewC WImageView3_16s; -typedef WImageBufferC WImageBuffer3_16s; - -typedef WImage WImage_16u; -typedef WImageView WImageView_16u; -typedef WImageBuffer WImageBuffer_16u; - -typedef WImageC WImage1_16u; -typedef WImageViewC WImageView1_16u; -typedef WImageBufferC WImageBuffer1_16u; - -typedef WImageC WImage3_16u; -typedef WImageViewC WImageView3_16u; -typedef WImageBufferC WImageBuffer3_16u; - -/** @brief Image class which provides a thin layer around an IplImage. - -The goals of the class design are: - - -# All the data has explicit ownership to avoid memory leaks - -# No hidden allocations or copies for performance. - -# Easy access to OpenCV methods (which will access IPP if available) - -# Can easily treat external data as an image - -# Easy to create images which are subsets of other images - -# Fast pixel access which can take advantage of number of channels if known at compile time. - -The WImage class is the image class which provides the data accessors. The 'W' comes from the fact -that it is also a wrapper around the popular but inconvenient IplImage class. A WImage can be -constructed either using a WImageBuffer class which allocates and frees the data, or using a -WImageView class which constructs a subimage or a view into external data. The view class does no -memory management. Each class actually has two versions, one when the number of channels is known -at compile time and one when it isn't. Using the one with the number of channels specified can -provide some compile time optimizations by using the fact that the number of channels is a -constant. - -We use the convention (c,r) to refer to column c and row r with (0,0) being the upper left corner. -This is similar to standard Euclidean coordinates with the first coordinate varying in the -horizontal direction and the second coordinate varying in the vertical direction. Thus (c,r) is -usually in the domain [0, width) X [0, height) - -Example usage: -@code -WImageBuffer3_b im(5,7); // Make a 5X7 3 channel image of type uchar -WImageView3_b sub_im(im, 2,2, 3,3); // 3X3 submatrix -vector vec(10, 3.0f); -WImageView1_f user_im(&vec[0], 2, 5); // 2X5 image w/ supplied data - -im.SetZero(); // same as cvSetZero(im.Ipl()) -*im(2, 3) = 15; // Modify the element at column 2, row 3 -MySetRand(&sub_im); - -// Copy the second row into the first. This can be done with no memory -// allocation and will use SSE if IPP is available. -int w = im.Width(); -im.View(0,0, w,1).CopyFrom(im.View(0,1, w,1)); - -// Doesn't care about source of data since using WImage -void MySetRand(WImage_b* im) { // Works with any number of channels -for (int r = 0; r < im->Height(); ++r) { - float* row = im->Row(r); - for (int c = 0; c < im->Width(); ++c) { - for (int ch = 0; ch < im->Channels(); ++ch, ++row) { - *row = uchar(rand() & 255); - } - } -} -} -@endcode - -Functions that are not part of the basic image allocation, viewing, and access should come from -OpenCV, except some useful functions that are not part of OpenCV can be found in wimage_util.h -*/ -template -class WImage -{ -public: - typedef T BaseType; - - // WImage is an abstract class with no other virtual methods so make the - // destructor virtual. - virtual ~WImage() = 0; - - // Accessors - IplImage* Ipl() {return image_; } - const IplImage* Ipl() const {return image_; } - T* ImageData() { return reinterpret_cast(image_->imageData); } - const T* ImageData() const { - return reinterpret_cast(image_->imageData); - } - - int Width() const {return image_->width; } - int Height() const {return image_->height; } - - // WidthStep is the number of bytes to go to the pixel with the next y coord - int WidthStep() const {return image_->widthStep; } - - int Channels() const {return image_->nChannels; } - int ChannelSize() const {return sizeof(T); } // number of bytes per channel - - // Number of bytes per pixel - int PixelSize() const {return Channels() * ChannelSize(); } - - // Return depth type (e.g. IPL_DEPTH_8U, IPL_DEPTH_32F) which is the number - // of bits per channel and with the signed bit set. - // This is known at compile time using specializations. - int Depth() const; - - inline const T* Row(int r) const { - return reinterpret_cast(image_->imageData + r*image_->widthStep); - } - - inline T* Row(int r) { - return reinterpret_cast(image_->imageData + r*image_->widthStep); - } - - // Pixel accessors which returns a pointer to the start of the channel - inline T* operator() (int c, int r) { - return reinterpret_cast(image_->imageData + r*image_->widthStep) + - c*Channels(); - } - - inline const T* operator() (int c, int r) const { - return reinterpret_cast(image_->imageData + r*image_->widthStep) + - c*Channels(); - } - - // Copy the contents from another image which is just a convenience to cvCopy - void CopyFrom(const WImage& src) { cvCopy(src.Ipl(), image_); } - - // Set contents to zero which is just a convenient to cvSetZero - void SetZero() { cvSetZero(image_); } - - // Construct a view into a region of this image - WImageView View(int c, int r, int width, int height); - -protected: - // Disallow copy and assignment - WImage(const WImage&); - void operator=(const WImage&); - - explicit WImage(IplImage* img) : image_(img) { - assert(!img || img->depth == Depth()); - } - - void SetIpl(IplImage* image) { - assert(!image || image->depth == Depth()); - image_ = image; - } - - IplImage* image_; -}; - - -/** Image class when both the pixel type and number of channels -are known at compile time. This wrapper will speed up some of the operations -like accessing individual pixels using the () operator. -*/ -template -class WImageC : public WImage -{ -public: - typedef typename WImage::BaseType BaseType; - enum { kChannels = C }; - - explicit WImageC(IplImage* img) : WImage(img) { - assert(!img || img->nChannels == Channels()); - } - - // Construct a view into a region of this image - WImageViewC View(int c, int r, int width, int height); - - // Copy the contents from another image which is just a convenience to cvCopy - void CopyFrom(const WImageC& src) { - cvCopy(src.Ipl(), WImage::image_); - } - - // WImageC is an abstract class with no other virtual methods so make the - // destructor virtual. - virtual ~WImageC() = 0; - - int Channels() const {return C; } - -protected: - // Disallow copy and assignment - WImageC(const WImageC&); - void operator=(const WImageC&); - - void SetIpl(IplImage* image) { - assert(!image || image->depth == WImage::Depth()); - WImage::SetIpl(image); - } -}; - -/** Image class which owns the data, so it can be allocated and is always -freed. It cannot be copied but can be explicitly cloned. -*/ -template -class WImageBuffer : public WImage -{ -public: - typedef typename WImage::BaseType BaseType; - - // Default constructor which creates an object that can be - WImageBuffer() : WImage(0) {} - - WImageBuffer(int width, int height, int nchannels) : WImage(0) { - Allocate(width, height, nchannels); - } - - // Constructor which takes ownership of a given IplImage so releases - // the image on destruction. - explicit WImageBuffer(IplImage* img) : WImage(img) {} - - // Allocate an image. Does nothing if current size is the same as - // the new size. - void Allocate(int width, int height, int nchannels); - - // Set the data to point to an image, releasing the old data - void SetIpl(IplImage* img) { - ReleaseImage(); - WImage::SetIpl(img); - } - - // Clone an image which reallocates the image if of a different dimension. - void CloneFrom(const WImage& src) { - Allocate(src.Width(), src.Height(), src.Channels()); - CopyFrom(src); - } - - ~WImageBuffer() { - ReleaseImage(); - } - - // Release the image if it isn't null. - void ReleaseImage() { - if (WImage::image_) { - IplImage* image = WImage::image_; - cvReleaseImage(&image); - WImage::SetIpl(0); - } - } - - bool IsNull() const {return WImage::image_ == NULL; } - -private: - // Disallow copy and assignment - WImageBuffer(const WImageBuffer&); - void operator=(const WImageBuffer&); -}; - -/** Like a WImageBuffer class but when the number of channels is known at compile time. -*/ -template -class WImageBufferC : public WImageC -{ -public: - typedef typename WImage::BaseType BaseType; - enum { kChannels = C }; - - // Default constructor which creates an object that can be - WImageBufferC() : WImageC(0) {} - - WImageBufferC(int width, int height) : WImageC(0) { - Allocate(width, height); - } - - // Constructor which takes ownership of a given IplImage so releases - // the image on destruction. - explicit WImageBufferC(IplImage* img) : WImageC(img) {} - - // Allocate an image. Does nothing if current size is the same as - // the new size. - void Allocate(int width, int height); - - // Set the data to point to an image, releasing the old data - void SetIpl(IplImage* img) { - ReleaseImage(); - WImageC::SetIpl(img); - } - - // Clone an image which reallocates the image if of a different dimension. - void CloneFrom(const WImageC& src) { - Allocate(src.Width(), src.Height()); - CopyFrom(src); - } - - ~WImageBufferC() { - ReleaseImage(); - } - - // Release the image if it isn't null. - void ReleaseImage() { - if (WImage::image_) { - IplImage* image = WImage::image_; - cvReleaseImage(&image); - WImageC::SetIpl(0); - } - } - - bool IsNull() const {return WImage::image_ == NULL; } - -private: - // Disallow copy and assignment - WImageBufferC(const WImageBufferC&); - void operator=(const WImageBufferC&); -}; - -/** View into an image class which allows treating a subimage as an image or treating external data -as an image -*/ -template class WImageView : public WImage -{ -public: - typedef typename WImage::BaseType BaseType; - - // Construct a subimage. No checks are done that the subimage lies - // completely inside the original image. - WImageView(WImage* img, int c, int r, int width, int height); - - // Refer to external data. - // If not given width_step assumed to be same as width. - WImageView(T* data, int width, int height, int channels, int width_step = -1); - - // Refer to external data. This does NOT take ownership - // of the supplied IplImage. - WImageView(IplImage* img) : WImage(img) {} - - // Copy constructor - WImageView(const WImage& img) : WImage(0) { - header_ = *(img.Ipl()); - WImage::SetIpl(&header_); - } - - WImageView& operator=(const WImage& img) { - header_ = *(img.Ipl()); - WImage::SetIpl(&header_); - return *this; - } - -protected: - IplImage header_; -}; - - -template -class WImageViewC : public WImageC -{ -public: - typedef typename WImage::BaseType BaseType; - enum { kChannels = C }; - - // Default constructor needed for vectors of views. - WImageViewC(); - - virtual ~WImageViewC() {} - - // Construct a subimage. No checks are done that the subimage lies - // completely inside the original image. - WImageViewC(WImageC* img, - int c, int r, int width, int height); - - // Refer to external data - WImageViewC(T* data, int width, int height, int width_step = -1); - - // Refer to external data. This does NOT take ownership - // of the supplied IplImage. - WImageViewC(IplImage* img) : WImageC(img) {} - - // Copy constructor which does a shallow copy to allow multiple views - // of same data. gcc-4.1.1 gets confused if both versions of - // the constructor and assignment operator are not provided. - WImageViewC(const WImageC& img) : WImageC(0) { - header_ = *(img.Ipl()); - WImageC::SetIpl(&header_); - } - WImageViewC(const WImageViewC& img) : WImageC(0) { - header_ = *(img.Ipl()); - WImageC::SetIpl(&header_); - } - - WImageViewC& operator=(const WImageC& img) { - header_ = *(img.Ipl()); - WImageC::SetIpl(&header_); - return *this; - } - WImageViewC& operator=(const WImageViewC& img) { - header_ = *(img.Ipl()); - WImageC::SetIpl(&header_); - return *this; - } - -protected: - IplImage header_; -}; - - -// Specializations for depth -template<> -inline int WImage::Depth() const {return IPL_DEPTH_8U; } -template<> -inline int WImage::Depth() const {return IPL_DEPTH_8S; } -template<> -inline int WImage::Depth() const {return IPL_DEPTH_16S; } -template<> -inline int WImage::Depth() const {return IPL_DEPTH_16U; } -template<> -inline int WImage::Depth() const {return IPL_DEPTH_32S; } -template<> -inline int WImage::Depth() const {return IPL_DEPTH_32F; } -template<> -inline int WImage::Depth() const {return IPL_DEPTH_64F; } - -template inline WImage::~WImage() {} -template inline WImageC::~WImageC() {} - -template -inline void WImageBuffer::Allocate(int width, int height, int nchannels) -{ - if (IsNull() || WImage::Width() != width || - WImage::Height() != height || WImage::Channels() != nchannels) { - ReleaseImage(); - WImage::image_ = cvCreateImage(cvSize(width, height), - WImage::Depth(), nchannels); - } -} - -template -inline void WImageBufferC::Allocate(int width, int height) -{ - if (IsNull() || WImage::Width() != width || WImage::Height() != height) { - ReleaseImage(); - WImageC::SetIpl(cvCreateImage(cvSize(width, height),WImage::Depth(), C)); - } -} - -template -WImageView::WImageView(WImage* img, int c, int r, int width, int height) - : WImage(0) -{ - header_ = *(img->Ipl()); - header_.imageData = reinterpret_cast((*img)(c, r)); - header_.width = width; - header_.height = height; - WImage::SetIpl(&header_); -} - -template -WImageView::WImageView(T* data, int width, int height, int nchannels, int width_step) - : WImage(0) -{ - cvInitImageHeader(&header_, cvSize(width, height), WImage::Depth(), nchannels); - header_.imageData = reinterpret_cast(data); - if (width_step > 0) { - header_.widthStep = width_step; - } - WImage::SetIpl(&header_); -} - -template -WImageViewC::WImageViewC(WImageC* img, int c, int r, int width, int height) - : WImageC(0) -{ - header_ = *(img->Ipl()); - header_.imageData = reinterpret_cast((*img)(c, r)); - header_.width = width; - header_.height = height; - WImageC::SetIpl(&header_); -} - -template -WImageViewC::WImageViewC() : WImageC(0) { - cvInitImageHeader(&header_, cvSize(0, 0), WImage::Depth(), C); - header_.imageData = reinterpret_cast(0); - WImageC::SetIpl(&header_); -} - -template -WImageViewC::WImageViewC(T* data, int width, int height, int width_step) - : WImageC(0) -{ - cvInitImageHeader(&header_, cvSize(width, height), WImage::Depth(), C); - header_.imageData = reinterpret_cast(data); - if (width_step > 0) { - header_.widthStep = width_step; - } - WImageC::SetIpl(&header_); -} - -// Construct a view into a region of an image -template -WImageView WImage::View(int c, int r, int width, int height) { - return WImageView(this, c, r, width, height); -} - -template -WImageViewC WImageC::View(int c, int r, int width, int height) { - return WImageViewC(this, c, r, width, height); -} - -//! @} core - -} // end of namespace - -#endif // __cplusplus - -#endif diff --git a/3rdparty/include/opencv2/core_detect.hpp b/3rdparty/include/opencv2/core_detect.hpp deleted file mode 100644 index a107b6e852..0000000000 --- a/3rdparty/include/opencv2/core_detect.hpp +++ /dev/null @@ -1,148 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. -#ifndef _OPENCV_DNN_OBJDETECT_CORE_DETECT_HPP_ -#define _OPENCV_DNN_OBJDETECT_CORE_DETECT_HPP_ - -#include -#include - -#include - -/** @defgroup dnn_objdetect DNN used for object detection -*/ - -namespace cv -{ -namespace dnn_objdetect -{ - - //! @addtogroup dnn_objdetect - //! @{ - - /** @brief Structure to hold the details pertaining to a single bounding box - */ - typedef struct - { - int xmin, xmax; - int ymin, ymax; - size_t class_idx; - std::string label_name; - double class_prob; - } object; - - - /** @brief A class to post process model predictions - */ - class CV_EXPORTS InferBbox - { - public: - /** @brief Default constructer - @param _delta_bbox Blob containing relative coordinates of bounding boxes - @param _class_scores Blob containing the probability values of each class - @param _conf_scores Blob containing the confidence scores - */ - InferBbox(Mat _delta_bbox, Mat _class_scores, Mat _conf_scores); - - /** @brief Filters the bounding boxes. - */ - void filter(double thresh = 0.8); - - /** @brief Vector which holds the final detections of the model - */ - std::vector detections; - - protected: - /** @brief Transform relative coordinates from ConvDet to bounding box coordinates - @param bboxes Vector to hold the predicted bounding boxes - */ - void transform_bboxes(std::vector > *bboxes); - - /** @brief Computes final probability values of each bounding box - @param final_probs Vector to hold the probability values - */ - void final_probability_dist(std::vector > *final_probs); - - /** @brief Transform bounding boxes from [x, y, h, w] to [xmin, ymin, xmax, ymax] - @param pre Vector conatining initial co-ordinates - @param post Vector containing the transformed co-ordinates - */ - void transform_bboxes_inv(std::vector > *pre, - std::vector > *post); - - /** @brief Ensures that the bounding box values are within image boundaries - @param min_max_boxes Vector containing bounding boxes of the form [xmin, ymin, xmax, ymax] - */ - void assert_predictions(std::vector > *min_max_boxes); - - /** @brief Filter top `n` predictions - @param probs Final probability values of bounding boxes - @param boxes Predicted bounding box co-ordinates - @param top_n_boxes Contains bounding box co-ordinates of top `n` boxes - @param top_n_idxs Containes class indices of top `n` bounding boxes - @param top_n_probs Contains probability values of top `n` bounding boxes - */ - void filter_top_n(std::vector > *probs, - std::vector > *boxes, - std::vector > &top_n_boxes, - std::vector &top_n_idxs, - std::vector &top_n_probs); - - /** @brief Wrapper to apply Non-Maximal Supression - @param top_n_boxes Contains bounding box co-ordinates of top `n` boxes - @param top_n_idxs Containes class indices of top `n` bounding boxes - @param top_n_probs Contains probability values of top `n` bounding boxes - */ - void nms_wrapper(std::vector > &top_n_boxes, - std::vector &top_n_idxs, - std::vector &top_n_probs); - - /** @brief Applies Non-Maximal Supression - @param boxes Bounding box co-ordinates belonging to one class - @param probs Probability values of boxes belonging to one class - */ - std::vector non_maximal_suppression(std::vector > - *boxes, std::vector *probs); - - /** @brief Computes intersection over union of bounding boxes - @param boxes Vector of bounding box co-ordinates - @param base_box Base box wrt which IOU is calculated - @param iou Vector to store IOU values - */ - void intersection_over_union(std::vector > *boxes, - std::vector *base_box, std::vector *iou); - - static inline bool comparator (std::pair l1, - std::pair l2) - { - return l1.first > l2.first; - } - - private: - Mat delta_bbox; - Mat class_scores; - Mat conf_scores; - - unsigned int image_width; - unsigned int image_height; - - unsigned int W, H; - std::vector > anchors_values; - std::vector > anchor_center; - std::vector > anchor_shapes; - - std::vector label_map; - - unsigned int num_classes; - unsigned int anchors_per_grid; - size_t anchors; - double intersection_thresh; - double nms_intersection_thresh; - size_t n_top_detections; - double epsilon; - }; - - //! @} -} // namespace dnn_objdetect -} // namespace cv -#endif diff --git a/3rdparty/include/opencv2/cvconfig.h b/3rdparty/include/opencv2/cvconfig.h index c914958591..922e5891ad 100644 --- a/3rdparty/include/opencv2/cvconfig.h +++ b/3rdparty/include/opencv2/cvconfig.h @@ -19,18 +19,6 @@ /* Compile for 'virtual' NVIDIA PTX architectures */ #define CUDA_ARCH_PTX "" -/* AVFoundation video libraries */ -/* #undef HAVE_AVFOUNDATION */ - -/* V4L capturing support */ -/* #undef HAVE_CAMV4L */ - -/* V4L2 capturing support */ -/* #undef HAVE_CAMV4L2 */ - -/* Carbon windowing environment */ -/* #undef HAVE_CARBON */ - /* AMD's Basic Linear Algebra Subprograms Library*/ /* #undef HAVE_CLAMDBLAS */ @@ -40,27 +28,18 @@ /* Clp support */ /* #undef HAVE_CLP */ -/* Cocoa API */ -/* #undef HAVE_COCOA */ - -/* C= */ -/* #undef HAVE_CSTRIPES */ +/* NVIDIA CUDA Runtime API*/ +/* #undef HAVE_CUDA */ /* NVIDIA CUDA Basic Linear Algebra Subprograms (BLAS) API*/ /* #undef HAVE_CUBLAS */ -/* NVIDIA CUDA Runtime API*/ -/* #undef HAVE_CUDA */ +/* NVIDIA CUDA Deep Neural Network (cuDNN) API*/ +/* #undef HAVE_CUDNN */ /* NVIDIA CUDA Fast Fourier Transform (FFT) API*/ /* #undef HAVE_CUFFT */ -/* IEEE1394 capturing support */ -/* #undef HAVE_DC1394 */ - -/* IEEE1394 capturing support - libdc1394 v2.x */ -/* #undef HAVE_DC1394_2 */ - /* DirectX */ #define HAVE_DIRECTX #define HAVE_DIRECTX_NV12 @@ -68,44 +47,30 @@ #define HAVE_D3D10 #define HAVE_D3D9 -/* DirectShow Video Capture library */ -#define HAVE_DSHOW - /* Eigen Matrix & Linear Algebra Library */ /* #undef HAVE_EIGEN */ -/* FFMpeg video library */ -/* #undef HAVE_FFMPEG */ - /* Geospatial Data Abstraction Library */ /* #undef HAVE_GDAL */ -/* GStreamer multimedia framework */ -/* #undef HAVE_GSTREAMER */ - -/* GTK+ 2.0 Thread support */ -/* #undef HAVE_GTHREAD */ - -/* GTK+ 2.x toolkit */ -/* #undef HAVE_GTK */ - /* Halide support */ /* #undef HAVE_HALIDE */ +/* Vulkan support */ +/* #undef HAVE_VULKAN */ + /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 -/* Intel Perceptual Computing SDK library */ -/* #undef HAVE_INTELPERC */ - /* Intel Integrated Performance Primitives */ -/* #undef HAVE_IPP */ -/* #undef HAVE_IPP_ICV */ -/* #undef HAVE_IPP_IW */ -/* #undef HAVE_IPP_IW_LL */ +#define HAVE_IPP +#define HAVE_IPP_ICV +#define HAVE_IPP_IW +#define HAVE_IPP_IW_LL /* JPEG-2000 codec */ -#define HAVE_JASPER +#define HAVE_OPENJPEG +/* #undef HAVE_JASPER */ /* IJG JPEG codec */ #define HAVE_JPEG @@ -116,12 +81,6 @@ /* GDCM DICOM codec */ /* #undef HAVE_GDCM */ -/* V4L/V4L2 capturing support via libv4l */ -/* #undef HAVE_LIBV4L */ - -/* Microsoft Media Foundation Capture library */ -#define HAVE_MSMF - /* NVIDIA Video Decoding API*/ /* #undef HAVE_NVCUVID */ /* #undef HAVE_NVCUVID_HEADER */ @@ -144,12 +103,6 @@ /* OpenGL support*/ /* #undef HAVE_OPENGL */ -/* OpenNI library */ -/* #undef HAVE_OPENNI */ - -/* OpenNI library */ -/* #undef HAVE_OPENNI2 */ - /* PNG codec */ #define HAVE_PNG @@ -159,58 +112,25 @@ /* parallel_for with pthreads */ /* #undef HAVE_PTHREADS_PF */ -/* Qt support */ -/* #undef HAVE_QT */ - -/* Qt OpenGL support */ -/* #undef HAVE_QT_OPENGL */ - -/* QuickTime video libraries */ -/* #undef HAVE_QUICKTIME */ - -/* QTKit video libraries */ -/* #undef HAVE_QTKIT */ - /* Intel Threading Building Blocks */ /* #undef HAVE_TBB */ +/* Ste||ar Group High Performance ParallelX */ +/* #undef HAVE_HPX */ + /* TIFF codec */ #define HAVE_TIFF -/* Unicap video capture library */ -/* #undef HAVE_UNICAP */ - -/* Video for Windows support */ -/* #undef HAVE_VFW */ - -/* V4L2 capturing support in videoio.h */ -/* #undef HAVE_VIDEOIO */ - -/* Win32 UI */ -#define HAVE_WIN32UI - -/* XIMEA camera support */ -/* #undef HAVE_XIMEA */ - -/* Xine video library */ -/* #undef HAVE_XINE */ - /* Define if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ /* #undef WORDS_BIGENDIAN */ -/* gPhoto2 library */ -/* #undef HAVE_GPHOTO2 */ - /* VA library (libva) */ /* #undef HAVE_VA */ /* Intel VA-API/OpenCL */ /* #undef HAVE_VA_INTEL */ -/* Intel Media SDK */ -/* #undef HAVE_MFX */ - /* Lapack */ /* #undef HAVE_LAPACK */ @@ -220,27 +140,6 @@ /* OpenVX */ /* #undef HAVE_OPENVX */ -#if defined(HAVE_XINE) || \ - defined(HAVE_GSTREAMER) || \ - defined(HAVE_QUICKTIME) || \ - defined(HAVE_QTKIT) || \ - defined(HAVE_AVFOUNDATION) || \ - /*defined(HAVE_OPENNI) || too specialized */ \ - defined(HAVE_FFMPEG) || \ - defined(HAVE_MSMF) -#define HAVE_VIDEO_INPUT -#endif - -#if /*defined(HAVE_XINE) || */\ - defined(HAVE_GSTREAMER) || \ - defined(HAVE_QUICKTIME) || \ - defined(HAVE_QTKIT) || \ - defined(HAVE_AVFOUNDATION) || \ - defined(HAVE_FFMPEG) || \ - defined(HAVE_MSMF) -#define HAVE_VIDEO_OUTPUT -#endif - /* OpenCV trace utilities */ #define OPENCV_TRACE diff --git a/3rdparty/include/opencv2/datasets/ar_hmdb.hpp b/3rdparty/include/opencv2/datasets/ar_hmdb.hpp deleted file mode 100644 index fa257ad257..0000000000 --- a/3rdparty/include/opencv2/datasets/ar_hmdb.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_AR_HMDB_HPP -#define OPENCV_DATASETS_AR_HMDB_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_ar -//! @{ - -struct AR_hmdbObj : public Object -{ - int id; - std::string name; - std::string videoName; -}; - -class CV_EXPORTS AR_hmdb : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/ar_sports.hpp b/3rdparty/include/opencv2/datasets/ar_sports.hpp deleted file mode 100644 index cb24e38e77..0000000000 --- a/3rdparty/include/opencv2/datasets/ar_sports.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_AR_SPORTS_HPP -#define OPENCV_DATASETS_AR_SPORTS_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_ar -//! @{ - -struct AR_sportsObj : public Object -{ - std::string videoUrl; - std::vector labels; -}; - -class CV_EXPORTS AR_sports : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/dataset.hpp b/3rdparty/include/opencv2/datasets/dataset.hpp deleted file mode 100644 index f62da15555..0000000000 --- a/3rdparty/include/opencv2/datasets/dataset.hpp +++ /dev/null @@ -1,545 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_DATASET_HPP -#define OPENCV_DATASETS_DATASET_HPP - -#include -#include - -#include - -/** @defgroup datasets Framework for working with different datasets - -The datasets module includes classes for working with different datasets: load data, evaluate -different algorithms on them, contains benchmarks, etc. - -It is planned to have: - -- basic: loading code for all datasets to help start work with them. -- next stage: quick benchmarks for all datasets to show how to solve them using OpenCV and -implement evaluation code. -- finally: implement on OpenCV state-of-the-art algorithms, which solve these tasks. - -@{ -@defgroup datasets_ar Action Recognition - -### HMDB: A Large Human Motion Database - -Implements loading dataset: - -"HMDB: A Large Human Motion Database": - -Usage: --# From link above download dataset files: `hmdb51_org.rar` & `test_train_splits.rar`. --# Unpack them. Unpack all archives from directory: `hmdb51_org/` and remove them. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_ar_hmdb -p=/home/user/path_to_unpacked_folders/ -~~~ - -#### Benchmark - -For this dataset was implemented benchmark with accuracy: 0.107407 (using precomputed HOG/HOF -"STIP" features from site, averaging for 3 splits) - -To run this benchmark execute: -~~~ -./opencv/build/bin/example_datasets_ar_hmdb_benchmark -p=/home/user/path_to_unpacked_folders/ -~~~ - -@note -Precomputed features should be unpacked in the same folder: `/home/user/path_to_unpacked_folders/hmdb51_org_stips/`. -Also unpack all archives from directory: `hmdb51_org_stips/` and remove them. - -### Sports-1M %Dataset - -Implements loading dataset: - -"Sports-1M Dataset": - -Usage: --# From link above download dataset files (`git clone https://code.google.com/p/sports-1m-dataset/`). --# To load data run: -~~~ -./opencv/build/bin/example_datasets_ar_sports -p=/home/user/path_to_downloaded_folders/ -~~~ - -@defgroup datasets_fr Face Recognition - -### Adience - -Implements loading dataset: - -"Adience": - -Usage: --# From link above download any dataset file: `faces.tar.gz\aligned.tar.gz` and files with splits: -`fold_0_data.txt-fold_4_data.txt`, `fold_frontal_0_data.txt-fold_frontal_4_data.txt`. (For -face recognition task another splits should be created) --# Unpack dataset file to some folder and place split files into the same folder. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_fr_adience -p=/home/user/path_to_created_folder/ -~~~ - -### Labeled Faces in the Wild - -Implements loading dataset: - -"Labeled Faces in the Wild": - -Usage: --# From link above download any dataset file: -`lfw.tgz\lfwa.tar.gz\lfw-deepfunneled.tgz\lfw-funneled.tgz` and files with pairs: 10 test -splits: `pairs.txt` and developer train split: `pairsDevTrain.txt`. --# Unpack dataset file and place `pairs.txt` and `pairsDevTrain.txt` in created folder. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_fr_lfw -p=/home/user/path_to_unpacked_folder/lfw2/ -~~~ - -#### Benchmark - -For this dataset was implemented benchmark with accuracy: 0.623833 +- 0.005223 (train split: -`pairsDevTrain.txt`, dataset: lfwa) - -To run this benchmark execute: -~~~ -./opencv/build/bin/example_datasets_fr_lfw_benchmark -p=/home/user/path_to_unpacked_folder/lfw2/ -~~~ - -@defgroup datasets_gr Gesture Recognition - -### ChaLearn Looking at People - -Implements loading dataset: - -"ChaLearn Looking at People": - -Usage --# Follow instruction from site above, download files for dataset "Track 3: Gesture Recognition": -`Train1.zip`-`Train5.zip`, `Validation1.zip`-`Validation3.zip` (Register on site: www.codalab.org and -accept the terms and conditions of competition: - There are three mirrors for -downloading dataset files. When I downloaded data only mirror: "Universitat Oberta de Catalunya" -works). --# Unpack train archives `Train1.zip`-`Train5.zip` to folder `Train/`, validation archives -`Validation1.zip`-`Validation3.zip` to folder `Validation/` --# Unpack all archives in `Train/` & `Validation/` in the folders with the same names, for example: -`Sample0001.zip` to `Sample0001/` --# To load data run: -~~~ -./opencv/build/bin/example_datasets_gr_chalearn -p=/home/user/path_to_unpacked_folders/ -~~~ - -### Sheffield Kinect Gesture Dataset - -Implements loading dataset: - -"Sheffield Kinect Gesture Dataset": - -Usage: --# From link above download dataset files: `subject1_dep.7z`-`subject6_dep.7z`, `subject1_rgb.7z`-`subject6_rgb.7z`. --# Unpack them. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_gr_skig -p=/home/user/path_to_unpacked_folders/ -~~~ - -@defgroup datasets_hpe Human Pose Estimation - -### HumanEva Dataset - -Implements loading dataset: - -"HumanEva Dataset": - -Usage: --# From link above download dataset files for `HumanEva-I` (tar) & `HumanEva-II`. --# Unpack them to `HumanEva_1` & `HumanEva_2` accordingly. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_hpe_humaneva -p=/home/user/path_to_unpacked_folders/ -~~~ - -### PARSE Dataset - -Implements loading dataset: - -"PARSE Dataset": - -Usage: --# From link above download dataset file: `people.zip`. --# Unpack it. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_hpe_parse -p=/home/user/path_to_unpacked_folder/people_all/ -~~~ - -@defgroup datasets_ir Image Registration - -### Affine Covariant Regions Datasets - -Implements loading dataset: - -"Affine Covariant Regions Datasets": - -Usage: --# From link above download dataset files: -`bark\bikes\boat\graf\leuven\trees\ubc\wall.tar.gz`. --# Unpack them. --# To load data, for example, for "bark", run: -``` -./opencv/build/bin/example_datasets_ir_affine -p=/home/user/path_to_unpacked_folder/bark/ -``` - -### Robot Data Set - -Implements loading dataset: - -"Robot Data Set, Point Feature Data Set – 2010": - -Usage: --# From link above download dataset files: `SET001_6.tar.gz`-`SET055_60.tar.gz` --# Unpack them to one folder. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_ir_robot -p=/home/user/path_to_unpacked_folder/ -~~~ - -@defgroup datasets_is Image Segmentation - -### The Berkeley Segmentation Dataset and Benchmark - -Implements loading dataset: - -"The Berkeley Segmentation Dataset and Benchmark": - -Usage: --# From link above download dataset files: `BSDS300-human.tgz` & `BSDS300-images.tgz`. --# Unpack them. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_is_bsds -p=/home/user/path_to_unpacked_folder/BSDS300/ -~~~ - -### Weizmann Segmentation Evaluation Database - -Implements loading dataset: - -"Weizmann Segmentation Evaluation Database": - -Usage: --# From link above download dataset files: `Weizmann_Seg_DB_1obj.ZIP` & `Weizmann_Seg_DB_2obj.ZIP`. --# Unpack them. --# To load data, for example, for `1 object` dataset, run: -~~~ -./opencv/build/bin/example_datasets_is_weizmann -p=/home/user/path_to_unpacked_folder/1obj/ -~~~ - -@defgroup datasets_msm Multiview Stereo Matching - -### EPFL Multi-View Stereo - -Implements loading dataset: - -"EPFL Multi-View Stereo": - -Usage: --# From link above download dataset files: -`castle_dense\castle_dense_large\castle_entry\fountain\herzjesu_dense\herzjesu_dense_large_bounding\cameras\images\p.tar.gz`. --# Unpack them in separate folder for each object. For example, for "fountain", in folder `fountain/` : -`fountain_dense_bounding.tar.gz -> bounding/`, -`fountain_dense_cameras.tar.gz -> camera/`, -`fountain_dense_images.tar.gz -> png/`, -`fountain_dense_p.tar.gz -> P/` --# To load data, for example, for "fountain", run: -~~~ -./opencv/build/bin/example_datasets_msm_epfl -p=/home/user/path_to_unpacked_folder/fountain/ -~~~ - -### Stereo – Middlebury Computer Vision - -Implements loading dataset: - -"Stereo – Middlebury Computer Vision": - -Usage: --# From link above download dataset files: -`dino\dinoRing\dinoSparseRing\temple\templeRing\templeSparseRing.zip` --# Unpack them. --# To load data, for example "temple" dataset, run: -~~~ -./opencv/build/bin/example_datasets_msm_middlebury -p=/home/user/path_to_unpacked_folder/temple/ -~~~ - -@defgroup datasets_or Object Recognition - -### ImageNet - -Implements loading dataset: "ImageNet": - -Usage: --# From link above download dataset files: -`ILSVRC2010_images_train.tar\ILSVRC2010_images_test.tar\ILSVRC2010_images_val.tar` & devkit: -`ILSVRC2010_devkit-1.0.tar.gz` (Implemented loading of 2010 dataset as only this dataset has ground -truth for test data, but structure for ILSVRC2014 is similar) --# Unpack them to: `some_folder/train/`, `some_folder/test/`, `some_folder/val` & -`some_folder/ILSVRC2010_validation_ground_truth.txt`, -`some_folder/ILSVRC2010_test_ground_truth.txt`. --# Create file with labels: `some_folder/labels.txt`, for example, using python script below (each -file's row format: `synset,labelID,description`. For example: "n07751451,18,plum"). --# Unpack all tar files in train. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_or_imagenet -p=/home/user/some_folder/ -~~~ - -Python script to parse `meta.mat`: -~~~{py} - import scipy.io - meta_mat = scipy.io.loadmat("devkit-1.0/data/meta.mat") - - labels_dic = dict((m[0][1][0], m[0][0][0][0]-1) for m in meta_mat['synsets'] - label_names_dic = dict((m[0][1][0], m[0][2][0]) for m in meta_mat['synsets'] - - for label in labels_dic.keys(): - print "{0},{1},{2}".format(label, labels_dic[label], label_names_dic[label]) -~~~ - -### MNIST - -Implements loading dataset: - -"MNIST": - -Usage: --# From link above download dataset files: -`t10k-images-idx3-ubyte.gz`, `t10k-labels-idx1-ubyte.gz`, `train-images-idx3-ubyte.gz`, `train-labels-idx1-ubyte.gz`. --# Unpack them. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_or_mnist -p=/home/user/path_to_unpacked_files/ -~~~ - -### SUN Database - -Implements loading dataset: - -"SUN Database, Scene Recognition Benchmark. SUN397": - -Usage: --# From link above download dataset file: `SUN397.tar` & file with splits: `Partitions.zip` --# Unpack `SUN397.tar` into folder: `SUN397/` & `Partitions.zip` into folder: `SUN397/Partitions/` --# To load data run: -~~~ -./opencv/build/bin/example_datasets_or_sun -p=/home/user/path_to_unpacked_files/SUN397/ -~~~ - -@defgroup datasets_pd Pedestrian Detection - -### Caltech Pedestrian Detection Benchmark - -Implements loading dataset: - -"Caltech Pedestrian Detection Benchmark": - -@note First version of Caltech Pedestrian dataset loading. Code to unpack all frames from seq files -commented as their number is huge! So currently load only meta information without data. Also -ground truth isn't processed, as need to convert it from mat files first. - -Usage: --# From link above download dataset files: `set00.tar`-`set10.tar`. --# Unpack them to separate folder. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_pd_caltech -p=/home/user/path_to_unpacked_folders/ -~~~ - -@defgroup datasets_slam SLAM - -### KITTI Vision Benchmark - -Implements loading dataset: - -"KITTI Vision Benchmark": - -Usage: --# From link above download "Odometry" dataset files: -`data_odometry_gray\data_odometry_color\data_odometry_velodyne\data_odometry_poses\data_odometry_calib.zip`. --# Unpack `data_odometry_poses.zip`, it creates folder `dataset/poses/`. After that unpack -`data_odometry_gray.zip`, `data_odometry_color.zip`, `data_odometry_velodyne.zip`. Folder -`dataset/sequences/` will be created with folders `00/..21/`. Each of these folders will contain: -`image_0/`, `image_1/`, `image_2/`, `image_3/`, `velodyne/` and files `calib.txt` & `times.txt`. -These two last files will be replaced after unpacking `data_odometry_calib.zip` at the end. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_slam_kitti -p=/home/user/path_to_unpacked_folder/dataset/ -~~~ - -### TUMindoor Dataset - -Implements loading dataset: - -"TUMindoor Dataset": - -Usage: --# From link above download dataset files: `dslr\info\ladybug\pointcloud.tar.bz2` for each dataset: -`11-11-28 (1st floor)\11-12-13 (1st floor N1)\11-12-17a (4th floor)\11-12-17b (3rd floor)\11-12-17c (Ground I)\11-12-18a (Ground II)\11-12-18b (2nd floor)` --# Unpack them in separate folder for each dataset. -`dslr.tar.bz2 -> dslr/`, -`info.tar.bz2 -> info/`, -`ladybug.tar.bz2 -> ladybug/`, -`pointcloud.tar.bz2 -> pointcloud/`. --# To load each dataset run: -~~~ -./opencv/build/bin/example_datasets_slam_tumindoor -p=/home/user/path_to_unpacked_folders/ -~~~ - -@defgroup datasets_tr Text Recognition - -### The Chars74K Dataset - -Implements loading dataset: - -"The Chars74K Dataset": - -Usage: --# From link above download dataset files: -`EnglishFnt\EnglishHnd\EnglishImg\KannadaHnd\KannadaImg.tgz`, `ListsTXT.tgz`. --# Unpack them. --# Move `.m` files from folder `ListsTXT/` to appropriate folder. For example, -`English/list_English_Img.m` for `EnglishImg.tgz`. --# To load data, for example "EnglishImg", run: -~~~ -./opencv/build/bin/example_datasets_tr_chars -p=/home/user/path_to_unpacked_folder/English/ -~~~ - -### The Street View Text Dataset - -Implements loading dataset: - -"The Street View Text Dataset": - -Usage: --# From link above download dataset file: `svt.zip`. --# Unpack it. --# To load data run: -~~~ -./opencv/build/bin/example_datasets_tr_svt -p=/home/user/path_to_unpacked_folder/svt/svt1/ -~~~ - -#### Benchmark - -For this dataset was implemented benchmark with accuracy (mean f1): 0.217 - -To run benchmark execute: -~~~ -./opencv/build/bin/example_datasets_tr_svt_benchmark -p=/home/user/path_to_unpacked_folders/svt/svt1/ -~~~ - -@defgroup datasets_track Tracking - -### VOT 2015 Database - -Implements loading dataset: - -"VOT 2015 dataset comprises 60 short sequences showing various objects in challenging backgrounds. -The sequences were chosen from a large pool of sequences including the ALOV dataset, OTB2 dataset, -non-tracking datasets, Computer Vision Online, Professor Bob Fisher's Image Database, Videezy, -Center for Research in Computer Vision, University of Central Florida, USA, NYU Center for Genomics -and Systems Biology, Data Wrangling, Open Access Directory and Learning and Recognition in Vision -Group, INRIA, France. The VOT sequence selection protocol was applied to obtain a representative -set of challenging sequences.": - -Usage: --# From link above download dataset file: `vot2015.zip` --# Unpack `vot2015.zip` into folder: `VOT2015/` --# To load data run: -~~~ -./opencv/build/bin/example_datasets_track_vot -p=/home/user/path_to_unpacked_files/VOT2015/ -~~~ -@} - -*/ - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets -//! @{ - -struct Object -{ -}; - -class CV_EXPORTS Dataset -{ -public: - Dataset() {} - virtual ~Dataset() {} - - virtual void load(const std::string &path) = 0; - - std::vector< Ptr >& getTrain(int splitNum = 0); - std::vector< Ptr >& getTest(int splitNum = 0); - std::vector< Ptr >& getValidation(int splitNum = 0); - - int getNumSplits() const; - -protected: - std::vector< std::vector< Ptr > > train; - std::vector< std::vector< Ptr > > test; - std::vector< std::vector< Ptr > > validation; - -private: - std::vector< Ptr > empty; -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/fr_adience.hpp b/3rdparty/include/opencv2/datasets/fr_adience.hpp deleted file mode 100644 index 2df5d8df48..0000000000 --- a/3rdparty/include/opencv2/datasets/fr_adience.hpp +++ /dev/null @@ -1,98 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_FR_ADIENCE_HPP -#define OPENCV_DATASETS_FR_ADIENCE_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_fr -//! @{ - -enum genderType -{ - male = 0, - female, - none -}; - -struct FR_adienceObj : public Object -{ - std::string user_id; - std::string original_image; - int face_id; - std::string age; - genderType gender; - int x; - int y; - int dx; - int dy; - int tilt_ang; - int fiducial_yaw_angle; - int fiducial_score; -}; - -class CV_EXPORTS FR_adience : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); - - std::vector paths; -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/fr_lfw.hpp b/3rdparty/include/opencv2/datasets/fr_lfw.hpp deleted file mode 100644 index 16d6315743..0000000000 --- a/3rdparty/include/opencv2/datasets/fr_lfw.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_FR_LFW_HPP -#define OPENCV_DATASETS_FR_LFW_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_fr -//! @{ - -struct FR_lfwObj : public Object -{ - std::string image1, image2; - bool same; -}; - -class CV_EXPORTS FR_lfw : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/gr_chalearn.hpp b/3rdparty/include/opencv2/datasets/gr_chalearn.hpp deleted file mode 100644 index 6a5c764127..0000000000 --- a/3rdparty/include/opencv2/datasets/gr_chalearn.hpp +++ /dev/null @@ -1,96 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_GR_CHALEARN_HPP -#define OPENCV_DATASETS_GR_CHALEARN_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_gr -//! @{ - -struct groundTruth -{ - int gestureID, initialFrame, lastFrame; -}; - -struct join -{ - double Wx, Wy, Wz, Rx, Ry, Rz, Rw, Px, Py; -}; - -struct skeleton -{ - join s[20]; -}; - -struct GR_chalearnObj : public Object -{ - std::string name, nameColor, nameDepth, nameUser; - int numFrames, fps, depth; - std::vector groundTruths; - std::vector skeletons; -}; - -class CV_EXPORTS GR_chalearn : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/gr_skig.hpp b/3rdparty/include/opencv2/datasets/gr_skig.hpp deleted file mode 100644 index 35bc6f4f6b..0000000000 --- a/3rdparty/include/opencv2/datasets/gr_skig.hpp +++ /dev/null @@ -1,118 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_GR_SKIG_HPP -#define OPENCV_DATASETS_GR_SKIG_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_gr -//! @{ - -enum actionType -{ - circle = 1, - triangle, - updown, - rightleft, - wave, - z, - cross, - comehere, - turnaround, - pat -}; - -enum poseType -{ - fist = 1, - index, - flat -}; - -enum illuminationType -{ - light = 1, - dark -}; - -enum backgroundType -{ - woodenBoard = 1, - whitePaper, - paperWithCharacters -}; - -struct GR_skigObj : public Object -{ - std::string rgb; - std::string dep; - char person; // 1..6 - backgroundType background; - illuminationType illumination; - poseType pose; - actionType type; -}; - -class CV_EXPORTS GR_skig : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/hpe_humaneva.hpp b/3rdparty/include/opencv2/datasets/hpe_humaneva.hpp deleted file mode 100644 index 2eba8cfca7..0000000000 --- a/3rdparty/include/opencv2/datasets/hpe_humaneva.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_HPE_HUMANEVA_HPP -#define OPENCV_DATASETS_HPE_HUMANEVA_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_hpe -//! @{ - -struct HPE_humanevaObj : public Object -{ - char person; // 1..4 - std::string action; - int type1; - std::string type2; - Matx13d ofs; - std::string fileName; - std::vector imageNames; // for HumanEva_II -}; - -enum datasetType -{ - humaneva_1 = 1, - humaneva_2 -}; - -class CV_EXPORTS HPE_humaneva : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(int num=humaneva_1); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/hpe_parse.hpp b/3rdparty/include/opencv2/datasets/hpe_parse.hpp deleted file mode 100644 index 42294df837..0000000000 --- a/3rdparty/include/opencv2/datasets/hpe_parse.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_HPE_PARSE_HPP -#define OPENCV_DATASETS_HPE_PARSE_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_hpe -//! @{ - -struct HPE_parseObj : public Object -{ - std::string name; -}; - -class CV_EXPORTS HPE_parse : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/ir_affine.hpp b/3rdparty/include/opencv2/datasets/ir_affine.hpp deleted file mode 100644 index 7cc0c0908f..0000000000 --- a/3rdparty/include/opencv2/datasets/ir_affine.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_IR_AFFINE_HPP -#define OPENCV_DATASETS_IR_AFFINE_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_ir -//! @{ - -struct IR_affineObj : public Object -{ - std::string imageName; - Matx33d mat; -}; - -class CV_EXPORTS IR_affine : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/ir_robot.hpp b/3rdparty/include/opencv2/datasets/ir_robot.hpp deleted file mode 100644 index 446e3be6bb..0000000000 --- a/3rdparty/include/opencv2/datasets/ir_robot.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_IR_ROBOT_HPP -#define OPENCV_DATASETS_IR_ROBOT_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_ir -//! @{ - -// calibration matrix from calibrationFile.mat -// 2.8290e+03 0.0000e+00 8.0279e+02 -// 0.0000e+00 2.8285e+03 6.1618e+02 -// 0.0000e+00 0.0000e+00 1.0000e+00 - -struct cameraPos -{ - std::vector images; -}; - -struct IR_robotObj : public Object -{ - std::string name; - std::vector pos; -}; - -class CV_EXPORTS IR_robot : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/is_bsds.hpp b/3rdparty/include/opencv2/datasets/is_bsds.hpp deleted file mode 100644 index b4a3e65789..0000000000 --- a/3rdparty/include/opencv2/datasets/is_bsds.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_IS_BSDS_HPP -#define OPENCV_DATASETS_IS_BSDS_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_is -//! @{ - -struct IS_bsdsObj : public Object -{ - std::string name; -}; - -class CV_EXPORTS IS_bsds : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/is_weizmann.hpp b/3rdparty/include/opencv2/datasets/is_weizmann.hpp deleted file mode 100644 index 4f61578a61..0000000000 --- a/3rdparty/include/opencv2/datasets/is_weizmann.hpp +++ /dev/null @@ -1,81 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_IS_WEIZMANN_HPP -#define OPENCV_DATASETS_IS_WEIZMANN_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_is -//! @{ - -struct IS_weizmannObj : public Object -{ - std::string imageName; - std::string srcBw; - std::string srcColor; - std::string humanSeg; // TODO: read human segmented -}; - -class CV_EXPORTS IS_weizmann : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/msm_epfl.hpp b/3rdparty/include/opencv2/datasets/msm_epfl.hpp deleted file mode 100644 index 54aebde926..0000000000 --- a/3rdparty/include/opencv2/datasets/msm_epfl.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_MSM_EPFL_HPP -#define OPENCV_DATASETS_MSM_EPFL_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_msm -//! @{ - -struct cameraParam -{ - Matx33d mat1; - double mat2[3]; - Matx33d mat3; - double mat4[3]; - int imageWidth, imageHeight; -}; - -struct MSM_epflObj : public Object -{ - std::string imageName; - Matx23d bounding; - Matx34d p; - cameraParam camera; -}; - -class CV_EXPORTS MSM_epfl : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/msm_middlebury.hpp b/3rdparty/include/opencv2/datasets/msm_middlebury.hpp deleted file mode 100644 index 9b883e59ae..0000000000 --- a/3rdparty/include/opencv2/datasets/msm_middlebury.hpp +++ /dev/null @@ -1,81 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_MSM_MIDDLEBURY_HPP -#define OPENCV_DATASETS_MSM_MIDDLEBURY_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_msm -//! @{ - -struct MSM_middleburyObj : public Object -{ - std::string imageName; - Matx33d k; - Matx33d r; - double t[3]; -}; - -class CV_EXPORTS MSM_middlebury : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/or_imagenet.hpp b/3rdparty/include/opencv2/datasets/or_imagenet.hpp deleted file mode 100644 index 079165bf93..0000000000 --- a/3rdparty/include/opencv2/datasets/or_imagenet.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_OR_IMAGENET_HPP -#define OPENCV_DATASETS_OR_IMAGENET_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_or -//! @{ - -struct OR_imagenetObj : public Object -{ - int id; - std::string image; -}; - -class CV_EXPORTS OR_imagenet : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/or_mnist.hpp b/3rdparty/include/opencv2/datasets/or_mnist.hpp deleted file mode 100644 index ac4d838ed5..0000000000 --- a/3rdparty/include/opencv2/datasets/or_mnist.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_OR_MNIST_HPP -#define OPENCV_DATASETS_OR_MNIST_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_or -//! @{ - -struct OR_mnistObj : public Object -{ - char label; // 0..9 - Mat image; // [28][28] -}; - -class CV_EXPORTS OR_mnist : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/or_pascal.hpp b/3rdparty/include/opencv2/datasets/or_pascal.hpp deleted file mode 100644 index c5f27af9fc..0000000000 --- a/3rdparty/include/opencv2/datasets/or_pascal.hpp +++ /dev/null @@ -1,102 +0,0 @@ -/*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) 2015, Itseez 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 Itseez Inc 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_DATASETS_VOC_PASCAL_HPP -#define OPENCV_DATASETS_VOC_PASCAL_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_or -//! @{ -struct PascalPart: public Object -{ - std::string name; - int xmin; - int ymin; - int xmax; - int ymax; -}; - -struct PascalObj: public PascalPart -{ - std::string pose; - bool truncated; - bool difficult; - bool occluded; - - std::vector parts; -}; - -struct OR_pascalObj : public Object -{ - std::string filename; - - int width; - int height; - int depth; - - std::vector objects; -}; - -class CV_EXPORTS OR_pascal : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -}// namespace dataset -}// namespace cv - -#endif diff --git a/3rdparty/include/opencv2/datasets/or_sun.hpp b/3rdparty/include/opencv2/datasets/or_sun.hpp deleted file mode 100644 index 7d3d8878a4..0000000000 --- a/3rdparty/include/opencv2/datasets/or_sun.hpp +++ /dev/null @@ -1,81 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_OR_SUN_HPP -#define OPENCV_DATASETS_OR_SUN_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_or -//! @{ - -struct OR_sunObj : public Object -{ - int label; - std::string name; -}; - -class CV_EXPORTS OR_sun : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); - - std::vector paths; -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/pd_caltech.hpp b/3rdparty/include/opencv2/datasets/pd_caltech.hpp deleted file mode 100644 index c8545e2f1e..0000000000 --- a/3rdparty/include/opencv2/datasets/pd_caltech.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_PD_CALTECH_HPP -#define OPENCV_DATASETS_PD_CALTECH_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_pd -//! @{ - -struct PD_caltechObj : public Object -{ - //double groundTrue[][]; - //Mat image; - std::string name; - std::vector< std::string > imageNames; -}; - -// -// first version of Caltech Pedestrian dataset loading -// code to unpack all frames from seq files commented as their number is huge -// so currently load only meta information without data -// -// also ground truth isn't processed, as need to convert it from mat files first -// - -class CV_EXPORTS PD_caltech : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/pd_inria.hpp b/3rdparty/include/opencv2/datasets/pd_inria.hpp deleted file mode 100644 index 9e1d30b89c..0000000000 --- a/3rdparty/include/opencv2/datasets/pd_inria.hpp +++ /dev/null @@ -1,96 +0,0 @@ -/*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) 2015, Itseez 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 Itseez Inc 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_DATASETS_PD_INRIA_HPP -#define OPENCV_DATASETS_PD_INRIA_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_pd -//! @{ - -enum sampleType -{ - POS = 0, - NEG = 1 -}; - -struct PD_inriaObj : public Object -{ - // image file name - std::string filename; - - // positive or negative - sampleType sType; - - // image size - int width; - int height; - int depth; - - // bounding boxes - std::vector< Rect > bndboxes; -}; - -class CV_EXPORTS PD_inria : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/slam_kitti.hpp b/3rdparty/include/opencv2/datasets/slam_kitti.hpp deleted file mode 100644 index a004b95f45..0000000000 --- a/3rdparty/include/opencv2/datasets/slam_kitti.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_SLAM_KITTI_HPP -#define OPENCV_DATASETS_SLAM_KITTI_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_slam -//! @{ - -struct pose -{ - double elem[12]; -}; - -struct SLAM_kittiObj : public Object -{ - std::string name; - std::vector images[4]; - std::vector velodyne; - std::vector times, p[4]; - std::vector posesArray; -}; - -class CV_EXPORTS SLAM_kitti : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/slam_tumindoor.hpp b/3rdparty/include/opencv2/datasets/slam_tumindoor.hpp deleted file mode 100644 index eca07addae..0000000000 --- a/3rdparty/include/opencv2/datasets/slam_tumindoor.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_SLAM_TUMINDOOR_HPP -#define OPENCV_DATASETS_SLAM_TUMINDOOR_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_slam -//! @{ - -enum imageType -{ - LEFT = 0, - RIGHT, - LADYBUG -}; - -struct SLAM_tumindoorObj : public Object -{ - std::string name; - Matx44d transformMat; - imageType type; -}; - -class CV_EXPORTS SLAM_tumindoor : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/tr_chars.hpp b/3rdparty/include/opencv2/datasets/tr_chars.hpp deleted file mode 100644 index 69aab83a24..0000000000 --- a/3rdparty/include/opencv2/datasets/tr_chars.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_TR_CHARS_HPP -#define OPENCV_DATASETS_TR_CHARS_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_tr -//! @{ - -struct TR_charsObj : public Object -{ - std::string imgName; - int label; -}; - -class CV_EXPORTS TR_chars : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/tr_icdar.hpp b/3rdparty/include/opencv2/datasets/tr_icdar.hpp deleted file mode 100644 index 3b43d69740..0000000000 --- a/3rdparty/include/opencv2/datasets/tr_icdar.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_TR_ICDAR_HPP -#define OPENCV_DATASETS_TR_ICDAR_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_tr -//! @{ - -struct word -{ - std::string value; - int height, width, x, y; -}; - -struct TR_icdarObj : public Object -{ - std::string fileName; - std::vector lex100; - std::vector lexFull; - std::vector words; -}; - -class CV_EXPORTS TR_icdar : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/tr_svt.hpp b/3rdparty/include/opencv2/datasets/tr_svt.hpp deleted file mode 100644 index 7b941802e8..0000000000 --- a/3rdparty/include/opencv2/datasets/tr_svt.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_TR_SVT_HPP -#define OPENCV_DATASETS_TR_SVT_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_tr -//! @{ - -struct tag -{ - std::string value; - int height, width, x, y; -}; - -struct TR_svtObj : public Object -{ - std::string fileName; - std::vector lex; - std::vector tags; -}; - -class CV_EXPORTS TR_svt : public Dataset -{ -public: - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - static Ptr create(); -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/track_alov.hpp b/3rdparty/include/opencv2/datasets/track_alov.hpp deleted file mode 100644 index a3c5da0236..0000000000 --- a/3rdparty/include/opencv2/datasets/track_alov.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_TRACK_ALOV_HPP -#define OPENCV_DATASETS_TRACK_ALOV_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" -#include "opencv2/datasets/util.hpp" - -using namespace std; - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_track -//! @{ - -struct TRACK_alovObj : public Object -{ - int id; - std::string imagePath; - vector gtbb; -}; - -const string sectionNames[] = { "01-Light", "02-SurfaceCover", "03-Specularity", "04-Transparency", "05-Shape", "06-MotionSmoothness", "07-MotionCoherence", -"08-Clutter", "09-Confusion", "10-LowContrast", "11-Occlusion", "12-MovingCamera", "13-ZoomingCamera", "14-LongDuration" }; - -const int sectionSizes[] = { 33, 15, 18, 20, 24, 22, 12, 15, 37, 23, 34, 22, 29, 10 }; - -class CV_EXPORTS TRACK_alov : public Dataset -{ -public: - static Ptr create(); - - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - //Load only frames with annotations (~every 5-th frame) - virtual void loadAnnotatedOnly(const std::string &path) = 0; - - virtual int getDatasetsNum() = 0; - - virtual int getDatasetLength(int id) = 0; - - virtual bool initDataset(int id) = 0; - - virtual bool getNextFrame(Mat &frame) = 0; - virtual vector getNextGT() = 0; - - //Get frame/GT by datasetID (1..N) frameID (1..K) - virtual bool getFrame(Mat &frame, int datasetID, int frameID) = 0; - virtual vector getGT(int datasetID, int frameID) = 0; - -protected: - vector > > data; - int activeDatasetID; - int frameCounter; -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/track_vot.hpp b/3rdparty/include/opencv2/datasets/track_vot.hpp deleted file mode 100644 index a5a9c6fd8c..0000000000 --- a/3rdparty/include/opencv2/datasets/track_vot.hpp +++ /dev/null @@ -1,96 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_TRACK_VOT_HPP -#define OPENCV_DATASETS_TRACK_VOT_HPP - -#include -#include - -#include "opencv2/datasets/dataset.hpp" -#include "opencv2/datasets/util.hpp" - -using namespace std; - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets_track -//! @{ - -struct TRACK_votObj : public Object -{ - int id; - std::string imagePath; - vector gtbb; -}; - -class CV_EXPORTS TRACK_vot : public Dataset -{ -public: - static Ptr create(); - - virtual void load(const std::string &path) CV_OVERRIDE = 0; - - virtual int getDatasetsNum() = 0; - - virtual int getDatasetLength(int id) = 0; - - virtual bool initDataset(int id) = 0; - - virtual bool getNextFrame(Mat &frame) = 0; - - virtual vector getGT() = 0; - -protected: - vector > > data; - int activeDatasetID; - int frameCounter; -}; - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/datasets/util.hpp b/3rdparty/include/opencv2/datasets/util.hpp deleted file mode 100644 index 316de3a7a9..0000000000 --- a/3rdparty/include/opencv2/datasets/util.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/*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) 2014, Itseez 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 Itseez Inc 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_DATASETS_UTIL_HPP -#define OPENCV_DATASETS_UTIL_HPP - -#include -#include - -#include -#include // atoi, atof - -#include - -#include - -namespace cv -{ -namespace datasets -{ - -//! @addtogroup datasets -//! @{ - -void CV_EXPORTS split(const std::string &s, std::vector &elems, char delim); - -void CV_EXPORTS createDirectory(const std::string &path); - -void CV_EXPORTS getDirList(const std::string &dirName, std::vector &fileNames); - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/dnn/all_layers.hpp b/3rdparty/include/opencv2/dnn/all_layers.hpp index ffc2568a89..24d35646df 100644 --- a/3rdparty/include/opencv2/dnn/all_layers.hpp +++ b/3rdparty/include/opencv2/dnn/all_layers.hpp @@ -45,7 +45,7 @@ namespace cv { namespace dnn { -CV__DNN_EXPERIMENTAL_NS_BEGIN +CV__DNN_INLINE_NS_BEGIN //! @addtogroup dnn //! @{ @@ -364,6 +364,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN * Inner vector has slice ranges for the first number of input dimensions. */ std::vector > sliceRanges; + std::vector > sliceSteps; int axis; int num_split; @@ -499,6 +500,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN static Ptr create(const LayerParams ¶ms); }; + class CV_EXPORTS ExpLayer : public ActivationLayer + { + public: + float base, scale, shift; + + static Ptr create(const LayerParams ¶ms); + }; + /* Layers used in semantic segmentation */ class CV_EXPORTS CropLayer : public Layer @@ -593,6 +602,8 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN class CV_EXPORTS RegionLayer : public Layer { public: + float nmsThreshold; + static Ptr create(const LayerParams& params); }; @@ -680,7 +691,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN //! @} //! @} -CV__DNN_EXPERIMENTAL_NS_END +CV__DNN_INLINE_NS_END } } #endif diff --git a/3rdparty/include/opencv2/dnn/dict.hpp b/3rdparty/include/opencv2/dnn/dict.hpp index 60c2aa5ddb..463d314bee 100644 --- a/3rdparty/include/opencv2/dnn/dict.hpp +++ b/3rdparty/include/opencv2/dnn/dict.hpp @@ -50,7 +50,7 @@ namespace cv { namespace dnn { -CV__DNN_EXPERIMENTAL_NS_BEGIN +CV__DNN_INLINE_NS_BEGIN //! @addtogroup dnn //! @{ @@ -96,7 +96,7 @@ struct CV_EXPORTS_W DictValue private: - int type; + Param type; union { @@ -106,7 +106,7 @@ private: void *pv; }; - DictValue(int _type, void *_p) : type(_type), pv(_p) {} + DictValue(Param _type, void *_p) : type(_type), pv(_p) {} void release(); }; @@ -153,7 +153,7 @@ public: }; //! @} -CV__DNN_EXPERIMENTAL_NS_END +CV__DNN_INLINE_NS_END } } diff --git a/3rdparty/include/opencv2/dnn/dnn.hpp b/3rdparty/include/opencv2/dnn/dnn.hpp index b2dd0e6e16..255b41de88 100644 --- a/3rdparty/include/opencv2/dnn/dnn.hpp +++ b/3rdparty/include/opencv2/dnn/dnn.hpp @@ -46,20 +46,13 @@ #include #include "opencv2/core/async.hpp" -#if !defined CV_DOXYGEN && !defined CV_STATIC_ANALYSIS && !defined CV_DNN_DONT_ADD_EXPERIMENTAL_NS -#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_34_v20 { -#define CV__DNN_EXPERIMENTAL_NS_END } -namespace cv { namespace dnn { namespace experimental_dnn_34_v20 { } using namespace experimental_dnn_34_v20; }} -#else -#define CV__DNN_EXPERIMENTAL_NS_BEGIN -#define CV__DNN_EXPERIMENTAL_NS_END -#endif +#include "../dnn/version.hpp" #include namespace cv { namespace dnn { -CV__DNN_EXPERIMENTAL_NS_BEGIN +CV__DNN_INLINE_NS_BEGIN //! @addtogroup dnn //! @{ @@ -79,9 +72,8 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN DNN_BACKEND_INFERENCE_ENGINE, //!< Intel's Inference Engine computational backend //!< @sa setInferenceEngineBackendType DNN_BACKEND_OPENCV, - // OpenCV 4.x: DNN_BACKEND_VKCOM, - // OpenCV 4.x: DNN_BACKEND_CUDA, - + DNN_BACKEND_VKCOM, + DNN_BACKEND_CUDA, #ifdef __OPENCV_BUILD DNN_BACKEND_INFERENCE_ENGINE_NGRAPH = 1000000, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType() DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType() @@ -98,12 +90,28 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN DNN_TARGET_OPENCL, DNN_TARGET_OPENCL_FP16, DNN_TARGET_MYRIAD, - DNN_TARGET_FPGA //!< FPGA device with CPU fallbacks using Inference Engine's Heterogeneous plugin. + DNN_TARGET_VULKAN, + DNN_TARGET_FPGA, //!< FPGA device with CPU fallbacks using Inference Engine's Heterogeneous plugin. + DNN_TARGET_CUDA, + DNN_TARGET_CUDA_FP16, + DNN_TARGET_HDDL }; CV_EXPORTS std::vector< std::pair > getAvailableBackends(); CV_EXPORTS_W std::vector getAvailableTargets(dnn::Backend be); + /** + * @brief Enables detailed logging of the DNN model loading with CV DNN API. + * @param[in] isDiagnosticsMode Indicates whether diagnostic mode should be set. + * + * Diagnostic mode provides detailed logging of the model loading stage to explore + * potential problems (ex.: not implemented layer type). + * + * @note In diagnostic mode series of assertions will be skipped, it can lead to the + * expected application crash. + */ + CV_EXPORTS void enableModelDiagnostics(bool isDiagnosticsMode); + /** @brief This class provides all data needed to initialize layer. * * It includes dictionary with scalar params (which can be read by using Dict interface), @@ -288,6 +296,21 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN virtual Ptr initNgraph(const std::vector > &inputs, const std::vector >& nodes); + virtual Ptr initVkCom(const std::vector > &inputs); + + /** + * @brief Returns a CUDA backend node + * + * @param context void pointer to CSLContext object + * @param inputs layer inputs + * @param outputs layer outputs + */ + virtual Ptr initCUDA( + void *context, + const std::vector>& inputs, + const std::vector>& outputs + ); + /** * @brief Automatic Halide scheduling based on layer hyper-parameters. * @param[in] node Backend node with Halide functions. @@ -555,13 +578,16 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN * @see Target * * List of supported combinations backend / target: - * | | DNN_BACKEND_OPENCV | DNN_BACKEND_INFERENCE_ENGINE | DNN_BACKEND_HALIDE | - * |------------------------|--------------------|------------------------------|--------------------| - * | DNN_TARGET_CPU | + | + | + | - * | DNN_TARGET_OPENCL | + | + | + | - * | DNN_TARGET_OPENCL_FP16 | + | + | | - * | DNN_TARGET_MYRIAD | | + | | - * | DNN_TARGET_FPGA | | + | | + * | | DNN_BACKEND_OPENCV | DNN_BACKEND_INFERENCE_ENGINE | DNN_BACKEND_HALIDE | DNN_BACKEND_CUDA | + * |------------------------|--------------------|------------------------------|--------------------|-------------------| + * | DNN_TARGET_CPU | + | + | + | | + * | DNN_TARGET_OPENCL | + | + | + | | + * | DNN_TARGET_OPENCL_FP16 | + | + | | | + * | DNN_TARGET_MYRIAD | | + | | | + * | DNN_TARGET_FPGA | | + | | | + * | DNN_TARGET_CUDA | | | | + | + * | DNN_TARGET_CUDA_FP16 | | | | + | + * | DNN_TARGET_HDDL | | + | | | */ CV_WRAP void setPreferableTarget(int targetId); @@ -712,9 +738,11 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN CV_WRAP void enableFusion(bool fusion); /** @brief Returns overall time for inference and timings (in ticks) for layers. + * * Indexes in returned vector correspond to layers ids. Some layers can be fused with others, - * in this case zero ticks count will be return for that skipped layers. - * @param timings vector for tick timings for all layers. + * in this case zero ticks count will be return for that skipped layers. Supported by DNN_BACKEND_OPENCV on DNN_TARGET_CPU only. + * + * @param[out] timings vector for tick timings for all layers. * @return overall ticks for model inference. */ CV_WRAP int64 getPerfProfile(CV_OUT std::vector& timings); @@ -1056,8 +1084,513 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN CV_OUT std::vector& indices, const float eta = 1.f, const int top_k = 0); + + /** @brief This class is presented high-level API for neural networks. + * + * Model allows to set params for preprocessing input image. + * Model creates net from file with trained weights and config, + * sets preprocessing input and runs forward pass. + */ + class CV_EXPORTS_W_SIMPLE Model + { + public: + CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first) + Model(); + + Model(const Model&) = default; + Model(Model&&) = default; + Model& operator=(const Model&) = default; + Model& operator=(Model&&) = default; + + /** + * @brief Create model from deep learning network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP Model(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP Model(const Net& network); + + /** @brief Set input size for frame. + * @param[in] size New input size. + * @note If shape of the new blob less than 0, then frame size not change. + */ + CV_WRAP Model& setInputSize(const Size& size); + + /** @overload + * @param[in] width New input width. + * @param[in] height New input height. + */ + CV_WRAP inline + Model& setInputSize(int width, int height) { return setInputSize(Size(width, height)); } + + /** @brief Set mean value for frame. + * @param[in] mean Scalar with mean values which are subtracted from channels. + */ + CV_WRAP Model& setInputMean(const Scalar& mean); + + /** @brief Set scalefactor value for frame. + * @param[in] scale Multiplier for frame values. + */ + CV_WRAP Model& setInputScale(double scale); + + /** @brief Set flag crop for frame. + * @param[in] crop Flag which indicates whether image will be cropped after resize or not. + */ + CV_WRAP Model& setInputCrop(bool crop); + + /** @brief Set flag swapRB for frame. + * @param[in] swapRB Flag which indicates that swap first and last channels. + */ + CV_WRAP Model& setInputSwapRB(bool swapRB); + + /** @brief Set preprocessing parameters for frame. + * @param[in] size New input size. + * @param[in] mean Scalar with mean values which are subtracted from channels. + * @param[in] scale Multiplier for frame values. + * @param[in] swapRB Flag which indicates that swap first and last channels. + * @param[in] crop Flag which indicates whether image will be cropped after resize or not. + * blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) ) + */ + CV_WRAP void setInputParams(double scale = 1.0, const Size& size = Size(), + const Scalar& mean = Scalar(), bool swapRB = false, bool crop = false); + + /** @brief Given the @p input frame, create input blob, run net and return the output @p blobs. + * @param[in] frame The input image. + * @param[out] outs Allocated output blobs, which will store results of the computation. + */ + CV_WRAP void predict(InputArray frame, OutputArrayOfArrays outs) const; + + + // ============================== Net proxy methods ============================== + // Never expose methods with network implementation details, like: + // - addLayer, addLayerToPrev, connect, setInputsNames, setInputShape, setParam, getParam + // - getLayer*, getUnconnectedOutLayers, getUnconnectedOutLayersNames, getLayersShapes + // - forward* methods, setInput + + /// @sa Net::setPreferableBackend + CV_WRAP Model& setPreferableBackend(dnn::Backend backendId); + /// @sa Net::setPreferableTarget + CV_WRAP Model& setPreferableTarget(dnn::Target targetId); + + CV_DEPRECATED_EXTERNAL + operator Net&() const { return getNetwork_(); } + + //protected: - internal/tests usage only + Net& getNetwork_() const; + inline Net& getNetwork_() { return const_cast(this)->getNetwork_(); } + + struct Impl; + inline Impl* getImpl() const { return impl.get(); } + inline Impl& getImplRef() const { CV_DbgAssert(impl); return *impl.get(); } + protected: + Ptr impl; + }; + + /** @brief This class represents high-level API for classification models. + * + * ClassificationModel allows to set params for preprocessing input image. + * ClassificationModel creates net from file with trained weights and config, + * sets preprocessing input, runs forward pass and return top-1 prediction. + */ + class CV_EXPORTS_W_SIMPLE ClassificationModel : public Model + { + public: + /** + * @brief Create classification model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP ClassificationModel(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP ClassificationModel(const Net& network); + + /** @brief Given the @p input frame, create input blob, run net and return top-1 prediction. + * @param[in] frame The input image. + */ + std::pair classify(InputArray frame); + + /** @overload */ + CV_WRAP void classify(InputArray frame, CV_OUT int& classId, CV_OUT float& conf); + }; + + /** @brief This class represents high-level API for keypoints models + * + * KeypointsModel allows to set params for preprocessing input image. + * KeypointsModel creates net from file with trained weights and config, + * sets preprocessing input, runs forward pass and returns the x and y coordinates of each detected keypoint + */ + class CV_EXPORTS_W_SIMPLE KeypointsModel: public Model + { + public: + /** + * @brief Create keypoints model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP KeypointsModel(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP KeypointsModel(const Net& network); + + /** @brief Given the @p input frame, create input blob, run net + * @param[in] frame The input image. + * @param thresh minimum confidence threshold to select a keypoint + * @returns a vector holding the x and y coordinates of each detected keypoint + * + */ + CV_WRAP std::vector estimate(InputArray frame, float thresh=0.5); + }; + + /** @brief This class represents high-level API for segmentation models + * + * SegmentationModel allows to set params for preprocessing input image. + * SegmentationModel creates net from file with trained weights and config, + * sets preprocessing input, runs forward pass and returns the class prediction for each pixel. + */ + class CV_EXPORTS_W_SIMPLE SegmentationModel: public Model + { + public: + /** + * @brief Create segmentation model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP SegmentationModel(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP SegmentationModel(const Net& network); + + /** @brief Given the @p input frame, create input blob, run net + * @param[in] frame The input image. + * @param[out] mask Allocated class prediction for each pixel + */ + CV_WRAP void segment(InputArray frame, OutputArray mask); + }; + + /** @brief This class represents high-level API for object detection networks. + * + * DetectionModel allows to set params for preprocessing input image. + * DetectionModel creates net from file with trained weights and config, + * sets preprocessing input, runs forward pass and return result detections. + * For DetectionModel SSD, Faster R-CNN, YOLO topologies are supported. + */ + class CV_EXPORTS_W_SIMPLE DetectionModel : public Model + { + public: + /** + * @brief Create detection model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP DetectionModel(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP DetectionModel(const Net& network); + + CV_DEPRECATED_EXTERNAL // avoid using in C++ code (need to fix bindings first) + DetectionModel(); + + /** + * @brief nmsAcrossClasses defaults to false, + * such that when non max suppression is used during the detect() function, it will do so per-class. + * This function allows you to toggle this behaviour. + * @param[in] value The new value for nmsAcrossClasses + */ + CV_WRAP DetectionModel& setNmsAcrossClasses(bool value); + + /** + * @brief Getter for nmsAcrossClasses. This variable defaults to false, + * such that when non max suppression is used during the detect() function, it will do so only per-class + */ + CV_WRAP bool getNmsAcrossClasses(); + + /** @brief Given the @p input frame, create input blob, run net and return result detections. + * @param[in] frame The input image. + * @param[out] classIds Class indexes in result detection. + * @param[out] confidences A set of corresponding confidences. + * @param[out] boxes A set of bounding boxes. + * @param[in] confThreshold A threshold used to filter boxes by confidences. + * @param[in] nmsThreshold A threshold used in non maximum suppression. + */ + CV_WRAP void detect(InputArray frame, CV_OUT std::vector& classIds, + CV_OUT std::vector& confidences, CV_OUT std::vector& boxes, + float confThreshold = 0.5f, float nmsThreshold = 0.0f); + }; + + +/** @brief This class represents high-level API for text recognition networks. + * + * TextRecognitionModel allows to set params for preprocessing input image. + * TextRecognitionModel creates net from file with trained weights and config, + * sets preprocessing input, runs forward pass and return recognition result. + * For TextRecognitionModel, CRNN-CTC is supported. + */ +class CV_EXPORTS_W_SIMPLE TextRecognitionModel : public Model +{ +public: + CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first) + TextRecognitionModel(); + + /** + * @brief Create Text Recognition model from deep learning network + * Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method + * @param[in] network Net object + */ + CV_WRAP TextRecognitionModel(const Net& network); + + /** + * @brief Create text recognition model from network represented in one of the supported formats + * Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method + * @param[in] model Binary file contains trained weights + * @param[in] config Text file contains network configuration + */ + CV_WRAP inline + TextRecognitionModel(const std::string& model, const std::string& config = "") + : TextRecognitionModel(readNet(model, config)) { /* nothing */ } + + /** + * @brief Set the decoding method of translating the network output into string + * @param[in] decodeType The decoding method of translating the network output into string: {'CTC-greedy': greedy decoding for the output of CTC-based methods} + */ + CV_WRAP + TextRecognitionModel& setDecodeType(const std::string& decodeType); + + /** + * @brief Get the decoding method + * @return the decoding method + */ + CV_WRAP + const std::string& getDecodeType() const; + + /** + * @brief Set the vocabulary for recognition. + * @param[in] vocabulary the associated vocabulary of the network. + */ + CV_WRAP + TextRecognitionModel& setVocabulary(const std::vector& vocabulary); + + /** + * @brief Get the vocabulary for recognition. + * @return vocabulary the associated vocabulary + */ + CV_WRAP + const std::vector& getVocabulary() const; + + /** + * @brief Given the @p input frame, create input blob, run net and return recognition result + * @param[in] frame The input image + * @return The text recognition result + */ + CV_WRAP + std::string recognize(InputArray frame) const; + + /** + * @brief Given the @p input frame, create input blob, run net and return recognition result + * @param[in] frame The input image + * @param[in] roiRects List of text detection regions of interest (cv::Rect, CV_32SC4). ROIs is be cropped as the network inputs + * @param[out] results A set of text recognition results. + */ + CV_WRAP + void recognize(InputArray frame, InputArrayOfArrays roiRects, CV_OUT std::vector& results) const; +}; + + +/** @brief Base class for text detection networks + */ +class CV_EXPORTS_W_SIMPLE TextDetectionModel : public Model +{ +protected: + CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first) + TextDetectionModel(); + +public: + + /** @brief Performs detection + * + * Given the input @p frame, prepare network input, run network inference, post-process network output and return result detections. + * + * Each result is quadrangle's 4 points in this order: + * - bottom-left + * - top-left + * - top-right + * - bottom-right + * + * Use cv::getPerspectiveTransform function to retrive image region without perspective transformations. + * + * @note If DL model doesn't support that kind of output then result may be derived from detectTextRectangles() output. + * + * @param[in] frame The input image + * @param[out] detections array with detections' quadrangles (4 points per result) + * @param[out] confidences array with detection confidences + */ + CV_WRAP + void detect( + InputArray frame, + CV_OUT std::vector< std::vector >& detections, + CV_OUT std::vector& confidences + ) const; + + /** @overload */ + CV_WRAP + void detect( + InputArray frame, + CV_OUT std::vector< std::vector >& detections + ) const; + + /** @brief Performs detection + * + * Given the input @p frame, prepare network input, run network inference, post-process network output and return result detections. + * + * Each result is rotated rectangle. + * + * @note Result may be inaccurate in case of strong perspective transformations. + * + * @param[in] frame the input image + * @param[out] detections array with detections' RotationRect results + * @param[out] confidences array with detection confidences + */ + CV_WRAP + void detectTextRectangles( + InputArray frame, + CV_OUT std::vector& detections, + CV_OUT std::vector& confidences + ) const; + + /** @overload */ + CV_WRAP + void detectTextRectangles( + InputArray frame, + CV_OUT std::vector& detections + ) const; +}; + +/** @brief This class represents high-level API for text detection DL networks compatible with EAST model. + * + * Configurable parameters: + * - (float) confThreshold - used to filter boxes by confidences, default: 0.5f + * - (float) nmsThreshold - used in non maximum suppression, default: 0.0f + */ +class CV_EXPORTS_W_SIMPLE TextDetectionModel_EAST : public TextDetectionModel +{ +public: + CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first) + TextDetectionModel_EAST(); + + /** + * @brief Create text detection algorithm from deep learning network + * @param[in] network Net object + */ + CV_WRAP TextDetectionModel_EAST(const Net& network); + + /** + * @brief Create text detection model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP inline + TextDetectionModel_EAST(const std::string& model, const std::string& config = "") + : TextDetectionModel_EAST(readNet(model, config)) { /* nothing */ } + + /** + * @brief Set the detection confidence threshold + * @param[in] confThreshold A threshold used to filter boxes by confidences + */ + CV_WRAP + TextDetectionModel_EAST& setConfidenceThreshold(float confThreshold); + + /** + * @brief Get the detection confidence threshold + */ + CV_WRAP + float getConfidenceThreshold() const; + + /** + * @brief Set the detection NMS filter threshold + * @param[in] nmsThreshold A threshold used in non maximum suppression + */ + CV_WRAP + TextDetectionModel_EAST& setNMSThreshold(float nmsThreshold); + + /** + * @brief Get the detection confidence threshold + */ + CV_WRAP + float getNMSThreshold() const; +}; + +/** @brief This class represents high-level API for text detection DL networks compatible with DB model. + * + * Related publications: @cite liao2020real + * Paper: https://arxiv.org/abs/1911.08947 + * For more information about the hyper-parameters setting, please refer to https://github.com/MhLiao/DB + * + * Configurable parameters: + * - (float) binaryThreshold - The threshold of the binary map. It is usually set to 0.3. + * - (float) polygonThreshold - The threshold of text polygons. It is usually set to 0.5, 0.6, and 0.7. Default is 0.5f + * - (double) unclipRatio - The unclip ratio of the detected text region, which determines the output size. It is usually set to 2.0. + * - (int) maxCandidates - The max number of the output results. + */ +class CV_EXPORTS_W_SIMPLE TextDetectionModel_DB : public TextDetectionModel +{ +public: + CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first) + TextDetectionModel_DB(); + + /** + * @brief Create text detection algorithm from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP TextDetectionModel_DB(const Net& network); + + /** + * @brief Create text detection model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP inline + TextDetectionModel_DB(const std::string& model, const std::string& config = "") + : TextDetectionModel_DB(readNet(model, config)) { /* nothing */ } + + CV_WRAP TextDetectionModel_DB& setBinaryThreshold(float binaryThreshold); + CV_WRAP float getBinaryThreshold() const; + + CV_WRAP TextDetectionModel_DB& setPolygonThreshold(float polygonThreshold); + CV_WRAP float getPolygonThreshold() const; + + CV_WRAP TextDetectionModel_DB& setUnclipRatio(double unclipRatio); + CV_WRAP double getUnclipRatio() const; + + CV_WRAP TextDetectionModel_DB& setMaxCandidates(int maxCandidates); + CV_WRAP int getMaxCandidates() const; +}; + //! @} -CV__DNN_EXPERIMENTAL_NS_END +CV__DNN_INLINE_NS_END } } diff --git a/3rdparty/include/opencv2/dnn/dnn.inl.hpp b/3rdparty/include/opencv2/dnn/dnn.inl.hpp index 17d4c200bd..8312a418f3 100644 --- a/3rdparty/include/opencv2/dnn/dnn.inl.hpp +++ b/3rdparty/include/opencv2/dnn/dnn.inl.hpp @@ -46,7 +46,7 @@ namespace cv { namespace dnn { -CV__DNN_EXPERIMENTAL_NS_BEGIN +CV__DNN_INLINE_NS_BEGIN template DictValue DictValue::arrayInt(TypeIter begin, int size) @@ -199,6 +199,16 @@ inline void DictValue::release() case Param::REAL: delete pd; break; + case Param::BOOLEAN: + case Param::MAT: + case Param::MAT_VECTOR: + case Param::ALGORITHM: + case Param::FLOAT: + case Param::UNSIGNED_INT: + case Param::UINT64: + case Param::UCHAR: + case Param::SCALAR: + break; // unhandled } } @@ -237,6 +247,7 @@ inline DictValue & DictValue::operator=(const DictValue &r) } inline DictValue::DictValue(const DictValue &r) + : pv(NULL) { type = r.type; @@ -273,12 +284,18 @@ inline int DictValue::size() const return (int)ps->size(); case Param::REAL: return (int)pd->size(); + case Param::BOOLEAN: + case Param::MAT: + case Param::MAT_VECTOR: + case Param::ALGORITHM: + case Param::FLOAT: + case Param::UNSIGNED_INT: + case Param::UINT64: + case Param::UCHAR: + case Param::SCALAR: + break; // unhandled } -#ifdef __OPENCV_BUILD - CV_Error(Error::StsInternal, ""); -#else - CV_ErrorNoReturn(Error::StsInternal, ""); -#endif + CV_Error_(Error::StsInternal, ("Unhandled type (%d)", static_cast(type))); } inline std::ostream &operator<<(std::ostream &stream, const DictValue &dictv) @@ -388,7 +405,7 @@ inline std::map::const_iterator Dict::end() const return dict.end(); } -CV__DNN_EXPERIMENTAL_NS_END +CV__DNN_INLINE_NS_END } } diff --git a/3rdparty/include/opencv2/dnn/layer.details.hpp b/3rdparty/include/opencv2/dnn/layer.details.hpp index 619514e827..1133da562e 100644 --- a/3rdparty/include/opencv2/dnn/layer.details.hpp +++ b/3rdparty/include/opencv2/dnn/layer.details.hpp @@ -9,7 +9,7 @@ namespace cv { namespace dnn { -CV__DNN_EXPERIMENTAL_NS_BEGIN +CV__DNN_INLINE_NS_BEGIN /** @brief Registers layer constructor in runtime. * @param type string, containing type name of the layer. @@ -72,7 +72,7 @@ public: }; } // namespace -CV__DNN_EXPERIMENTAL_NS_END +CV__DNN_INLINE_NS_END }} // namespace #endif diff --git a/3rdparty/include/opencv2/dnn/layer.hpp b/3rdparty/include/opencv2/dnn/layer.hpp index c4712b8e7a..8500599371 100644 --- a/3rdparty/include/opencv2/dnn/layer.hpp +++ b/3rdparty/include/opencv2/dnn/layer.hpp @@ -45,7 +45,7 @@ namespace cv { namespace dnn { -CV__DNN_EXPERIMENTAL_NS_BEGIN +CV__DNN_INLINE_NS_BEGIN //! @addtogroup dnn //! @{ //! @@ -79,7 +79,7 @@ private: //! @} //! @} -CV__DNN_EXPERIMENTAL_NS_END +CV__DNN_INLINE_NS_END } } #endif diff --git a/3rdparty/include/opencv2/dnn/shape_utils.hpp b/3rdparty/include/opencv2/dnn/shape_utils.hpp index c975fcff04..4c610f6cef 100644 --- a/3rdparty/include/opencv2/dnn/shape_utils.hpp +++ b/3rdparty/include/opencv2/dnn/shape_utils.hpp @@ -50,7 +50,7 @@ namespace cv { namespace dnn { -CV__DNN_EXPERIMENTAL_NS_BEGIN +CV__DNN_INLINE_NS_BEGIN //Slicing @@ -205,25 +205,55 @@ static inline std::ostream& operator<<(std::ostream &out, const MatShape& shape) return out; } -inline int clamp(int ax, int dims) +/// @brief Converts axis from `[-dims; dims)` (similar to Python's slice notation) to `[0; dims)` range. +static inline +int normalize_axis(int axis, int dims) { - return ax < 0 ? ax + dims : ax; + CV_Check(axis, axis >= -dims && axis < dims, ""); + axis = (axis < 0) ? (dims + axis) : axis; + CV_DbgCheck(axis, axis >= 0 && axis < dims, ""); + return axis; } -inline int clamp(int ax, const MatShape& shape) +static inline +int normalize_axis(int axis, const MatShape& shape) { - return clamp(ax, (int)shape.size()); + return normalize_axis(axis, (int)shape.size()); } -inline Range clamp(const Range& r, int axisSize) +static inline +Range normalize_axis_range(const Range& r, int axisSize) { - Range clamped(std::max(r.start, 0), + if (r == Range::all()) + return Range(0, axisSize); + CV_CheckGE(r.start, 0, ""); + Range clamped(r.start, r.end > 0 ? std::min(r.end, axisSize) : axisSize + r.end + 1); - CV_Assert_N(clamped.start < clamped.end, clamped.end <= axisSize); + CV_DbgCheckGE(clamped.start, 0, ""); + CV_CheckLT(clamped.start, clamped.end, ""); + CV_CheckLE(clamped.end, axisSize, ""); return clamped; } -CV__DNN_EXPERIMENTAL_NS_END +static inline +bool isAllOnes(const MatShape &inputShape, int startPos, int endPos) +{ + CV_Assert(!inputShape.empty()); + + CV_CheckGE((int) inputShape.size(), startPos, ""); + CV_CheckGE(startPos, 0, ""); + CV_CheckLE(startPos, endPos, ""); + CV_CheckLE((size_t)endPos, inputShape.size(), ""); + + for (size_t i = startPos; i < endPos; i++) + { + if (inputShape[i] != 1) + return false; + } + return true; +} + +CV__DNN_INLINE_NS_END } } #endif diff --git a/3rdparty/include/opencv2/dnn/utils/inference_engine.hpp b/3rdparty/include/opencv2/dnn/utils/inference_engine.hpp index cda2f9bfad..333b1bfdd2 100644 --- a/3rdparty/include/opencv2/dnn/utils/inference_engine.hpp +++ b/3rdparty/include/opencv2/dnn/utils/inference_engine.hpp @@ -11,7 +11,7 @@ #include "../dnn.hpp" namespace cv { namespace dnn { -CV__DNN_EXPERIMENTAL_NS_BEGIN +CV__DNN_INLINE_NS_BEGIN /* Values for 'OPENCV_DNN_BACKEND_INFERENCE_ENGINE_TYPE' parameter */ @@ -49,6 +49,8 @@ CV_EXPORTS_W void resetMyriadDevice(); #define CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2 "Myriad2" /// Intel(R) Neural Compute Stick 2, NCS2 (USB 03e7:2485), MyriadX (https://software.intel.com/ru-ru/neural-compute-stick) #define CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X "MyriadX" +#define CV_DNN_INFERENCE_ENGINE_CPU_TYPE_ARM_COMPUTE "ARM_COMPUTE" +#define CV_DNN_INFERENCE_ENGINE_CPU_TYPE_X86 "X86" /** @brief Returns Inference Engine VPU type. @@ -57,8 +59,18 @@ CV_EXPORTS_W void resetMyriadDevice(); */ CV_EXPORTS_W cv::String getInferenceEngineVPUType(); +/** @brief Returns Inference Engine CPU type. + * + * Specify OpenVINO plugin: CPU or ARM. + */ +CV_EXPORTS_W cv::String getInferenceEngineCPUType(); -CV__DNN_EXPERIMENTAL_NS_END +/** @brief Release a HDDL plugin. + */ +CV_EXPORTS_W void releaseHDDLPlugin(); + + +CV__DNN_INLINE_NS_END }} // namespace #endif // OPENCV_DNN_UTILS_INF_ENGINE_HPP diff --git a/3rdparty/include/opencv2/dnn/version.hpp b/3rdparty/include/opencv2/dnn/version.hpp new file mode 100644 index 0000000000..0efc9c0237 --- /dev/null +++ b/3rdparty/include/opencv2/dnn/version.hpp @@ -0,0 +1,21 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_DNN_VERSION_HPP +#define OPENCV_DNN_VERSION_HPP + +/// Use with major OpenCV version only. +#define OPENCV_DNN_API_VERSION 20210608 + +#if !defined CV_DOXYGEN && !defined CV_STATIC_ANALYSIS && !defined CV_DNN_DONT_ADD_INLINE_NS +#define CV__DNN_INLINE_NS __CV_CAT(dnn4_v, OPENCV_DNN_API_VERSION) +#define CV__DNN_INLINE_NS_BEGIN namespace CV__DNN_INLINE_NS { +#define CV__DNN_INLINE_NS_END } +namespace cv { namespace dnn { namespace CV__DNN_INLINE_NS { } using namespace CV__DNN_INLINE_NS; }} +#else +#define CV__DNN_INLINE_NS_BEGIN +#define CV__DNN_INLINE_NS_END +#endif + +#endif // OPENCV_DNN_VERSION_HPP diff --git a/3rdparty/include/opencv2/dpm.hpp b/3rdparty/include/opencv2/dpm.hpp deleted file mode 100644 index ab604abf3f..0000000000 --- a/3rdparty/include/opencv2/dpm.hpp +++ /dev/null @@ -1,153 +0,0 @@ -/*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) 2015, Itseez 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 Itseez Inc 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. -// -// Implementation authors: -// Jiaolong Xu - jiaolongxu@gmail.com -// Evgeniy Kozinov - evgeniy.kozinov@gmail.com -// Valentina Kustikova - valentina.kustikova@gmail.com -// Nikolai Zolotykh - Nikolai.Zolotykh@gmail.com -// Iosif Meyerov - meerov@vmk.unn.ru -// Alexey Polovinkin - polovinkin.alexey@gmail.com -// -//M*/ - -#ifndef __OPENCV_LATENTSVM_HPP__ -#define __OPENCV_LATENTSVM_HPP__ - -#include "opencv2/core.hpp" - -#include -#include -#include - -/** @defgroup dpm Deformable Part-based Models - -Discriminatively Trained Part Based Models for Object Detection ---------------------------------------------------------------- - -The object detector described below has been initially proposed by P.F. Felzenszwalb in -@cite Felzenszwalb2010a . It is based on a Dalal-Triggs detector that uses a single filter on histogram -of oriented gradients (HOG) features to represent an object category. This detector uses a sliding -window approach, where a filter is applied at all positions and scales of an image. The first -innovation is enriching the Dalal-Triggs model using a star-structured part-based model defined by a -"root" filter (analogous to the Dalal-Triggs filter) plus a set of parts filters and associated -deformation models. The score of one of star models at a particular position and scale within an -image is the score of the root filter at the given location plus the sum over parts of the maximum, -over placements of that part, of the part filter score on its location minus a deformation cost -easuring the deviation of the part from its ideal location relative to the root. Both root and part -filter scores are defined by the dot product between a filter (a set of weights) and a subwindow of -a feature pyramid computed from the input image. Another improvement is a representation of the -class of models by a mixture of star models. The score of a mixture model at a particular position -and scale is the maximum over components, of the score of that component model at the given -location. - -The detector was dramatically speeded-up with cascade algorithm proposed by P.F. Felzenszwalb in -@cite Felzenszwalb2010b . The algorithm prunes partial hypotheses using thresholds on their scores.The -basic idea of the algorithm is to use a hierarchy of models defined by an ordering of the original -model's parts. For a model with (n+1) parts, including the root, a sequence of (n+1) models is -obtained. The i-th model in this sequence is defined by the first i parts from the original model. -Using this hierarchy, low scoring hypotheses can be pruned after looking at the best configuration -of a subset of the parts. Hypotheses that score high under a weak model are evaluated further using -a richer model. - -In OpenCV there is an C++ implementation of DPM cascade detector. - -*/ - -namespace cv -{ - -namespace dpm -{ - -//! @addtogroup dpm -//! @{ - -/** @brief This is a C++ abstract class, it provides external user API to work with DPM. - */ -class CV_EXPORTS_W DPMDetector -{ -public: - - struct CV_EXPORTS_W ObjectDetection - { - ObjectDetection(); - ObjectDetection( const Rect& rect, float score, int classID=-1 ); - Rect rect; - float score; - int classID; - }; - - virtual bool isEmpty() const = 0; - - /** @brief Find rectangular regions in the given image that are likely to contain objects of loaded classes - (models) and corresponding confidence levels. - @param image An image. - @param objects The detections: rectangulars, scores and class IDs. - */ - virtual void detect(cv::Mat &image, CV_OUT std::vector &objects) = 0; - - /** @brief Return the class (model) names that were passed in constructor or method load or extracted from - models filenames in those methods. - */ - virtual std::vector const& getClassNames() const = 0; - - /** @brief Return a count of loaded models (classes). - */ - virtual size_t getClassCount() const = 0; - - /** @brief Load the trained models from given .xml files and return cv::Ptr\. - @param filenames A set of filenames storing the trained detectors (models). Each file contains one - model. See examples of such files here `/opencv_extra/testdata/cv/dpm/VOC2007_Cascade/`. - @param classNames A set of trained models names. If it's empty then the name of each model will be - constructed from the name of file containing the model. E.g. the model stored in - "/home/user/cat.xml" will get the name "cat". - */ - static cv::Ptr create(std::vector const &filenames, - std::vector const &classNames = std::vector()); - - virtual ~DPMDetector(){} -}; - -//! @} - -} // namespace dpm -} // namespace cv - -#endif diff --git a/3rdparty/include/opencv2/face.hpp b/3rdparty/include/opencv2/face.hpp deleted file mode 100644 index b24c07e41e..0000000000 --- a/3rdparty/include/opencv2/face.hpp +++ /dev/null @@ -1,386 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2013, OpenCV Foundation, 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -#ifndef __OPENCV_FACE_HPP__ -#define __OPENCV_FACE_HPP__ - -/** -@defgroup face Face Analysis - -- @ref face_changelog -- @ref tutorial_face_main - -*/ - -#include "opencv2/core.hpp" -#include "face/predict_collector.hpp" -#include - -namespace cv { namespace face { - -//! @addtogroup face -//! @{ - -/** @brief Abstract base class for all face recognition models - -All face recognition models in OpenCV are derived from the abstract base class FaceRecognizer, which -provides a unified access to all face recongition algorithms in OpenCV. - -### Description - -I'll go a bit more into detail explaining FaceRecognizer, because it doesn't look like a powerful -interface at first sight. But: Every FaceRecognizer is an Algorithm, so you can easily get/set all -model internals (if allowed by the implementation). Algorithm is a relatively new OpenCV concept, -which is available since the 2.4 release. I suggest you take a look at its description. - -Algorithm provides the following features for all derived classes: - -- So called "virtual constructor". That is, each Algorithm derivative is registered at program - start and you can get the list of registered algorithms and create instance of a particular - algorithm by its name (see Algorithm::create). If you plan to add your own algorithms, it is - good practice to add a unique prefix to your algorithms to distinguish them from other - algorithms. -- Setting/Retrieving algorithm parameters by name. If you used video capturing functionality from - OpenCV highgui module, you are probably familar with cv::cvSetCaptureProperty, -ocvcvGetCaptureProperty, VideoCapture::set and VideoCapture::get. Algorithm provides similar - method where instead of integer id's you specify the parameter names as text Strings. See - Algorithm::set and Algorithm::get for details. -- Reading and writing parameters from/to XML or YAML files. Every Algorithm derivative can store - all its parameters and then read them back. There is no need to re-implement it each time. - -Moreover every FaceRecognizer supports the: - -- **Training** of a FaceRecognizer with FaceRecognizer::train on a given set of images (your face - database!). -- **Prediction** of a given sample image, that means a face. The image is given as a Mat. -- **Loading/Saving** the model state from/to a given XML or YAML. -- **Setting/Getting labels info**, that is stored as a string. String labels info is useful for - keeping names of the recognized people. - -@note When using the FaceRecognizer interface in combination with Python, please stick to Python 2. -Some underlying scripts like create_csv will not work in other versions, like Python 3. Setting the -Thresholds +++++++++++++++++++++++ - -Sometimes you run into the situation, when you want to apply a threshold on the prediction. A common -scenario in face recognition is to tell, whether a face belongs to the training dataset or if it is -unknown. You might wonder, why there's no public API in FaceRecognizer to set the threshold for the -prediction, but rest assured: It's supported. It just means there's no generic way in an abstract -class to provide an interface for setting/getting the thresholds of *every possible* FaceRecognizer -algorithm. The appropriate place to set the thresholds is in the constructor of the specific -FaceRecognizer and since every FaceRecognizer is a Algorithm (see above), you can get/set the -thresholds at runtime! - -Here is an example of setting a threshold for the Eigenfaces method, when creating the model: - -@code -// Let's say we want to keep 10 Eigenfaces and have a threshold value of 10.0 -int num_components = 10; -double threshold = 10.0; -// Then if you want to have a cv::FaceRecognizer with a confidence threshold, -// create the concrete implementation with the appropriate parameters: -Ptr model = EigenFaceRecognizer::create(num_components, threshold); -@endcode - -Sometimes it's impossible to train the model, just to experiment with threshold values. Thanks to -Algorithm it's possible to set internal model thresholds during runtime. Let's see how we would -set/get the prediction for the Eigenface model, we've created above: - -@code -// The following line reads the threshold from the Eigenfaces model: -double current_threshold = model->getDouble("threshold"); -// And this line sets the threshold to 0.0: -model->set("threshold", 0.0); -@endcode - -If you've set the threshold to 0.0 as we did above, then: - -@code -// -Mat img = imread("person1/3.jpg", CV_LOAD_IMAGE_GRAYSCALE); -// Get a prediction from the model. Note: We've set a threshold of 0.0 above, -// since the distance is almost always larger than 0.0, you'll get -1 as -// label, which indicates, this face is unknown -int predicted_label = model->predict(img); -// ... -@endcode - -is going to yield -1 as predicted label, which states this face is unknown. - -### Getting the name of a FaceRecognizer - -Since every FaceRecognizer is a Algorithm, you can use Algorithm::name to get the name of a -FaceRecognizer: - -@code -// Create a FaceRecognizer: -Ptr model = EigenFaceRecognizer::create(); -// And here's how to get its name: -String name = model->name(); -@endcode - - */ -class CV_EXPORTS_W FaceRecognizer : public Algorithm -{ -public: - /** @brief Trains a FaceRecognizer with given data and associated labels. - - @param src The training images, that means the faces you want to learn. The data has to be - given as a vector\. - @param labels The labels corresponding to the images have to be given either as a vector\ - or a Mat of type CV_32SC1. - - The following source code snippet shows you how to learn a Fisherfaces model on a given set of - images. The images are read with imread and pushed into a std::vector\. The labels of each - image are stored within a std::vector\ (you could also use a Mat of type CV_32SC1). Think of - the label as the subject (the person) this image belongs to, so same subjects (persons) should have - the same label. For the available FaceRecognizer you don't have to pay any attention to the order of - the labels, just make sure same persons have the same label: - - @code - // holds images and labels - vector images; - vector labels; - // using Mat of type CV_32SC1 - // Mat labels(number_of_samples, 1, CV_32SC1); - // images for first person - images.push_back(imread("person0/0.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0); - images.push_back(imread("person0/1.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0); - images.push_back(imread("person0/2.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0); - // images for second person - images.push_back(imread("person1/0.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1); - images.push_back(imread("person1/1.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1); - images.push_back(imread("person1/2.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1); - @endcode - - Now that you have read some images, we can create a new FaceRecognizer. In this example I'll create - a Fisherfaces model and decide to keep all of the possible Fisherfaces: - - @code - // Create a new Fisherfaces model and retain all available Fisherfaces, - // this is the most common usage of this specific FaceRecognizer: - // - Ptr model = FisherFaceRecognizer::create(); - @endcode - - And finally train it on the given dataset (the face images and labels): - - @code - // This is the common interface to train all of the available cv::FaceRecognizer - // implementations: - // - model->train(images, labels); - @endcode - */ - CV_WRAP virtual void train(InputArrayOfArrays src, InputArray labels) = 0; - - /** @brief Updates a FaceRecognizer with given data and associated labels. - - @param src The training images, that means the faces you want to learn. The data has to be given - as a vector\. - @param labels The labels corresponding to the images have to be given either as a vector\ or - a Mat of type CV_32SC1. - - This method updates a (probably trained) FaceRecognizer, but only if the algorithm supports it. The - Local Binary Patterns Histograms (LBPH) recognizer (see createLBPHFaceRecognizer) can be updated. - For the Eigenfaces and Fisherfaces method, this is algorithmically not possible and you have to - re-estimate the model with FaceRecognizer::train. In any case, a call to train empties the existing - model and learns a new model, while update does not delete any model data. - - @code - // Create a new LBPH model (it can be updated) and use the default parameters, - // this is the most common usage of this specific FaceRecognizer: - // - Ptr model = LBPHFaceRecognizer::create(); - // This is the common interface to train all of the available cv::FaceRecognizer - // implementations: - // - model->train(images, labels); - // Some containers to hold new image: - vector newImages; - vector newLabels; - // You should add some images to the containers: - // - // ... - // - // Now updating the model is as easy as calling: - model->update(newImages,newLabels); - // This will preserve the old model data and extend the existing model - // with the new features extracted from newImages! - @endcode - - Calling update on an Eigenfaces model (see EigenFaceRecognizer::create), which doesn't support - updating, will throw an error similar to: - - @code - OpenCV Error: The function/feature is not implemented (This FaceRecognizer (FaceRecognizer.Eigenfaces) does not support updating, you have to use FaceRecognizer::train to update it.) in update, file /home/philipp/git/opencv/modules/contrib/src/facerec.cpp, line 305 - terminate called after throwing an instance of 'cv::Exception' - @endcode - - @note The FaceRecognizer does not store your training images, because this would be very - memory intense and it's not the responsibility of te FaceRecognizer to do so. The caller is - responsible for maintaining the dataset, he want to work with. - */ - CV_WRAP virtual void update(InputArrayOfArrays src, InputArray labels); - - /** @overload */ - CV_WRAP_AS(predict_label) int predict(InputArray src) const; - - - /** @brief Predicts a label and associated confidence (e.g. distance) for a given input image. - - @param src Sample image to get a prediction from. - @param label The predicted label for the given image. - @param confidence Associated confidence (e.g. distance) for the predicted label. - - The suffix const means that prediction does not affect the internal model state, so the method can - be safely called from within different threads. - - The following example shows how to get a prediction from a trained model: - - @code - using namespace cv; - // Do your initialization here (create the cv::FaceRecognizer model) ... - // ... - // Read in a sample image: - Mat img = imread("person1/3.jpg", CV_LOAD_IMAGE_GRAYSCALE); - // And get a prediction from the cv::FaceRecognizer: - int predicted = model->predict(img); - @endcode - - Or to get a prediction and the associated confidence (e.g. distance): - - @code - using namespace cv; - // Do your initialization here (create the cv::FaceRecognizer model) ... - // ... - Mat img = imread("person1/3.jpg", CV_LOAD_IMAGE_GRAYSCALE); - // Some variables for the predicted label and associated confidence (e.g. distance): - int predicted_label = -1; - double predicted_confidence = 0.0; - // Get the prediction and associated confidence from the model - model->predict(img, predicted_label, predicted_confidence); - @endcode - */ - CV_WRAP void predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) const; - - - /** @brief - if implemented - send all result of prediction to collector that can be used for somehow custom result handling - @param src Sample image to get a prediction from. - @param collector User-defined collector object that accepts all results - - To implement this method u just have to do same internal cycle as in predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) but - not try to get "best@ result, just resend it to caller side with given collector - */ - CV_WRAP_AS(predict_collect) virtual void predict(InputArray src, Ptr collector) const = 0; - - /** @brief Saves a FaceRecognizer and its model state. - - Saves this model to a given filename, either as XML or YAML. - @param filename The filename to store this FaceRecognizer to (either XML/YAML). - - Every FaceRecognizer overwrites FaceRecognizer::save(FileStorage& fs) to save the internal model - state. FaceRecognizer::save(const String& filename) saves the state of a model to the given - filename. - - The suffix const means that prediction does not affect the internal model state, so the method can - be safely called from within different threads. - */ - CV_WRAP virtual void write(const String& filename) const; - - /** @brief Loads a FaceRecognizer and its model state. - - Loads a persisted model and state from a given XML or YAML file . Every FaceRecognizer has to - overwrite FaceRecognizer::load(FileStorage& fs) to enable loading the model state. - FaceRecognizer::load(FileStorage& fs) in turn gets called by - FaceRecognizer::load(const String& filename), to ease saving a model. - */ - CV_WRAP virtual void read(const String& filename); - - /** @overload - Saves this model to a given FileStorage. - @param fs The FileStorage to store this FaceRecognizer to. - */ - virtual void write(FileStorage& fs) const CV_OVERRIDE = 0; - - /** @overload */ - virtual void read(const FileNode& fn) CV_OVERRIDE = 0; - - /** @overload */ - virtual bool empty() const CV_OVERRIDE = 0; - - /** @brief Sets string info for the specified model's label. - - The string info is replaced by the provided value if it was set before for the specified label. - */ - CV_WRAP virtual void setLabelInfo(int label, const String& strInfo); - - /** @brief Gets string information by label. - - If an unknown label id is provided or there is no label information associated with the specified - label id the method returns an empty string. - */ - CV_WRAP virtual String getLabelInfo(int label) const; - - /** @brief Gets vector of labels by string. - - The function searches for the labels containing the specified sub-string in the associated string - info. - */ - CV_WRAP virtual std::vector getLabelsByString(const String& str) const; - /** @brief threshold parameter accessor - required for default BestMinDist collector */ - virtual double getThreshold() const = 0; - /** @brief Sets threshold of model */ - virtual void setThreshold(double val) = 0; -protected: - // Stored pairs "label id - string info" - std::map _labelsInfo; -}; - -//! @} - -}} - -#include "opencv2/face/facerec.hpp" -#include "opencv2/face/facemark.hpp" -#include "opencv2/face/facemark_train.hpp" -#include "opencv2/face/facemarkLBF.hpp" -#include "opencv2/face/facemarkAAM.hpp" -#include "opencv2/face/face_alignment.hpp" -#include "opencv2/face/mace.hpp" - -#endif // __OPENCV_FACE_HPP__ diff --git a/3rdparty/include/opencv2/face/bif.hpp b/3rdparty/include/opencv2/face/bif.hpp deleted file mode 100644 index d4f0ec53b3..0000000000 --- a/3rdparty/include/opencv2/face/bif.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2000-2015, Intel Corporation, all rights reserved. -Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. -Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. -Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. -Copyright (C) 2015, OpenCV Foundation, all rights reserved. -Copyright (C) 2015, Itseez 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -#ifndef __OPENCV_BIF_HPP__ -#define __OPENCV_BIF_HPP__ - -#include "opencv2/core.hpp" - -namespace cv { -namespace face { - -/** Implementation of bio-inspired features (BIF) from the paper: - * Guo, Guodong, et al. "Human age estimation using bio-inspired features." - * Computer Vision and Pattern Recognition, 2009. CVPR 2009. - */ -class CV_EXPORTS_W BIF : public Algorithm { -public: - /** @returns The number of filter bands used for computing BIF. */ - CV_WRAP virtual int getNumBands() const = 0; - - /** @returns The number of image rotations. */ - CV_WRAP virtual int getNumRotations() const = 0; - - /** Computes features sby input image. - * @param image Input image (CV_32FC1). - * @param features Feature vector (CV_32FC1). - */ - CV_WRAP virtual void compute(InputArray image, - OutputArray features) const = 0; - - /** - * @param num_bands The number of filter bands (<=8) used for computing BIF. - * @param num_rotations The number of image rotations for computing BIF. - * @returns Object for computing BIF. - */ - CV_WRAP static Ptr create(int num_bands = 8, int num_rotations = 12); -}; - -} // namespace cv -} // namespace face - -#endif // #ifndef __OPENCV_FACEREC_HPP__ diff --git a/3rdparty/include/opencv2/face/face_alignment.hpp b/3rdparty/include/opencv2/face/face_alignment.hpp deleted file mode 100644 index e96081c77b..0000000000 --- a/3rdparty/include/opencv2/face/face_alignment.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. -#ifndef __OPENCV_FACE_ALIGNMENT_HPP__ -#define __OPENCV_FACE_ALIGNMENT_HPP__ - -#include "opencv2/face/facemark_train.hpp" - -namespace cv{ -namespace face{ -class CV_EXPORTS_W FacemarkKazemi : public Facemark -{ -public: - struct CV_EXPORTS Params - { - /** - * \brief Constructor - */ - Params(); - /// cascade_depth This stores the deapth of cascade used for training. - unsigned long cascade_depth; - /// tree_depth This stores the max height of the regression tree built. - unsigned long tree_depth; - /// num_trees_per_cascade_level This stores number of trees fit per cascade level. - unsigned long num_trees_per_cascade_level; - /// learning_rate stores the learning rate in gradient boosting, also referred as shrinkage. - float learning_rate; - /// oversampling_amount stores number of initialisations used to create training samples. - unsigned long oversampling_amount; - /// num_test_coordinates stores number of test coordinates. - unsigned long num_test_coordinates; - /// lambda stores a value to calculate probability of closeness of two coordinates. - float lambda; - /// num_test_splits stores number of random test splits generated. - unsigned long num_test_splits; - /// configfile stores the name of the file containing the values of training parameters - String configfile; - }; - static Ptr create(const FacemarkKazemi::Params ¶meters = FacemarkKazemi::Params()); - virtual ~FacemarkKazemi(); - - /** @brief This function is used to train the model using gradient boosting to get a cascade of regressors - *which can then be used to predict shape. - *@param images A vector of type cv::Mat which stores the images which are used in training samples. - *@param landmarks A vector of vectors of type cv::Point2f which stores the landmarks detected in a particular image. - *@param scale A size of type cv::Size to which all images and landmarks have to be scaled to. - *@param configfile A variable of type std::string which stores the name of the file storing parameters for training the model. - *@param modelFilename A variable of type std::string which stores the name of the trained model file that has to be saved. - *@returns A boolean value. The function returns true if the model is trained properly or false if it is not trained. - */ - virtual bool training(std::vector& images, std::vector< std::vector >& landmarks,std::string configfile,Size scale,std::string modelFilename = "face_landmarks.dat")=0; - - /// set the custom face detector - virtual bool setFaceDetector(bool(*f)(InputArray , OutputArray, void*), void* userData)=0; - /// get faces using the custom detector - virtual bool getFaces(InputArray image, OutputArray faces)=0; -}; - -}} // namespace -#endif diff --git a/3rdparty/include/opencv2/face/facemark.hpp b/3rdparty/include/opencv2/face/facemark.hpp deleted file mode 100644 index 86e9384342..0000000000 --- a/3rdparty/include/opencv2/face/facemark.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -/* -This file was part of GSoC Project: Facemark API for OpenCV -Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc -Student: Laksono Kurnianggoro -Mentor: Delia Passalacqua -*/ - -#ifndef __OPENCV_FACELANDMARK_HPP__ -#define __OPENCV_FACELANDMARK_HPP__ - -/** -@defgroup face Face Analysis -- @ref tutorial_table_of_content_facemark -- The Facemark API -*/ - -#include "opencv2/core.hpp" -#include - - -namespace cv { -namespace face { - - -/** @brief Abstract base class for all facemark models - -To utilize this API in your program, please take a look at the @ref tutorial_table_of_content_facemark -### Description - -Facemark is a base class which provides universal access to any specific facemark algorithm. -Therefore, the users should declare a desired algorithm before they can use it in their application. - -Here is an example on how to declare a facemark algorithm: -@code -// Using Facemark in your code: -Ptr facemark = createFacemarkLBF(); -@endcode - -The typical pipeline for facemark detection is as follows: -- Load the trained model using Facemark::loadModel. -- Perform the fitting on an image via Facemark::fit. -*/ -class CV_EXPORTS_W Facemark : public virtual Algorithm -{ -public: - - /** @brief A function to load the trained model before the fitting process. - @param model A string represent the filename of a trained model. - - Example of usage - @code - facemark->loadModel("../data/lbf.model"); - @endcode - */ - CV_WRAP virtual void loadModel( String model ) = 0; - // virtual void saveModel(String fs)=0; - - /** @brief Detect facial landmarks from an image. - @param image Input image. - @param faces Output of the function which represent region of interest of the detected faces. - Each face is stored in cv::Rect container. - @param landmarks The detected landmark points for each faces. - - Example of usage - @code - Mat image = imread("image.jpg"); - std::vector faces; - std::vector > landmarks; - facemark->fit(image, faces, landmarks); - @endcode - */ - CV_WRAP virtual bool fit( InputArray image, - InputArray faces, - OutputArrayOfArrays landmarks) = 0; -}; /* Facemark*/ - - -//! construct an AAM facemark detector -CV_EXPORTS_W Ptr createFacemarkAAM(); - -//! construct an LBF facemark detector -CV_EXPORTS_W Ptr createFacemarkLBF(); - -//! construct a Kazemi facemark detector -CV_EXPORTS_W Ptr createFacemarkKazemi(); - - -} // face -} // cv - -#endif //__OPENCV_FACELANDMARK_HPP__ diff --git a/3rdparty/include/opencv2/face/facemarkAAM.hpp b/3rdparty/include/opencv2/face/facemarkAAM.hpp deleted file mode 100644 index 6f96e4a22f..0000000000 --- a/3rdparty/include/opencv2/face/facemarkAAM.hpp +++ /dev/null @@ -1,162 +0,0 @@ -/* -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 - (3-clause BSD License) -Copyright (C) 2013, OpenCV Foundation, 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: - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions 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. - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. - -This file was part of GSoC Project: Facemark API for OpenCV -Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc -Student: Laksono Kurnianggoro -Mentor: Delia Passalacqua -*/ - -#ifndef __OPENCV_FACEMARK_AAM_HPP__ -#define __OPENCV_FACEMARK_AAM_HPP__ - -#include "opencv2/face/facemark_train.hpp" -namespace cv { -namespace face { - -//! @addtogroup face -//! @{ - -class CV_EXPORTS_W FacemarkAAM : public FacemarkTrain -{ -public: - struct CV_EXPORTS Params - { - /** - * \brief Constructor - */ - Params(); - - /** - * \brief Read parameters from file, currently unused - */ - void read(const FileNode& /*fn*/); - - /** - * \brief Read parameters from file, currently unused - */ - void write(FileStorage& /*fs*/) const; - - std::string model_filename; - int m; - int n; - int n_iter; - bool verbose; - bool save_model; - int max_m, max_n, texture_max_m; - std::vectorscales; - }; - - /** - * \brief Optional parameter for fitting process. - */ - struct CV_EXPORTS Config - { - Config( Mat rot = Mat::eye(2,2,CV_32F), - Point2f trans = Point2f(0.0f, 0.0f), - float scaling = 1.0f, - int scale_id=0 - ); - - Mat R; - Point2f t; - float scale; - int model_scale_idx; - - }; - - /** - * \brief Data container for the facemark::getData function - */ - struct CV_EXPORTS Data - { - std::vector s0; - }; - - /** - * \brief The model of AAM Algorithm - */ - struct CV_EXPORTS Model - { - std::vectorscales; - //!< defines the scales considered to build the model - - /*warping*/ - std::vector triangles; - //!< each element contains 3 values, represent index of facemarks that construct one triangle (obtained using delaunay triangulation) - - struct Texture{ - int max_m; //!< unused delete - Rect resolution; - //!< resolution of the current scale - Mat A; - //!< gray values from all face region in the dataset, projected in PCA space - Mat A0; - //!< average of gray values from all face region in the dataset - Mat AA; - //!< gray values from all erorded face region in the dataset, projected in PCA space - Mat AA0; - //!< average of gray values from all erorded face region in the dataset - - std::vector > textureIdx; - //!< index for warping of each delaunay triangle region constructed by 3 facemarks - std::vector base_shape; - //!< basic shape, normalized to be fit in an image with current detection resolution - std::vector ind1; - //!< index of pixels for mapping process to obtains the grays values of face region - std::vector ind2; - //!< index of pixels for mapping process to obtains the grays values of eroded face region - }; - std::vector textures; - //!< a container to holds the texture data for each scale of fitting - - /*shape*/ - std::vector s0; - //!< the basic shape obtained from training dataset - Mat S,Q; - //!< the encoded shapes from training data - - }; - - //! overload with additional Config structures - virtual bool fitConfig( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks, const std::vector &runtime_params ) = 0; - - - //! initializer - static Ptr create(const FacemarkAAM::Params ¶meters = FacemarkAAM::Params() ); - virtual ~FacemarkAAM() {} - -}; /* AAM */ - -//! @} - -} /* namespace face */ -} /* namespace cv */ -#endif diff --git a/3rdparty/include/opencv2/face/facemarkLBF.hpp b/3rdparty/include/opencv2/face/facemarkLBF.hpp deleted file mode 100644 index 7f4cd325c7..0000000000 --- a/3rdparty/include/opencv2/face/facemarkLBF.hpp +++ /dev/null @@ -1,120 +0,0 @@ -/* -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 - (3-clause BSD License) -Copyright (C) 2013, OpenCV Foundation, 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: - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions 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. - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. - -This file was part of GSoC Project: Facemark API for OpenCV -Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc -Student: Laksono Kurnianggoro -Mentor: Delia Passalacqua -*/ - -#ifndef __OPENCV_FACEMARK_LBF_HPP__ -#define __OPENCV_FACEMARK_LBF_HPP__ - -#include "opencv2/face/facemark_train.hpp" - -namespace cv { -namespace face { - -//! @addtogroup face -//! @{ - -class CV_EXPORTS_W FacemarkLBF : public FacemarkTrain -{ -public: - struct CV_EXPORTS Params - { - /** - * \brief Constructor - */ - Params(); - - double shape_offset; - //!< offset for the loaded face landmark points - String cascade_face; - //!< filename of the face detector model - bool verbose; - //!< show the training print-out - - int n_landmarks; - //!< number of landmark points - int initShape_n; - //!< multiplier for augment the training data - - int stages_n; - //!< number of refinement stages - int tree_n; - //!< number of tree in the model for each landmark point refinement - int tree_depth; - //!< the depth of decision tree, defines the size of feature - double bagging_overlap; - //!< overlap ratio for training the LBF feature - - std::string model_filename; - //!< filename where the trained model will be saved - bool save_model; //!< flag to save the trained model or not - unsigned int seed; //!< seed for shuffling the training data - - std::vector feats_m; - std::vector radius_m; - std::vector pupils[2]; - //!< index of facemark points on pupils of left and right eye - - Rect detectROI; - - void read(const FileNode& /*fn*/); - void write(FileStorage& /*fs*/) const; - - }; - - class BBox { - public: - BBox(); - ~BBox(); - BBox(double x, double y, double w, double h); - - Mat project(const Mat &shape) const; - Mat reproject(const Mat &shape) const; - - double x, y; - double x_center, y_center; - double x_scale, y_scale; - double width, height; - }; - - static Ptr create(const FacemarkLBF::Params ¶meters = FacemarkLBF::Params() ); - virtual ~FacemarkLBF(){}; -}; /* LBF */ - -//! @} - -} /* namespace face */ -}/* namespace cv */ - -#endif diff --git a/3rdparty/include/opencv2/face/facemark_train.hpp b/3rdparty/include/opencv2/face/facemark_train.hpp deleted file mode 100644 index d6e27e9fac..0000000000 --- a/3rdparty/include/opencv2/face/facemark_train.hpp +++ /dev/null @@ -1,392 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -/* -This file was part of GSoC Project: Facemark API for OpenCV -Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc -Student: Laksono Kurnianggoro -Mentor: Delia Passalacqua -*/ - -#ifndef __OPENCV_FACELANDMARKTRAIN_HPP__ -#define __OPENCV_FACELANDMARKTRAIN_HPP__ - -/** -@defgroup face Face Analysis -- @ref tutorial_table_of_content_facemark -- The Facemark API -*/ - -#include "opencv2/face/facemark.hpp" -#include "opencv2/objdetect.hpp" -#include -#include - - -namespace cv { -namespace face { - -//! @addtogroup face -//! @{ - -typedef bool(*FN_FaceDetector)(InputArray, OutputArray, void* userData); - -struct CParams{ - String cascade; //!< the face detector - double scaleFactor; //!< Parameter specifying how much the image size is reduced at each image scale. - int minNeighbors; //!< Parameter specifying how many neighbors each candidate rectangle should have to retain it. - Size minSize; //!< Minimum possible object size. - Size maxSize; //!< Maximum possible object size. - - CV_EXPORTS CParams( - String cascade_model, - double sf = 1.1, - int minN = 3, - Size minSz = Size(30, 30), - Size maxSz = Size() - ); - - CascadeClassifier face_cascade; -}; - -/** @brief Default face detector -This function is mainly utilized by the implementation of a Facemark Algorithm. -End users are advised to use function Facemark::getFaces which can be manually defined -and circumvented to the algorithm by Facemark::setFaceDetector. - -@param image The input image to be processed. -@param faces Output of the function which represent region of interest of the detected faces. -Each face is stored in cv::Rect container. -@param params detector parameters - -Example of usage -@code -std::vector faces; -CParams params("haarcascade_frontalface_alt.xml"); -cv::face::getFaces(frame, faces, ¶ms); -for(int j=0;j images_train; -std::vector landmarks_train; -loadDatasetList(imageFiles,ptsFiles,images_train,landmarks_train); -@endcode -*/ -CV_EXPORTS_W bool loadDatasetList(String imageList, - String annotationList, - std::vector & images, - std::vector & annotations); - -/** @brief A utility to load facial landmark dataset from a single file. - -@param filename The filename of a file that contains the dataset information. -Each line contains the filename of an image followed by -pairs of x and y values of facial landmarks points separated by a space. -Example -@code -/home/user/ibug/image_003_1.jpg 336.820955 240.864510 334.238298 260.922709 335.266918 ... -/home/user/ibug/image_005_1.jpg 376.158428 230.845712 376.736984 254.924635 383.265403 ... -@endcode -@param images A vector where each element represent the filename of image in the dataset. -Images are not loaded by default to save the memory. -@param facePoints The loaded landmark points for all training data. -@param delim Delimiter between each element, the default value is a whitespace. -@param offset An offset value to adjust the loaded points. - -Example of usage -@code -cv::String imageFiles = "../data/images_train.txt"; -cv::String ptsFiles = "../data/points_train.txt"; -std::vector images; -std::vector > facePoints; -loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0f); -@endcode -*/ -CV_EXPORTS_W bool loadTrainingData( String filename , std::vector & images, - OutputArray facePoints, - char delim = ' ', float offset = 0.0f); - -/** @brief A utility to load facial landmark information from the dataset. - -@param imageList A file contains the list of image filenames in the training dataset. -@param groundTruth A file contains the list of filenames -where the landmarks points information are stored. -The content in each file should follow the standard format (see face::loadFacePoints). -@param images A vector where each element represent the filename of image in the dataset. -Images are not loaded by default to save the memory. -@param facePoints The loaded landmark points for all training data. -@param offset An offset value to adjust the loaded points. - -Example of usage -@code -cv::String imageFiles = "../data/images_train.txt"; -cv::String ptsFiles = "../data/points_train.txt"; -std::vector images; -std::vector > facePoints; -loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0f); -@endcode - -example of content in the images_train.txt -@code -/home/user/ibug/image_003_1.jpg -/home/user/ibug/image_004_1.jpg -/home/user/ibug/image_005_1.jpg -/home/user/ibug/image_006.jpg -@endcode - -example of content in the points_train.txt -@code -/home/user/ibug/image_003_1.pts -/home/user/ibug/image_004_1.pts -/home/user/ibug/image_005_1.pts -/home/user/ibug/image_006.pts -@endcode -*/ -CV_EXPORTS_W bool loadTrainingData( String imageList, String groundTruth, - std::vector & images, - OutputArray facePoints, - float offset = 0.0f); - -/** @brief This function extracts the data for training from .txt files which contains the corresponding image name and landmarks. -*The first file in each file should give the path of the image whose -*landmarks are being described in the file. Then in the subsequent -*lines there should be coordinates of the landmarks in the image -*i.e each line should be of the form x,y -*where x represents the x coordinate of the landmark and y represents -*the y coordinate of the landmark. -* -*For reference you can see the files as provided in the -*HELEN dataset -* -* @param filename A vector of type cv::String containing name of the .txt files. -* @param trainlandmarks A vector of type cv::Point2f that would store shape or landmarks of all images. -* @param trainimages A vector of type cv::String which stores the name of images whose landmarks are tracked -* @returns A boolean value. It returns true when it reads the data successfully and false otherwise -*/ -CV_EXPORTS_W bool loadTrainingData(std::vector filename,std::vector< std::vector > - &trainlandmarks,std::vector & trainimages); - -/** @brief A utility to load facial landmark information from a given file. - -@param filename The filename of file contains the facial landmarks data. -@param points The loaded facial landmark points. -@param offset An offset value to adjust the loaded points. - -Example of usage -@code -std::vector points; -face::loadFacePoints("filename.txt", points, 0.0f); -@endcode - -The annotation file should follow the default format which is -@code -version: 1 -n_points: 68 -{ -212.716603 499.771793 -230.232816 566.290071 -... -} -@endcode -where n_points is the number of points considered -and each point is represented as its position in x and y. -*/ -CV_EXPORTS_W bool loadFacePoints( String filename, OutputArray points, - float offset = 0.0f); - -/** @brief Utility to draw the detected facial landmark points - -@param image The input image to be processed. -@param points Contains the data of points which will be drawn. -@param color The color of points in BGR format represented by cv::Scalar. - -Example of usage -@code -std::vector faces; -std::vector > landmarks; -facemark->getFaces(img, faces); -facemark->fit(img, faces, landmarks); -for(int j=0;j facemark = FacemarkLBF::create(); -@endcode - - -The typical pipeline for facemark detection is listed as follows: -- (Non-mandatory) Set a user defined face detection using FacemarkTrain::setFaceDetector. - The facemark algorithms are designed to fit the facial points into a face. - Therefore, the face information should be provided to the facemark algorithm. - Some algorithms might provides a default face recognition function. - However, the users might prefer to use their own face detector to obtains the best possible detection result. -- (Non-mandatory) Training the model for a specific algorithm using FacemarkTrain::training. - In this case, the model should be automatically saved by the algorithm. - If the user already have a trained model, then this part can be omitted. -- Load the trained model using Facemark::loadModel. -- Perform the fitting via the Facemark::fit. -*/ -class CV_EXPORTS_W FacemarkTrain : public Facemark -{ -public: - /** @brief Add one training sample to the trainer. - - @param image Input image. - @param landmarks The ground-truth of facial landmarks points corresponds to the image. - - Example of usage - @code - String imageFiles = "../data/images_train.txt"; - String ptsFiles = "../data/points_train.txt"; - std::vector images_train; - std::vector landmarks_train; - - // load the list of dataset: image paths and landmark file paths - loadDatasetList(imageFiles,ptsFiles,images_train,landmarks_train); - - Mat image; - std::vector facial_points; - for(size_t i=0;iaddTrainingSample(image, facial_points); - } - @endcode - - The contents in the training files should follows the standard format. - Here are examples for the contents in these files. - example of content in the images_train.txt - @code - /home/user/ibug/image_003_1.jpg - /home/user/ibug/image_004_1.jpg - /home/user/ibug/image_005_1.jpg - /home/user/ibug/image_006.jpg - @endcode - - example of content in the points_train.txt - @code - /home/user/ibug/image_003_1.pts - /home/user/ibug/image_004_1.pts - /home/user/ibug/image_005_1.pts - /home/user/ibug/image_006.pts - @endcode - - */ - virtual bool addTrainingSample(InputArray image, InputArray landmarks)=0; - - /** @brief Trains a Facemark algorithm using the given dataset. - Before the training process, training samples should be added to the trainer - using face::addTrainingSample function. - - @param parameters Optional extra parameters (algorithm dependent). - - Example of usage - @code - FacemarkLBF::Params params; - params.model_filename = "ibug68.model"; // filename to save the trained model - Ptr facemark = FacemarkLBF::create(params); - - // add training samples (see Facemark::addTrainingSample) - - facemark->training(); - @endcode - */ - - virtual void training(void* parameters=0)=0; - - /** @brief Set a user defined face detector for the Facemark algorithm. - @param detector The user defined face detector function - @param userData Detector parameters - - Example of usage - @code - MyDetectorParameters detectorParameters(...); - facemark->setFaceDetector(myDetector, &detectorParameters); - @endcode - - Example of a user defined face detector - @code - bool myDetector( InputArray image, OutputArray faces, void* userData) - { - MyDetectorParameters* params = (MyDetectorParameters*)userData; - // -------- do something -------- - } - @endcode - - TODO Lifetime of detector parameters is uncontrolled. Rework interface design to "Ptr". - */ - virtual bool setFaceDetector(FN_FaceDetector detector, void* userData = 0)=0; - - /** @brief Detect faces from a given image using default or user defined face detector. - Some Algorithm might not provide a default face detector. - - @param image Input image. - @param faces Output of the function which represent region of interest of the detected faces. Each face is stored in cv::Rect container. - - Example of usage - @code - std::vector faces; - facemark->getFaces(img, faces); - for(int j=0;jExample of usage - @code - Ptr facemark = FacemarkAAM::create(); - facemark->loadModel("AAM.yml"); - - FacemarkAAM::Data data; - facemark->getData(&data); - std::vector s0 = data.s0; - - cout<. -// Third party copyrights are property of their respective owners. - -#ifndef __OPENCV_FACEREC_HPP__ -#define __OPENCV_FACEREC_HPP__ - -#include "opencv2/face.hpp" -#include "opencv2/core.hpp" - -namespace cv { namespace face { - -//! @addtogroup face -//! @{ - -// base for two classes -class CV_EXPORTS_W BasicFaceRecognizer : public FaceRecognizer -{ -public: - /** @see setNumComponents */ - CV_WRAP int getNumComponents() const; - /** @copybrief getNumComponents @see getNumComponents */ - CV_WRAP void setNumComponents(int val); - /** @see setThreshold */ - CV_WRAP double getThreshold() const CV_OVERRIDE; - /** @copybrief getThreshold @see getThreshold */ - CV_WRAP void setThreshold(double val) CV_OVERRIDE; - CV_WRAP std::vector getProjections() const; - CV_WRAP cv::Mat getLabels() const; - CV_WRAP cv::Mat getEigenValues() const; - CV_WRAP cv::Mat getEigenVectors() const; - CV_WRAP cv::Mat getMean() const; - - virtual void read(const FileNode& fn) CV_OVERRIDE; - virtual void write(FileStorage& fs) const CV_OVERRIDE; - virtual bool empty() const CV_OVERRIDE; - - using FaceRecognizer::read; - using FaceRecognizer::write; - -protected: - int _num_components; - double _threshold; - std::vector _projections; - Mat _labels; - Mat _eigenvectors; - Mat _eigenvalues; - Mat _mean; -}; - -class CV_EXPORTS_W EigenFaceRecognizer : public BasicFaceRecognizer -{ -public: - /** - @param num_components The number of components (read: Eigenfaces) kept for this Principal - Component Analysis. As a hint: There's no rule how many components (read: Eigenfaces) should be - kept for good reconstruction capabilities. It is based on your input data, so experiment with the - number. Keeping 80 components should almost always be sufficient. - @param threshold The threshold applied in the prediction. - - ### Notes: - - - Training and prediction must be done on grayscale images, use cvtColor to convert between the - color spaces. - - **THE EIGENFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL - SIZE.** (caps-lock, because I got so many mails asking for this). You have to make sure your - input data has the correct shape, else a meaningful exception is thrown. Use resize to resize - the images. - - This model does not support updating. - - ### Model internal data: - - - num_components see EigenFaceRecognizer::create. - - threshold see EigenFaceRecognizer::create. - - eigenvalues The eigenvalues for this Principal Component Analysis (ordered descending). - - eigenvectors The eigenvectors for this Principal Component Analysis (ordered by their - eigenvalue). - - mean The sample mean calculated from the training data. - - projections The projections of the training data. - - labels The threshold applied in the prediction. If the distance to the nearest neighbor is - larger than the threshold, this method returns -1. - */ - CV_WRAP static Ptr create(int num_components = 0, double threshold = DBL_MAX); -}; - -class CV_EXPORTS_W FisherFaceRecognizer : public BasicFaceRecognizer -{ -public: - /** - @param num_components The number of components (read: Fisherfaces) kept for this Linear - Discriminant Analysis with the Fisherfaces criterion. It's useful to keep all components, that - means the number of your classes c (read: subjects, persons you want to recognize). If you leave - this at the default (0) or set it to a value less-equal 0 or greater (c-1), it will be set to the - correct number (c-1) automatically. - @param threshold The threshold applied in the prediction. If the distance to the nearest neighbor - is larger than the threshold, this method returns -1. - - ### Notes: - - - Training and prediction must be done on grayscale images, use cvtColor to convert between the - color spaces. - - **THE FISHERFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL - SIZE.** (caps-lock, because I got so many mails asking for this). You have to make sure your - input data has the correct shape, else a meaningful exception is thrown. Use resize to resize - the images. - - This model does not support updating. - - ### Model internal data: - - - num_components see FisherFaceRecognizer::create. - - threshold see FisherFaceRecognizer::create. - - eigenvalues The eigenvalues for this Linear Discriminant Analysis (ordered descending). - - eigenvectors The eigenvectors for this Linear Discriminant Analysis (ordered by their - eigenvalue). - - mean The sample mean calculated from the training data. - - projections The projections of the training data. - - labels The labels corresponding to the projections. - */ - CV_WRAP static Ptr create(int num_components = 0, double threshold = DBL_MAX); -}; - - -class CV_EXPORTS_W LBPHFaceRecognizer : public FaceRecognizer -{ -public: - /** @see setGridX */ - CV_WRAP virtual int getGridX() const = 0; - /** @copybrief getGridX @see getGridX */ - CV_WRAP virtual void setGridX(int val) = 0; - /** @see setGridY */ - CV_WRAP virtual int getGridY() const = 0; - /** @copybrief getGridY @see getGridY */ - CV_WRAP virtual void setGridY(int val) = 0; - /** @see setRadius */ - CV_WRAP virtual int getRadius() const = 0; - /** @copybrief getRadius @see getRadius */ - CV_WRAP virtual void setRadius(int val) = 0; - /** @see setNeighbors */ - CV_WRAP virtual int getNeighbors() const = 0; - /** @copybrief getNeighbors @see getNeighbors */ - CV_WRAP virtual void setNeighbors(int val) = 0; - /** @see setThreshold */ - CV_WRAP virtual double getThreshold() const CV_OVERRIDE = 0; - /** @copybrief getThreshold @see getThreshold */ - CV_WRAP virtual void setThreshold(double val) CV_OVERRIDE = 0; - CV_WRAP virtual std::vector getHistograms() const = 0; - CV_WRAP virtual cv::Mat getLabels() const = 0; - - /** - @param radius The radius used for building the Circular Local Binary Pattern. The greater the - radius, the smoother the image but more spatial information you can get. - @param neighbors The number of sample points to build a Circular Local Binary Pattern from. An - appropriate value is to use `8` sample points. Keep in mind: the more sample points you include, - the higher the computational cost. - @param grid_x The number of cells in the horizontal direction, 8 is a common value used in - publications. The more cells, the finer the grid, the higher the dimensionality of the resulting - feature vector. - @param grid_y The number of cells in the vertical direction, 8 is a common value used in - publications. The more cells, the finer the grid, the higher the dimensionality of the resulting - feature vector. - @param threshold The threshold applied in the prediction. If the distance to the nearest neighbor - is larger than the threshold, this method returns -1. - - ### Notes: - - - The Circular Local Binary Patterns (used in training and prediction) expect the data given as - grayscale images, use cvtColor to convert between the color spaces. - - This model supports updating. - - ### Model internal data: - - - radius see LBPHFaceRecognizer::create. - - neighbors see LBPHFaceRecognizer::create. - - grid_x see LLBPHFaceRecognizer::create. - - grid_y see LBPHFaceRecognizer::create. - - threshold see LBPHFaceRecognizer::create. - - histograms Local Binary Patterns Histograms calculated from the given training data (empty if - none was given). - - labels Labels corresponding to the calculated Local Binary Patterns Histograms. - */ - CV_WRAP static Ptr create(int radius=1, int neighbors=8, int grid_x=8, int grid_y=8, double threshold = DBL_MAX); -}; - -//! @} - -}} //namespace cv::face - -#endif //__OPENCV_FACEREC_HPP__ diff --git a/3rdparty/include/opencv2/face/mace.hpp b/3rdparty/include/opencv2/face/mace.hpp deleted file mode 100644 index ba3ec860e6..0000000000 --- a/3rdparty/include/opencv2/face/mace.hpp +++ /dev/null @@ -1,114 +0,0 @@ -// This file is part of the OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#ifndef __mace_h_onboard__ -#define __mace_h_onboard__ - -#include "opencv2/core.hpp" - - -namespace cv { -namespace face { - -//! @addtogroup face -//! @{ - - -/** -@brief Minimum Average Correlation Energy Filter - useful for authentication with (cancellable) biometrical features. - (does not need many positives to train (10-50), and no negatives at all, also robust to noise/salting) - - see also: @cite Savvides04 - - this implementation is largely based on: https://code.google.com/archive/p/pam-face-authentication (GSOC 2009) - - use it like: - @code - - Ptr mace = face::MACE::create(64); - - vector pos_images = ... - mace->train(pos_images); - - Mat query = ... - bool same = mace->same(query); - - @endcode - - you can also use two-factor authentication, with an additional passphrase: - - @code - String owners_passphrase = "ilikehotdogs"; - Ptr mace = face::MACE::create(64); - mace->salt(owners_passphrase); - vector pos_images = ... - mace->train(pos_images); - - // now, users have to give a valid passphrase, along with the image: - Mat query = ... - cout << "enter passphrase: "; - string pass; - getline(cin, pass); - mace->salt(pass); - bool same = mace->same(query); - @endcode - - save/load your model: - @code - Ptr mace = face::MACE::create(64); - mace->train(pos_images); - mace->save("my_mace.xml"); - - // later: - Ptr reloaded = MACE::load("my_mace.xml"); - reloaded->same(some_image); - @endcode - -*/ - -class CV_EXPORTS_W MACE : public cv::Algorithm -{ -public: - /** - @brief optionally encrypt images with random convolution - @param passphrase a crc64 random seed will get generated from this - */ - CV_WRAP virtual void salt(const cv::String &passphrase) = 0; - - /** - @brief train it on positive features - compute the mace filter: `h = D(-1) * X * (X(+) * D(-1) * X)(-1) * C` - also calculate a minimal threshold for this class, the smallest self-similarity from the train images - @param images a vector with the train images - */ - CV_WRAP virtual void train(cv::InputArrayOfArrays images) = 0; - - /** - @brief correlate query img and threshold to min class value - @param query a Mat with query image - */ - CV_WRAP virtual bool same(cv::InputArray query) const = 0; - - - /** - @brief constructor - @param filename build a new MACE instance from a pre-serialized FileStorage - @param objname (optional) top-level node in the FileStorage - */ - CV_WRAP static cv::Ptr load(const String &filename, const String &objname=String()); - - /** - @brief constructor - @param IMGSIZE images will get resized to this (should be an even number) - */ - CV_WRAP static cv::Ptr create(int IMGSIZE=64); -}; - -//! @} - -}/* namespace face */ -}/* namespace cv */ - -#endif // __mace_h_onboard__ diff --git a/3rdparty/include/opencv2/face/predict_collector.hpp b/3rdparty/include/opencv2/face/predict_collector.hpp deleted file mode 100644 index dba3c7e3be..0000000000 --- a/3rdparty/include/opencv2/face/predict_collector.hpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2000-2015, Intel Corporation, all rights reserved. -Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. -Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. -Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. -Copyright (C) 2015, OpenCV Foundation, all rights reserved. -Copyright (C) 2015, Itseez 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -#ifndef __OPENCV_PREDICT_COLLECTOR_HPP__ -#define __OPENCV_PREDICT_COLLECTOR_HPP__ - -#include -#include -#include -#include - -#include "opencv2/core/base.hpp" - -namespace cv { -namespace face { -//! @addtogroup face -//! @{ -/** @brief Abstract base class for all strategies of prediction result handling -*/ -class CV_EXPORTS_W PredictCollector -{ -public: - virtual ~PredictCollector() {} - - /** @brief Interface method called by face recognizer before results processing - @param size total size of prediction evaluation that recognizer could perform - */ - virtual void init(size_t size) { CV_UNUSED(size); } - - /** @brief Interface method called by face recognizer for each result - @param label current prediction label - @param dist current prediction distance (confidence) - */ - virtual bool collect(int label, double dist) = 0; -}; - -/** @brief Default predict collector - -Trace minimal distance with treshhold checking (that is default behavior for most predict logic) -*/ -class CV_EXPORTS_W StandardCollector : public PredictCollector -{ -public: - struct PredictResult - { - int label; - double distance; - PredictResult(int label_ = -1, double distance_ = DBL_MAX) : label(label_), distance(distance_) {} - }; -protected: - double threshold; - PredictResult minRes; - std::vector data; -public: - /** @brief Constructor - @param threshold_ set threshold - */ - StandardCollector(double threshold_ = DBL_MAX); - /** @brief overloaded interface method */ - void init(size_t size) CV_OVERRIDE; - /** @brief overloaded interface method */ - bool collect(int label, double dist) CV_OVERRIDE; - /** @brief Returns label with minimal distance */ - CV_WRAP int getMinLabel() const; - /** @brief Returns minimal distance value */ - CV_WRAP double getMinDist() const; - /** @brief Return results as vector - @param sorted If set, results will be sorted by distance - Each values is a pair of label and distance. - */ - CV_WRAP std::vector< std::pair > getResults(bool sorted = false) const; - /** @brief Return results as map - Labels are keys, values are minimal distances - */ - std::map getResultsMap() const; - /** @brief Static constructor - @param threshold set threshold - */ - CV_WRAP static Ptr create(double threshold = DBL_MAX); -}; - -//! @} -} -} - -#endif diff --git a/3rdparty/include/opencv2/features2d.hpp b/3rdparty/include/opencv2/features2d.hpp index 293b5beff0..e51bd92044 100644 --- a/3rdparty/include/opencv2/features2d.hpp +++ b/3rdparty/include/opencv2/features2d.hpp @@ -61,25 +61,11 @@ easily switch between different algorithms solving the same problem. This sectio matching descriptors that are represented as vectors in a multidimensional space. All objects that implement vector descriptor matchers inherit the DescriptorMatcher interface. -@note - - An example explaining keypoint matching can be found at - opencv_source_code/samples/cpp/descriptor_extractor_matcher.cpp - - An example on descriptor matching evaluation can be found at - opencv_source_code/samples/cpp/detector_descriptor_matcher_evaluation.cpp - - An example on one to many image matching can be found at - opencv_source_code/samples/cpp/matching_to_many_images.cpp - @defgroup features2d_draw Drawing Function of Keypoints and Matches @defgroup features2d_category Object Categorization This section describes approaches based on local 2D features and used to categorize objects. -@note - - A complete Bag-Of-Words sample can be found at - opencv_source_code/samples/cpp/bagofwords_classification.cpp - - (Python) An example using the features2D framework to perform object categorization can be - found at opencv_source_code/samples/python/find_obj.py - @defgroup feature2d_hal Hardware Acceleration Layer @{ @defgroup features2d_hal_interface Interface @@ -90,7 +76,7 @@ This section describes approaches based on local 2D features and used to categor namespace cv { -//! @addtogroup features2d +//! @addtogroup features2d_main //! @{ // //! writes vector of keypoints to the file storage @@ -241,9 +227,6 @@ the vector descriptor extractors inherit the DescriptorExtractor interface. */ typedef Feature2D DescriptorExtractor; -//! @addtogroup features2d_main -//! @{ - /** @brief Class for implementing the wrapper which makes detectors and extractors to be affine invariant, described as ASIFT in @cite YM11 . @@ -380,6 +363,18 @@ public: const std::vector &numberList, float dMax=5.85f, float dMin=8.2f, const std::vector& indexChange=std::vector()); CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; + + /** @brief Set detection threshold. + @param threshold AGAST detection threshold score. + */ + CV_WRAP virtual void setThreshold(int threshold) { CV_UNUSED(threshold); return; } + CV_WRAP virtual int getThreshold() const { return -1; } + + /** @brief Set detection octaves. + @param octaves detection octaves. Use 0 to do single scale. + */ + CV_WRAP virtual void setOctaves(int octaves) { CV_UNUSED(octaves); return; } + CV_WRAP virtual int getOctaves() const { return -1; } }; /** @brief Class implementing the ORB (*oriented BRIEF*) keypoint detector and descriptor extractor @@ -392,7 +387,8 @@ k-tuples) are rotated according to the measured orientation). class CV_EXPORTS_W ORB : public Feature2D { public: - enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; + enum ScoreType { HARRIS_SCORE=0, FAST_SCORE=1 }; + static const int kBytes = 32; /** @brief The ORB constructor @@ -426,7 +422,7 @@ public: @param fastThreshold the fast threshold */ CV_WRAP static Ptr create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31, - int firstLevel=0, int WTA_K=2, int scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20); + int firstLevel=0, int WTA_K=2, ORB::ScoreType scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20); CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; CV_WRAP virtual int getMaxFeatures() const = 0; @@ -446,8 +442,8 @@ public: CV_WRAP virtual void setWTA_K(int wta_k) = 0; CV_WRAP virtual int getWTA_K() const = 0; - CV_WRAP virtual void setScoreType(int scoreType) = 0; - CV_WRAP virtual int getScoreType() const = 0; + CV_WRAP virtual void setScoreType(ORB::ScoreType scoreType) = 0; + CV_WRAP virtual ORB::ScoreType getScoreType() const = 0; CV_WRAP virtual void setPatchSize(int patchSize) = 0; CV_WRAP virtual int getPatchSize() const = 0; @@ -468,8 +464,7 @@ article](http://en.wikipedia.org/wiki/Maximally_stable_extremal_regions)). than union-find method; it actually get 1.5~2m/s on my centrino L7200 1.2GHz laptop. - the color image algorithm is taken from: @cite forssen2007maximally ; it should be much slower -than grey image method ( 3~4 times ); the chi_table.h file is taken directly from paper's source -code which is distributed under GPL. +than grey image method ( 3~4 times ) - (Python) A complete example showing the use of the %MSER detector can be found at samples/python/mser.py */ @@ -478,20 +473,20 @@ class CV_EXPORTS_W MSER : public Feature2D public: /** @brief Full constructor for %MSER detector - @param _delta it compares \f$(size_{i}-size_{i-delta})/size_{i-delta}\f$ - @param _min_area prune the area which smaller than minArea - @param _max_area prune the area which bigger than maxArea - @param _max_variation prune the area have similar size to its children - @param _min_diversity for color image, trace back to cut off mser with diversity less than min_diversity - @param _max_evolution for color image, the evolution steps - @param _area_threshold for color image, the area threshold to cause re-initialize - @param _min_margin for color image, ignore too small margin - @param _edge_blur_size for color image, the aperture size for edge blur + @param delta it compares \f$(size_{i}-size_{i-delta})/size_{i-delta}\f$ + @param min_area prune the area which smaller than minArea + @param max_area prune the area which bigger than maxArea + @param max_variation prune the area have similar size to its children + @param min_diversity for color image, trace back to cut off mser with diversity less than min_diversity + @param max_evolution for color image, the evolution steps + @param area_threshold for color image, the area threshold to cause re-initialize + @param min_margin for color image, ignore too small margin + @param edge_blur_size for color image, the aperture size for edge blur */ - CV_WRAP static Ptr create( int _delta=5, int _min_area=60, int _max_area=14400, - double _max_variation=0.25, double _min_diversity=.2, - int _max_evolution=200, double _area_threshold=1.01, - double _min_margin=0.003, int _edge_blur_size=5 ); + CV_WRAP static Ptr create( int delta=5, int min_area=60, int max_area=14400, + double max_variation=0.25, double min_diversity=.2, + int max_evolution=200, double area_threshold=1.01, + double min_margin=0.003, int edge_blur_size=5 ); /** @brief Detect %MSER regions @@ -517,6 +512,41 @@ public: CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; }; +//! @} features2d_main + +//! @addtogroup features2d_main +//! @{ + +/** @brief Wrapping class for feature detection using the FAST method. : + */ +class CV_EXPORTS_W FastFeatureDetector : public Feature2D +{ +public: + enum DetectorType + { + TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2 + }; + enum + { + THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002 + }; + + + CV_WRAP static Ptr create( int threshold=10, + bool nonmaxSuppression=true, + FastFeatureDetector::DetectorType type=FastFeatureDetector::TYPE_9_16 ); + + CV_WRAP virtual void setThreshold(int threshold) = 0; + CV_WRAP virtual int getThreshold() const = 0; + + CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; + CV_WRAP virtual bool getNonmaxSuppression() const = 0; + + CV_WRAP virtual void setType(FastFeatureDetector::DetectorType type) = 0; + CV_WRAP virtual FastFeatureDetector::DetectorType getType() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + /** @overload */ CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector& keypoints, int threshold, bool nonmaxSuppression=true ); @@ -535,32 +565,36 @@ FastFeatureDetector::TYPE_5_8 Detects corners using the FAST algorithm by @cite Rosten06 . -@note In Python API, types are given as cv2.FAST_FEATURE_DETECTOR_TYPE_5_8, -cv2.FAST_FEATURE_DETECTOR_TYPE_7_12 and cv2.FAST_FEATURE_DETECTOR_TYPE_9_16. For corner -detection, use cv2.FAST.detect() method. +@note In Python API, types are given as cv.FAST_FEATURE_DETECTOR_TYPE_5_8, +cv.FAST_FEATURE_DETECTOR_TYPE_7_12 and cv.FAST_FEATURE_DETECTOR_TYPE_9_16. For corner +detection, use cv.FAST.detect() method. */ CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector& keypoints, - int threshold, bool nonmaxSuppression, int type ); + int threshold, bool nonmaxSuppression, FastFeatureDetector::DetectorType type ); //! @} features2d_main //! @addtogroup features2d_main //! @{ -/** @brief Wrapping class for feature detection using the FAST method. : +/** @brief Wrapping class for feature detection using the AGAST method. : */ -class CV_EXPORTS_W FastFeatureDetector : public Feature2D +class CV_EXPORTS_W AgastFeatureDetector : public Feature2D { public: - enum + enum DetectorType { - TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2, - THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002, + AGAST_5_8 = 0, AGAST_7_12d = 1, AGAST_7_12s = 2, OAST_9_16 = 3, }; - CV_WRAP static Ptr create( int threshold=10, - bool nonmaxSuppression=true, - int type=FastFeatureDetector::TYPE_9_16 ); + enum + { + THRESHOLD = 10000, NONMAX_SUPPRESSION = 10001, + }; + + CV_WRAP static Ptr create( int threshold=10, + bool nonmaxSuppression=true, + AgastFeatureDetector::DetectorType type = AgastFeatureDetector::OAST_9_16); CV_WRAP virtual void setThreshold(int threshold) = 0; CV_WRAP virtual int getThreshold() const = 0; @@ -568,8 +602,8 @@ public: CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; CV_WRAP virtual bool getNonmaxSuppression() const = 0; - CV_WRAP virtual void setType(int type) = 0; - CV_WRAP virtual int getType() const = 0; + CV_WRAP virtual void setType(AgastFeatureDetector::DetectorType type) = 0; + CV_WRAP virtual AgastFeatureDetector::DetectorType getType() const = 0; CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; }; @@ -596,37 +630,7 @@ Detects corners using the AGAST algorithm by @cite mair2010_agast . */ CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector& keypoints, - int threshold, bool nonmaxSuppression, int type ); -//! @} features2d_main - -//! @addtogroup features2d_main -//! @{ - -/** @brief Wrapping class for feature detection using the AGAST method. : - */ -class CV_EXPORTS_W AgastFeatureDetector : public Feature2D -{ -public: - enum - { - AGAST_5_8 = 0, AGAST_7_12d = 1, AGAST_7_12s = 2, OAST_9_16 = 3, - THRESHOLD = 10000, NONMAX_SUPPRESSION = 10001, - }; - - CV_WRAP static Ptr create( int threshold=10, - bool nonmaxSuppression=true, - int type=AgastFeatureDetector::OAST_9_16 ); - - CV_WRAP virtual void setThreshold(int threshold) = 0; - CV_WRAP virtual int getThreshold() const = 0; - - CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; - CV_WRAP virtual bool getNonmaxSuppression() const = 0; - - CV_WRAP virtual void setType(int type) = 0; - CV_WRAP virtual int getType() const = 0; - CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; -}; + int threshold, bool nonmaxSuppression, AgastFeatureDetector::DetectorType type ); /** @brief Wrapping class for feature detection using the goodFeaturesToTrack function. : */ @@ -738,7 +742,7 @@ F. Alcantarilla, Adrien Bartoli and Andrew J. Davison. In European Conference on class CV_EXPORTS_W KAZE : public Feature2D { public: - enum + enum DiffusivityType { DIFF_PM_G1 = 0, DIFF_PM_G2 = 1, @@ -759,7 +763,7 @@ public: CV_WRAP static Ptr create(bool extended=false, bool upright=false, float threshold = 0.001f, int nOctaves = 4, int nOctaveLayers = 4, - int diffusivity = KAZE::DIFF_PM_G2); + KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2); CV_WRAP virtual void setExtended(bool extended) = 0; CV_WRAP virtual bool getExtended() const = 0; @@ -776,8 +780,8 @@ public: CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0; CV_WRAP virtual int getNOctaveLayers() const = 0; - CV_WRAP virtual void setDiffusivity(int diff) = 0; - CV_WRAP virtual int getDiffusivity() const = 0; + CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0; + CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0; CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; }; @@ -801,7 +805,7 @@ class CV_EXPORTS_W AKAZE : public Feature2D { public: // AKAZE descriptor type - enum + enum DescriptorType { DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation DESCRIPTOR_KAZE = 3, @@ -821,13 +825,13 @@ public: @param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or DIFF_CHARBONNIER */ - CV_WRAP static Ptr create(int descriptor_type=AKAZE::DESCRIPTOR_MLDB, + CV_WRAP static Ptr create(AKAZE::DescriptorType descriptor_type = AKAZE::DESCRIPTOR_MLDB, int descriptor_size = 0, int descriptor_channels = 3, float threshold = 0.001f, int nOctaves = 4, - int nOctaveLayers = 4, int diffusivity = KAZE::DIFF_PM_G2); + int nOctaveLayers = 4, KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2); - CV_WRAP virtual void setDescriptorType(int dtype) = 0; - CV_WRAP virtual int getDescriptorType() const = 0; + CV_WRAP virtual void setDescriptorType(AKAZE::DescriptorType dtype) = 0; + CV_WRAP virtual AKAZE::DescriptorType getDescriptorType() const = 0; CV_WRAP virtual void setDescriptorSize(int dsize) = 0; CV_WRAP virtual int getDescriptorSize() const = 0; @@ -844,8 +848,8 @@ public: CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0; CV_WRAP virtual int getNOctaveLayers() const = 0; - CV_WRAP virtual void setDiffusivity(int diff) = 0; - CV_WRAP virtual int getDiffusivity() const = 0; + CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0; + CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0; CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; }; @@ -872,7 +876,7 @@ template<> struct Accumulator { typedef float Type; }; template struct CV_EXPORTS SL2 { - enum { normType = NORM_L2SQR }; + static const NormTypes normType = NORM_L2SQR; typedef T ValueType; typedef typename Accumulator::Type ResultType; @@ -888,7 +892,7 @@ struct CV_EXPORTS SL2 template struct L2 { - enum { normType = NORM_L2 }; + static const NormTypes normType = NORM_L2; typedef T ValueType; typedef typename Accumulator::Type ResultType; @@ -904,7 +908,7 @@ struct L2 template struct L1 { - enum { normType = NORM_L1 }; + static const NormTypes normType = NORM_L1; typedef T ValueType; typedef typename Accumulator::Type ResultType; @@ -929,7 +933,7 @@ an image set. class CV_EXPORTS_W DescriptorMatcher : public Algorithm { public: - enum + enum MatcherType { FLANNBASED = 1, BRUTEFORCE = 2, @@ -938,6 +942,7 @@ public: BRUTEFORCE_HAMMINGLUT = 5, BRUTEFORCE_SL2 = 6 }; + virtual ~DescriptorMatcher(); /** @brief Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor @@ -1115,7 +1120,7 @@ public: */ CV_WRAP static Ptr create( const String& descriptorMatcherType ); - CV_WRAP static Ptr create( int matcherType ); + CV_WRAP static Ptr create( const DescriptorMatcher::MatcherType& matcherType ); // see corresponding cv::Algorithm method @@ -1270,20 +1275,20 @@ protected: //! @addtogroup features2d_draw //! @{ -struct CV_EXPORTS DrawMatchesFlags +enum struct DrawMatchesFlags { - enum{ DEFAULT = 0, //!< Output image matrix will be created (Mat::create), - //!< i.e. existing memory of output image may be reused. - //!< Two source image, matches and single keypoints will be drawn. - //!< For each keypoint only the center point will be drawn (without - //!< the circle around keypoint with keypoint size and orientation). - DRAW_OVER_OUTIMG = 1, //!< Output image matrix will not be created (Mat::create). - //!< Matches will be drawn on existing content of output image. - NOT_DRAW_SINGLE_POINTS = 2, //!< Single keypoints will not be drawn. - DRAW_RICH_KEYPOINTS = 4 //!< For each keypoint the circle around keypoint with keypoint size and - //!< orientation will be drawn. - }; + DEFAULT = 0, //!< Output image matrix will be created (Mat::create), + //!< i.e. existing memory of output image may be reused. + //!< Two source image, matches and single keypoints will be drawn. + //!< For each keypoint only the center point will be drawn (without + //!< the circle around keypoint with keypoint size and orientation). + DRAW_OVER_OUTIMG = 1, //!< Output image matrix will not be created (Mat::create). + //!< Matches will be drawn on existing content of output image. + NOT_DRAW_SINGLE_POINTS = 2, //!< Single keypoints will not be drawn. + DRAW_RICH_KEYPOINTS = 4 //!< For each keypoint the circle around keypoint with keypoint size and + //!< orientation will be drawn. }; +CV_ENUM_FLAGS(DrawMatchesFlags) /** @brief Draws keypoints. @@ -1296,12 +1301,12 @@ output image. See possible flags bit values below. DrawMatchesFlags. See details above in drawMatches . @note -For Python API, flags are modified as cv2.DRAW_MATCHES_FLAGS_DEFAULT, -cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS, cv2.DRAW_MATCHES_FLAGS_DRAW_OVER_OUTIMG, -cv2.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS +For Python API, flags are modified as cv.DRAW_MATCHES_FLAGS_DEFAULT, +cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS, cv.DRAW_MATCHES_FLAGS_DRAW_OVER_OUTIMG, +cv.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS */ CV_EXPORTS_W void drawKeypoints( InputArray image, const std::vector& keypoints, InputOutputArray outImage, - const Scalar& color=Scalar::all(-1), int flags=DrawMatchesFlags::DEFAULT ); + const Scalar& color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); /** @brief Draws the found matches of keypoints from two images. @@ -1329,14 +1334,21 @@ CV_EXPORTS_W void drawMatches( InputArray img1, const std::vector& key InputArray img2, const std::vector& keypoints2, const std::vector& matches1to2, InputOutputArray outImg, const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1), - const std::vector& matchesMask=std::vector(), int flags=DrawMatchesFlags::DEFAULT ); + const std::vector& matchesMask=std::vector(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); /** @overload */ +CV_EXPORTS_W void drawMatches( InputArray img1, const std::vector& keypoints1, + InputArray img2, const std::vector& keypoints2, + const std::vector& matches1to2, InputOutputArray outImg, + const int matchesThickness, const Scalar& matchColor=Scalar::all(-1), + const Scalar& singlePointColor=Scalar::all(-1), const std::vector& matchesMask=std::vector(), + DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); + CV_EXPORTS_AS(drawMatchesKnn) void drawMatches( InputArray img1, const std::vector& keypoints1, InputArray img2, const std::vector& keypoints2, const std::vector >& matches1to2, InputOutputArray outImg, const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1), - const std::vector >& matchesMask=std::vector >(), int flags=DrawMatchesFlags::DEFAULT ); + const std::vector >& matchesMask=std::vector >(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); //! @} features2d_draw diff --git a/3rdparty/include/opencv2/flann.hpp b/3rdparty/include/opencv2/flann.hpp index 5c52bfeeb5..04689037eb 100644 --- a/3rdparty/include/opencv2/flann.hpp +++ b/3rdparty/include/opencv2/flann.hpp @@ -230,14 +230,8 @@ public: int branching = 32, int iterations = 11, flann_centers_init_t centers_init = CENTERS_RANDOM, - float cb_index = 0.2 ); - - KMeansIndexParams( - int branching, - int iterations, - flann_centers_init_t centers_init, - float cb_index, - int trees ); + float cb_index = 0.2, + int trees = 1); }; @endcode - **CompositeIndexParams** When using a parameters object of this type the index created @@ -262,9 +256,9 @@ public: struct LshIndexParams : public IndexParams { LshIndexParams( - unsigned int table_number, - unsigned int key_size, - unsigned int multi_probe_level ); + int table_number, + int key_size, + int multi_probe_level ); }; @endcode - **AutotunedIndexParams** When passing an object of this type the index created is diff --git a/3rdparty/include/opencv2/flann/any.h b/3rdparty/include/opencv2/flann/any.h index f5684e9962..4906fec081 100644 --- a/3rdparty/include/opencv2/flann/any.h +++ b/3rdparty/include/opencv2/flann/any.h @@ -167,17 +167,15 @@ class SinglePolicy public: static base_any_policy* get_policy(); - -private: - static typename choose_policy::type policy; }; -template -typename choose_policy::type SinglePolicy::policy; - /// This function will return a different policy for each type. template -inline base_any_policy* SinglePolicy::get_policy() { return &policy; } +inline base_any_policy* SinglePolicy::get_policy() +{ + static typename choose_policy::type policy; + return &policy; +} } // namespace anyimpl diff --git a/3rdparty/include/opencv2/flann/hierarchical_clustering_index.h b/3rdparty/include/opencv2/flann/hierarchical_clustering_index.h index 7085d6901e..2d39d4f0f6 100644 --- a/3rdparty/include/opencv2/flann/hierarchical_clustering_index.h +++ b/3rdparty/include/opencv2/flann/hierarchical_clustering_index.h @@ -529,6 +529,7 @@ public: { const int maxChecks = get_param(searchParams,"checks",32); + const bool explore_all_trees = get_param(searchParams,"explore_all_trees",false); // Priority queue storing intermediate branches in the best-bin-first search Heap* heap = new Heap((int)size_); @@ -536,15 +537,15 @@ public: std::vector checked(size_,false); int checks = 0; for (int i=0; i= maxChecks) && result.full()) + findNN(root[i], result, vec, checks, maxChecks, heap, checked, explore_all_trees); + if (!explore_all_trees && (checks >= maxChecks) && result.full()) break; } BranchSt branch; while (heap->popMin(branch) && (checks& result, const ElementType* vec, int& checks, int maxChecks, - Heap* heap, std::vector& checked) + Heap* heap, std::vector& checked, bool explore_all_trees = false) { if (node->childs==NULL) { - if ((checks>=maxChecks) && result.full()) { + if (!explore_all_trees && (checks>=maxChecks) && result.full()) { return; } for (int i=0; isize; ++i) { @@ -773,7 +774,7 @@ private: } } delete[] domain_distances; - findNN(node->childs[best_index],result,vec, checks, maxChecks, heap, checked); + findNN(node->childs[best_index],result,vec, checks, maxChecks, heap, checked, explore_all_trees); } } diff --git a/3rdparty/include/opencv2/flann/kdtree_index.h b/3rdparty/include/opencv2/flann/kdtree_index.h index ea3550ad1d..603fdbd421 100644 --- a/3rdparty/include/opencv2/flann/kdtree_index.h +++ b/3rdparty/include/opencv2/flann/kdtree_index.h @@ -203,14 +203,15 @@ public: */ void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE { - int maxChecks = get_param(searchParams,"checks", 32); - float epsError = 1+get_param(searchParams,"eps",0.0f); + const int maxChecks = get_param(searchParams,"checks", 32); + const float epsError = 1+get_param(searchParams,"eps",0.0f); + const bool explore_all_trees = get_param(searchParams,"explore_all_trees",false); if (maxChecks==FLANN_CHECKS_UNLIMITED) { getExactNeighbors(result, vec, epsError); } else { - getNeighbors(result, vec, maxChecks, epsError); + getNeighbors(result, vec, maxChecks, epsError, explore_all_trees); } } @@ -439,7 +440,8 @@ private: * because the tree traversal is abandoned after a given number of descends in * the tree. */ - void getNeighbors(ResultSet& result, const ElementType* vec, int maxCheck, float epsError) + void getNeighbors(ResultSet& result, const ElementType* vec, + int maxCheck, float epsError, bool explore_all_trees = false) { int i; BranchSt branch; @@ -450,12 +452,16 @@ private: /* Search once through each tree down to root. */ for (i = 0; i < trees_; ++i) { - searchLevel(result, vec, tree_roots_[i], 0, checkCount, maxCheck, epsError, heap, checked); + searchLevel(result, vec, tree_roots_[i], 0, checkCount, maxCheck, + epsError, heap, checked, explore_all_trees); + if (!explore_all_trees && (checkCount >= maxCheck) && result.full()) + break; } /* Keep searching other branches from heap until finished. */ while ( heap->popMin(branch) && (checkCount < maxCheck || !result.full() )) { - searchLevel(result, vec, branch.node, branch.mindist, checkCount, maxCheck, epsError, heap, checked); + searchLevel(result, vec, branch.node, branch.mindist, checkCount, maxCheck, + epsError, heap, checked, false); } delete heap; @@ -470,7 +476,7 @@ private: * at least "mindistsq". */ void searchLevel(ResultSet& result_set, const ElementType* vec, NodePtr node, DistanceType mindist, int& checkCount, int maxCheck, - float epsError, Heap* heap, DynamicBitset& checked) + float epsError, Heap* heap, DynamicBitset& checked, bool explore_all_trees = false) { if (result_set.worstDist()divfeat; - if ( checked.test(index) || ((checkCount>=maxCheck)&& result_set.full()) ) return; + if ( checked.test(index) || + (!explore_all_trees && (checkCount>=maxCheck) && result_set.full()) ) { + return; + } checked.set(index); checkCount++; diff --git a/3rdparty/include/opencv2/flann/kmeans_index.h b/3rdparty/include/opencv2/flann/kmeans_index.h index 10b272daaa..f73669999f 100644 --- a/3rdparty/include/opencv2/flann/kmeans_index.h +++ b/3rdparty/include/opencv2/flann/kmeans_index.h @@ -60,8 +60,9 @@ namespace cvflann struct KMeansIndexParams : public IndexParams { - void indexParams(int branching, int iterations, - flann_centers_init_t centers_init, float cb_index, int trees) + KMeansIndexParams(int branching = 32, int iterations = 11, + flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, + float cb_index = 0.2, int trees = 1 ) { (*this)["algorithm"] = FLANN_INDEX_KMEANS; // branching factor @@ -75,18 +76,6 @@ struct KMeansIndexParams : public IndexParams // number of kmeans trees to search in (*this)["trees"] = trees; } - - KMeansIndexParams(int branching = 32, int iterations = 11, - flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, float cb_index = 0.2 ) - { - indexParams(branching, iterations, centers_init, cb_index, 1); - } - - KMeansIndexParams(int branching, int iterations, - flann_centers_init_t centers_init, float cb_index, int trees) - { - indexParams(branching, iterations, centers_init, cb_index, trees); - } }; diff --git a/3rdparty/include/opencv2/flann/lsh_index.h b/3rdparty/include/opencv2/flann/lsh_index.h index 9ff86b8b66..b5e87f6041 100644 --- a/3rdparty/include/opencv2/flann/lsh_index.h +++ b/3rdparty/include/opencv2/flann/lsh_index.h @@ -61,15 +61,15 @@ namespace cvflann struct LshIndexParams : public IndexParams { - LshIndexParams(unsigned int table_number = 12, unsigned int key_size = 20, unsigned int multi_probe_level = 2) + LshIndexParams(int table_number = 12, int key_size = 20, int multi_probe_level = 2) { (*this)["algorithm"] = FLANN_INDEX_LSH; // The number of hash tables to use - (*this)["table_number"] = static_cast(table_number); + (*this)["table_number"] = table_number; // The length of the key in the hash tables - (*this)["key_size"] = static_cast(key_size); + (*this)["key_size"] = key_size; // Number of levels to use in multi-probe (0 for standard LSH) - (*this)["multi_probe_level"] = static_cast(multi_probe_level); + (*this)["multi_probe_level"] = multi_probe_level; } }; diff --git a/3rdparty/include/opencv2/flann/miniflann.hpp b/3rdparty/include/opencv2/flann/miniflann.hpp index 1deeeb93f0..b8df92d758 100644 --- a/3rdparty/include/opencv2/flann/miniflann.hpp +++ b/3rdparty/include/opencv2/flann/miniflann.hpp @@ -54,6 +54,20 @@ namespace cv namespace flann { +enum FlannIndexType { + FLANN_INDEX_TYPE_8U = CV_8U, + FLANN_INDEX_TYPE_8S = CV_8S, + FLANN_INDEX_TYPE_16U = CV_16U, + FLANN_INDEX_TYPE_16S = CV_16S, + FLANN_INDEX_TYPE_32S = CV_32S, + FLANN_INDEX_TYPE_32F = CV_32F, + FLANN_INDEX_TYPE_64F = CV_64F, + FLANN_INDEX_TYPE_STRING, + FLANN_INDEX_TYPE_BOOL, + FLANN_INDEX_TYPE_ALGORITHM, + LAST_VALUE_FLANN_INDEX_TYPE = FLANN_INDEX_TYPE_ALGORITHM +}; + struct CV_EXPORTS IndexParams { IndexParams(); @@ -70,8 +84,9 @@ struct CV_EXPORTS IndexParams void setBool(const String& key, bool value); void setAlgorithm(int value); + // FIXIT: replace by void write(FileStorage& fs) const + read() void getAll(std::vector& names, - std::vector& types, + std::vector& types, std::vector& strValues, std::vector& numValues) const; @@ -128,39 +143,39 @@ struct CV_EXPORTS SavedIndexParams : public IndexParams struct CV_EXPORTS SearchParams : public IndexParams { + SearchParams( int checks, float eps, bool sorted, bool explore_all_trees ); SearchParams( int checks = 32, float eps = 0, bool sorted = true ); }; -class CV_EXPORTS Index +class CV_EXPORTS_W Index { public: - Index(); - - /// @note 'features' must have extended lifetime (as cv::Mat) than this #Index instance (to avoid dangling pointers) - Index(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); + CV_WRAP Index(); + CV_WRAP Index(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); virtual ~Index(); - /// @note 'features' must have extended lifetime (as cv::Mat) than this #Index instance (to avoid dangling pointers) - virtual void build(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); - - virtual void knnSearch(InputArray query, OutputArray indices, + CV_WRAP virtual void build(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); + CV_WRAP virtual void knnSearch(InputArray query, OutputArray indices, OutputArray dists, int knn, const SearchParams& params=SearchParams()); - virtual int radiusSearch(InputArray query, OutputArray indices, + CV_WRAP virtual int radiusSearch(InputArray query, OutputArray indices, OutputArray dists, double radius, int maxResults, const SearchParams& params=SearchParams()); - virtual void save(const String& filename) const; - virtual bool load(InputArray features, const String& filename); - virtual void release(); - cvflann::flann_distance_t getDistance() const; - cvflann::flann_algorithm_t getAlgorithm() const; + CV_WRAP virtual void save(const String& filename) const; + CV_WRAP virtual bool load(InputArray features, const String& filename); + CV_WRAP virtual void release(); + CV_WRAP cvflann::flann_distance_t getDistance() const; + CV_WRAP cvflann::flann_algorithm_t getAlgorithm() const; protected: + bool load_(const String& filename); + cvflann::flann_distance_t distType; cvflann::flann_algorithm_t algo; int featureType; void* index; + Mat features_clone; // index may store features pointer internally for searching, so avoid dangling pointers: https://github.com/opencv/opencv/issues/17553 }; } } // namespace cv::flann diff --git a/3rdparty/include/opencv2/flann/params.h b/3rdparty/include/opencv2/flann/params.h index a7920d0b71..c9093cde8c 100644 --- a/3rdparty/include/opencv2/flann/params.h +++ b/3rdparty/include/opencv2/flann/params.h @@ -46,6 +46,16 @@ typedef std::map IndexParams; struct SearchParams : public IndexParams { SearchParams(int checks = 32, float eps = 0, bool sorted = true ) + { + init(checks, eps, sorted, false); + } + + SearchParams(int checks, float eps, bool sorted, bool explore_all_trees ) + { + init(checks, eps, sorted, explore_all_trees); + } + + void init(int checks = 32, float eps = 0, bool sorted = true, bool explore_all_trees = false ) { // how many leafs to visit when searching for neighbours (-1 for unlimited) (*this)["checks"] = checks; @@ -53,6 +63,10 @@ struct SearchParams : public IndexParams (*this)["eps"] = eps; // only for radius search, require neighbours sorted by distance (default: true) (*this)["sorted"] = sorted; + // if false, search stops at the tree reaching the number of max checks (original behavior). + // When true, we do a descent in each tree and. Like before the alternative paths + // stored in the heap are not be processed further when max checks is reached. + (*this)["explore_all_trees"] = explore_all_trees; } }; diff --git a/3rdparty/include/opencv2/fuzzy.hpp b/3rdparty/include/opencv2/fuzzy.hpp deleted file mode 100644 index d660cc3615..0000000000 --- a/3rdparty/include/opencv2/fuzzy.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/*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) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, -// Pavel Vlasanek, 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_FUZZY_H__ -#define __OPENCV_FUZZY_H__ - -#include "opencv2/fuzzy/types.hpp" -#include "opencv2/fuzzy/fuzzy_F0_math.hpp" -#include "opencv2/fuzzy/fuzzy_F1_math.hpp" -#include "opencv2/fuzzy/fuzzy_image.hpp" - -/** -@defgroup fuzzy Image processing based on fuzzy mathematics - -Namespace for all functions is `ft`. The module brings implementation of the last image processing algorithms based on fuzzy mathematics. Method are named based on the pattern `FT`_degree_dimension`_`method. - - @{ - @defgroup f0_math Math with F0-transform support - -Fuzzy transform (\f$F^0\f$-transform) of the 0th degree transforms whole image to a matrix of its components. These components are used in latter computation where each of them represents average color of certain subarea. - - @defgroup f1_math Math with F1-transform support - -Fuzzy transform (\f$F^1\f$-transform) of the 1th degree transforms whole image to a matrix of its components. Each component is polynomial of the 1th degree carrying information about average color and average gradient of certain subarea. - - @defgroup f_image Fuzzy image processing - -Image proceesing based on fuzzy mathematics namely F-transform. - @} - -*/ - -#endif // __OPENCV_FUZZY_H__ diff --git a/3rdparty/include/opencv2/fuzzy/fuzzy_F0_math.hpp b/3rdparty/include/opencv2/fuzzy/fuzzy_F0_math.hpp deleted file mode 100644 index 7beeb9bd2f..0000000000 --- a/3rdparty/include/opencv2/fuzzy/fuzzy_F0_math.hpp +++ /dev/null @@ -1,121 +0,0 @@ -/*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) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, -// Pavel Vlasanek, 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_FUZZY_F0_MATH_H__ -#define __OPENCV_FUZZY_F0_MATH_H__ - -#include "opencv2/fuzzy/types.hpp" -#include "opencv2/core.hpp" - -namespace cv -{ - -namespace ft -{ - //! @addtogroup f0_math - //! @{ - - /** @brief Computes components of the array using direct \f$F^0\f$-transform. - @param matrix Input array. - @param kernel Kernel used for processing. Function `ft::createKernel` can be used. - @param components Output 32-bit float array for the components. - @param mask Mask can be used for unwanted area marking. - - The function computes components using predefined kernel and mask. - */ - CV_EXPORTS_W void FT02D_components(InputArray matrix, InputArray kernel, OutputArray components, InputArray mask = noArray()); - - /** @brief Computes inverse \f$F^0\f$-transfrom. - @param components Input 32-bit float single channel array for the components. - @param kernel Kernel used for processing. Function `ft::createKernel` can be used. - @param output Output 32-bit float array. - @param width Width of the output array. - @param height Height of the output array. - - Computation of inverse F-transform. - */ - CV_EXPORTS_W void FT02D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height); - - /** @brief Computes \f$F^0\f$-transfrom and inverse \f$F^0\f$-transfrom at once. - @param matrix Input matrix. - @param kernel Kernel used for processing. Function `ft::createKernel` can be used. - @param output Output 32-bit float array. - @param mask Mask used for unwanted area marking. - - This function computes F-transfrom and inverse F-transfotm in one step. It is fully sufficient and optimized for `cv::Mat`. - */ - CV_EXPORTS_W void FT02D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask = noArray()); - - /** @brief Computes \f$F^0\f$-transfrom and inverse \f$F^0\f$-transfrom at once and return state. - @param matrix Input matrix. - @param kernel Kernel used for processing. Function `ft::createKernel` can be used. - @param output Output 32-bit float array. - @param mask Mask used for unwanted area marking. - @param maskOutput Mask after one iteration. - @param firstStop If **true** function returns -1 when first problem appears. In case of `false` the process is completed and summation of all problems returned. - - This function computes iteration of F-transfrom and inverse F-transfotm and handle image and mask change. The function is used in `ft::inpaint` function. - */ - CV_EXPORTS_W int FT02D_iteration(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask, OutputArray maskOutput, bool firstStop); - - /** @brief Sligtly less accurate version of \f$F^0\f$-transfrom computation optimized for higher speed. The methods counts with linear basic function. - @param matrix Input 3 channels matrix. - @param radius Radius of the `ft::LINEAR` basic function. - @param output Output array. - - This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~10 times faster than `ft::FT02D_process` method. - */ - CV_EXPORTS_W void FT02D_FL_process(InputArray matrix, const int radius, OutputArray output); - - /** @brief Sligtly less accurate version of \f$F^0\f$-transfrom computation optimized for higher speed. The methods counts with linear basic function. - @param matrix Input 3 channels matrix. - @param radius Radius of the `ft::LINEAR` basic function. - @param output Output array. - - This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~9 times faster then `ft::FT02D_process` method and more accurate than `ft::FT02D_FL_process` method. - */ - CV_EXPORTS_W void FT02D_FL_process_float(InputArray matrix, const int radius, OutputArray output); - - //! @} -} -} - -#endif // __OPENCV_FUZZY_F0_MATH_H__ diff --git a/3rdparty/include/opencv2/fuzzy/fuzzy_F1_math.hpp b/3rdparty/include/opencv2/fuzzy/fuzzy_F1_math.hpp deleted file mode 100644 index 3320e67376..0000000000 --- a/3rdparty/include/opencv2/fuzzy/fuzzy_F1_math.hpp +++ /dev/null @@ -1,124 +0,0 @@ -/*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) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, -// Pavel Vlasanek, 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_FUZZY_F1_MATH_H__ -#define __OPENCV_FUZZY_F1_MATH_H__ - -#include "opencv2/fuzzy/types.hpp" -#include "opencv2/core.hpp" - -namespace cv -{ - -namespace ft -{ - //! @addtogroup f1_math - //! @{ - - /** @brief Computes components of the array using direct \f$F^1\f$-transform. - @param matrix Input array. - @param kernel Kernel used for processing. Function `ft::createKernel` can be used. - @param components Output 32-bit float array for the components. - - The function computes linear components using predefined kernel. - */ - CV_EXPORTS_W void FT12D_components(InputArray matrix, InputArray kernel, OutputArray components); - - /** @brief Computes elements of \f$F^1\f$-transform components. - @param matrix Input array. - @param kernel Kernel used for processing. Function `ft::createKernel` can be used. - @param c00 Elements represent average color. - @param c10 Elements represent average vertical gradient. - @param c01 Elements represent average horizontal gradient. - @param components Output 32-bit float array for the components. - @param mask Mask can be used for unwanted area marking. - - The function computes components and its elements using predefined kernel and mask. - */ - CV_EXPORTS_W void FT12D_polynomial(InputArray matrix, InputArray kernel, OutputArray c00, OutputArray c10, OutputArray c01, OutputArray components, InputArray mask = noArray()); - - /** @brief Creates vertical matrix for \f$F^1\f$-transform computation. - @param radius Radius of the basic function. - @param matrix The vertical matrix. - @param chn Number of channels. - - The function creates helper vertical matrix for \f$F^1\f$-transfrom processing. It is used for gradient computation. - */ - CV_EXPORTS_W void FT12D_createPolynomMatrixVertical(int radius, OutputArray matrix, const int chn); - - /** @brief Creates horizontal matrix for \f$F^1\f$-transform computation. - @param radius Radius of the basic function. - @param matrix The horizontal matrix. - @param chn Number of channels. - - The function creates helper horizontal matrix for \f$F^1\f$-transfrom processing. It is used for gradient computation. - */ - CV_EXPORTS_W void FT12D_createPolynomMatrixHorizontal(int radius, OutputArray matrix, const int chn); - - /** @brief Computes \f$F^1\f$-transfrom and inverse \f$F^1\f$-transfrom at once. - @param matrix Input matrix. - @param kernel Kernel used for processing. Function `ft::createKernel` can be used. - @param output Output 32-bit float array. - @param mask Mask used for unwanted area marking. - - This function computes \f$F^1\f$-transfrom and inverse \f$F^1\f$-transfotm in one step. It is fully sufficient and optimized for `cv::Mat`. - - @note - F-transform technique of first degreee is described in paper @cite Vlas:FT. - */ - CV_EXPORTS_W void FT12D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask = noArray()); - - /** @brief Computes inverse \f$F^1\f$-transfrom. - @param components Input 32-bit float single channel array for the components. - @param kernel Kernel used for processing. The same kernel as for components computation must be used. - @param output Output 32-bit float array. - @param width Width of the output array. - @param height Height of the output array. - - Computation of inverse \f$F^1\f$-transform. - */ - CV_EXPORTS_W void FT12D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height); - - //! @} -} -} - -#endif // __OPENCV_FUZZY_F1_MATH_H__ diff --git a/3rdparty/include/opencv2/fuzzy/fuzzy_image.hpp b/3rdparty/include/opencv2/fuzzy/fuzzy_image.hpp deleted file mode 100644 index 9c9eeff321..0000000000 --- a/3rdparty/include/opencv2/fuzzy/fuzzy_image.hpp +++ /dev/null @@ -1,109 +0,0 @@ -/*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) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, -// Pavel Vlasanek, 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_FUZZY_IMAGE_H__ -#define __OPENCV_FUZZY_IMAGE_H__ - -#include "types.hpp" -#include "opencv2/core.hpp" - -namespace cv -{ - -namespace ft -{ - //! @addtogroup f_image - //! @{ - - /** @brief Creates kernel from basic functions. - @param A Basic function used in axis **x**. - @param B Basic function used in axis **y**. - @param kernel Final 32-bit kernel derived from **A** and **B**. - @param chn Number of kernel channels. - - The function creates kernel usable for latter fuzzy image processing. - */ - CV_EXPORTS_AS(createKernel1) void createKernel(InputArray A, InputArray B, OutputArray kernel, const int chn); - - /** @brief Creates kernel from general functions. - @param function Function type could be one of the following: - - **LINEAR** Linear basic function. - @param radius Radius of the basic function. - @param kernel Final 32-bit kernel. - @param chn Number of kernel channels. - - The function creates kernel from predefined functions. - */ - CV_EXPORTS_W void createKernel(int function, int radius, OutputArray kernel, const int chn); - - /** @brief Image inpainting - @param image Input image. - @param mask Mask used for unwanted area marking. - @param output Output 32-bit image. - @param radius Radius of the basic function. - @param function Function type could be one of the following: - - `ft::LINEAR` Linear basic function. - @param algorithm Algorithm could be one of the following: - - `ft::ONE_STEP` One step algorithm. - - `ft::MULTI_STEP` This algorithm automaticaly increases radius of the basic function. - - `ft::ITERATIVE` Iterative algorithm running in more steps using partial computations. - - This function provides inpainting technique based on the fuzzy mathematic. - - @note - The algorithms are described in paper @cite Perf:rec. - */ - CV_EXPORTS_W void inpaint(InputArray image, InputArray mask, OutputArray output, int radius, int function, int algorithm); - - /** @brief Image filtering - @param image Input image. - @param kernel Final 32-bit kernel. - @param output Output 32-bit image. - - Filtering of the input image by means of F-transform. - */ - CV_EXPORTS_W void filter(InputArray image, InputArray kernel, OutputArray output); - - //! @} -} -} - -#endif // __OPENCV_FUZZY_IMAGE_H__ diff --git a/3rdparty/include/opencv2/fuzzy/types.hpp b/3rdparty/include/opencv2/fuzzy/types.hpp deleted file mode 100644 index 22e0a0165f..0000000000 --- a/3rdparty/include/opencv2/fuzzy/types.hpp +++ /dev/null @@ -1,70 +0,0 @@ -/*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) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, -// Pavel Vlasanek, 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_FUZZY_TYPES_H__ -#define __OPENCV_FUZZY_TYPES_H__ - -namespace cv -{ - -namespace ft -{ - //! @addtogroup fuzzy - //! @{ - - enum - { - LINEAR = 1, //!< linear (triangular) shape - SINUS = 2 //!< sinusoidal shape - }; - - enum - { - ONE_STEP = 1, //!< processing in one step - MULTI_STEP = 2, //!< processing in multiple step - ITERATIVE = 3 //!< processing in several iterations - }; - - //! @} -} -} - -#endif // __OPENCV_FUZZY_TYPES_H__ diff --git a/3rdparty/include/opencv2/gapi.hpp b/3rdparty/include/opencv2/gapi.hpp new file mode 100644 index 0000000000..e4b2021479 --- /dev/null +++ b/3rdparty/include/opencv2/gapi.hpp @@ -0,0 +1,41 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_HPP +#define OPENCV_GAPI_HPP + +#include + +/** \defgroup gapi G-API framework +@{ + @defgroup gapi_main_classes G-API Main Classes + @defgroup gapi_data_objects G-API Data Types + @{ + @defgroup gapi_meta_args G-API Metadata Descriptors + @} + @defgroup gapi_std_backends G-API Standard Backends + @defgroup gapi_compile_args G-API Graph Compilation Arguments +@} + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Include these files here to avoid cyclic dependency between +// Desync & GKernel & GComputation & GStreamingCompiled. +#include +#include + +#endif // OPENCV_GAPI_HPP diff --git a/3rdparty/include/opencv2/gapi/core.hpp b/3rdparty/include/opencv2/gapi/core.hpp new file mode 100644 index 0000000000..b7f65b6719 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/core.hpp @@ -0,0 +1,1987 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_CORE_HPP +#define OPENCV_GAPI_CORE_HPP + +#include + +#include // std::tuple + +#include + +#include +#include +#include +#include + +/** \defgroup gapi_core G-API Core functionality +@{ + @defgroup gapi_math Graph API: Math operations + @defgroup gapi_pixelwise Graph API: Pixelwise operations + @defgroup gapi_matrixop Graph API: Operations on matrices + @defgroup gapi_transform Graph API: Image and channel composition functions +@} + */ + +namespace cv { namespace gapi { +/** + * @brief This namespace contains G-API Operation Types for OpenCV + * Core module functionality. + */ +namespace core { + using GMat2 = std::tuple; + using GMat3 = std::tuple; // FIXME: how to avoid this? + using GMat4 = std::tuple; + using GMatScalar = std::tuple; + + G_TYPED_KERNEL(GAdd, , "org.opencv.core.math.add") { + static GMatDesc outMeta(GMatDesc a, GMatDesc b, int ddepth) { + if (ddepth == -1) + { + // OpenCV: When the input arrays in add/subtract/multiply/divide + // functions have different depths, the output array depth must be + // explicitly specified! + // See artim_op() @ arithm.cpp + GAPI_Assert(a.chan == b.chan); + GAPI_Assert(a.depth == b.depth); + return a; + } + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GAddC, , "org.opencv.core.math.addC") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GSub, , "org.opencv.core.math.sub") { + static GMatDesc outMeta(GMatDesc a, GMatDesc b, int ddepth) { + if (ddepth == -1) + { + // This macro should select a larger data depth from a and b + // considering the number of channels in the same + // FIXME!!! Clarify if it is valid for sub() + GAPI_Assert(a.chan == b.chan); + ddepth = std::max(a.depth, b.depth); + } + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GSubC, , "org.opencv.core.math.subC") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GSubRC,, "org.opencv.core.math.subRC") { + static GMatDesc outMeta(GScalarDesc, GMatDesc b, int ddepth) { + return b.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMul, , "org.opencv.core.math.mul") { + static GMatDesc outMeta(GMatDesc a, GMatDesc, double, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMulCOld, , "org.opencv.core.math.mulCOld") { + static GMatDesc outMeta(GMatDesc a, double, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMulC, , "org.opencv.core.math.mulC"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMulS, , "org.opencv.core.math.muls") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a; + } + }; // FIXME: Merge with MulC + + G_TYPED_KERNEL(GDiv, , "org.opencv.core.math.div") { + static GMatDesc outMeta(GMatDesc a, GMatDesc b, double, int ddepth) { + if (ddepth == -1) + { + GAPI_Assert(a.depth == b.depth); + return b; + } + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GDivC, , "org.opencv.core.math.divC") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc, double, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GDivRC, , "org.opencv.core.math.divRC") { + static GMatDesc outMeta(GScalarDesc, GMatDesc b, double, int ddepth) { + return b.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMean, , "org.opencv.core.math.mean") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL_M(GPolarToCart, , "org.opencv.core.math.polarToCart") { + static std::tuple outMeta(GMatDesc, GMatDesc a, bool) { + return std::make_tuple(a, a); + } + }; + + G_TYPED_KERNEL_M(GCartToPolar, , "org.opencv.core.math.cartToPolar") { + static std::tuple outMeta(GMatDesc x, GMatDesc, bool) { + return std::make_tuple(x, x); + } + }; + + G_TYPED_KERNEL(GPhase, , "org.opencv.core.math.phase") { + static GMatDesc outMeta(const GMatDesc &inx, const GMatDesc &, bool) { + return inx; + } + }; + + G_TYPED_KERNEL(GMask, , "org.opencv.core.pixelwise.mask") { + static GMatDesc outMeta(GMatDesc in, GMatDesc) { + return in; + } + }; + + G_TYPED_KERNEL(GCmpGT, , "org.opencv.core.pixelwise.compare.cmpGT") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpGE, , "org.opencv.core.pixelwise.compare.cmpGE") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpLE, , "org.opencv.core.pixelwise.compare.cmpLE") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpLT, , "org.opencv.core.pixelwise.compare.cmpLT") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpEQ, , "org.opencv.core.pixelwise.compare.cmpEQ") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpNE, , "org.opencv.core.pixelwise.compare.cmpNE") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpGTScalar, , "org.opencv.core.pixelwise.compare.cmpGTScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpGEScalar, , "org.opencv.core.pixelwise.compare.cmpGEScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpLEScalar, , "org.opencv.core.pixelwise.compare.cmpLEScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpLTScalar, , "org.opencv.core.pixelwise.compare.cmpLTScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpEQScalar, , "org.opencv.core.pixelwise.compare.cmpEQScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpNEScalar, , "org.opencv.core.pixelwise.compare.cmpNEScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GAnd, , "org.opencv.core.pixelwise.bitwise_and") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GAndS, , "org.opencv.core.pixelwise.bitwise_andS") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GOr, , "org.opencv.core.pixelwise.bitwise_or") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GOrS, , "org.opencv.core.pixelwise.bitwise_orS") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GXor, , "org.opencv.core.pixelwise.bitwise_xor") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GXorS, , "org.opencv.core.pixelwise.bitwise_xorS") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GNot, , "org.opencv.core.pixelwise.bitwise_not") { + static GMatDesc outMeta(GMatDesc a) { + return a; + } + }; + + G_TYPED_KERNEL(GSelect, , "org.opencv.core.pixelwise.select") { + static GMatDesc outMeta(GMatDesc a, GMatDesc, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GMin, , "org.opencv.core.matrixop.min") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GMax, , "org.opencv.core.matrixop.max") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GAbsDiff, , "org.opencv.core.matrixop.absdiff") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GAbsDiffC, , "org.opencv.core.matrixop.absdiffC") { + static GMatDesc outMeta(const GMatDesc& a, const GScalarDesc&) { + return a; + } + }; + + G_TYPED_KERNEL(GSum, , "org.opencv.core.matrixop.sum") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL(GCountNonZero, (GMat)>, "org.opencv.core.matrixop.countNonZero") { + static GOpaqueDesc outMeta(GMatDesc in) { + GAPI_Assert(in.chan == 1); + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GAddW, , "org.opencv.core.matrixop.addweighted") { + static GMatDesc outMeta(GMatDesc a, double, GMatDesc b, double, double, int ddepth) { + if (ddepth == -1) + { + // OpenCV: When the input arrays in add/subtract/multiply/divide + // functions have different depths, the output array depth must be + // explicitly specified! + // See artim_op() @ arithm.cpp + GAPI_Assert(a.chan == b.chan); + GAPI_Assert(a.depth == b.depth); + return a; + } + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GNormL1, , "org.opencv.core.matrixop.norml1") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL(GNormL2, , "org.opencv.core.matrixop.norml2") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL(GNormInf, , "org.opencv.core.matrixop.norminf") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL_M(GIntegral, , "org.opencv.core.matrixop.integral") { + static std::tuple outMeta(GMatDesc in, int sd, int sqd) { + return std::make_tuple(in.withSizeDelta(1,1).withDepth(sd), + in.withSizeDelta(1,1).withDepth(sqd)); + } + }; + + G_TYPED_KERNEL(GThreshold, , "org.opencv.core.matrixop.threshold") { + static GMatDesc outMeta(GMatDesc in, GScalarDesc, GScalarDesc, int) { + return in; + } + }; + + + G_TYPED_KERNEL_M(GThresholdOT, , "org.opencv.core.matrixop.thresholdOT") { + static std::tuple outMeta(GMatDesc in, GScalarDesc, int) { + return std::make_tuple(in, empty_scalar_desc()); + } + }; + + G_TYPED_KERNEL(GInRange, , "org.opencv.core.matrixop.inrange") { + static GMatDesc outMeta(GMatDesc in, GScalarDesc, GScalarDesc) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL_M(GSplit3, , "org.opencv.core.transform.split3") { + static std::tuple outMeta(GMatDesc in) { + const auto out_depth = in.depth; + const auto out_desc = in.withType(out_depth, 1); + return std::make_tuple(out_desc, out_desc, out_desc); + } + }; + + G_TYPED_KERNEL_M(GSplit4, ,"org.opencv.core.transform.split4") { + static std::tuple outMeta(GMatDesc in) { + const auto out_depth = in.depth; + const auto out_desc = in.withType(out_depth, 1); + return std::make_tuple(out_desc, out_desc, out_desc, out_desc); + } + }; + + G_TYPED_KERNEL(GResize, , "org.opencv.core.transform.resize") { + static GMatDesc outMeta(GMatDesc in, Size sz, double fx, double fy, int) { + if (sz.width != 0 && sz.height != 0) + { + return in.withSize(sz); + } + else + { + int outSz_w = static_cast(round(in.size.width * fx)); + int outSz_h = static_cast(round(in.size.height * fy)); + GAPI_Assert(outSz_w > 0 && outSz_h > 0); + return in.withSize(Size(outSz_w, outSz_h)); + } + } + }; + + G_TYPED_KERNEL(GResizeP, , "org.opencv.core.transform.resizeP") { + static GMatDesc outMeta(GMatDesc in, Size sz, int interp) { + GAPI_Assert(in.depth == CV_8U); + GAPI_Assert(in.chan == 3); + GAPI_Assert(in.planar); + GAPI_Assert(interp == cv::INTER_LINEAR); + return in.withSize(sz); + } + }; + + G_TYPED_KERNEL(GMerge3, , "org.opencv.core.transform.merge3") { + static GMatDesc outMeta(GMatDesc in, GMatDesc, GMatDesc) { + // Preserve depth and add channel component + return in.withType(in.depth, 3); + } + }; + + G_TYPED_KERNEL(GMerge4, , "org.opencv.core.transform.merge4") { + static GMatDesc outMeta(GMatDesc in, GMatDesc, GMatDesc, GMatDesc) { + // Preserve depth and add channel component + return in.withType(in.depth, 4); + } + }; + + G_TYPED_KERNEL(GRemap, , "org.opencv.core.transform.remap") { + static GMatDesc outMeta(GMatDesc in, Mat m1, Mat, int, int, Scalar) { + return in.withSize(m1.size()); + } + }; + + G_TYPED_KERNEL(GFlip, , "org.opencv.core.transform.flip") { + static GMatDesc outMeta(GMatDesc in, int) { + return in; + } + }; + + // TODO: eliminate the need in this kernel (streaming) + G_TYPED_KERNEL(GCrop, , "org.opencv.core.transform.crop") { + static GMatDesc outMeta(GMatDesc in, Rect rc) { + return in.withSize(Size(rc.width, rc.height)); + } + }; + + G_TYPED_KERNEL(GConcatHor, , "org.opencv.imgproc.transform.concatHor") { + static GMatDesc outMeta(GMatDesc l, GMatDesc r) { + return l.withSizeDelta(+r.size.width, 0); + } + }; + + G_TYPED_KERNEL(GConcatVert, , "org.opencv.imgproc.transform.concatVert") { + static GMatDesc outMeta(GMatDesc t, GMatDesc b) { + return t.withSizeDelta(0, +b.size.height); + } + }; + + G_TYPED_KERNEL(GLUT, , "org.opencv.core.transform.LUT") { + static GMatDesc outMeta(GMatDesc in, Mat) { + return in; + } + }; + + G_TYPED_KERNEL(GConvertTo, , "org.opencv.core.transform.convertTo") { + static GMatDesc outMeta(GMatDesc in, int rdepth, double, double) { + return rdepth < 0 ? in : in.withDepth(rdepth); + } + }; + + G_TYPED_KERNEL(GSqrt, , "org.opencv.core.math.sqrt") { + static GMatDesc outMeta(GMatDesc in) { + return in; + } + }; + + G_TYPED_KERNEL(GNormalize, , "org.opencv.core.normalize") { + static GMatDesc outMeta(GMatDesc in, double, double, int, int ddepth) { + // unlike opencv doesn't have a mask as a parameter + return (ddepth < 0 ? in : in.withDepth(ddepth)); + } + }; + + G_TYPED_KERNEL(GWarpPerspective, , "org.opencv.core.warpPerspective") { + static GMatDesc outMeta(GMatDesc in, const Mat&, Size dsize, int, int borderMode, const cv::Scalar&) { + GAPI_Assert((borderMode == cv::BORDER_CONSTANT || borderMode == cv::BORDER_REPLICATE) && + "cv::gapi::warpPerspective supports only cv::BORDER_CONSTANT and cv::BORDER_REPLICATE border modes"); + return in.withType(in.depth, in.chan).withSize(dsize); + } + }; + + G_TYPED_KERNEL(GWarpAffine, , "org.opencv.core.warpAffine") { + static GMatDesc outMeta(GMatDesc in, const Mat&, Size dsize, int, int border_mode, const cv::Scalar&) { + GAPI_Assert(border_mode != cv::BORDER_TRANSPARENT && + "cv::BORDER_TRANSPARENT mode is not supported in cv::gapi::warpAffine"); + return in.withType(in.depth, in.chan).withSize(dsize); + } + }; + + G_TYPED_KERNEL( + GKMeansND, + ,GMat,GMat>(GMat,int,GMat,TermCriteria,int,KmeansFlags)>, + "org.opencv.core.kmeansND") { + + static std::tuple + outMeta(const GMatDesc& in, int K, const GMatDesc& bestLabels, const TermCriteria&, int, + KmeansFlags flags) { + GAPI_Assert(in.depth == CV_32F); + std::vector amount_n_dim = detail::checkVector(in); + int amount = amount_n_dim[0], dim = amount_n_dim[1]; + if (amount == -1) // Mat with height != 1, width != 1, channels != 1 given + { // which means that kmeans will consider the following: + amount = in.size.height; + dim = in.size.width * in.chan; + } + // kmeans sets these labels' sizes when no bestLabels given: + GMatDesc out_labels(CV_32S, 1, Size{1, amount}); + // kmeans always sets these centers' sizes: + GMatDesc centers (CV_32F, 1, Size{dim, K}); + if (flags & KMEANS_USE_INITIAL_LABELS) + { + GAPI_Assert(bestLabels.depth == CV_32S); + int labels_amount = detail::checkVector(bestLabels, 1u); + GAPI_Assert(labels_amount == amount); + out_labels = bestLabels; // kmeans preserves bestLabels' sizes if given + } + return std::make_tuple(empty_gopaque_desc(), out_labels, centers); + } + }; + + G_TYPED_KERNEL( + GKMeansNDNoInit, + ,GMat,GMat>(GMat,int,TermCriteria,int,KmeansFlags)>, + "org.opencv.core.kmeansNDNoInit") { + + static std::tuple + outMeta(const GMatDesc& in, int K, const TermCriteria&, int, KmeansFlags flags) { + GAPI_Assert( !(flags & KMEANS_USE_INITIAL_LABELS) ); + GAPI_Assert(in.depth == CV_32F); + std::vector amount_n_dim = detail::checkVector(in); + int amount = amount_n_dim[0], dim = amount_n_dim[1]; + if (amount == -1) // Mat with height != 1, width != 1, channels != 1 given + { // which means that kmeans will consider the following: + amount = in.size.height; + dim = in.size.width * in.chan; + } + GMatDesc out_labels(CV_32S, 1, Size{1, amount}); + GMatDesc centers (CV_32F, 1, Size{dim, K}); + return std::make_tuple(empty_gopaque_desc(), out_labels, centers); + } + }; + + G_TYPED_KERNEL(GKMeans2D, ,GArray,GArray> + (GArray,int,GArray,TermCriteria,int,KmeansFlags)>, + "org.opencv.core.kmeans2D") { + static std::tuple + outMeta(const GArrayDesc&,int,const GArrayDesc&,const TermCriteria&,int,KmeansFlags) { + return std::make_tuple(empty_gopaque_desc(), empty_array_desc(), empty_array_desc()); + } + }; + + G_TYPED_KERNEL(GKMeans3D, ,GArray,GArray> + (GArray,int,GArray,TermCriteria,int,KmeansFlags)>, + "org.opencv.core.kmeans3D") { + static std::tuple + outMeta(const GArrayDesc&,int,const GArrayDesc&,const TermCriteria&,int,KmeansFlags) { + return std::make_tuple(empty_gopaque_desc(), empty_array_desc(), empty_array_desc()); + } + }; + + G_TYPED_KERNEL(GTranspose, , "org.opencv.core.transpose") { + static GMatDesc outMeta(GMatDesc in) { + return in.withSize({in.size.height, in.size.width}); + } + }; +} // namespace core + +namespace streaming { + +// Operations for Streaming (declared in this header for convenience) +G_TYPED_KERNEL(GSize, (GMat)>, "org.opencv.streaming.size") { + static GOpaqueDesc outMeta(const GMatDesc&) { + return empty_gopaque_desc(); + } +}; + +G_TYPED_KERNEL(GSizeR, (GOpaque)>, "org.opencv.streaming.sizeR") { + static GOpaqueDesc outMeta(const GOpaqueDesc&) { + return empty_gopaque_desc(); + } +}; + +G_TYPED_KERNEL(GSizeMF, (GFrame)>, "org.opencv.streaming.sizeMF") { + static GOpaqueDesc outMeta(const GFrameDesc&) { + return empty_gopaque_desc(); + } +}; +} // namespace streaming + +//! @addtogroup gapi_math +//! @{ + +/** @brief Calculates the per-element sum of two matrices. + +The function add calculates sum of two matrices of the same size and the same number of channels: +\f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f] + +The function can be replaced with matrix expressions: + \f[\texttt{dst} = \texttt{src1} + \texttt{src2}\f] + +The input matrices and the output matrix can all have the same or different depths. For example, you +can add a 16-bit unsigned matrix to a 8-bit signed matrix and store the sum as a 32-bit +floating-point matrix. Depth of the output matrix is determined by the ddepth parameter. +If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have +the same depth as the input matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.add" +@param src1 first input matrix. +@param src2 second input matrix. +@param ddepth optional depth of the output matrix. +@sa sub, addWeighted +*/ +GAPI_EXPORTS_W GMat add(const GMat& src1, const GMat& src2, int ddepth = -1); + +/** @brief Calculates the per-element sum of matrix and given scalar. + +The function addC adds a given scalar value to each element of given matrix. +The function can be replaced with matrix expressions: + + \f[\texttt{dst} = \texttt{src1} + \texttt{c}\f] + +Depth of the output matrix is determined by the ddepth parameter. +If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix. +The matrices can be single or multi channel. Output matrix must have the same size and number of channels as the input matrix. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.addC" +@param src1 first input matrix. +@param c scalar value to be added. +@param ddepth optional depth of the output matrix. +@sa sub, addWeighted +*/ +GAPI_EXPORTS_W GMat addC(const GMat& src1, const GScalar& c, int ddepth = -1); +//! @overload +GAPI_EXPORTS GMat addC(const GScalar& c, const GMat& src1, int ddepth = -1); + +/** @brief Calculates the per-element difference between two matrices. + +The function sub calculates difference between two matrices, when both matrices have the same size and the same number of +channels: + \f[\texttt{dst}(I) = \texttt{src1}(I) - \texttt{src2}(I)\f] + +The function can be replaced with matrix expressions: +\f[\texttt{dst} = \texttt{src1} - \texttt{src2}\f] + +The input matrices and the output matrix can all have the same or different depths. For example, you +can subtract two 8-bit unsigned matrices store the result as a 16-bit signed matrix. +Depth of the output matrix is determined by the ddepth parameter. +If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have +the same depth as the input matrices. The matrices can be single or multi channel. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.sub" +@param src1 first input matrix. +@param src2 second input matrix. +@param ddepth optional depth of the output matrix. +@sa add, addC + */ +GAPI_EXPORTS GMat sub(const GMat& src1, const GMat& src2, int ddepth = -1); + +/** @brief Calculates the per-element difference between matrix and given scalar. + +The function can be replaced with matrix expressions: + \f[\texttt{dst} = \texttt{src} - \texttt{c}\f] + +Depth of the output matrix is determined by the ddepth parameter. +If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix. +The matrices can be single or multi channel. Output matrix must have the same size as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.subC" +@param src first input matrix. +@param c scalar value to subtracted. +@param ddepth optional depth of the output matrix. +@sa add, addC, subRC + */ +GAPI_EXPORTS GMat subC(const GMat& src, const GScalar& c, int ddepth = -1); + +/** @brief Calculates the per-element difference between given scalar and the matrix. + +The function can be replaced with matrix expressions: + \f[\texttt{dst} = \texttt{val} - \texttt{src}\f] + +Depth of the output matrix is determined by the ddepth parameter. +If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix. +The matrices can be single or multi channel. Output matrix must have the same size as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.subRC" +@param c scalar value to subtract from. +@param src input matrix to be subtracted. +@param ddepth optional depth of the output matrix. +@sa add, addC, subC + */ +GAPI_EXPORTS GMat subRC(const GScalar& c, const GMat& src, int ddepth = -1); + +/** @brief Calculates the per-element scaled product of two matrices. + +The function mul calculates the per-element product of two matrices: + +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I))\f] + +If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have +the same depth as the input matrices. The matrices can be single or multi channel. +Output matrix must have the same size as input matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.mul" +@param src1 first input matrix. +@param src2 second input matrix of the same size and the same depth as src1. +@param scale optional scale factor. +@param ddepth optional depth of the output matrix. +@sa add, sub, div, addWeighted +*/ +GAPI_EXPORTS GMat mul(const GMat& src1, const GMat& src2, double scale = 1.0, int ddepth = -1); + +/** @brief Multiplies matrix by scalar. + +The function mulC multiplies each element of matrix src by given scalar value: + +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I) \cdot \texttt{multiplier} )\f] + +The matrices can be single or multi channel. Output matrix must have the same size as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.mulC" +@param src input matrix. +@param multiplier factor to be multiplied. +@param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth. +@sa add, sub, div, addWeighted +*/ +GAPI_EXPORTS GMat mulC(const GMat& src, double multiplier, int ddepth = -1); +//! @overload +GAPI_EXPORTS GMat mulC(const GMat& src, const GScalar& multiplier, int ddepth = -1); // FIXME: merge with mulc +//! @overload +GAPI_EXPORTS GMat mulC(const GScalar& multiplier, const GMat& src, int ddepth = -1); // FIXME: merge with mulc + +/** @brief Performs per-element division of two matrices. + +The function divides one matrix by another: +\f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f] + +When src2(I) is zero, dst(I) will also be zero. Different channels of +multi-channel matrices are processed independently. +The matrices can be single or multi channel. Output matrix must have the same size and depth as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.div" +@param src1 first input matrix. +@param src2 second input matrix of the same size and depth as src1. +@param scale scalar factor. +@param ddepth optional depth of the output matrix; you can only pass -1 when src1.depth() == src2.depth(). +@sa mul, add, sub +*/ +GAPI_EXPORTS GMat div(const GMat& src1, const GMat& src2, double scale, int ddepth = -1); + +/** @brief Divides matrix by scalar. + +The function divC divides each element of matrix src by given scalar value: + +\f[\texttt{dst(I) = saturate(src(I)*scale/divisor)}\f] + +When divisor is zero, dst(I) will also be zero. Different channels of +multi-channel matrices are processed independently. +The matrices can be single or multi channel. Output matrix must have the same size and depth as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.divC" +@param src input matrix. +@param divisor number to be divided by. +@param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth. +@param scale scale factor. +@sa add, sub, div, addWeighted +*/ +GAPI_EXPORTS GMat divC(const GMat& src, const GScalar& divisor, double scale, int ddepth = -1); + +/** @brief Divides scalar by matrix. + +The function divRC divides given scalar by each element of matrix src and keep the division result in new matrix of the same size and type as src: + +\f[\texttt{dst(I) = saturate(divident*scale/src(I))}\f] + +When src(I) is zero, dst(I) will also be zero. Different channels of +multi-channel matrices are processed independently. +The matrices can be single or multi channel. Output matrix must have the same size and depth as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.divRC" +@param src input matrix. +@param divident number to be divided. +@param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth. +@param scale scale factor +@sa add, sub, div, addWeighted +*/ +GAPI_EXPORTS GMat divRC(const GScalar& divident, const GMat& src, double scale, int ddepth = -1); + +/** @brief Applies a mask to a matrix. + +The function mask set value from given matrix if the corresponding pixel value in mask matrix set to true, +and set the matrix value to 0 otherwise. + +Supported src matrix data types are @ref CV_8UC1, @ref CV_16SC1, @ref CV_16UC1. Supported mask data type is @ref CV_8UC1. + +@note Function textual ID is "org.opencv.core.math.mask" +@param src input matrix. +@param mask input mask matrix. +*/ +GAPI_EXPORTS GMat mask(const GMat& src, const GMat& mask); + +/** @brief Calculates an average (mean) of matrix elements. + +The function mean calculates the mean value M of matrix elements, +independently for each channel, and return it. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.mean" +@param src input matrix. +@sa countNonZero, min, max +*/ +GAPI_EXPORTS_W GScalar mean(const GMat& src); + +/** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle. + +The function polarToCart calculates the Cartesian coordinates of each 2D +vector represented by the corresponding elements of magnitude and angle: +\f[\begin{array}{l} \texttt{x} (I) = \texttt{magnitude} (I) \cos ( \texttt{angle} (I)) \\ \texttt{y} (I) = \texttt{magnitude} (I) \sin ( \texttt{angle} (I)) \\ \end{array}\f] + +The relative accuracy of the estimated coordinates is about 1e-6. + +First output is a matrix of x-coordinates of 2D vectors. +Second output is a matrix of y-coordinates of 2D vectors. +Both output must have the same size and depth as input matrices. + +@note Function textual ID is "org.opencv.core.math.polarToCart" + +@param magnitude input floating-point @ref CV_32FC1 matrix (1xN) of magnitudes of 2D vectors; +@param angle input floating-point @ref CV_32FC1 matrix (1xN) of angles of 2D vectors. +@param angleInDegrees when true, the input angles are measured in +degrees, otherwise, they are measured in radians. +@sa cartToPolar, exp, log, pow, sqrt +*/ +GAPI_EXPORTS std::tuple polarToCart(const GMat& magnitude, const GMat& angle, + bool angleInDegrees = false); + +/** @brief Calculates the magnitude and angle of 2D vectors. + +The function cartToPolar calculates either the magnitude, angle, or both +for every 2D vector (x(I),y(I)): +\f[\begin{array}{l} \texttt{magnitude} (I)= \sqrt{\texttt{x}(I)^2+\texttt{y}(I)^2} , \\ \texttt{angle} (I)= \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))[ \cdot180 / \pi ] \end{array}\f] + +The angles are calculated with accuracy about 0.3 degrees. For the point +(0,0), the angle is set to 0. + +First output is a matrix of magnitudes of the same size and depth as input x. +Second output is a matrix of angles that has the same size and depth as +x; the angles are measured in radians (from 0 to 2\*Pi) or in degrees (0 to 360 degrees). + +@note Function textual ID is "org.opencv.core.math.cartToPolar" + +@param x matrix of @ref CV_32FC1 x-coordinates. +@param y array of @ref CV_32FC1 y-coordinates. +@param angleInDegrees a flag, indicating whether the angles are measured +in radians (which is by default), or in degrees. +@sa polarToCart +*/ +GAPI_EXPORTS std::tuple cartToPolar(const GMat& x, const GMat& y, + bool angleInDegrees = false); + +/** @brief Calculates the rotation angle of 2D vectors. + +The function cv::phase calculates the rotation angle of each 2D vector that +is formed from the corresponding elements of x and y : +\f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f] + +The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 , +the corresponding angle(I) is set to 0. +@param x input floating-point array of x-coordinates of 2D vectors. +@param y input array of y-coordinates of 2D vectors; it must have the +same size and the same type as x. +@param angleInDegrees when true, the function calculates the angle in +degrees, otherwise, they are measured in radians. +@return array of vector angles; it has the same size and same type as x. +*/ +GAPI_EXPORTS GMat phase(const GMat& x, const GMat &y, bool angleInDegrees = false); + +/** @brief Calculates a square root of array elements. + +The function cv::gapi::sqrt calculates a square root of each input array element. +In case of multi-channel arrays, each channel is processed +independently. The accuracy is approximately the same as of the built-in +std::sqrt . +@param src input floating-point array. +@return output array of the same size and type as src. +*/ +GAPI_EXPORTS GMat sqrt(const GMat &src); + +//! @} gapi_math +//! +//! @addtogroup gapi_pixelwise +//! @{ + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are greater compare to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) > \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: +\f[\texttt{dst} = \texttt{src1} > \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices/matrix. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGT" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpLE, cmpGE, cmpLT +*/ +GAPI_EXPORTS GMat cmpGT(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGTScalar" +*/ +GAPI_EXPORTS GMat cmpGT(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are less than elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) < \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} < \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices/matrix. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLT" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpLE, cmpGE, cmpGT +*/ +GAPI_EXPORTS GMat cmpLT(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLTScalar" +*/ +GAPI_EXPORTS GMat cmpLT(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are greater or equal compare to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) >= \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} >= \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGE" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpLE, cmpGT, cmpLT +*/ +GAPI_EXPORTS GMat cmpGE(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLGEcalar" +*/ +GAPI_EXPORTS GMat cmpGE(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are less or equal compare to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) <= \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} <= \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLE" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpGT, cmpGE, cmpLT +*/ +GAPI_EXPORTS GMat cmpLE(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLEScalar" +*/ +GAPI_EXPORTS GMat cmpLE(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are equal to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) == \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} == \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpEQ" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpNE +*/ +GAPI_EXPORTS GMat cmpEQ(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpEQScalar" +*/ +GAPI_EXPORTS GMat cmpEQ(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are not equal to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) != \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} != \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpNE" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpEQ +*/ +GAPI_EXPORTS GMat cmpNE(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpNEScalar" +*/ +GAPI_EXPORTS GMat cmpNE(const GMat& src1, const GScalar& src2); + +/** @brief computes bitwise conjunction of the two matrixes (src1 & src2) +Calculates the per-element bit-wise logical conjunction of two matrices of the same size. + +In case of floating-point matrices, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel matrices, each channel is processed +independently. Output matrix must have the same size and depth as the input +matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_and" + +@param src1 first input matrix. +@param src2 second input matrix. +*/ +GAPI_EXPORTS GMat bitwise_and(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_andS" +@param src1 first input matrix. +@param src2 scalar, which will be per-lemenetly conjuncted with elements of src1. +*/ +GAPI_EXPORTS GMat bitwise_and(const GMat& src1, const GScalar& src2); + +/** @brief computes bitwise disjunction of the two matrixes (src1 | src2) +Calculates the per-element bit-wise logical disjunction of two matrices of the same size. + +In case of floating-point matrices, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel matrices, each channel is processed +independently. Output matrix must have the same size and depth as the input +matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_or" + +@param src1 first input matrix. +@param src2 second input matrix. +*/ +GAPI_EXPORTS GMat bitwise_or(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_orS" +@param src1 first input matrix. +@param src2 scalar, which will be per-lemenetly disjuncted with elements of src1. +*/ +GAPI_EXPORTS GMat bitwise_or(const GMat& src1, const GScalar& src2); + + +/** @brief computes bitwise logical "exclusive or" of the two matrixes (src1 ^ src2) +Calculates the per-element bit-wise logical "exclusive or" of two matrices of the same size. + +In case of floating-point matrices, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel matrices, each channel is processed +independently. Output matrix must have the same size and depth as the input +matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_xor" + +@param src1 first input matrix. +@param src2 second input matrix. +*/ +GAPI_EXPORTS GMat bitwise_xor(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_xorS" +@param src1 first input matrix. +@param src2 scalar, for which per-lemenet "logical or" operation on elements of src1 will be performed. +*/ +GAPI_EXPORTS GMat bitwise_xor(const GMat& src1, const GScalar& src2); + + +/** @brief Inverts every bit of an array. + +The function bitwise_not calculates per-element bit-wise inversion of the input +matrix: +\f[\texttt{dst} (I) = \neg \texttt{src} (I)\f] + +In case of floating-point matrices, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel matrices, each channel is processed +independently. Output matrix must have the same size and depth as the input +matrix. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_not" + +@param src input matrix. +*/ +GAPI_EXPORTS GMat bitwise_not(const GMat& src); + +/** @brief Select values from either first or second of input matrices by given mask. +The function set to the output matrix either the value from the first input matrix if corresponding value of mask matrix is 255, + or value from the second input matrix (if value of mask matrix set to 0). + +Input mask matrix must be of @ref CV_8UC1 type, two other inout matrices and output matrix should be of the same type. The size should +be the same for all input and output matrices. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.select" + +@param src1 first input matrix. +@param src2 second input matrix. +@param mask mask input matrix. +*/ +GAPI_EXPORTS GMat select(const GMat& src1, const GMat& src2, const GMat& mask); + +//! @} gapi_pixelwise + + +//! @addtogroup gapi_matrixop +//! @{ +/** @brief Calculates per-element minimum of two matrices. + +The function min calculates the per-element minimum of two matrices of the same size, number of channels and depth: +\f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f] + where I is a multi-dimensional index of matrix elements. In case of + multi-channel matrices, each channel is processed independently. +Output matrix must be of the same size and depth as src1. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.min" +@param src1 first input matrix. +@param src2 second input matrix of the same size and depth as src1. +@sa max, cmpEQ, cmpLT, cmpLE +*/ +GAPI_EXPORTS GMat min(const GMat& src1, const GMat& src2); + +/** @brief Calculates per-element maximum of two matrices. + +The function max calculates the per-element maximum of two matrices of the same size, number of channels and depth: +\f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f] + where I is a multi-dimensional index of matrix elements. In case of + multi-channel matrices, each channel is processed independently. +Output matrix must be of the same size and depth as src1. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.max" +@param src1 first input matrix. +@param src2 second input matrix of the same size and depth as src1. +@sa min, compare, cmpEQ, cmpGT, cmpGE +*/ +GAPI_EXPORTS GMat max(const GMat& src1, const GMat& src2); + +/** @brief Calculates the per-element absolute difference between two matrices. + +The function absDiff calculates absolute difference between two matrices of the same size and depth: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2}(I)|)\f] + where I is a multi-dimensional index of matrix elements. In case of + multi-channel matrices, each channel is processed independently. +Output matrix must have the same size and depth as input matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.absdiff" +@param src1 first input matrix. +@param src2 second input matrix. +@sa abs +*/ +GAPI_EXPORTS GMat absDiff(const GMat& src1, const GMat& src2); + +/** @brief Calculates absolute value of matrix elements. + +The function abs calculates absolute difference between matrix elements and given scalar value: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{matC}(I)|)\f] + where matC is constructed from given scalar c and has the same sizes and depth as input matrix src. + +Output matrix must be of the same size and depth as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.absdiffC" +@param src input matrix. +@param c scalar to be subtracted. +@sa min, max +*/ +GAPI_EXPORTS GMat absDiffC(const GMat& src, const GScalar& c); + +/** @brief Calculates sum of all matrix elements. + +The function sum calculates sum of all matrix elements, independently for each channel. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.sum" +@param src input matrix. +@sa countNonZero, mean, min, max +*/ +GAPI_EXPORTS GScalar sum(const GMat& src); + +/** @brief Counts non-zero array elements. + +The function returns the number of non-zero elements in src : +\f[\sum _{I: \; \texttt{src} (I) \ne0 } 1\f] + +Supported matrix data types are @ref CV_8UC1, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.countNonZero" +@param src input single-channel matrix. +@sa mean, min, max +*/ +GAPI_EXPORTS GOpaque countNonZero(const GMat& src); + +/** @brief Calculates the weighted sum of two matrices. + +The function addWeighted calculates the weighted sum of two matrices as follows: +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} )\f] +where I is a multi-dimensional index of array elements. In case of multi-channel matrices, each +channel is processed independently. + +The function can be replaced with a matrix expression: + \f[\texttt{dst}(I) = \texttt{alpha} * \texttt{src1}(I) - \texttt{beta} * \texttt{src2}(I) + \texttt{gamma} \f] + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.addweighted" +@param src1 first input matrix. +@param alpha weight of the first matrix elements. +@param src2 second input matrix of the same size and channel number as src1. +@param beta weight of the second matrix elements. +@param gamma scalar added to each sum. +@param ddepth optional depth of the output matrix. +@sa add, sub +*/ +GAPI_EXPORTS GMat addWeighted(const GMat& src1, double alpha, const GMat& src2, double beta, double gamma, int ddepth = -1); + +/** @brief Calculates the absolute L1 norm of a matrix. + +This version of normL1 calculates the absolute L1 norm of src. + +As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. +The \f$ L_{1} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ +is calculated as follows +\f{align*} + \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\ +\f} +and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is +\f{align*} + \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\ +\f} + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.norml1" +@param src input matrix. +@sa normL2, normInf +*/ +GAPI_EXPORTS GScalar normL1(const GMat& src); + +/** @brief Calculates the absolute L2 norm of a matrix. + +This version of normL2 calculates the absolute L2 norm of src. + +As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. +The \f$ L_{2} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ +is calculated as follows +\f{align*} + \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\ +\f} +and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is +\f{align*} + \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\ +\f} + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +@note Function textual ID is "org.opencv.core.matrixop.norml2" +@param src input matrix. +@sa normL1, normInf +*/ +GAPI_EXPORTS GScalar normL2(const GMat& src); + +/** @brief Calculates the absolute infinite norm of a matrix. + +This version of normInf calculates the absolute infinite norm of src. + +As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. +The \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ +is calculated as follows +\f{align*} + \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2 +\f} +and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is +\f{align*} + \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5. +\f} + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.norminf" +@param src input matrix. +@sa normL1, normL2 +*/ +GAPI_EXPORTS GScalar normInf(const GMat& src); + +/** @brief Calculates the integral of an image. + +The function calculates one or more integral images for the source image as follows: + +\f[\texttt{sum} (X,Y) = \sum _{x integral(const GMat& src, int sdepth = -1, int sqdepth = -1); + +/** @brief Applies a fixed-level threshold to each matrix element. + +The function applies fixed-level thresholding to a single- or multiple-channel matrix. +The function is typically used to get a bi-level (binary) image out of a grayscale image ( cmp functions could be also used for +this purpose) or for removing a noise, that is, filtering out pixels with too small or too large +values. There are several types of thresholding supported by the function. They are determined by +type parameter. + +Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the +above values. In these cases, the function determines the optimal threshold value using the Otsu's +or Triangle algorithm and uses it instead of the specified thresh . The function returns the +computed threshold value in addititon to thresholded matrix. +The Otsu's and Triangle methods are implemented only for 8-bit matrices. + +Input image should be single channel only in case of cv::THRESH_OTSU or cv::THRESH_TRIANGLE flags. +Output matrix must be of the same size and depth as src. + +@note Function textual ID is "org.opencv.core.matrixop.threshold" + +@param src input matrix (@ref CV_8UC1, @ref CV_8UC3, or @ref CV_32FC1). +@param thresh threshold value. +@param maxval maximum value to use with the cv::THRESH_BINARY and cv::THRESH_BINARY_INV thresholding +types. +@param type thresholding type (see the cv::ThresholdTypes). + +@sa min, max, cmpGT, cmpLE, cmpGE, cmpLT + */ +GAPI_EXPORTS GMat threshold(const GMat& src, const GScalar& thresh, const GScalar& maxval, int type); +/** @overload +This function applicable for all threshold types except CV_THRESH_OTSU and CV_THRESH_TRIANGLE +@note Function textual ID is "org.opencv.core.matrixop.thresholdOT" +*/ +GAPI_EXPORTS_W std::tuple threshold(const GMat& src, const GScalar& maxval, int type); + +/** @brief Applies a range-level threshold to each matrix element. + +The function applies range-level thresholding to a single- or multiple-channel matrix. +It sets output pixel value to OxFF if the corresponding pixel value of input matrix is in specified range,or 0 otherwise. + +Input and output matrices must be CV_8UC1. + +@note Function textual ID is "org.opencv.core.matrixop.inRange" + +@param src input matrix (CV_8UC1). +@param threshLow lower boundary value. +@param threshUp upper boundary value. + +@sa threshold + */ +GAPI_EXPORTS GMat inRange(const GMat& src, const GScalar& threshLow, const GScalar& threshUp); + +//! @} gapi_matrixop + +//! @addtogroup gapi_transform +//! @{ +/** @brief Resizes an image. + +The function resizes the image src down to or up to the specified size. + +Output image size will have the size dsize (when dsize is non-zero) or the size computed from +src.size(), fx, and fy; the depth of output is the same as of src. + +If you want to resize src so that it fits the pre-created dst, +you may call the function as follows: +@code + // explicitly specify dsize=dst.size(); fx and fy will be computed from that. + resize(src, dst, dst.size(), 0, 0, interpolation); +@endcode +If you want to decimate the image by factor of 2 in each direction, you can call the function this +way: +@code + // specify fx and fy and let the function compute the destination image size. + resize(src, dst, Size(), 0.5, 0.5, interpolation); +@endcode +To shrink an image, it will generally look best with cv::INTER_AREA interpolation, whereas to +enlarge an image, it will generally look best with cv::INTER_CUBIC (slow) or cv::INTER_LINEAR +(faster but still looks OK). + +@note Function textual ID is "org.opencv.core.transform.resize" + +@param src input image. +@param dsize output image size; if it equals zero, it is computed as: + \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f] + Either dsize or both fx and fy must be non-zero. +@param fx scale factor along the horizontal axis; when it equals 0, it is computed as +\f[\texttt{(double)dsize.width/src.cols}\f] +@param fy scale factor along the vertical axis; when it equals 0, it is computed as +\f[\texttt{(double)dsize.height/src.rows}\f] +@param interpolation interpolation method, see cv::InterpolationFlags + +@sa warpAffine, warpPerspective, remap, resizeP + */ +GAPI_EXPORTS_W GMat resize(const GMat& src, const Size& dsize, double fx = 0, double fy = 0, int interpolation = INTER_LINEAR); + +/** @brief Resizes a planar image. + +The function resizes the image src down to or up to the specified size. +Planar image memory layout is three planes laying in the memory contiguously, +so the image height should be plane_height*plane_number, image type is @ref CV_8UC1. + +Output image size will have the size dsize, the depth of output is the same as of src. + +@note Function textual ID is "org.opencv.core.transform.resizeP" + +@param src input image, must be of @ref CV_8UC1 type; +@param dsize output image size; +@param interpolation interpolation method, only cv::INTER_LINEAR is supported at the moment + +@sa warpAffine, warpPerspective, remap, resize + */ +GAPI_EXPORTS GMatP resizeP(const GMatP& src, const Size& dsize, int interpolation = cv::INTER_LINEAR); + +/** @brief Creates one 4-channel matrix out of 4 single-channel ones. + +The function merges several matrices to make a single multi-channel matrix. That is, each +element of the output matrix will be a concatenation of the elements of the input matrices, where +elements of i-th input matrix are treated as mv[i].channels()-element vectors. +Output matrix must be of @ref CV_8UC4 type. + +The function split4 does the reverse operation. + +@note + - Function textual ID is "org.opencv.core.transform.merge4" + +@param src1 first input @ref CV_8UC1 matrix to be merged. +@param src2 second input @ref CV_8UC1 matrix to be merged. +@param src3 third input @ref CV_8UC1 matrix to be merged. +@param src4 fourth input @ref CV_8UC1 matrix to be merged. +@sa merge3, split4, split3 +*/ +GAPI_EXPORTS GMat merge4(const GMat& src1, const GMat& src2, const GMat& src3, const GMat& src4); + +/** @brief Creates one 3-channel matrix out of 3 single-channel ones. + +The function merges several matrices to make a single multi-channel matrix. That is, each +element of the output matrix will be a concatenation of the elements of the input matrices, where +elements of i-th input matrix are treated as mv[i].channels()-element vectors. +Output matrix must be of @ref CV_8UC3 type. + +The function split3 does the reverse operation. + +@note + - Function textual ID is "org.opencv.core.transform.merge3" + +@param src1 first input @ref CV_8UC1 matrix to be merged. +@param src2 second input @ref CV_8UC1 matrix to be merged. +@param src3 third input @ref CV_8UC1 matrix to be merged. +@sa merge4, split4, split3 +*/ +GAPI_EXPORTS GMat merge3(const GMat& src1, const GMat& src2, const GMat& src3); + +/** @brief Divides a 4-channel matrix into 4 single-channel matrices. + +The function splits a 4-channel matrix into 4 single-channel matrices: +\f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f] + +All output matrices must be of @ref CV_8UC1 type. + +The function merge4 does the reverse operation. + +@note + - Function textual ID is "org.opencv.core.transform.split4" + +@param src input @ref CV_8UC4 matrix. +@sa split3, merge3, merge4 +*/ +GAPI_EXPORTS std::tuple split4(const GMat& src); + +/** @brief Divides a 3-channel matrix into 3 single-channel matrices. + +The function splits a 3-channel matrix into 3 single-channel matrices: +\f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f] + +All output matrices must be of @ref CV_8UC1 type. + +The function merge3 does the reverse operation. + +@note + - Function textual ID is "org.opencv.core.transform.split3" + +@param src input @ref CV_8UC3 matrix. +@sa split4, merge3, merge4 +*/ +GAPI_EXPORTS_W std::tuple split3(const GMat& src); + +/** @brief Applies a generic geometrical transformation to an image. + +The function remap transforms the source image using the specified map: + +\f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f] + +where values of pixels with non-integer coordinates are computed using one of available +interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps +in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in +\f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to +convert from floating to fixed-point representations of a map is that they can yield much faster +(\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x), +cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients. +Output image must be of the same size and depth as input one. + +@note + - Function textual ID is "org.opencv.core.transform.remap" + - Due to current implementation limitations the size of an input and output images should be less than 32767x32767. + +@param src Source image. +@param map1 The first map of either (x,y) points or just x values having the type CV_16SC2, +CV_32FC1, or CV_32FC2. +@param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map +if map1 is (x,y) points), respectively. +@param interpolation Interpolation method (see cv::InterpolationFlags). The methods #INTER_AREA +and #INTER_LINEAR_EXACT are not supported by this function. +@param borderMode Pixel extrapolation method (see cv::BorderTypes). When +borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that +corresponds to the "outliers" in the source image are not modified by the function. +@param borderValue Value used in case of a constant border. By default, it is 0. + */ +GAPI_EXPORTS GMat remap(const GMat& src, const Mat& map1, const Mat& map2, + int interpolation, int borderMode = BORDER_CONSTANT, + const Scalar& borderValue = Scalar()); + +/** @brief Flips a 2D matrix around vertical, horizontal, or both axes. + +The function flips the matrix in one of three different ways (row +and column indices are 0-based): +\f[\texttt{dst} _{ij} = +\left\{ +\begin{array}{l l} +\texttt{src} _{\texttt{src.rows}-i-1,j} & if\; \texttt{flipCode} = 0 \\ +\texttt{src} _{i, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} > 0 \\ +\texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\ +\end{array} +\right.\f] +The example scenarios of using the function are the following: +* Vertical flipping of the image (flipCode == 0) to switch between + top-left and bottom-left image origin. This is a typical operation + in video processing on Microsoft Windows\* OS. +* Horizontal flipping of the image with the subsequent horizontal + shift and absolute difference calculation to check for a + vertical-axis symmetry (flipCode \> 0). +* Simultaneous horizontal and vertical flipping of the image with + the subsequent shift and absolute difference calculation to check + for a central symmetry (flipCode \< 0). +* Reversing the order of point arrays (flipCode \> 0 or + flipCode == 0). +Output image must be of the same depth as input one, size should be correct for given flipCode. + +@note Function textual ID is "org.opencv.core.transform.flip" + +@param src input matrix. +@param flipCode a flag to specify how to flip the array; 0 means +flipping around the x-axis and positive value (for example, 1) means +flipping around y-axis. Negative value (for example, -1) means flipping +around both axes. +@sa remap +*/ +GAPI_EXPORTS GMat flip(const GMat& src, int flipCode); + +/** @brief Crops a 2D matrix. + +The function crops the matrix by given cv::Rect. + +Output matrix must be of the same depth as input one, size is specified by given rect size. + +@note Function textual ID is "org.opencv.core.transform.crop" + +@param src input matrix. +@param rect a rect to crop a matrix to +@sa resize +*/ +GAPI_EXPORTS GMat crop(const GMat& src, const Rect& rect); + +/** @brief Applies horizontal concatenation to given matrices. + +The function horizontally concatenates two GMat matrices (with the same number of rows). +@code{.cpp} + GMat A = { 1, 4, + 2, 5, + 3, 6 }; + GMat B = { 7, 10, + 8, 11, + 9, 12 }; + + GMat C = gapi::concatHor(A, B); + //C: + //[1, 4, 7, 10; + // 2, 5, 8, 11; + // 3, 6, 9, 12] +@endcode +Output matrix must the same number of rows and depth as the src1 and src2, and the sum of cols of the src1 and src2. +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.imgproc.transform.concatHor" + +@param src1 first input matrix to be considered for horizontal concatenation. +@param src2 second input matrix to be considered for horizontal concatenation. +@sa concatVert +*/ +GAPI_EXPORTS GMat concatHor(const GMat& src1, const GMat& src2); + +/** @overload +The function horizontally concatenates given number of GMat matrices (with the same number of columns). +Output matrix must the same number of columns and depth as the input matrices, and the sum of rows of input matrices. + +@param v vector of input matrices to be concatenated horizontally. +*/ +GAPI_EXPORTS GMat concatHor(const std::vector &v); + +/** @brief Applies vertical concatenation to given matrices. + +The function vertically concatenates two GMat matrices (with the same number of cols). + @code{.cpp} + GMat A = { 1, 7, + 2, 8, + 3, 9 }; + GMat B = { 4, 10, + 5, 11, + 6, 12 }; + + GMat C = gapi::concatVert(A, B); + //C: + //[1, 7; + // 2, 8; + // 3, 9; + // 4, 10; + // 5, 11; + // 6, 12] + @endcode + +Output matrix must the same number of cols and depth as the src1 and src2, and the sum of rows of the src1 and src2. +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.imgproc.transform.concatVert" + +@param src1 first input matrix to be considered for vertical concatenation. +@param src2 second input matrix to be considered for vertical concatenation. +@sa concatHor +*/ +GAPI_EXPORTS GMat concatVert(const GMat& src1, const GMat& src2); + +/** @overload +The function vertically concatenates given number of GMat matrices (with the same number of columns). +Output matrix must the same number of columns and depth as the input matrices, and the sum of rows of input matrices. + +@param v vector of input matrices to be concatenated vertically. +*/ +GAPI_EXPORTS GMat concatVert(const std::vector &v); + + +/** @brief Performs a look-up table transform of a matrix. + +The function LUT fills the output matrix with values from the look-up table. Indices of the entries +are taken from the input matrix. That is, the function processes each element of src as follows: +\f[\texttt{dst} (I) \leftarrow \texttt{lut(src(I))}\f] + +Supported matrix data types are @ref CV_8UC1. +Output is a matrix of the same size and number of channels as src, and the same depth as lut. + +@note Function textual ID is "org.opencv.core.transform.LUT" + +@param src input matrix of 8-bit elements. +@param lut look-up table of 256 elements; in case of multi-channel input array, the table should +either have a single channel (in this case the same table is used for all channels) or the same +number of channels as in the input matrix. +*/ +GAPI_EXPORTS GMat LUT(const GMat& src, const Mat& lut); + +/** @brief Converts a matrix to another data depth with optional scaling. + +The method converts source pixel values to the target data depth. saturate_cast\<\> is applied at +the end to avoid possible overflows: + +\f[m(x,y) = saturate \_ cast( \alpha (*this)(x,y) + \beta )\f] +Output matrix must be of the same size as input one. + +@note Function textual ID is "org.opencv.core.transform.convertTo" +@param src input matrix to be converted from. +@param rdepth desired output matrix depth or, rather, the depth since the number of channels are the +same as the input has; if rdepth is negative, the output matrix will have the same depth as the input. +@param alpha optional scale factor. +@param beta optional delta added to the scaled values. + */ +GAPI_EXPORTS GMat convertTo(const GMat& src, int rdepth, double alpha=1, double beta=0); + +/** @brief Normalizes the norm or value range of an array. + +The function normalizes scale and shift the input array elements so that +\f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f] +(where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that +\f[\min _I \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I \texttt{dst} (I)= \texttt{beta}\f] +when normType=NORM_MINMAX (for dense arrays only). + +@note Function textual ID is "org.opencv.core.normalize" + +@param src input array. +@param alpha norm value to normalize to or the lower range boundary in case of the range +normalization. +@param beta upper range boundary in case of the range normalization; it is not used for the norm +normalization. +@param norm_type normalization type (see cv::NormTypes). +@param ddepth when negative, the output array has the same type as src; otherwise, it has the same +number of channels as src and the depth =ddepth. +@sa norm, Mat::convertTo +*/ +GAPI_EXPORTS GMat normalize(const GMat& src, double alpha, double beta, + int norm_type, int ddepth = -1); + +/** @brief Applies a perspective transformation to an image. + +The function warpPerspective transforms the source image using the specified matrix: + +\f[\texttt{dst} (x,y) = \texttt{src} \left ( \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} , + \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\f] + +when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert +and then put in the formula above instead of M. The function cannot operate in-place. + +@param src input image. +@param M \f$3\times 3\f$ transformation matrix. +@param dsize size of the output image. +@param flags combination of interpolation methods (#INTER_LINEAR or #INTER_NEAREST) and the +optional flag #WARP_INVERSE_MAP, that sets M as the inverse transformation ( +\f$\texttt{dst}\rightarrow\texttt{src}\f$ ). +@param borderMode pixel extrapolation method (#BORDER_CONSTANT or #BORDER_REPLICATE). +@param borderValue value used in case of a constant border; by default, it equals 0. + +@sa warpAffine, resize, remap, getRectSubPix, perspectiveTransform + */ +GAPI_EXPORTS GMat warpPerspective(const GMat& src, const Mat& M, const Size& dsize, int flags = cv::INTER_LINEAR, + int borderMode = cv::BORDER_CONSTANT, const Scalar& borderValue = Scalar()); + +/** @brief Applies an affine transformation to an image. + +The function warpAffine transforms the source image using the specified matrix: + +\f[\texttt{dst} (x,y) = \texttt{src} ( \texttt{M} _{11} x + \texttt{M} _{12} y + \texttt{M} _{13}, \texttt{M} _{21} x + \texttt{M} _{22} y + \texttt{M} _{23})\f] + +when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted +with #invertAffineTransform and then put in the formula above instead of M. The function cannot +operate in-place. + +@param src input image. +@param M \f$2\times 3\f$ transformation matrix. +@param dsize size of the output image. +@param flags combination of interpolation methods (see #InterpolationFlags) and the optional +flag #WARP_INVERSE_MAP that means that M is the inverse transformation ( +\f$\texttt{dst}\rightarrow\texttt{src}\f$ ). +@param borderMode pixel extrapolation method (see #BorderTypes); +borderMode=#BORDER_TRANSPARENT isn't supported +@param borderValue value used in case of a constant border; by default, it is 0. + +@sa warpPerspective, resize, remap, getRectSubPix, transform + */ +GAPI_EXPORTS GMat warpAffine(const GMat& src, const Mat& M, const Size& dsize, int flags = cv::INTER_LINEAR, + int borderMode = cv::BORDER_CONSTANT, const Scalar& borderValue = Scalar()); +//! @} gapi_transform + +/** @brief Finds centers of clusters and groups input samples around the clusters. + +The function kmeans implements a k-means algorithm that finds the centers of K clusters +and groups the input samples around the clusters. As an output, \f$\texttt{bestLabels}_i\f$ +contains a 0-based cluster index for the \f$i^{th}\f$ sample. + +@note + - Function textual ID is "org.opencv.core.kmeansND" + - In case of an N-dimentional points' set given, input GMat can have the following traits: +2 dimensions, a single row or column if there are N channels, +or N columns if there is a single channel. Mat should have @ref CV_32F depth. + - Although, if GMat with height != 1, width != 1, channels != 1 given as data, n-dimensional +samples are considered given in amount of A, where A = height, n = width * channels. + - In case of GMat given as data: + - the output labels are returned as 1-channel GMat with sizes +width = 1, height = A, where A is samples amount, or width = bestLabels.width, +height = bestLabels.height if bestLabels given; + - the cluster centers are returned as 1-channel GMat with sizes +width = n, height = K, where n is samples' dimentionality and K is clusters' amount. + - As one of possible usages, if you want to control the initial labels for each attempt +by yourself, you can utilize just the core of the function. To do that, set the number +of attempts to 1, initialize labels each time using a custom algorithm, pass them with the +( flags = #KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best (most-compact) clustering. + +@param data Data for clustering. An array of N-Dimensional points with float coordinates is needed. +Function can take GArray, GArray for 2D and 3D cases or GMat for any +dimentionality and channels. +@param K Number of clusters to split the set by. +@param bestLabels Optional input integer array that can store the supposed initial cluster indices +for every sample. Used when ( flags = #KMEANS_USE_INITIAL_LABELS ) flag is set. +@param criteria The algorithm termination criteria, that is, the maximum number of iterations +and/or the desired accuracy. The accuracy is specified as criteria.epsilon. As soon as each of +the cluster centers moves by less than criteria.epsilon on some iteration, the algorithm stops. +@param attempts Flag to specify the number of times the algorithm is executed using different +initial labellings. The algorithm returns the labels that yield the best compactness (see the first +function return value). +@param flags Flag that can take values of cv::KmeansFlags . + +@return + - Compactness measure that is computed as +\f[\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2\f] +after every attempt. The best (minimum) value is chosen and the corresponding labels and the +compactness value are returned by the function. + - Integer array that stores the cluster indices for every sample. + - Array of the cluster centers. +*/ +GAPI_EXPORTS std::tuple,GMat,GMat> +kmeans(const GMat& data, const int K, const GMat& bestLabels, + const TermCriteria& criteria, const int attempts, const KmeansFlags flags); + +/** @overload +@note + - Function textual ID is "org.opencv.core.kmeansNDNoInit" + - #KMEANS_USE_INITIAL_LABELS flag must not be set while using this overload. + */ +GAPI_EXPORTS_W std::tuple,GMat,GMat> +kmeans(const GMat& data, const int K, const TermCriteria& criteria, const int attempts, + const KmeansFlags flags); + +/** @overload +@note Function textual ID is "org.opencv.core.kmeans2D" + */ +GAPI_EXPORTS_W std::tuple,GArray,GArray> +kmeans(const GArray& data, const int K, const GArray& bestLabels, + const TermCriteria& criteria, const int attempts, const KmeansFlags flags); + +/** @overload +@note Function textual ID is "org.opencv.core.kmeans3D" + */ +GAPI_EXPORTS std::tuple,GArray,GArray> +kmeans(const GArray& data, const int K, const GArray& bestLabels, + const TermCriteria& criteria, const int attempts, const KmeansFlags flags); + + +/** @brief Transposes a matrix. + +The function transposes the matrix: +\f[\texttt{dst} (i,j) = \texttt{src} (j,i)\f] + +@note + - Function textual ID is "org.opencv.core.transpose" + - No complex conjugation is done in case of a complex matrix. It should be done separately if needed. + +@param src input array. +*/ +GAPI_EXPORTS GMat transpose(const GMat& src); + + +namespace streaming { +/** @brief Gets dimensions from Mat. + +@note Function textual ID is "org.opencv.streaming.size" + +@param src Input tensor +@return Size (tensor dimensions). +*/ +GAPI_EXPORTS_W GOpaque size(const GMat& src); + +/** @overload +Gets dimensions from rectangle. + +@note Function textual ID is "org.opencv.streaming.sizeR" + +@param r Input rectangle. +@return Size (rectangle dimensions). +*/ +GAPI_EXPORTS_W GOpaque size(const GOpaque& r); + +/** @brief Gets dimensions from MediaFrame. + +@note Function textual ID is "org.opencv.streaming.sizeMF" + +@param src Input frame +@return Size (frame dimensions). +*/ +GAPI_EXPORTS GOpaque size(const GFrame& src); +} //namespace streaming +} //namespace gapi +} //namespace cv + +#endif //OPENCV_GAPI_CORE_HPP diff --git a/3rdparty/include/opencv2/gapi/cpu/core.hpp b/3rdparty/include/opencv2/gapi/cpu/core.hpp new file mode 100644 index 0000000000..ac08f91c78 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/cpu/core.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_CPU_CORE_API_HPP +#define OPENCV_GAPI_CPU_CORE_API_HPP + +#include // GKernelPackage +#include // GAPI_EXPORTS + +namespace cv { +namespace gapi { +namespace core { +namespace cpu { + +GAPI_EXPORTS_W cv::gapi::GKernelPackage kernels(); + +} // namespace cpu +} // namespace core +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_CPU_CORE_API_HPP diff --git a/3rdparty/include/opencv2/gapi/cpu/gcpukernel.hpp b/3rdparty/include/opencv2/gapi/cpu/gcpukernel.hpp new file mode 100644 index 0000000000..009c19688b --- /dev/null +++ b/3rdparty/include/opencv2/gapi/cpu/gcpukernel.hpp @@ -0,0 +1,542 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GCPUKERNEL_HPP +#define OPENCV_GAPI_GCPUKERNEL_HPP + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include //suppress_unused_warning +#include + +// FIXME: namespace scheme for backends? +namespace cv { + +namespace gimpl +{ + // Forward-declare an internal class + class GCPUExecutable; + + namespace render + { + namespace ocv + { + class GRenderExecutable; + } + } +} // namespace gimpl + +namespace gapi +{ +/** + * @brief This namespace contains G-API CPU backend functions, + * structures, and symbols. + */ +namespace cpu +{ + /** + * \addtogroup gapi_std_backends + * @{ + * + * @brief G-API backends available in this OpenCV version + * + * G-API backends play a corner stone role in G-API execution + * stack. Every backend is hardware-oriented and thus can run its + * kernels efficiently on the target platform. + * + * Backends are usually "black boxes" for G-API users -- on the API + * side, all backends are represented as different objects of the + * same class cv::gapi::GBackend. + * User can manipulate with backends by specifying which kernels to use. + * + * @sa @ref gapi_hld + */ + + /** + * @brief Get a reference to CPU (OpenCV) backend. + * + * This is the default backend in G-API at the moment, providing + * broader functional coverage but losing some graph model + * advantages. Provided mostly for reference and prototyping + * purposes. + * + * @sa gapi_std_backends + */ + GAPI_EXPORTS cv::gapi::GBackend backend(); + /** @} */ + + class GOCVFunctor; + + //! @cond IGNORED + template + GOCVFunctor ocv_kernel(const Callable& c); + + template + GOCVFunctor ocv_kernel(Callable& c); + //! @endcond + +} // namespace cpu +} // namespace gapi + +// Represents arguments which are passed to a wrapped CPU function +// FIXME: put into detail? +class GAPI_EXPORTS GCPUContext +{ +public: + // Generic accessor API + template + const T& inArg(int input) { return m_args.at(input).get(); } + + // Syntax sugar + const cv::Mat& inMat(int input); + cv::Mat& outMatR(int output); // FIXME: Avoid cv::Mat m = ctx.outMatR() + + const cv::Scalar& inVal(int input); + cv::Scalar& outValR(int output); // FIXME: Avoid cv::Scalar s = ctx.outValR() + cv::MediaFrame& outFrame(int output); + template std::vector& outVecR(int output) // FIXME: the same issue + { + return outVecRef(output).wref(); + } + template T& outOpaqueR(int output) // FIXME: the same issue + { + return outOpaqueRef(output).wref(); + } + + GArg state() + { + return m_state; + } + +protected: + detail::VectorRef& outVecRef(int output); + detail::OpaqueRef& outOpaqueRef(int output); + + std::vector m_args; + GArg m_state; + + //FIXME: avoid conversion of arguments from internal representation to OpenCV one on each call + //to OCV kernel. (This can be achieved by a two single time conversions in GCPUExecutable::run, + //once on enter for input and output arguments, and once before return for output arguments only + std::unordered_map m_results; + + friend class gimpl::GCPUExecutable; + friend class gimpl::render::ocv::GRenderExecutable; +}; + +class GAPI_EXPORTS GCPUKernel +{ +public: + // This function is a kernel's execution entry point (does the processing work) + using RunF = std::function; + // This function is a stateful kernel's setup routine (configures state) + using SetupF = std::function; + + GCPUKernel(); + GCPUKernel(const RunF& runF, const SetupF& setupF = nullptr); + + RunF m_runF = nullptr; + SetupF m_setupF = nullptr; + + bool m_isStateful = false; +}; + +// FIXME: This is an ugly ad-hoc implementation. TODO: refactor + +namespace detail +{ +template struct get_in; +template<> struct get_in +{ + static cv::Mat get(GCPUContext &ctx, int idx) { return ctx.inMat(idx); } +}; +template<> struct get_in +{ + static cv::Mat get(GCPUContext &ctx, int idx) { return get_in::get(ctx, idx); } +}; +template<> struct get_in +{ + static cv::MediaFrame get(GCPUContext &ctx, int idx) { return ctx.inArg(idx); } +}; +template<> struct get_in +{ + static cv::Scalar get(GCPUContext &ctx, int idx) { return ctx.inVal(idx); } +}; +template struct get_in > +{ + static const std::vector& get(GCPUContext &ctx, int idx) { return ctx.inArg(idx).rref(); } +}; +template struct get_in > +{ + static const U& get(GCPUContext &ctx, int idx) { return ctx.inArg(idx).rref(); } +}; + +//FIXME(dm): GArray/GArray conversion should be done more gracefully in the system +template<> struct get_in >: public get_in > +{ +}; + +//FIXME(dm): GArray/GArray conversion should be done more gracefully in the system +template<> struct get_in >: public get_in > +{ +}; + +// FIXME(dm): GArray>/GArray> conversion should be done more gracefully in the system +template struct get_in> >: public get_in> > +{ +}; + +//FIXME(dm): GOpaque/GOpaque conversion should be done more gracefully in the system +template<> struct get_in >: public get_in > +{ +}; + +//FIXME(dm): GOpaque/GOpaque conversion should be done more gracefully in the system +template<> struct get_in >: public get_in > +{ +}; + +template struct get_in +{ + static T get(GCPUContext &ctx, int idx) { return ctx.inArg(idx); } +}; + +struct tracked_cv_mat{ + tracked_cv_mat(cv::Mat& m) : r{m}, original_data{m.data} {} + cv::Mat r; + uchar* original_data; + + operator cv::Mat& (){ return r;} + void validate() const{ + if (r.data != original_data) + { + util::throw_error + (std::logic_error + ("OpenCV kernel output parameter was reallocated. \n" + "Incorrect meta data was provided ?")); + } + } +}; + +template +void postprocess(Outputs&... outs) +{ + struct + { + void operator()(tracked_cv_mat* bm) { bm->validate(); } + void operator()(...) { } + + } validate; + //dummy array to unfold parameter pack + int dummy[] = { 0, (validate(&outs), 0)... }; + cv::util::suppress_unused_warning(dummy); +} + +template struct get_out; +template<> struct get_out +{ + static tracked_cv_mat get(GCPUContext &ctx, int idx) + { + auto& r = ctx.outMatR(idx); + return {r}; + } +}; +template<> struct get_out +{ + static tracked_cv_mat get(GCPUContext &ctx, int idx) + { + return get_out::get(ctx, idx); + } +}; +template<> struct get_out +{ + static cv::Scalar& get(GCPUContext &ctx, int idx) + { + return ctx.outValR(idx); + } +}; +template<> struct get_out +{ + static cv::MediaFrame& get(GCPUContext &ctx, int idx) + { + return ctx.outFrame(idx); + } +}; +template struct get_out> +{ + static std::vector& get(GCPUContext &ctx, int idx) + { + return ctx.outVecR(idx); + } +}; + +//FIXME(dm): GArray/GArray conversion should be done more gracefully in the system +template<> struct get_out >: public get_out > +{ +}; + +// FIXME(dm): GArray>/GArray> conversion should be done more gracefully in the system +template struct get_out> >: public get_out> > +{ +}; + +template struct get_out> +{ + static U& get(GCPUContext &ctx, int idx) + { + return ctx.outOpaqueR(idx); + } +}; + +template +struct OCVSetupHelper; + +template +struct OCVSetupHelper> +{ + // Using 'auto' return type and 'decltype' specifier in both 'setup_impl' versions + // to check existence of required 'Impl::setup' functions. + // While 'decltype' specifier accepts expression we pass expression with 'comma-operator' + // where first operand of comma-operator is call attempt to desired 'Impl::setup' and + // the second operand is 'void()' expression. + // + // SFINAE for 'Impl::setup' which accepts compile arguments. + template + static auto setup_impl(const GMetaArgs &metaArgs, const GArgs &args, + GArg &state, const GCompileArgs &compileArgs, + detail::Seq) -> + decltype(Impl::setup(detail::get_in_meta(metaArgs, args, IIs)..., + std::declval + >::type + >(), + compileArgs) + , void()) + { + // TODO: unique_ptr <-> shared_ptr conversion ? + // To check: Conversion is possible only if the state which should be passed to + // 'setup' user callback isn't required to have previous value + std::shared_ptr stPtr; + Impl::setup(detail::get_in_meta(metaArgs, args, IIs)..., stPtr, compileArgs); + state = GArg(stPtr); + } + + // SFINAE for 'Impl::setup' which doesn't accept compile arguments. + template + static auto setup_impl(const GMetaArgs &metaArgs, const GArgs &args, + GArg &state, const GCompileArgs &/* compileArgs */, + detail::Seq) -> + decltype(Impl::setup(detail::get_in_meta(metaArgs, args, IIs)..., + std::declval + >::type + >() + ) + , void()) + { + // The same comment as in 'setup' above. + std::shared_ptr stPtr; + Impl::setup(detail::get_in_meta(metaArgs, args, IIs)..., stPtr); + state = GArg(stPtr); + } + + static void setup(const GMetaArgs &metaArgs, const GArgs &args, + GArg& state, const GCompileArgs &compileArgs) + { + setup_impl(metaArgs, args, state, compileArgs, + typename detail::MkSeq::type()); + } +}; + +// OCVCallHelper is a helper class to call stateless OCV kernels and OCV kernel functors. +template +struct OCVCallHelper; + +// FIXME: probably can be simplified with std::apply or analogue. +template +struct OCVCallHelper, std::tuple> +{ + template + struct call_and_postprocess + { + template + static void call(Inputs&&... ins, Outputs&&... outs) + { + //not using a std::forward on outs is deliberate in order to + //cause compilation error, by trying to bind rvalue references to lvalue references + Impl::run(std::forward(ins)..., outs...); + postprocess(outs...); + } + + template + static void call(Impl& impl, Inputs&&... ins, Outputs&&... outs) + { + impl(std::forward(ins)..., outs...); + } + }; + + template + static void call_impl(GCPUContext &ctx, detail::Seq, detail::Seq) + { + //Make sure that OpenCV kernels do not reallocate memory for output parameters + //by comparing it's state (data ptr) before and after the call. + //This is done by converting each output Mat into tracked_cv_mat object, and binding + //them to parameters of ad-hoc function + call_and_postprocess::get(ctx, IIs))...> + ::call(get_in::get(ctx, IIs)..., get_out::get(ctx, OIs)...); + } + + template + static void call_impl(cv::GCPUContext &ctx, Impl& impl, + detail::Seq, detail::Seq) + { + call_and_postprocess::get(ctx, IIs))...> + ::call(impl, get_in::get(ctx, IIs)..., get_out::get(ctx, OIs)...); + } + + static void call(GCPUContext &ctx) + { + call_impl(ctx, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } + + // NB: Same as call but calling the object + // This necessary for kernel implementations that have a state + // and are represented as an object + static void callFunctor(cv::GCPUContext &ctx, Impl& impl) + { + call_impl(ctx, impl, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } +}; + +// OCVStCallHelper is a helper class to call stateful OCV kernels. +template +struct OCVStCallHelper; + +template +struct OCVStCallHelper, std::tuple> : + OCVCallHelper, std::tuple> +{ + template + struct call_and_postprocess + { + template + static void call(typename Impl::State& st, Inputs&&... ins, Outputs&&... outs) + { + Impl::run(std::forward(ins)..., outs..., st); + postprocess(outs...); + } + }; + + template + static void call_impl(GCPUContext &ctx, detail::Seq, detail::Seq) + { + auto& st = *ctx.state().get>(); + call_and_postprocess::get(ctx, IIs))...> + ::call(st, get_in::get(ctx, IIs)..., get_out::get(ctx, OIs)...); + } + + static void call(GCPUContext &ctx) + { + call_impl(ctx, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } +}; + +} // namespace detail + +template +class GCPUKernelImpl: public cv::detail::KernelTag +{ + using CallHelper = cv::detail::OCVCallHelper; + +public: + using API = K; + + static cv::gapi::GBackend backend() { return cv::gapi::cpu::backend(); } + static cv::GCPUKernel kernel() { return GCPUKernel(&CallHelper::call); } +}; + +template +class GCPUStKernelImpl: public cv::detail::KernelTag +{ + using StSetupHelper = detail::OCVSetupHelper; + using StCallHelper = detail::OCVStCallHelper; + +public: + using API = K; + using State = S; + + static cv::gapi::GBackend backend() { return cv::gapi::cpu::backend(); } + static cv::GCPUKernel kernel() { return GCPUKernel(&StCallHelper::call, + &StSetupHelper::setup); } +}; + +#define GAPI_OCV_KERNEL(Name, API) struct Name: public cv::GCPUKernelImpl + +// TODO: Reuse Anatoliy's logic for support of types with commas in macro. +// Retrieve the common part from Anatoliy's logic to the separate place. +#define GAPI_OCV_KERNEL_ST(Name, API, State) \ + struct Name: public cv::GCPUStKernelImpl \ + +/// @private +class gapi::cpu::GOCVFunctor : public gapi::GFunctor +{ +public: + using Impl = std::function; + using Meta = cv::GKernel::M; + + GOCVFunctor(const char* id, const Meta &meta, const Impl& impl) + : gapi::GFunctor(id), impl_{GCPUKernel(impl), meta} + { + } + + GKernelImpl impl() const override { return impl_; } + gapi::GBackend backend() const override { return gapi::cpu::backend(); } + +private: + GKernelImpl impl_; +}; + +//! @cond IGNORED +template +gapi::cpu::GOCVFunctor gapi::cpu::ocv_kernel(Callable& c) +{ + using P = cv::detail::OCVCallHelper; + return GOCVFunctor{ K::id() + , &K::getOutMeta + , std::bind(&P::callFunctor, std::placeholders::_1, std::ref(c)) + }; +} + +template +gapi::cpu::GOCVFunctor gapi::cpu::ocv_kernel(const Callable& c) +{ + using P = cv::detail::OCVCallHelper; + return GOCVFunctor{ K::id() + , &K::getOutMeta + , std::bind(&P::callFunctor, std::placeholders::_1, c) + }; +} +//! @endcond + +} // namespace cv + +#endif // OPENCV_GAPI_GCPUKERNEL_HPP diff --git a/3rdparty/include/opencv2/gapi/cpu/imgproc.hpp b/3rdparty/include/opencv2/gapi/cpu/imgproc.hpp new file mode 100644 index 0000000000..0b96db08ae --- /dev/null +++ b/3rdparty/include/opencv2/gapi/cpu/imgproc.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_CPU_IMGPROC_API_HPP +#define OPENCV_GAPI_CPU_IMGPROC_API_HPP + +#include // GAPI_EXPORTS +#include // GKernelPackage + +namespace cv { +namespace gapi { +namespace imgproc { +namespace cpu { + +GAPI_EXPORTS GKernelPackage kernels(); + +} // namespace cpu +} // namespace imgproc +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_CPU_IMGPROC_API_HPP diff --git a/3rdparty/include/opencv2/gapi/cpu/stereo.hpp b/3rdparty/include/opencv2/gapi/cpu/stereo.hpp new file mode 100644 index 0000000000..e2a2242bd0 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/cpu/stereo.hpp @@ -0,0 +1,48 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2021 Intel Corporation + +#ifndef OPENCV_GAPI_CPU_STEREO_API_HPP +#define OPENCV_GAPI_CPU_STEREO_API_HPP + +#include // GKernelPackage + +namespace cv { +namespace gapi { +namespace calib3d { +namespace cpu { + +GAPI_EXPORTS GKernelPackage kernels(); + +/** @brief Structure for the Stereo operation initialization parameters.*/ +struct GAPI_EXPORTS StereoInitParam { + StereoInitParam(int nD, int bS, double bL, double f): + numDisparities(nD), blockSize(bS), baseline(bL), focus(f) {} + + StereoInitParam() = default; + + int numDisparities = 0; + int blockSize = 21; + double baseline = 63.5; + double focus = 3.6; +}; + +} // namespace cpu +} // namespace calib3d +} // namespace gapi + +namespace detail { + + template<> struct CompileArgTag { + static const char* tag() { + return "org.opencv.stereoInit"; + } +}; + +} // namespace detail +} // namespace cv + + +#endif // OPENCV_GAPI_CPU_STEREO_API_HPP diff --git a/3rdparty/include/opencv2/gapi/cpu/video.hpp b/3rdparty/include/opencv2/gapi/cpu/video.hpp new file mode 100644 index 0000000000..d3c1f2e670 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/cpu/video.hpp @@ -0,0 +1,25 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + +#ifndef OPENCV_GAPI_CPU_VIDEO_API_HPP +#define OPENCV_GAPI_CPU_VIDEO_API_HPP + +#include // GKernelPackage + +namespace cv { +namespace gapi { +namespace video { +namespace cpu { + +GAPI_EXPORTS GKernelPackage kernels(); + +} // namespace cpu +} // namespace video +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_CPU_VIDEO_API_HPP diff --git a/3rdparty/include/opencv2/gapi/fluid/core.hpp b/3rdparty/include/opencv2/gapi/fluid/core.hpp new file mode 100644 index 0000000000..9eceb82cb2 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/fluid/core.hpp @@ -0,0 +1,20 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_FLUID_CORE_HPP +#define OPENCV_GAPI_FLUID_CORE_HPP + +#include // GKernelPackage +#include // GAPI_EXPORTS + +namespace cv { namespace gapi { namespace core { namespace fluid { + +GAPI_EXPORTS_W cv::gapi::GKernelPackage kernels(); + +}}}} + +#endif // OPENCV_GAPI_FLUID_CORE_HPP diff --git a/3rdparty/include/opencv2/gapi/fluid/gfluidbuffer.hpp b/3rdparty/include/opencv2/gapi/fluid/gfluidbuffer.hpp new file mode 100644 index 0000000000..daa9d4153e --- /dev/null +++ b/3rdparty/include/opencv2/gapi/fluid/gfluidbuffer.hpp @@ -0,0 +1,154 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_FLUID_BUFFER_HPP +#define OPENCV_GAPI_FLUID_BUFFER_HPP + +#include +#include // accumulate +#include // ostream +#include // uint8_t + +#include +#include + +#include + +namespace cv { +namespace gapi { +namespace fluid { + +struct Border +{ + // This constructor is required to support existing kernels which are part of G-API + Border(int _type, cv::Scalar _val) : type(_type), value(_val) {}; + + int type; + cv::Scalar value; +}; + +using BorderOpt = util::optional; + +bool operator == (const Border& b1, const Border& b2); + +class GAPI_EXPORTS Buffer; + +class GAPI_EXPORTS View +{ +public: + struct Cache + { + std::vector m_linePtrs; + GMatDesc m_desc; + int m_border_size = 0; + + inline const uint8_t* linePtr(int index) const + { + // "out_of_window" check: + // user must not request the lines which are outside of specified kernel window + GAPI_DbgAssert(index >= -m_border_size + && index < -m_border_size + static_cast(m_linePtrs.size())); + return m_linePtrs[index + m_border_size]; + } + }; + + const inline uint8_t* InLineB(int index) const // -(w-1)/2...0...+(w-1)/2 for Filters + { + return m_cache->linePtr(index); + } + + template const inline T* InLine(int i) const + { + const uint8_t* ptr = this->InLineB(i); + return reinterpret_cast(ptr); + } + + inline operator bool() const { return m_priv != nullptr; } + bool ready() const; + inline int length() const { return m_cache->m_desc.size.width; } + int y() const; + + inline const GMatDesc& meta() const { return m_cache->m_desc; } + + class GAPI_EXPORTS Priv; // internal use only + Priv& priv(); // internal use only + const Priv& priv() const; // internal use only + + View(); + View(std::unique_ptr&& p); + View(View&& v); + View& operator=(View&& v); + ~View(); + +private: + std::unique_ptr m_priv; + const Cache* m_cache = nullptr; +}; + +class GAPI_EXPORTS Buffer +{ +public: + struct Cache + { + std::vector m_linePtrs; + GMatDesc m_desc; + }; + + // Default constructor (executable creation stage, + // all following initialization performed in Priv::init()) + Buffer(); + // Scratch constructor (user kernels) + Buffer(const cv::GMatDesc &desc); + + // Constructor for intermediate buffers (for tests) + Buffer(const cv::GMatDesc &desc, + int max_line_consumption, int border_size, + int skew, + int wlpi, + BorderOpt border); + // Constructor for in/out buffers (for tests) + Buffer(const cv::Mat &data, bool is_input); + ~Buffer(); + Buffer& operator=(Buffer&&); + + inline uint8_t* OutLineB(int index = 0) + { + return m_cache->m_linePtrs[index]; + } + + template inline T* OutLine(int index = 0) + { + uint8_t* ptr = this->OutLineB(index); + return reinterpret_cast(ptr); + } + + int y() const; + + int linesReady() const; + void debug(std::ostream &os) const; + inline int length() const { return m_cache->m_desc.size.width; } + int lpi() const; // LPI for WRITER + + inline const GMatDesc& meta() const { return m_cache->m_desc; } + + View mkView(int borderSize, bool ownStorage); + void addView(const View* v); + + class GAPI_EXPORTS Priv; // internal use only + Priv& priv(); // internal use only + const Priv& priv() const; // internal use only + +private: + std::unique_ptr m_priv; + const Cache* m_cache; +}; + +} // namespace cv::gapi::fluid +} // namespace cv::gapi +} // namespace cv + +#endif // OPENCV_GAPI_FLUID_BUFFER_HPP diff --git a/3rdparty/include/opencv2/gapi/fluid/gfluidkernel.hpp b/3rdparty/include/opencv2/gapi/fluid/gfluidkernel.hpp new file mode 100644 index 0000000000..53b68c4e21 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/fluid/gfluidkernel.hpp @@ -0,0 +1,442 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_FLUID_KERNEL_HPP +#define OPENCV_GAPI_FLUID_KERNEL_HPP + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +// FIXME: namespace scheme for backends? +namespace cv { + +namespace gapi +{ +/** + * @brief This namespace contains G-API Fluid backend functions, structures, and symbols. + */ +namespace fluid +{ + /** + * \addtogroup gapi_std_backends G-API Standard Backends + * @{ + */ + /** + * @brief Get a reference to Fluid backend. + * + * @sa gapi_std_backends + */ + GAPI_EXPORTS cv::gapi::GBackend backend(); + /** @} */ +} // namespace fluid +} // namespace gapi + + +class GAPI_EXPORTS GFluidKernel +{ +public: + enum class Kind + { + Filter, + Resize, + YUV420toRGB //Color conversion of 4:2:0 chroma sub-sampling formats (NV12, I420 ..etc) to RGB + }; + + // This function is a generic "doWork" callback + using F = std::function &)>; + + // This function is a generic "initScratch" callback + using IS = std::function; + + // This function is a generic "resetScratch" callback + using RS = std::function; + + // This function describes kernel metadata inference rule. + using M = std::function; + + // This function is a generic "getBorder" callback (extracts border-related data from kernel's input parameters) + using B = std::function; + + // This function is a generic "getWindow" callback (extracts window-related data from kernel's input parameters) + using GW = std::function; + + // FIXME: move implementations out of header file + GFluidKernel() {} + GFluidKernel(Kind k, int l, bool scratch, const F& f, const IS &is, const RS &rs, const B& b, const GW& win) + : m_kind(k) + , m_lpi(l) + , m_scratch(scratch) + , m_f(f) + , m_is(is) + , m_rs(rs) + , m_b(b) + , m_gw(win) {} + + Kind m_kind; + const int m_lpi = -1; + const bool m_scratch = false; + + const F m_f; + const IS m_is; + const RS m_rs; + const B m_b; + const GW m_gw; +}; + +// FIXME!!! +// This is the temporary and experimental API +// which should be replaced by runtime roi-based scheduling +/** \addtogroup gapi_compile_args + * @{ + */ +/** + * @brief This structure allows to control the output image region + * which Fluid backend will produce in the graph. + * + * This feature is useful for external tiling and parallelism, but + * will be deprecated in the future releases. + */ +struct GFluidOutputRois +{ + std::vector rois; +}; + +/** + * @brief This structure forces Fluid backend to generate multiple + * parallel output regions in the graph. These regions execute in parallel. + * + * This feature may be deprecated in the future releases. + */ +struct GFluidParallelOutputRois +{ + std::vector parallel_rois; +}; + +/** + * @brief This structure allows to customize the way how Fluid executes + * parallel regions. + * + * For example, user can utilize his own threading runtime via this parameter. + * The `parallel_for` member functor is called by the Fluid runtime with the + * following arguments: + * + * @param size Size of the parallel range to process + * @param f A function which should be called for every integer index + * in this range by the specified parallel_for implementation. + * + * This feature may be deprecated in the future releases. + */ +struct GFluidParallelFor +{ + //this function accepts: + // - size of the "parallel" range as the first argument + // - and a function to be called on the range items, designated by item index + std::function)> parallel_for; +}; +/** @} gapi_compile_args */ + +namespace detail +{ +template<> struct CompileArgTag +{ + static const char* tag() { return "gapi.fluid.outputRois"; } +}; + +template<> struct CompileArgTag +{ + static const char* tag() { return "gapi.fluid.parallelFor"; } +}; + +template<> struct CompileArgTag +{ + static const char* tag() { return "gapi.fluid.parallelOutputRois"; } +}; + +} // namespace detail + +namespace detail +{ +template struct fluid_get_in; +template<> struct fluid_get_in +{ + static const cv::gapi::fluid::View& get(const cv::GArgs &in_args, int idx) + { + return *in_args[idx].unsafe_get(); + } +}; + +template<> struct fluid_get_in +{ + // FIXME: change to return by reference when moved to own::Scalar + static const cv::Scalar get(const cv::GArgs &in_args, int idx) + { + return in_args[idx].unsafe_get(); + } +}; + +template struct fluid_get_in> +{ + static const std::vector& get(const cv::GArgs &in_args, int idx) + { + return in_args.at(idx).unsafe_get().rref(); + } +}; + +template struct fluid_get_in> +{ + static const U& get(const cv::GArgs &in_args, int idx) + { + return in_args.at(idx).unsafe_get().rref(); + } +}; + +template struct fluid_get_in +{ + static const T& get(const cv::GArgs &in_args, int idx) + { + return in_args[idx].unsafe_get(); + } +}; + +template +struct scratch_helper; + +template +struct scratch_helper +{ + // Init + template + static void help_init_impl(const cv::GMetaArgs &metas, + const cv::GArgs &in_args, + gapi::fluid::Buffer &scratch_buf, + detail::Seq) + { + Impl::initScratch(get_in_meta(metas, in_args, IIs)..., scratch_buf); + } + + static void help_init(const cv::GMetaArgs &metas, + const cv::GArgs &in_args, + gapi::fluid::Buffer &b) + { + help_init_impl(metas, in_args, b, typename detail::MkSeq::type()); + } + + // Reset + static void help_reset(gapi::fluid::Buffer &b) + { + Impl::resetScratch(b); + } +}; + +template +struct scratch_helper +{ + static void help_init(const cv::GMetaArgs &, + const cv::GArgs &, + gapi::fluid::Buffer &) + { + GAPI_Assert(false); + } + static void help_reset(gapi::fluid::Buffer &) + { + GAPI_Assert(false); + } +}; + +template struct is_gmat_type +{ + static const constexpr bool value = std::is_same::value; +}; + +template +struct get_border_helper; + +template +struct get_border_helper +{ + template + static gapi::fluid::BorderOpt get_border_impl(const GMetaArgs &metas, + const cv::GArgs &in_args, + cv::detail::Seq) + { + return util::make_optional(Impl::getBorder(cv::detail::get_in_meta(metas, in_args, IIs)...)); + } + + static gapi::fluid::BorderOpt help(const GMetaArgs &metas, + const cv::GArgs &in_args) + { + return get_border_impl(metas, in_args, typename detail::MkSeq::type()); + } +}; + +template +struct get_border_helper +{ + static gapi::fluid::BorderOpt help(const cv::GMetaArgs &, + const cv::GArgs &) + { + return {}; + } +}; + +template +struct get_window_helper; + +template +struct get_window_helper +{ + template + static int get_window_impl(const GMetaArgs &metas, + const cv::GArgs &in_args, + cv::detail::Seq) + { + return Impl::getWindow(cv::detail::get_in_meta(metas, in_args, IIs)...); + } + + static int help(const GMetaArgs &metas, const cv::GArgs &in_args) + { + return get_window_impl(metas, in_args, typename detail::MkSeq::type()); + } +}; + +template +struct get_window_helper +{ + static int help(const cv::GMetaArgs &, + const cv::GArgs &) + { + return Impl::Window; + } +}; + +template +struct has_Window +{ +private: + template + static constexpr auto Check(U*) -> typename std::is_same::type; + + template + static constexpr std::false_type Check(...); + + typedef decltype(Check(0)) Result; + +public: + static constexpr bool value = Result::value; +}; + +template +struct callCustomGetBorder; + +template +struct callCustomGetBorder +{ + static constexpr bool value = (Impl::Window != 1); +}; + +template +struct callCustomGetBorder +{ + static constexpr bool value = true; +}; + +template +struct FluidCallHelper; + +template +struct FluidCallHelper, std::tuple, UseScratch> +{ + static_assert(all_satisfy::value, "return type must be GMat"); + static_assert(contains::value, "input must contain at least one GMat"); + + // Execution dispatcher //////////////////////////////////////////////////// + template + static void call_impl(const cv::GArgs &in_args, + const std::vector &out_bufs, + detail::Seq, + detail::Seq) + { + Impl::run(fluid_get_in::get(in_args, IIs)..., *out_bufs[OIs]...); + } + + static void call(const cv::GArgs &in_args, + const std::vector &out_bufs) + { + constexpr int numOuts = (sizeof...(Outs)) + (UseScratch ? 1 : 0); + call_impl(in_args, out_bufs, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } + + // Scratch buffer initialization dispatcher //////////////////////////////// + static void init_scratch(const GMetaArgs &metas, + const cv::GArgs &in_args, + gapi::fluid::Buffer &b) + { + scratch_helper::help_init(metas, in_args, b); + } + + // Scratch buffer reset dispatcher ///////////////////////////////////////// + static void reset_scratch(gapi::fluid::Buffer &scratch_buf) + { + scratch_helper::help_reset(scratch_buf); + } + + static gapi::fluid::BorderOpt getBorder(const GMetaArgs &metas, const cv::GArgs &in_args) + { + constexpr bool hasWindow = has_Window::value; + + // User must provide "init" callback if Window != 1 + // TODO: move to constexpr if when we enable C++17 + return get_border_helper::value, Impl, Ins...>::help(metas, in_args); + } + + static int getWindow(const GMetaArgs &metas, const cv::GArgs &in_args) + { + constexpr bool callCustomGetWindow = !(has_Window::value); + return get_window_helper::help(metas, in_args); + } +}; +} // namespace detail + + +template +class GFluidKernelImpl : public cv::detail::KernelTag +{ + static const int LPI = 1; + static const auto Kind = GFluidKernel::Kind::Filter; + using P = detail::FluidCallHelper; + +public: + using API = K; + + static GFluidKernel kernel() + { + // FIXME: call() and getOutMeta() needs to be renamed so it is clear these + // functions are internal wrappers, not user API + return GFluidKernel(Impl::Kind, Impl::LPI, + UseScratch, + &P::call, &P::init_scratch, &P::reset_scratch, &P::getBorder, &P::getWindow); + } + + static cv::gapi::GBackend backend() { return cv::gapi::fluid::backend(); } +}; + +#define GAPI_FLUID_KERNEL(Name, API, Scratch) struct Name: public cv::GFluidKernelImpl + +} // namespace cv + +#endif // OPENCV_GAPI_GCPUKERNEL_HPP diff --git a/3rdparty/include/opencv2/gapi/fluid/imgproc.hpp b/3rdparty/include/opencv2/gapi/fluid/imgproc.hpp new file mode 100644 index 0000000000..dedfa9dbe1 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/fluid/imgproc.hpp @@ -0,0 +1,20 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_FLUID_IMGPROC_HPP +#define OPENCV_GAPI_FLUID_IMGPROC_HPP + +#include // GKernelPackage +#include // GAPI_EXPORTS + +namespace cv { namespace gapi { namespace imgproc { namespace fluid { + +GAPI_EXPORTS GKernelPackage kernels(); + +}}}} + +#endif // OPENCV_GAPI_FLUID_IMGPROC_HPP diff --git a/3rdparty/include/opencv2/gapi/garg.hpp b/3rdparty/include/opencv2/gapi/garg.hpp new file mode 100644 index 0000000000..20f2233bf9 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/garg.hpp @@ -0,0 +1,278 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GARG_HPP +#define OPENCV_GAPI_GARG_HPP + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace cv { + +class GArg; + +namespace detail { + template + using is_garg = std::is_same::type>; +} + +// Parameter holder class for a node +// Depending on platform capabilities, can either support arbitrary types +// (as `boost::any`) or a limited number of types (as `boot::variant`). +// FIXME: put into "details" as a user shouldn't use it in his code +class GAPI_EXPORTS GArg +{ +public: + GArg() {} + + template::value, int>::type = 0> + explicit GArg(const T &t) + : kind(detail::GTypeTraits::kind) + , opaque_kind(detail::GOpaqueTraits::kind) + , value(detail::wrap_gapi_helper::wrap(t)) + { + } + + template::value, int>::type = 0> + explicit GArg(T &&t) + : kind(detail::GTypeTraits::type>::kind) + , opaque_kind(detail::GOpaqueTraits::type>::kind) + , value(detail::wrap_gapi_helper::wrap(t)) + { + } + + template inline T& get() + { + return util::any_cast::type>(value); + } + + template inline const T& get() const + { + return util::any_cast::type>(value); + } + + template inline T& unsafe_get() + { + return util::unsafe_any_cast::type>(value); + } + + template inline const T& unsafe_get() const + { + return util::unsafe_any_cast::type>(value); + } + + detail::ArgKind kind = detail::ArgKind::OPAQUE_VAL; + detail::OpaqueKind opaque_kind = detail::OpaqueKind::CV_UNKNOWN; + +protected: + util::any value; +}; + +using GArgs = std::vector; + +// FIXME: Express as M::type +// FIXME: Move to a separate file! +using GRunArgBase = util::variant< +#if !defined(GAPI_STANDALONE) + cv::UMat, +#endif // !defined(GAPI_STANDALONE) + cv::RMat, + cv::gapi::wip::IStreamSource::Ptr, + cv::Mat, + cv::Scalar, + cv::detail::VectorRef, + cv::detail::OpaqueRef, + cv::MediaFrame + >; + +namespace detail { +template +struct in_variant; + +template +struct in_variant > + : std::integral_constant::value > { +}; +} // namespace detail + +struct GAPI_EXPORTS GRunArg: public GRunArgBase +{ + // Metadata information here + using Meta = std::unordered_map; + Meta meta; + + // Mimic the old GRunArg semantics here, old of the times when + // GRunArg was an alias to variant<> + GRunArg(); + GRunArg(const cv::GRunArg &arg); + GRunArg(cv::GRunArg &&arg); + + GRunArg& operator= (const GRunArg &arg); + GRunArg& operator= (GRunArg &&arg); + + template + GRunArg(const T &t, + const Meta &m = Meta{}, + typename std::enable_if< detail::in_variant::value, int>::type = 0) + : GRunArgBase(t) + , meta(m) + { + } + template + GRunArg(T &&t, + const Meta &m = Meta{}, + typename std::enable_if< detail::in_variant::value, int>::type = 0) + : GRunArgBase(std::move(t)) + , meta(m) + { + } + template auto operator= (const T &t) + -> typename std::enable_if< detail::in_variant::value, cv::GRunArg>::type& + { + GRunArgBase::operator=(t); + return *this; + } + template auto operator= (T&& t) + -> typename std::enable_if< detail::in_variant::value, cv::GRunArg>::type& + { + GRunArgBase::operator=(std::move(t)); + return *this; + } +}; +using GRunArgs = std::vector; + +// TODO: Think about the addition operator +/** + * @brief This operator allows to complement the input vector at runtime. + * + * It's an ordinary overload of addition assignment operator. + * + * Example of usage: + * @snippet dynamic_graph.cpp GRunArgs usage + * + */ +inline GRunArgs& operator += (GRunArgs &lhs, const GRunArgs &rhs) +{ + lhs.reserve(lhs.size() + rhs.size()); + lhs.insert(lhs.end(), rhs.begin(), rhs.end()); + return lhs; +} + +namespace gapi +{ +namespace wip +{ +/** + * @brief This aggregate type represents all types which G-API can + * handle (via variant). + * + * It only exists to overcome C++ language limitations (where a + * `using`-defined class can't be forward-declared). + */ +struct GAPI_EXPORTS Data: public GRunArg +{ + using GRunArg::GRunArg; + template + Data& operator= (const T& t) { GRunArg::operator=(t); return *this; } + template + Data& operator= (T&& t) { GRunArg::operator=(std::move(t)); return *this; } +}; +} // namespace wip +} // namespace gapi + +using GRunArgP = util::variant< +#if !defined(GAPI_STANDALONE) + cv::UMat*, +#endif // !defined(GAPI_STANDALONE) + cv::Mat*, + cv::RMat*, + cv::Scalar*, + cv::MediaFrame*, + cv::detail::VectorRef, + cv::detail::OpaqueRef + >; +using GRunArgsP = std::vector; + +// TODO: Think about the addition operator +/** + * @brief This operator allows to complement the output vector at runtime. + * + * It's an ordinary overload of addition assignment operator. + * + * Example of usage: + * @snippet dynamic_graph.cpp GRunArgsP usage + * + */ +inline GRunArgsP& operator += (GRunArgsP &lhs, const GRunArgsP &rhs) +{ + lhs.reserve(lhs.size() + rhs.size()); + lhs.insert(lhs.end(), rhs.begin(), rhs.end()); + return lhs; +} + +namespace gapi +{ + GAPI_EXPORTS cv::GRunArgsP bind(cv::GRunArgs &results); + GAPI_EXPORTS cv::GRunArg bind(cv::GRunArgP &out); // FIXME: think more about it +} + +template inline GRunArgs gin(const Ts&... args) +{ + return GRunArgs{ GRunArg(detail::wrap_host_helper::wrap_in(args))... }; +} + +template inline GRunArgsP gout(Ts&... args) +{ + return GRunArgsP{ GRunArgP(detail::wrap_host_helper::wrap_out(args))... }; +} + +struct GTypeInfo; +using GTypesInfo = std::vector; + +// FIXME: Needed for python bridge, must be moved to more appropriate header +namespace detail { +struct ExtractArgsCallback +{ + cv::GRunArgs operator()(const cv::GTypesInfo& info) const { return c(info); } + using CallBackT = std::function; + CallBackT c; +}; + +struct ExtractMetaCallback +{ + cv::GMetaArgs operator()(const cv::GTypesInfo& info) const { return c(info); } + using CallBackT = std::function; + CallBackT c; +}; + +void constructGraphOutputs(const cv::GTypesInfo &out_info, + cv::GRunArgs &args, + cv::GRunArgsP &outs); +} // namespace detail + +} // namespace cv + +#endif // OPENCV_GAPI_GARG_HPP diff --git a/3rdparty/include/opencv2/gapi/garray.hpp b/3rdparty/include/opencv2/gapi/garray.hpp new file mode 100644 index 0000000000..d7b365f7f9 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/garray.hpp @@ -0,0 +1,440 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GARRAY_HPP +#define OPENCV_GAPI_GARRAY_HPP + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include // flatten_g only! +#include // flatten_g only! + +namespace cv +{ +// Forward declaration; GNode and GOrigin are an internal +// (user-inaccessible) classes. +class GNode; +struct GOrigin; +template class GArray; + +/** + * \addtogroup gapi_meta_args + * @{ + */ +struct GAPI_EXPORTS_W_SIMPLE GArrayDesc +{ + // FIXME: Body + // FIXME: Also implement proper operator== then + bool operator== (const GArrayDesc&) const { return true; } +}; +template GArrayDesc descr_of(const std::vector &) { return {};} +GAPI_EXPORTS_W inline GArrayDesc empty_array_desc() {return {}; } +/** @} */ + +std::ostream& operator<<(std::ostream& os, const cv::GArrayDesc &desc); + +namespace detail +{ + // ConstructVec is a callback which stores information about T and is used by + // G-API runtime to construct arrays in host memory (T remains opaque for G-API). + // ConstructVec is carried into G-API internals by GArrayU. + // Currently it is suitable for Host (CPU) plugins only, real offload may require + // more information for manual memory allocation on-device. + class VectorRef; + using ConstructVec = std::function; + + // This is the base struct for GArrayU type holder + struct TypeHintBase{virtual ~TypeHintBase() = default;}; + + // This class holds type of initial GArray to be checked from GArrayU + template + struct TypeHint final : public TypeHintBase{}; + + // This class strips type information from GArray and makes it usable + // in the G-API graph compiler (expression unrolling, graph generation, etc). + // Part of GProtoArg. + class GAPI_EXPORTS GArrayU + { + public: + GArrayU(const GNode &n, std::size_t out); // Operation result constructor + + template + bool holds() const; // Check if was created from GArray + + GOrigin& priv(); // Internal use only + const GOrigin& priv() const; // Internal use only + + protected: + GArrayU(); // Default constructor + GArrayU(const detail::VectorRef& vref); // Constant value constructor + template friend class cv::GArray; // (available to GArray only) + + void setConstructFcn(ConstructVec &&cv); // Store T-aware constructor + + template + void specifyType(); // Store type of initial GArray + + template + void storeKind(); + + void setKind(cv::detail::OpaqueKind); + + std::shared_ptr m_priv; + std::shared_ptr m_hint; + }; + + template + bool GArrayU::holds() const{ + GAPI_Assert(m_hint != nullptr); + using U = typename std::decay::type; + return dynamic_cast*>(m_hint.get()) != nullptr; + }; + + template + void GArrayU::specifyType(){ + m_hint.reset(new TypeHint::type>); + }; + + template + void GArrayU::storeKind(){ + setKind(cv::detail::GOpaqueTraits::kind); + }; + + // This class represents a typed STL vector reference. + // Depending on origins, this reference may be either "just a" reference to + // an object created externally, OR actually own the underlying object + // (be value holder). + class BasicVectorRef + { + public: + // These fields are set by the derived class(es) + std::size_t m_elemSize = 0ul; + cv::GArrayDesc m_desc; + virtual ~BasicVectorRef() {} + + virtual void mov(BasicVectorRef &ref) = 0; + virtual const void* ptr() const = 0; + virtual std::size_t size() const = 0; + }; + + template class VectorRefT final: public BasicVectorRef + { + using empty_t = util::monostate; + using ro_ext_t = const std::vector *; + using rw_ext_t = std::vector *; + using rw_own_t = std::vector ; + util::variant m_ref; + + inline bool isEmpty() const { return util::holds_alternative(m_ref); } + inline bool isROExt() const { return util::holds_alternative(m_ref); } + inline bool isRWExt() const { return util::holds_alternative(m_ref); } + inline bool isRWOwn() const { return util::holds_alternative(m_ref); } + + void init(const std::vector* vec = nullptr) + { + m_elemSize = sizeof(T); + if (vec) m_desc = cv::descr_of(*vec); + } + + public: + VectorRefT() { init(); } + virtual ~VectorRefT() {} + + explicit VectorRefT(const std::vector& vec) : m_ref(&vec) { init(&vec); } + explicit VectorRefT(std::vector& vec) : m_ref(&vec) { init(&vec); } + explicit VectorRefT(std::vector&& vec) : m_ref(std::move(vec)) { init(&vec); } + + // Reset a VectorRefT. Called only for objects instantiated + // internally in G-API (e.g. temporary GArray's within a + // computation). Reset here means both initialization + // (creating an object) and reset (discarding its existing + // content before the next execution). Must never be called + // for external VectorRefTs. + void reset() + { + if (isEmpty()) + { + std::vector empty_vector; + m_desc = cv::descr_of(empty_vector); + m_ref = std::move(empty_vector); + GAPI_Assert(isRWOwn()); + } + else if (isRWOwn()) + { + util::get(m_ref).clear(); + } + else GAPI_Assert(false); // shouldn't be called in *EXT modes + } + + // Obtain a WRITE reference to underlying object + // Used by CPU kernel API wrappers when a kernel execution frame + // is created + std::vector& wref() + { + GAPI_Assert(isRWExt() || isRWOwn()); + if (isRWExt()) return *util::get(m_ref); + if (isRWOwn()) return util::get(m_ref); + util::throw_error(std::logic_error("Impossible happened")); + } + + // Obtain a READ reference to underlying object + // Used by CPU kernel API wrappers when a kernel execution frame + // is created + const std::vector& rref() const + { + // ANY vector can be accessed for reading, even if it declared for + // output. Example -- a GComputation from [in] to [out1,out2] + // where [out2] is a result of operation applied to [out1]: + // + // GComputation boundary + // . . . . . . . + // . . + // [in] ----> foo() ----> [out1] + // . . : + // . . . .:. . . + // . V . + // . bar() ---> [out2] + // . . . . . . . . . . . . + // + if (isROExt()) return *util::get(m_ref); + if (isRWExt()) return *util::get(m_ref); + if (isRWOwn()) return util::get(m_ref); + util::throw_error(std::logic_error("Impossible happened")); + } + + virtual void mov(BasicVectorRef &v) override { + VectorRefT *tv = dynamic_cast*>(&v); + GAPI_Assert(tv != nullptr); + wref() = std::move(tv->wref()); + } + + virtual const void* ptr() const override { return &rref(); } + virtual std::size_t size() const override { return rref().size(); } + }; + + // This class strips type information from VectorRefT<> and makes it usable + // in the G-API executables (carrying run-time data/information to kernels). + // Part of GRunArg. + // Its methods are typed proxies to VectorRefT. + // VectorRef maintains "reference" semantics so two copies of VectoRef refer + // to the same underlying object. + // FIXME: Put a good explanation on why cv::OutputArray doesn't fit this role + class VectorRef + { + std::shared_ptr m_ref; + cv::detail::OpaqueKind m_kind; + + template inline void check() const + { + GAPI_DbgAssert(dynamic_cast*>(m_ref.get()) != nullptr); + GAPI_Assert(sizeof(T) == m_ref->m_elemSize); + } + + public: + VectorRef() = default; + template explicit VectorRef(const std::vector& vec) + : m_ref(new VectorRefT(vec)) + , m_kind(GOpaqueTraits::kind) + {} + template explicit VectorRef(std::vector& vec) + : m_ref(new VectorRefT(vec)) + , m_kind(GOpaqueTraits::kind) + {} + template explicit VectorRef(std::vector&& vec) + : m_ref(new VectorRefT(std::move(vec))) + , m_kind(GOpaqueTraits::kind) + {} + + cv::detail::OpaqueKind getKind() const + { + return m_kind; + } + + template void reset() + { + if (!m_ref) m_ref.reset(new VectorRefT()); + check(); + storeKind(); + static_cast&>(*m_ref).reset(); + } + + template + void storeKind() + { + m_kind = cv::detail::GOpaqueTraits::kind; + } + + template std::vector& wref() + { + check(); + return static_cast&>(*m_ref).wref(); + } + + template const std::vector& rref() const + { + check(); + return static_cast&>(*m_ref).rref(); + } + + // Check if was created for/from std::vector + template bool holds() const + { + if (!m_ref) return false; + using U = typename std::decay::type; + return dynamic_cast*>(m_ref.get()) != nullptr; + } + + void mov(VectorRef &v) + { + m_ref->mov(*v.m_ref); + } + + cv::GArrayDesc descr_of() const + { + return m_ref->m_desc; + } + + std::size_t size() const + { + return m_ref->size(); + } + + // May be used to uniquely identify this object internally + const void *ptr() const { return m_ref->ptr(); } + }; + + // Helper (FIXME: work-around?) + // stripping G types to their host types + // like cv::GArray would still map to std::vector + // but not to std::vector +#if defined(GAPI_STANDALONE) +# define FLATTEN_NS cv::gapi::own +#else +# define FLATTEN_NS cv +#endif + template struct flatten_g; + template<> struct flatten_g { using type = FLATTEN_NS::Mat; }; + template<> struct flatten_g { using type = FLATTEN_NS::Scalar; }; + template struct flatten_g> { using type = std::vector; }; + template struct flatten_g { using type = T; }; +#undef FLATTEN_NS + // FIXME: the above mainly duplicates "ProtoToParam" thing from gtyped.hpp + // but I decided not to include gtyped here - probably worth moving that stuff + // to some common place? (DM) +} // namespace detail + +/** \addtogroup gapi_data_objects + * @{ + */ +/** + * @brief `cv::GArray` template class represents a list of objects + * of class `T` in the graph. + * + * `cv::GArray` describes a functional relationship between + * operations consuming and producing arrays of objects of class + * `T`. The primary purpose of `cv::GArray` is to represent a + * dynamic list of objects -- where the size of the list is not known + * at the graph construction or compile time. Examples include: corner + * and feature detectors (`cv::GArray`), object detection + * and tracking results (`cv::GArray`). Programmers can use + * their own types with `cv::GArray` in the custom operations. + * + * Similar to `cv::GScalar`, `cv::GArray` may be value-initialized + * -- in this case a graph-constant value is associated with the object. + * + * `GArray` is a virtual counterpart of `std::vector`, which is + * usually used to represent the `GArray` data in G-API during the + * execution. + * + * @sa `cv::GOpaque` + */ +template class GArray +{ +public: + // Host type (or Flat type) - the type this GArray is actually + // specified to. + /// @private + using HT = typename detail::flatten_g::type>::type; + + /** + * @brief Constructs a value-initialized `cv::GArray` + * + * `cv::GArray` objects may have their values + * be associated at graph construction time. It is useful when + * some operation has a `cv::GArray` input which doesn't change during + * the program execution, and is set only once. In this case, + * there is no need to declare such `cv::GArray` as a graph input. + * + * @note The value of `cv::GArray` may be overwritten by assigning some + * other `cv::GArray` to the object using `operator=` -- on the + * assigment, the old association or value is discarded. + * + * @param v a std::vector to associate with this + * `cv::GArray` object. Vector data is copied into the + * `cv::GArray` (no reference to the passed data is held). + */ + explicit GArray(const std::vector& v) // Constant value constructor + : m_ref(detail::GArrayU(detail::VectorRef(v))) { putDetails(); } + + /** + * @overload + * @brief Constructs a value-initialized `cv::GArray` + * + * @param v a std::vector to associate with this + * `cv::GArray` object. Vector data is moved into the `cv::GArray`. + */ + explicit GArray(std::vector&& v) // Move-constructor + : m_ref(detail::GArrayU(detail::VectorRef(std::move(v)))) { putDetails(); } + + /** + * @brief Constructs an empty `cv::GArray` + * + * Normally, empty G-API data objects denote a starting point of + * the graph. When an empty `cv::GArray` is assigned to a result + * of some operation, it obtains a functional link to this + * operation (and is not empty anymore). + */ + GArray() { putDetails(); } // Empty constructor + + /// @private + explicit GArray(detail::GArrayU &&ref) // GArrayU-based constructor + : m_ref(ref) { putDetails(); } // (used by GCall, not for users) + + /// @private + detail::GArrayU strip() const { + return m_ref; + } + /// @private + static void VCtor(detail::VectorRef& vref) { + vref.reset(); + } + +private: + void putDetails() { + m_ref.setConstructFcn(&VCtor); + m_ref.specifyType(); // FIXME: to unify those 2 to avoid excessive dynamic_cast + m_ref.storeKind(); // + } + + detail::GArrayU m_ref; +}; + +/** @} */ + +} // namespace cv + +#endif // OPENCV_GAPI_GARRAY_HPP diff --git a/3rdparty/include/opencv2/gapi/gasync_context.hpp b/3rdparty/include/opencv2/gapi/gasync_context.hpp new file mode 100644 index 0000000000..f49b59822d --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gasync_context.hpp @@ -0,0 +1,63 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_GASYNC_CONTEXT_HPP +#define OPENCV_GAPI_GASYNC_CONTEXT_HPP + +#if !defined(GAPI_STANDALONE) +# include +#else // Without OpenCV +# include +#endif // !defined(GAPI_STANDALONE) + +#include + +namespace cv { +namespace gapi{ + +/** + * @brief This namespace contains experimental G-API functionality, + * functions or structures in this namespace are subjects to change or + * removal in the future releases. This namespace also contains + * functions which API is not stabilized yet. + */ +namespace wip { + +/** + * @brief A class to group async requests to cancel them in a single shot. + * + * GAsyncContext is passed as an argument to async() and async_apply() functions + */ + +class GAPI_EXPORTS GAsyncContext{ + std::atomic cancelation_requested = {false}; +public: + /** + * @brief Start cancellation process for an associated request. + * + * User still has to wait for each individual request (either via callback or according std::future object) to make sure it actually canceled. + * + * @return true if it was a first request to cancel the context + */ + bool cancel(); + + /** + * @brief Returns true if cancellation was requested for this context. + * + * @return true if cancellation was requested for this context + */ + bool isCanceled() const; +}; + +class GAPI_EXPORTS GAsyncCanceled : public std::exception { +public: + virtual const char* what() const noexcept CV_OVERRIDE; +}; +} // namespace wip +} // namespace gapi +} // namespace cv + +#endif //OPENCV_GAPI_GASYNC_CONTEXT_HPP diff --git a/3rdparty/include/opencv2/gapi/gcall.hpp b/3rdparty/include/opencv2/gapi/gcall.hpp new file mode 100644 index 0000000000..8d1b8d6010 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gcall.hpp @@ -0,0 +1,78 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GCALL_HPP +#define OPENCV_GAPI_GCALL_HPP + +#include // GArg +#include // GMat +#include // GScalar +#include // GFrame +#include // GArray +#include // GOpaque + +namespace cv { + +struct GKernel; + +// The whole idea of this class is to represent an operation +// which is applied to arguments. This is part of public API, +// since it is what users should use to define kernel interfaces. + +class GAPI_EXPORTS GCall final +{ +public: + class Priv; + + explicit GCall(const GKernel &k); + ~GCall(); + + template + GCall& pass(Ts&&... args) + { + setArgs({cv::GArg(std::move(args))...}); + return *this; + } + + // A generic yield method - obtain a link to operator's particular GMat output + GMat yield (int output = 0); + GMatP yieldP (int output = 0); + GScalar yieldScalar(int output = 0); + GFrame yieldFrame (int output = 0); + + template GArray yieldArray(int output = 0) + { + return GArray(yieldArray(output)); + } + + template GOpaque yieldOpaque(int output = 0) + { + return GOpaque(yieldOpaque(output)); + } + + // Internal use only + Priv& priv(); + const Priv& priv() const; + + // GKernel and params can be modified, it's needed for infer, + // because information about output shapes doesn't exist in compile time + GKernel& kernel(); + cv::util::any& params(); + + void setArgs(std::vector &&args); + +protected: + std::shared_ptr m_priv; + + // Public versions return a typed array or opaque, those are implementation details + detail::GArrayU yieldArray(int output = 0); + detail::GOpaqueU yieldOpaque(int output = 0); +}; + +} // namespace cv + +#endif // OPENCV_GAPI_GCALL_HPP diff --git a/3rdparty/include/opencv2/gapi/gcommon.hpp b/3rdparty/include/opencv2/gapi/gcommon.hpp new file mode 100644 index 0000000000..d3c280816f --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gcommon.hpp @@ -0,0 +1,287 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMMON_HPP +#define OPENCV_GAPI_GCOMMON_HPP + +#include // std::hash +#include // std::vector +#include // decay + +#include + +#include +#include +#include +#include +#include +#include + +namespace cv { + +class GMat; // FIXME: forward declaration for GOpaqueTraits + +namespace detail +{ + // This is a trait-like structure to mark backend-specific compile arguments + // with tags + template struct CompileArgTag; + + // These structures are tags which separate kernels and transformations + struct KernelTag + {}; + struct TransformTag + {}; + + // This enum is utilized mostly by GArray and GOpaque to store and recognize their internal data + // types (aka Host type). Also it is widely used during serialization routine. + enum class OpaqueKind: int + { + CV_UNKNOWN, // Unknown, generic, opaque-to-GAPI data type unsupported in graph seriallization + CV_BOOL, // bool user G-API data + CV_INT, // int user G-API data + CV_INT64, // int64_t user G-API data + CV_DOUBLE, // double user G-API data + CV_FLOAT, // float user G-API data + CV_UINT64, // uint64_t user G-API data + CV_STRING, // std::string user G-API data + CV_POINT, // cv::Point user G-API data + CV_POINT2F, // cv::Point2f user G-API data + CV_SIZE, // cv::Size user G-API data + CV_RECT, // cv::Rect user G-API data + CV_SCALAR, // cv::Scalar user G-API data + CV_MAT, // cv::Mat user G-API data + CV_DRAW_PRIM, // cv::gapi::wip::draw::Prim user G-API data + }; + + // Type traits helper which simplifies the extraction of kind from type + template struct GOpaqueTraits; + template struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_UNKNOWN; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_INT; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_INT64; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_DOUBLE; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_FLOAT; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_UINT64; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_BOOL; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_STRING; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_SIZE; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_SCALAR; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_POINT; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_POINT2F; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_MAT; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_RECT; }; + template<> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_MAT; }; + template<> struct GOpaqueTraits + { static constexpr const OpaqueKind kind = OpaqueKind::CV_DRAW_PRIM; }; + using GOpaqueTraitsArrayTypes = std::tuple; + // GOpaque is not supporting cv::Mat and cv::Scalar since there are GScalar and GMat types + using GOpaqueTraitsOpaqueTypes = std::tuple; +} // namespace detail + +// This definition is here because it is reused by both public(?) and internal +// modules. Keeping it here wouldn't expose public details (e.g., API-level) +// to components which are internal and operate on a lower-level entities +// (e.g., compiler, backends). +// FIXME: merge with ArgKind? +// FIXME: replace with variant[format desc]? +enum class GShape: int +{ + GMAT, + GSCALAR, + GARRAY, + GOPAQUE, + GFRAME, +}; + +namespace gapi { +namespace s11n { +namespace detail { +template struct wrap_serialize; +} // namespace detail +} // namespace s11n +} // namespace gapi + + +struct GCompileArg; + +namespace detail { + template + using is_compile_arg = std::is_same::type>; +} // namespace detail + +// CompileArg is an unified interface over backend-specific compilation +// information +// FIXME: Move to a separate file? +/** \addtogroup gapi_compile_args + * @{ + * + * @brief Compilation arguments: data structures controlling the + * compilation process + * + * G-API comes with a number of graph compilation options which can be + * passed to cv::GComputation::apply() or + * cv::GComputation::compile(). Known compilation options are listed + * in this page, while extra backends may introduce their own + * compilation options (G-API transparently accepts _everything_ which + * can be passed to cv::compile_args(), it depends on underlying + * backends if an option would be interpreted or not). + * + * For example, if an example computation is executed like this: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_decl_apply + * + * Extra parameter specifying which kernels to compile with can be + * passed like this: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp apply_with_param + */ + +/** + * @brief Represents an arbitrary compilation argument. + * + * Any value can be wrapped into cv::GCompileArg, but only known ones + * (to G-API or its backends) can be interpreted correctly. + * + * Normally objects of this class shouldn't be created manually, use + * cv::compile_args() function which automatically wraps everything + * passed in (a variadic template parameter pack) into a vector of + * cv::GCompileArg objects. + */ +struct GCompileArg +{ +public: + // NB: Required for pythnon bindings + GCompileArg() = default; + + std::string tag; + + // FIXME: use decay in GArg/other trait-based wrapper before leg is shot! + template::value, int>::type = 0> + explicit GCompileArg(T &&t) + : tag(detail::CompileArgTag::type>::tag()) + , serializeF(cv::gapi::s11n::detail::has_S11N_spec::value ? + &cv::gapi::s11n::detail::wrap_serialize::serialize : + nullptr) + , arg(t) + { + } + + template T& get() + { + return util::any_cast(arg); + } + + template const T& get() const + { + return util::any_cast(arg); + } + + void serialize(cv::gapi::s11n::IOStream& os) const + { + if (serializeF) + { + serializeF(os, *this); + } + } + +private: + std::function serializeF; + util::any arg; +}; + +using GCompileArgs = std::vector; + +inline cv::GCompileArgs& operator += ( cv::GCompileArgs &lhs, + const cv::GCompileArgs &rhs) +{ + lhs.reserve(lhs.size() + rhs.size()); + lhs.insert(lhs.end(), rhs.begin(), rhs.end()); + return lhs; +} + +/** + * @brief Wraps a list of arguments (a parameter pack) into a vector of + * compilation arguments (cv::GCompileArg). + */ +template GCompileArgs compile_args(Ts&&... args) +{ + return GCompileArgs{ GCompileArg(args)... }; +} + +namespace gapi +{ +/** + * @brief Retrieves particular compilation argument by its type from + * cv::GCompileArgs + */ +template +inline cv::util::optional getCompileArg(const cv::GCompileArgs &args) +{ + for (auto &compile_arg : args) + { + if (compile_arg.tag == cv::detail::CompileArgTag::tag()) + { + return cv::util::optional(compile_arg.get()); + } + } + return cv::util::optional(); +} + +namespace s11n { +namespace detail { +template struct wrap_serialize +{ + static void serialize(IOStream& os, const GCompileArg& arg) + { + using DT = typename std::decay::type; + S11N
::serialize(os, arg.get
()); + } +}; +} // namespace detail +} // namespace s11n +} // namespace gapi + +/** + * @brief Ask G-API to dump compiled graph in Graphviz format under + * the given file name. + * + * Specifies a graph dump path (path to .dot file to be generated). + * G-API will dump a .dot file under specified path during a + * compilation process if this flag is passed. + */ +struct graph_dump_path +{ + std::string m_dump_path; +}; +/** @} */ + +namespace detail +{ + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.graph_dump_path"; } + }; +} + +} // namespace cv + +// std::hash overload for GShape +namespace std +{ +template<> struct hash +{ + size_t operator() (cv::GShape sh) const + { + return std::hash()(static_cast(sh)); + } +}; +} // namespace std + + +#endif // OPENCV_GAPI_GCOMMON_HPP diff --git a/3rdparty/include/opencv2/gapi/gcompiled.hpp b/3rdparty/include/opencv2/gapi/gcompiled.hpp new file mode 100644 index 0000000000..ac36783d62 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gcompiled.hpp @@ -0,0 +1,232 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMPILED_HPP +#define OPENCV_GAPI_GCOMPILED_HPP + +#include + +#include +#include +#include + +namespace cv { + +// This class represents a compiled computation. +// In theory (and ideally), it can be used w/o the rest of APIs. +// In theory (and ideally), it can be serialized/deserialized. +// It can enable scenarious like deployment to an autonomous devince, FuSa, etc. +// +// Currently GCompiled assumes all GMats you used to pass data to G-API +// are valid and not destroyed while you use a GCompiled object. +// +// FIXME: In future, there should be a way to name I/O objects and specify it +// to GCompiled externally (for example, when it is loaded on the target system). + +/** + * \addtogroup gapi_main_classes + * @{ + */ +/** + * @brief Represents a compiled computation (graph). Can only be used + * with image / data formats & resolutions it was compiled for, with + * some exceptions. + * + * This class represents a product of graph compilation (calling + * cv::GComputation::compile()). Objects of this class actually do + * data processing, and graph execution is incapsulated into objects + * of this class. Execution model itself depends on kernels and + * backends which were using during the compilation, see @ref + * gapi_compile_args for details. + * + * In a general case, GCompiled objects can be applied to data only in + * that formats/resolutions they were compiled for (see @ref + * gapi_meta_args). However, if the underlying backends allow, a + * compiled object can be _reshaped_ to handle data (images) of + * different resolution, though formats and types must remain the same. + * + * GCompiled is very similar to `std::function<>` in its semantics -- + * running it looks like a function call in the user code. + * + * At the moment, GCompiled objects are not reentrant -- generally, + * the objects are stateful since graph execution itself is a stateful + * process and this state is now maintained in GCompiled's own memory + * (not on the process stack). + * + * At the same time, two different GCompiled objects produced from the + * single cv::GComputation are completely independent and can be used + * concurrently. + * + * @sa GStreamingCompiled + */ +class GAPI_EXPORTS GCompiled +{ +public: + /// @private + class GAPI_EXPORTS Priv; + + /** + * @brief Constructs an empty object + */ + GCompiled(); + + /** + * @brief Run the compiled computation, a generic version. + * + * @param ins vector of inputs to process. + * @param outs vector of outputs to produce. + * + * Input/output vectors must have the same number of elements as + * defined in the cv::GComputation protocol (at the moment of its + * construction). Shapes of elements also must conform to protocol + * (e.g. cv::Mat needs to be passed where cv::GMat has been + * declared as input, and so on). Run-time exception is generated + * otherwise. + * + * Objects in output vector may remain empty (like cv::Mat) -- + * G-API will automatically initialize output objects to proper formats. + * + * @note Don't construct GRunArgs/GRunArgsP objects manually, use + * cv::gin()/cv::gout() wrappers instead. + */ + void operator() (GRunArgs &&ins, GRunArgsP &&outs); // Generic arg-to-arg +#if !defined(GAPI_STANDALONE) + + /** + * @brief Execute an unary computation + * + * @overload + * @param in input cv::Mat for unary computation + * @param out output cv::Mat for unary computation + * process. + */ + void operator() (cv::Mat in, cv::Mat &out); // Unary overload + + /** + * @brief Execute an unary computation + * + * @overload + * @param in input cv::Mat for unary computation + * @param out output cv::Scalar for unary computation + * process. + */ + void operator() (cv::Mat in, cv::Scalar &out); // Unary overload (scalar) + + /** + * @brief Execute a binary computation + * + * @overload + * @param in1 first input cv::Mat for binary computation + * @param in2 second input cv::Mat for binary computation + * @param out output cv::Mat for binary computation + * process. + */ + void operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out); // Binary overload + + /** + * @brief Execute an binary computation + * + * @overload + * @param in1 first input cv::Mat for binary computation + * @param in2 second input cv::Mat for binary computation + * @param out output cv::Scalar for binary computation + * process. + */ + void operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out); // Binary overload (scalar) + + /** + * @brief Execute a computation with arbitrary number of + * inputs/outputs. + * + * @overload + * @param ins vector of input cv::Mat objects to process by the + * computation. + * @param outs vector of output cv::Mat objects to produce by the + * computation. + * + * Numbers of elements in ins/outs vectors must match numbers of + * inputs/outputs which were used to define the source GComputation. + */ + void operator() (const std::vector &ins, // Compatibility overload + const std::vector &outs); +#endif // !defined(GAPI_STANDALONE) + /// @private + Priv& priv(); + + /** + * @brief Check if compiled object is valid (non-empty) + * + * @return true if the object is runnable (valid), false otherwise + */ + explicit operator bool () const; + + /** + * @brief Vector of metadata this graph was compiled for. + * + * @return Unless _reshape_ is not supported, return value is the + * same vector which was passed to cv::GComputation::compile() to + * produce this compiled object. Otherwise, it is the latest + * metadata vector passed to reshape() (if that call was + * successful). + */ + const GMetaArgs& metas() const; // Meta passed to compile() + + /** + * @brief Vector of metadata descriptions of graph outputs + * + * @return vector with formats/resolutions of graph's output + * objects, auto-inferred from input metadata vector by + * operations which form this computation. + * + * @note GCompiled objects produced from the same + * cv::GComputiation graph with different input metas may return + * different values in this vector. + */ + const GMetaArgs& outMetas() const; + + /** + * @brief Check if the underlying backends support reshape or not. + * + * @return true if supported, false otherwise. + */ + bool canReshape() const; + + /** + * @brief Reshape a compiled graph to support new image + * resolutions. + * + * Throws an exception if an error occurs. + * + * @param inMetas new metadata to reshape on. Vector size and + * metadata shapes must match the computation's protocol. + * @param args compilation arguments to use. + */ + // FIXME: Why it requires compile args? + void reshape(const GMetaArgs& inMetas, const GCompileArgs& args); + + /** + * @brief Prepare inner kernels states for a new video-stream. + * + * GCompiled objects may be used to process video streams frame by frame. + * In this case, a GCompiled is called on every image frame individually. + * Starting OpenCV 4.4, some kernels in the graph may have their internal + * states (see GAPI_OCV_KERNEL_ST for the OpenCV backend). + * In this case, if user starts processing another video stream with + * this GCompiled, this method needs to be called to let kernels re-initialize + * their internal states to a new video stream. + */ + void prepareForNewStream(); + +protected: + /// @private + std::shared_ptr m_priv; +}; +/** @} */ + +} + +#endif // OPENCV_GAPI_GCOMPILED_HPP diff --git a/3rdparty/include/opencv2/gapi/gcompiled_async.hpp b/3rdparty/include/opencv2/gapi/gcompiled_async.hpp new file mode 100644 index 0000000000..a0c2917d6a --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gcompiled_async.hpp @@ -0,0 +1,73 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMPILED_ASYNC_HPP +#define OPENCV_GAPI_GCOMPILED_ASYNC_HPP + +#include //for std::future +#include //for std::exception_ptr +#include //for std::function +#include +#include + +namespace cv { + //fwd declaration + class GCompiled; + +namespace gapi{ +namespace wip { + class GAsyncContext; + /** + These functions asynchronously (i.e. probably on a separate thread of execution) call GCompiled::operator() member function of their first argument with copies of rest of arguments (except callback) passed in. + The difference between the function is the way to get the completion notification (via callback or a waiting on std::future object) + If exception is occurred during execution of apply it is transferred to the callback (via function parameter) or passed to future (and will be thrown on call to std::future::get) + + N.B. : + Input arguments are copied on call to async function (actually on call to cv::gin) and thus do not have to outlive the actual completion of asynchronous activity. + While output arguments are "captured" by reference(pointer) and therefore _must_ outlive the asynchronous activity + (i.e. live at least until callback is called or future is unblocked) + + @param gcmpld Compiled computation (graph) to start asynchronously + @param callback Callback to be called when execution of gcmpld is done + @param ins Input parameters for gcmpld + @param outs Output parameters for gcmpld + */ + GAPI_EXPORTS void async(GCompiled& gcmpld, std::function&& callback, GRunArgs &&ins, GRunArgsP &&outs); + + /** @overload + @param gcmpld Compiled computation (graph) to run asynchronously + @param callback Callback to be called when execution of gcmpld is done + @param ins Input parameters for gcmpld + @param outs Output parameters for gcmpld + @param ctx Context this request belongs to + @see async GAsyncContext + */ + GAPI_EXPORTS void async(GCompiled& gcmpld, std::function&& callback, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx); + + /** @overload + @param gcmpld Compiled computation (graph) to run asynchronously + @param ins Input parameters for gcmpld + @param outs Output parameters for gcmpld + @return std::future object to wait for completion of async operation + @see async + */ + GAPI_EXPORTS std::future async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs); + + /** + @param gcmpld Compiled computation (graph) to run asynchronously + @param ins Input parameters for gcmpld + @param outs Output parameters for gcmpld + @param ctx Context this request belongs to + @return std::future object to wait for completion of async operation + @see async GAsyncContext + */ + GAPI_EXPORTS std::future async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx); +} // namespace wip +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_GCOMPILED_ASYNC_HPP diff --git a/3rdparty/include/opencv2/gapi/gcompoundkernel.hpp b/3rdparty/include/opencv2/gapi/gcompoundkernel.hpp new file mode 100644 index 0000000000..df0ce34045 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gcompoundkernel.hpp @@ -0,0 +1,139 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMPOUNDKERNEL_HPP +#define OPENCV_GAPI_GCOMPOUNDKERNEL_HPP + +#include +#include +#include +#include + +namespace cv { +namespace gapi +{ +namespace compound +{ + // FIXME User does not need to know about this function + // Needs that user may define compound kernels(as cpu kernels) + GAPI_EXPORTS cv::gapi::GBackend backend(); +} // namespace compound +} // namespace gapi + +namespace detail +{ + +struct GCompoundContext +{ + explicit GCompoundContext(const GArgs& in_args); + template + const T& inArg(int input) { return m_args.at(input).get(); } + + GArgs m_args; + GArgs m_results; +}; + +class GAPI_EXPORTS GCompoundKernel +{ +// Compound kernel must use all of it's inputs +public: + using F = std::function; + + explicit GCompoundKernel(const F& f); + void apply(GCompoundContext& ctx); + +protected: + F m_f; +}; + +template struct get_compound_in +{ + static T get(GCompoundContext &ctx, int idx) { return ctx.inArg(idx); } +}; + +template struct get_compound_in> +{ + static cv::GArray get(GCompoundContext &ctx, int idx) + { + auto array = cv::GArray(); + ctx.m_args[idx] = GArg(array); + return array; + } +}; + +template struct get_compound_in> +{ + static cv::GOpaque get(GCompoundContext &ctx, int idx) + { + auto opaq = cv::GOpaque(); + ctx.m_args[idx] = GArg(opaq); + return opaq; + } +}; + +template<> struct get_compound_in +{ + static cv::GMatP get(GCompoundContext &ctx, int idx) + { + auto mat = cv::GMatP(); + ctx.m_args[idx] = GArg(mat); + return mat; + } +}; + +template +struct GCompoundCallHelper; + +template +struct GCompoundCallHelper, std::tuple > +{ + template + static void expand_impl(GCompoundContext &ctx, detail::Seq, detail::Seq) + { + auto result = Impl::expand(get_compound_in::get(ctx, IIs)...); + auto tuple_return = tuple_wrap_helper::get(std::move(result)); + ctx.m_results = { cv::GArg(std::get(tuple_return))... }; + } + + static void expand(GCompoundContext &ctx) + { + expand_impl(ctx, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } +}; + +template +class GCompoundKernelImpl: public cv::detail::GCompoundCallHelper, + public cv::detail::KernelTag +{ + using P = cv::detail::GCompoundCallHelper; + +public: + using API = K; + + static cv::gapi::GBackend backend() { return cv::gapi::compound::backend(); } + static GCompoundKernel kernel() { return GCompoundKernel(&P::expand); } +}; + +} // namespace detail + + +/** + * Declares a new compound kernel. See this + * [documentation chapter](@ref gapi_kernel_compound) + * on compound kernels for more details. + * + * @param Name type name for new kernel + * @param API the interface this kernel implements + */ +#define GAPI_COMPOUND_KERNEL(Name, API) \ + struct Name: public cv::detail::GCompoundKernelImpl + +} // namespace cv + +#endif // OPENCV_GAPI_GCOMPOUNDKERNEL_HPP diff --git a/3rdparty/include/opencv2/gapi/gcomputation.hpp b/3rdparty/include/opencv2/gapi/gcomputation.hpp new file mode 100644 index 0000000000..a3566fb495 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gcomputation.hpp @@ -0,0 +1,580 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMPUTATION_HPP +#define OPENCV_GAPI_GCOMPUTATION_HPP + +#include + +#include +#include +#include +#include +#include +#include + +namespace cv { + +namespace detail +{ + // FIXME: move to algorithm, cover with separate tests + // FIXME: replace with O(1) version (both memory and compilation time) + template + struct last_type; + + template + struct last_type { using type = T;}; + + template + struct last_type { using type = typename last_type::type; }; + + template + using last_type_t = typename last_type::type; +} + +// Forward-declare the serialization objects +namespace gapi { +namespace s11n { + struct IIStream; + struct IOStream; +} // namespace s11n +} // namespace gapi + +/** + * \addtogroup gapi_main_classes + * @{ + * + * @brief G-API classes for constructed and compiled graphs. + */ +/** + * @brief GComputation class represents a captured computation + * graph. GComputation objects form boundaries for expression code + * user writes with G-API, allowing to compile and execute it. + * + * G-API computations are defined with input/output data + * objects. G-API will track automatically which operations connect + * specified outputs to the inputs, forming up a call graph to be + * executed. The below example expresses calculation of Sobel operator + * for edge detection (\f$G = \sqrt{G_x^2 + G_y^2}\f$): + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_def + * + * Full pipeline can be now captured with this object declaration: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_cap_full + * + * Input/output data objects on which a call graph should be + * reconstructed are passed using special wrappers cv::GIn and + * cv::GOut. G-API will track automatically which operations form a + * path from inputs to outputs and build the execution graph appropriately. + * + * Note that cv::GComputation doesn't take ownership on data objects + * it is defined. Moreover, multiple GComputation objects may be + * defined on the same expressions, e.g. a smaller pipeline which + * expects that image gradients are already pre-calculated may be + * defined like this: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_cap_sub + * + * The resulting graph would expect two inputs and produce one + * output. In this case, it doesn't matter if gx/gy data objects are + * results of cv::gapi::Sobel operators -- G-API will stop unrolling + * expressions and building the underlying graph one reaching this + * data objects. + * + * The way how GComputation is defined is important as its definition + * specifies graph _protocol_ -- the way how the graph should be + * used. Protocol is defined by number of inputs, number of outputs, + * and shapes of inputs and outputs. + * + * In the above example, sobelEdge expects one Mat on input and + * produces one Mat; while sobelEdgeSub expects two Mats on input and + * produces one Mat. GComputation's protocol defines how other + * computation methods should be used -- cv::GComputation::compile() and + * cv::GComputation::apply(). For example, if a graph is defined on + * two GMat inputs, two cv::Mat objects have to be passed to apply() + * for execution. GComputation checks protocol correctness in runtime + * so passing a different number of objects in apply() or passing + * cv::Scalar instead of cv::Mat there would compile well as a C++ + * source but raise an exception in run-time. G-API also comes with a + * typed wrapper cv::GComputationT<> which introduces this type-checking in + * compile-time. + * + * cv::GComputation itself is a thin object which just captures what + * the graph is. The compiled graph (which actually process data) is + * represented by class GCompiled. Use compile() method to generate a + * compiled graph with given compile options. cv::GComputation can + * also be used to process data with implicit graph compilation + * on-the-fly, see apply() for details. + * + * GComputation is a reference-counted object -- once defined, all its + * copies will refer to the same instance. + * + * @sa GCompiled + */ +class GAPI_EXPORTS_W GComputation +{ +public: + class Priv; + typedef std::function Generator; + + // Various constructors enable different ways to define a computation: ///// + // 1. Generic constructors + /** + * @brief Define a computation using a generator function. + * + * Graph can be defined in-place directly at the moment of its + * construction with a lambda: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_gen + * + * This may be useful since all temporary objects (cv::GMats) and + * namespaces can be localized to scope of lambda, without + * contaminating the parent scope with probably unnecessary objects + * and information. + * + * @param gen generator function which returns a cv::GComputation, + * see Generator. + */ + GComputation(const Generator& gen); // Generator + // overload + + /** + * @brief Generic GComputation constructor. + * + * Constructs a new graph with a given protocol, specified as a + * flow of operations connecting input/output objects. Throws if + * the passed boundaries are invalid, e.g. if there's no + * functional dependency (path) between given outputs and inputs. + * + * @param ins Input data vector. + * @param outs Output data vector. + * + * @note Don't construct GProtoInputArgs/GProtoOutputArgs objects + * directly, use cv::GIn()/cv::GOut() wrapper functions instead. + * + * @sa @ref gapi_data_objects + */ + GAPI_WRAP GComputation(GProtoInputArgs &&ins, + GProtoOutputArgs &&outs); // Arg-to-arg overload + + // 2. Syntax sugar and compatibility overloads + /** + * @brief Defines an unary (one input -- one output) computation + * + * @overload + * @param in input GMat of the defined unary computation + * @param out output GMat of the defined unary computation + */ + GAPI_WRAP GComputation(GMat in, GMat out); // Unary overload + + /** + * @brief Defines an unary (one input -- one output) computation + * + * @overload + * @param in input GMat of the defined unary computation + * @param out output GScalar of the defined unary computation + */ + GAPI_WRAP GComputation(GMat in, GScalar out); // Unary overload (scalar) + + /** + * @brief Defines a binary (two inputs -- one output) computation + * + * @overload + * @param in1 first input GMat of the defined binary computation + * @param in2 second input GMat of the defined binary computation + * @param out output GMat of the defined binary computation + */ + GAPI_WRAP GComputation(GMat in1, GMat in2, GMat out); // Binary overload + + /** + * @brief Defines a binary (two inputs -- one output) computation + * + * @overload + * @param in1 first input GMat of the defined binary computation + * @param in2 second input GMat of the defined binary computation + * @param out output GScalar of the defined binary computation + */ + GComputation(GMat in1, GMat in2, GScalar out); // Binary + // overload + // (scalar) + + /** + * @brief Defines a computation with arbitrary input/output number. + * + * @overload + * @param ins vector of inputs GMats for this computation + * @param outs vector of outputs GMats for this computation + * + * Use this overload for cases when number of computation + * inputs/outputs is not known in compile-time -- e.g. when graph + * is programmatically generated to build an image pyramid with + * the given number of levels, etc. + */ + GComputation(const std::vector &ins, // Compatibility overload + const std::vector &outs); + + // Various versions of apply(): //////////////////////////////////////////// + // 1. Generic apply() + /** + * @brief Compile graph on-the-fly and immediately execute it on + * the inputs data vectors. + * + * Number of input/output data objects must match GComputation's + * protocol, also types of host data objects (cv::Mat, cv::Scalar) + * must match the shapes of data objects from protocol (cv::GMat, + * cv::GScalar). If there's a mismatch, a run-time exception will + * be generated. + * + * Internally, a cv::GCompiled object is created for the given + * input format configuration, which then is executed on the input + * data immediately. cv::GComputation caches compiled objects + * produced within apply() -- if this method would be called next + * time with the same input parameters (image formats, image + * resolution, etc), the underlying compiled graph will be reused + * without recompilation. If new metadata doesn't match the cached + * one, the underlying compiled graph is regenerated. + * + * @note compile() always triggers a compilation process and + * produces a new GCompiled object regardless if a similar one has + * been cached via apply() or not. + * + * @param ins vector of input data to process. Don't create + * GRunArgs object manually, use cv::gin() wrapper instead. + * @param outs vector of output data to fill results in. cv::Mat + * objects may be empty in this vector, G-API will automatically + * initialize it with the required format & dimensions. Don't + * create GRunArgsP object manually, use cv::gout() wrapper instead. + * @param args a list of compilation arguments to pass to the + * underlying compilation process. Don't create GCompileArgs + * object manually, use cv::compile_args() wrapper instead. + * + * @sa @ref gapi_data_objects, @ref gapi_compile_args + */ + void apply(GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args = {}); // Arg-to-arg overload + + /// @private -- Exclude this function from OpenCV documentation + GAPI_WRAP GRunArgs apply(const cv::detail::ExtractArgsCallback &callback, + GCompileArgs &&args = {}); + + /// @private -- Exclude this function from OpenCV documentation + void apply(const std::vector& ins, // Compatibility overload + const std::vector& outs, + GCompileArgs &&args = {}); + + // 2. Syntax sugar and compatibility overloads +#if !defined(GAPI_STANDALONE) + /** + * @brief Execute an unary computation (with compilation on the fly) + * + * @overload + * @param in input cv::Mat for unary computation + * @param out output cv::Mat for unary computation + * @param args compilation arguments for underlying compilation + * process. + */ + void apply(cv::Mat in, cv::Mat &out, GCompileArgs &&args = {}); // Unary overload + + /** + * @brief Execute an unary computation (with compilation on the fly) + * + * @overload + * @param in input cv::Mat for unary computation + * @param out output cv::Scalar for unary computation + * @param args compilation arguments for underlying compilation + * process. + */ + void apply(cv::Mat in, cv::Scalar &out, GCompileArgs &&args = {}); // Unary overload (scalar) + + /** + * @brief Execute a binary computation (with compilation on the fly) + * + * @overload + * @param in1 first input cv::Mat for binary computation + * @param in2 second input cv::Mat for binary computation + * @param out output cv::Mat for binary computation + * @param args compilation arguments for underlying compilation + * process. + */ + void apply(cv::Mat in1, cv::Mat in2, cv::Mat &out, GCompileArgs &&args = {}); // Binary overload + + /** + * @brief Execute an binary computation (with compilation on the fly) + * + * @overload + * @param in1 first input cv::Mat for binary computation + * @param in2 second input cv::Mat for binary computation + * @param out output cv::Scalar for binary computation + * @param args compilation arguments for underlying compilation + * process. + */ + void apply(cv::Mat in1, cv::Mat in2, cv::Scalar &out, GCompileArgs &&args = {}); // Binary overload (scalar) + + /** + * @brief Execute a computation with arbitrary number of + * inputs/outputs (with compilation on-the-fly). + * + * @overload + * @param ins vector of input cv::Mat objects to process by the + * computation. + * @param outs vector of output cv::Mat objects to produce by the + * computation. + * @param args compilation arguments for underlying compilation + * process. + * + * Numbers of elements in ins/outs vectors must match numbers of + * inputs/outputs which were used to define this GComputation. + */ + void apply(const std::vector& ins, // Compatibility overload + std::vector& outs, + GCompileArgs &&args = {}); +#endif // !defined(GAPI_STANDALONE) + // Various versions of compile(): ////////////////////////////////////////// + // 1. Generic compile() - requires metas to be passed as vector + /** + * @brief Compile the computation for specific input format(s). + * + * This method triggers compilation process and produces a new + * GCompiled object which then can process data of the given + * format. Passing data with different format to the compiled + * computation will generate a run-time exception. + * + * @param in_metas vector of input metadata configuration. Grab + * metadata from real data objects (like cv::Mat or cv::Scalar) + * using cv::descr_of(), or create it on your own. + * @param args compilation arguments for this compilation + * process. Compilation arguments directly affect what kind of + * executable object would be produced, e.g. which kernels (and + * thus, devices) would be used to execute computation. + * + * @return GCompiled, an executable computation compiled + * specifically for the given input parameters. + * + * @sa @ref gapi_compile_args + */ + GCompiled compile(GMetaArgs &&in_metas, GCompileArgs &&args = {}); + + // 2. Syntax sugar - variadic list of metas, no extra compile args + // FIXME: SFINAE looks ugly in the generated documentation + /** + * @overload + * + * Takes a variadic parameter pack with metadata + * descriptors for which a compiled object needs to be produced. + * + * @return GCompiled, an executable computation compiled + * specifically for the given input parameters. + */ + template + auto compile(const Ts&... metas) -> + typename std::enable_if::value, GCompiled>::type + { + return compile(GMetaArgs{GMetaArg(metas)...}, GCompileArgs()); + } + + // 3. Syntax sugar - variadic list of metas, extra compile args + // (seems optional parameters don't work well when there's an variadic template + // comes first) + // + // Ideally it should look like: + // + // template + // GCompiled compile(const Ts&... metas, GCompileArgs &&args) + // + // But not all compilers can handle this (and seems they shouldn't be able to). + // FIXME: SFINAE looks ugly in the generated documentation + /** + * @overload + * + * Takes a variadic parameter pack with metadata + * descriptors for which a compiled object needs to be produced, + * followed by GCompileArgs object representing compilation + * arguments for this process. + * + * @return GCompiled, an executable computation compiled + * specifically for the given input parameters. + */ + template + auto compile(const Ts&... meta_and_compile_args) -> + typename std::enable_if::value + && std::is_same >::value, + GCompiled>::type + { + //FIXME: wrapping meta_and_compile_args into a tuple to unwrap them inside a helper function is the overkill + return compile(std::make_tuple(meta_and_compile_args...), + typename detail::MkSeq::type()); + } + + + // FIXME: Document properly in the Doxygen format + // Video-oriented pipeline compilation: + // 1. A generic version + /** + * @brief Compile the computation for streaming mode. + * + * This method triggers compilation process and produces a new + * GStreamingCompiled object which then can process video stream + * data of the given format. Passing a stream in a different + * format to the compiled computation will generate a run-time + * exception. + * + * @param in_metas vector of input metadata configuration. Grab + * metadata from real data objects (like cv::Mat or cv::Scalar) + * using cv::descr_of(), or create it on your own. + * + * @param args compilation arguments for this compilation + * process. Compilation arguments directly affect what kind of + * executable object would be produced, e.g. which kernels (and + * thus, devices) would be used to execute computation. + * + * @return GStreamingCompiled, a streaming-oriented executable + * computation compiled specifically for the given input + * parameters. + * + * @sa @ref gapi_compile_args + */ + GStreamingCompiled compileStreaming(GMetaArgs &&in_metas, GCompileArgs &&args = {}); + + /// @private -- Exclude this function from OpenCV documentation + GAPI_WRAP GStreamingCompiled compileStreaming(const cv::detail::ExtractMetaCallback &callback, + GCompileArgs &&args = {}); + + /** + * @brief Compile the computation for streaming mode. + * + * This method triggers compilation process and produces a new + * GStreamingCompiled object which then can process video stream + * data in any format. Underlying mechanisms will be adjusted to + * every new input video stream automatically, but please note that + * _not all_ existing backends support this (see reshape()). + * + * @param args compilation arguments for this compilation + * process. Compilation arguments directly affect what kind of + * executable object would be produced, e.g. which kernels (and + * thus, devices) would be used to execute computation. + * + * @return GStreamingCompiled, a streaming-oriented executable + * computation compiled for any input image format. + * + * @sa @ref gapi_compile_args + */ + GAPI_WRAP GStreamingCompiled compileStreaming(GCompileArgs &&args = {}); + + // 2. Direct metadata version + /** + * @overload + * + * Takes a variadic parameter pack with metadata + * descriptors for which a compiled object needs to be produced. + * + * @return GStreamingCompiled, a streaming-oriented executable + * computation compiled specifically for the given input + * parameters. + */ + template + auto compileStreaming(const Ts&... metas) -> + typename std::enable_if::value, GStreamingCompiled>::type + { + return compileStreaming(GMetaArgs{GMetaArg(metas)...}, GCompileArgs()); + } + + // 2. Direct metadata + compile arguments version + /** + * @overload + * + * Takes a variadic parameter pack with metadata + * descriptors for which a compiled object needs to be produced, + * followed by GCompileArgs object representing compilation + * arguments for this process. + * + * @return GStreamingCompiled, a streaming-oriented executable + * computation compiled specifically for the given input + * parameters. + */ + template + auto compileStreaming(const Ts&... meta_and_compile_args) -> + typename std::enable_if::value + && std::is_same >::value, + GStreamingCompiled>::type + { + //FIXME: wrapping meta_and_compile_args into a tuple to unwrap them inside a helper function is the overkill + return compileStreaming(std::make_tuple(meta_and_compile_args...), + typename detail::MkSeq::type()); + } + + // Internal use only + /// @private + Priv& priv(); + /// @private + const Priv& priv() const; + /// @private + explicit GComputation(cv::gapi::s11n::IIStream &); + /// @private + void serialize(cv::gapi::s11n::IOStream &) const; + +protected: + + // 4. Helper methods for (3) + /// @private + template + GCompiled compile(const std::tuple &meta_and_compile_args, detail::Seq) + { + GMetaArgs meta_args = {GMetaArg(std::get(meta_and_compile_args))...}; + GCompileArgs comp_args = std::get(meta_and_compile_args); + return compile(std::move(meta_args), std::move(comp_args)); + } + template + GStreamingCompiled compileStreaming(const std::tuple &meta_and_compile_args, detail::Seq) + { + GMetaArgs meta_args = {GMetaArg(std::get(meta_and_compile_args))...}; + GCompileArgs comp_args = std::get(meta_and_compile_args); + return compileStreaming(std::move(meta_args), std::move(comp_args)); + } + void recompile(GMetaArgs&& in_metas, GCompileArgs &&args); + /// @private + std::shared_ptr m_priv; +}; +/** @} */ + +namespace gapi +{ + // FIXME: all these standalone functions need to be added to some + // common documentation section + /** + * @brief Define an tagged island (subgraph) within a computation. + * + * Declare an Island tagged with `name` and defined from `ins` to `outs` + * (exclusively, as ins/outs are data objects, and regioning is done on + * operations level). + * Throws if any operation between `ins` and `outs` are already assigned + * to another island. + * + * Islands allow to partition graph into subgraphs, fine-tuning + * the way it is scheduled by the underlying executor. + * + * @param name name of the Island to create + * @param ins vector of input data objects where the subgraph + * begins + * @param outs vector of output data objects where the subgraph + * ends. + * + * The way how an island is defined is similar to how + * cv::GComputation is defined on input/output data objects. + * Same rules apply here as well -- if there's no functional + * dependency between inputs and outputs or there's not enough + * input data objects were specified to properly calculate all + * outputs, an exception is thrown. + * + * Use cv::GIn() / cv::GOut() to specify input/output vectors. + */ + void GAPI_EXPORTS island(const std::string &name, + GProtoInputArgs &&ins, + GProtoOutputArgs &&outs); +} // namespace gapi + +} // namespace cv +#endif // OPENCV_GAPI_GCOMPUTATION_HPP diff --git a/3rdparty/include/opencv2/gapi/gcomputation_async.hpp b/3rdparty/include/opencv2/gapi/gcomputation_async.hpp new file mode 100644 index 0000000000..8af603efea --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gcomputation_async.hpp @@ -0,0 +1,69 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_GCOMPUTATION_ASYNC_HPP +#define OPENCV_GAPI_GCOMPUTATION_ASYNC_HPP + + +#include //for std::future +#include //for std::exception_ptr +#include //for std::function +#include //for GRunArgs, GRunArgsP +#include //for GCompileArgs +#include + + +namespace cv { + //fwd declaration + class GComputation; +namespace gapi { +namespace wip { + class GAsyncContext; + /** In contrast to async() functions, these do call GComputation::apply() member function of the GComputation passed in. + + @param gcomp Computation (graph) to run asynchronously + @param callback Callback to be called when execution of gcomp is done + @param ins Input parameters for gcomp + @param outs Output parameters for gcomp + @param args Compile arguments to pass to GComputation::apply() + @see async + */ + GAPI_EXPORTS void async_apply(GComputation& gcomp, std::function&& callback, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args = {}); + /** @overload + @param gcomp Computation (graph) to run asynchronously + @param callback Callback to be called when execution of gcomp is done + @param ins Input parameters for gcomp + @param outs Output parameters for gcomp + @param args Compile arguments to pass to GComputation::apply() + @param ctx Context this request belongs to + @see async_apply async GAsyncContext + */ + GAPI_EXPORTS void async_apply(GComputation& gcomp, std::function&& callback, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args, GAsyncContext& ctx); + /** @overload + @param gcomp Computation (graph) to run asynchronously + @param ins Input parameters for gcomp + @param outs Output parameters for gcomp + @param args Compile arguments to pass to GComputation::apply() + @return std::future object to wait for completion of async operation + @see async_apply async + */ + GAPI_EXPORTS std::future async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args = {}); + /** @overload + @param gcomp Computation (graph) to run asynchronously + @param ins Input parameters for gcomp + @param outs Output parameters for gcomp + @param args Compile arguments to pass to GComputation::apply() + @param ctx Context this request belongs to + @return std::future object to wait for completion of async operation + @see async_apply async GAsyncContext + */ + GAPI_EXPORTS std::future async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args, GAsyncContext& ctx); +} // namespace wip +} // namespace gapi +} // namespace cv + + +#endif //OPENCV_GAPI_GCOMPUTATION_ASYNC_HPP diff --git a/3rdparty/include/opencv2/gapi/gframe.hpp b/3rdparty/include/opencv2/gapi/gframe.hpp new file mode 100644 index 0000000000..96913dc4cc --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gframe.hpp @@ -0,0 +1,112 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GFRAME_HPP +#define OPENCV_GAPI_GFRAME_HPP + +#include +#include // std::shared_ptr + +#include +#include // GShape + +#include +#include + +// TODO GAPI_EXPORTS or so +namespace cv +{ +// Forward declaration; GNode and GOrigin are an internal +// (user-inaccessible) classes. +class GNode; +struct GOrigin; + +/** \addtogroup gapi_data_objects + * @{ + */ +/** + * @brief GFrame class represents an image or media frame in the graph. + * + * GFrame doesn't store any data itself, instead it describes a + * functional relationship between operations consuming and producing + * GFrame objects. + * + * GFrame is introduced to handle various media formats (e.g., NV12 or + * I420) under the same type. Various image formats may differ in the + * number of planes (e.g. two for NV12, three for I420) and the pixel + * layout inside. GFrame type allows to handle these media formats in + * the graph uniformly -- the graph structure will not change if the + * media format changes, e.g. a different camera or decoder is used + * with the same graph. G-API provides a number of operations which + * operate directly on GFrame, like `infer<>()` or + * renderFrame(); these operations are expected to handle different + * media formats inside. There is also a number of accessor + * operations like BGR(), Y(), UV() -- these operations provide + * access to frame's data in the familiar cv::GMat form, which can be + * used with the majority of the existing G-API operations. These + * accessor functions may perform color space converion on the fly if + * the image format of the GFrame they are applied to differs from the + * operation's semantic (e.g. the BGR() accessor is called on an NV12 + * image frame). + * + * GFrame is a virtual counterpart of cv::MediaFrame. + * + * @sa cv::MediaFrame, cv::GFrameDesc, BGR(), Y(), UV(), infer<>(). + */ +class GAPI_EXPORTS_W_SIMPLE GFrame +{ +public: + /** + * @brief Constructs an empty GFrame + * + * Normally, empty G-API data objects denote a starting point of + * the graph. When an empty GFrame is assigned to a result of some + * operation, it obtains a functional link to this operation (and + * is not empty anymore). + */ + GAPI_WRAP GFrame(); // Empty constructor + + /// @private + GFrame(const GNode &n, std::size_t out); // Operation result constructor + /// @private + GOrigin& priv(); // Internal use only + /// @private + const GOrigin& priv() const; // Internal use only + +private: + std::shared_ptr m_priv; +}; +/** @} */ + +enum class MediaFormat: int +{ + BGR = 0, + NV12, +}; + +/** + * \addtogroup gapi_meta_args + * @{ + */ +struct GAPI_EXPORTS GFrameDesc +{ + MediaFormat fmt; + cv::Size size; + + bool operator== (const GFrameDesc &) const; +}; +static inline GFrameDesc empty_gframe_desc() { return GFrameDesc{}; } +/** @} */ + +class MediaFrame; +GAPI_EXPORTS GFrameDesc descr_of(const MediaFrame &frame); + +GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GFrameDesc &desc); + +} // namespace cv + +#endif // OPENCV_GAPI_GFRAME_HPP diff --git a/3rdparty/include/opencv2/gapi/gkernel.hpp b/3rdparty/include/opencv2/gapi/gkernel.hpp new file mode 100644 index 0000000000..cfac552bfe --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gkernel.hpp @@ -0,0 +1,749 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2021 Intel Corporation + + +#ifndef OPENCV_GAPI_GKERNEL_HPP +#define OPENCV_GAPI_GKERNEL_HPP + +#include +#include +#include // string +#include // false_type, true_type +#include // map (for GKernelPackage) +#include // tuple + +#include // CompileArgTag +#include // Seq +#include +#include // GArg +#include // GMetaArg +#include // GTypeTraits +#include //suppress_unused_warning +#include + +namespace cv { + +struct GTypeInfo +{ + GShape shape; + cv::detail::OpaqueKind kind; + detail::HostCtor ctor; +}; + +using GShapes = std::vector; +using GKinds = std::vector; +using GCtors = std::vector; +using GTypesInfo = std::vector; + +// GKernel describes kernel API to the system +// FIXME: add attributes of a kernel, (e.g. number and types +// of inputs, etc) +struct GAPI_EXPORTS GKernel +{ + using M = std::function; + + std::string name; // kernel ID, defined by its API (signature) + std::string tag; // some (implementation-specific) tag + M outMeta; // generic adaptor to API::outMeta(...) + GShapes outShapes; // types (shapes) kernel's outputs + GKinds inKinds; // kinds of kernel's inputs (fixme: below) + GCtors outCtors; // captured constructors for template output types +}; +// TODO: It's questionable if inKinds should really be here. Instead, +// this information could come from meta. + +// GKernelImpl describes particular kernel implementation to the system +struct GAPI_EXPORTS GKernelImpl +{ + util::any opaque; // backend-specific opaque info + GKernel::M outMeta; // for deserialized graphs, the outMeta is taken here +}; + +template class GKernelTypeM; + +namespace detail +{ + //////////////////////////////////////////////////////////////////////////// + // yield() is used in graph construction time as a generic method to obtain + // lazy "return value" of G-API operations + // + template struct Yield; + template<> struct Yield + { + static inline cv::GMat yield(cv::GCall &call, int i) { return call.yield(i); } + }; + template<> struct Yield + { + static inline cv::GMatP yield(cv::GCall &call, int i) { return call.yieldP(i); } + }; + template<> struct Yield + { + static inline cv::GScalar yield(cv::GCall &call, int i) { return call.yieldScalar(i); } + }; + template struct Yield > + { + static inline cv::GArray yield(cv::GCall &call, int i) { return call.yieldArray(i); } + }; + template struct Yield > + { + static inline cv::GOpaque yield(cv::GCall &call, int i) { return call.yieldOpaque(i); } + }; + template<> struct Yield + { + static inline cv::GFrame yield(cv::GCall &call, int i) { return call.yieldFrame(i); } + }; + + //////////////////////////////////////////////////////////////////////////// + // Helper classes which brings outputMeta() marshalling to kernel + // implementations + // + // 1. MetaType establishes G#Type -> G#Meta mapping between G-API dynamic + // types and its metadata descriptor types. + // This mapping is used to transform types to call outMeta() callback. + template struct MetaType; + template<> struct MetaType { using type = GMatDesc; }; + template<> struct MetaType { using type = GMatDesc; }; + template<> struct MetaType { using type = GFrameDesc; }; + template<> struct MetaType { using type = GScalarDesc; }; + template struct MetaType > { using type = GArrayDesc; }; + template struct MetaType > { using type = GOpaqueDesc; }; + template struct MetaType { using type = T; }; // opaque args passed as-is + // FIXME: Move it to type traits? + + // 2. Hacky test based on MetaType to check if we operate on G-* type or not + template using is_nongapi_type = std::is_same::type>; + + // 3. Two ways to transform input arguments to its meta - for G-* and non-G* types: + template + typename std::enable_if::value, typename MetaType::type> + ::type get_in_meta(const GMetaArgs &in_meta, const GArgs &, int idx) + { + return util::get::type>(in_meta.at(idx)); + } + + template + typename std::enable_if::value, T> + ::type get_in_meta(const GMetaArgs &, const GArgs &in_args, int idx) + { + return in_args.at(idx).template get(); + } + + // 4. The MetaHelper itself: an entity which generates outMeta() call + // based on kernel signature, with arguments properly substituted. + // 4.1 - case for multiple return values + // FIXME: probably can be simplified with std::apply or analogue. + template + struct MetaHelper; + + template + struct MetaHelper, std::tuple > + { + template + static GMetaArgs getOutMeta_impl(const GMetaArgs &in_meta, + const GArgs &in_args, + detail::Seq, + detail::Seq) + { + // FIXME: decay? + using R = std::tuple::type...>; + const R r = K::outMeta( get_in_meta(in_meta, in_args, IIs)... ); + return GMetaArgs{ GMetaArg(std::get(r))... }; + } + // FIXME: help users identify how outMeta must look like (via default impl w/static_assert?) + + static GMetaArgs getOutMeta(const GMetaArgs &in_meta, + const GArgs &in_args) + { + return getOutMeta_impl(in_meta, + in_args, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } + }; + + // 4.1 - case for a single return value + // FIXME: How to avoid duplication here? + template + struct MetaHelper, Out > + { + template + static GMetaArgs getOutMeta_impl(const GMetaArgs &in_meta, + const GArgs &in_args, + detail::Seq) + { + // FIXME: decay? + using R = typename MetaType::type; + const R r = K::outMeta( get_in_meta(in_meta, in_args, IIs)... ); + return GMetaArgs{ GMetaArg(r) }; + } + // FIXME: help users identify how outMeta must look like (via default impl w/static_assert?) + + static GMetaArgs getOutMeta(const GMetaArgs &in_meta, + const GArgs &in_args) + { + return getOutMeta_impl(in_meta, + in_args, + typename detail::MkSeq::type()); + } + }; + + //////////////////////////////////////////////////////////////////////////// + // Helper class to introduce tags to calls. By default there's no tag + struct NoTag { + static constexpr const char *tag() { return ""; } + }; + +} // namespace detail + +// GKernelType and GKernelTypeM are base classes which implement typed ::on() +// method based on kernel signature. GKernelTypeM stands for multiple-return-value kernels +// +// G_TYPED_KERNEL and G_TYPED_KERNEL_M macros inherit user classes from GKernelType and +// GKernelTypeM respectively. + +template +class GKernelTypeM(Args...)> > + : public detail::MetaHelper, std::tuple> + , public detail::NoTag +{ + template + static std::tuple yield(cv::GCall &call, detail::Seq) + { + return std::make_tuple(detail::Yield::yield(call, IIs)...); + } + +public: + using InArgs = std::tuple; + using OutArgs = std::tuple; + + // TODO: Args&&... here? + static std::tuple on(Args... args) + { + cv::GCall call(GKernel{ K::id() + , K::tag() + , &K::getOutMeta + , {detail::GTypeTraits::shape...} + , {detail::GTypeTraits::op_kind...} + , {detail::GObtainCtor::get()...}}); + call.pass(args...); // TODO: std::forward() here? + return yield(call, typename detail::MkSeq::type()); + } +}; + +template class GKernelType; + +template +class GKernelType > + : public detail::MetaHelper, R> + , public detail::NoTag +{ +public: + using InArgs = std::tuple; + using OutArgs = std::tuple; + + static R on(Args... args) + { + cv::GCall call(GKernel{ K::id() + , K::tag() + , &K::getOutMeta + , {detail::GTypeTraits::shape} + , {detail::GTypeTraits::op_kind...} + , {detail::GObtainCtor::get()}}); + call.pass(args...); + return detail::Yield::yield(call, 0); + } +}; + +namespace detail { +// This tiny class eliminates the semantic difference between +// GKernelType and GKernelTypeM. +template class KernelTypeMedium; + +template +class KernelTypeMedium(Args...)>> : + public cv::GKernelTypeM(Args...)>> {}; + +template +class KernelTypeMedium> : + public cv::GKernelType> {}; +} // namespace detail + +} // namespace cv + + +// FIXME: I don't know a better way so far. Feel free to suggest one +// The problem is that every typed kernel should have ::id() but body +// of the class is defined by user (with outMeta, other stuff) + +//! @cond IGNORED +#define G_ID_HELPER_CLASS(Class) Class##IdHelper + +#define G_ID_HELPER_BODY(Class, Id) \ + struct G_ID_HELPER_CLASS(Class) \ + { \ + static constexpr const char * id() {return Id;} \ + }; \ +//! @endcond + +#define GET_G_TYPED_KERNEL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, NAME, ...) NAME +#define COMBINE_SIGNATURE(...) __VA_ARGS__ +// Ensure correct __VA_ARGS__ expansion on Windows +#define __WRAP_VAARGS(x) x + +/** + * Helper for G_TYPED_KERNEL declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) + * for more details. + * + * @param Class type name for this operation. + * @param API an `std::function<>`-like signature for the operation; + * return type is a single value or a tuple of multiple values. + * @param Id string identifier for the operation. Must be unique. + */ +#define G_TYPED_KERNEL_HELPER(Class, API, Id) \ + G_ID_HELPER_BODY(Class, Id) \ + struct Class final: public cv::detail::KernelTypeMedium, \ + public G_ID_HELPER_CLASS(Class) +// {body} is to be defined by user + +#define G_TYPED_KERNEL_HELPER_2(Class, _1, _2, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2), Id) + +#define G_TYPED_KERNEL_HELPER_3(Class, _1, _2, _3, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3), Id) + +#define G_TYPED_KERNEL_HELPER_4(Class, _1, _2, _3, _4, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4), Id) + +#define G_TYPED_KERNEL_HELPER_5(Class, _1, _2, _3, _4, _5, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5), Id) + +#define G_TYPED_KERNEL_HELPER_6(Class, _1, _2, _3, _4, _5, _6, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6), Id) + +#define G_TYPED_KERNEL_HELPER_7(Class, _1, _2, _3, _4, _5, _6, _7, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7), Id) + +#define G_TYPED_KERNEL_HELPER_8(Class, _1, _2, _3, _4, _5, _6, _7, _8, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8), Id) + +#define G_TYPED_KERNEL_HELPER_9(Class, _1, _2, _3, _4, _5, _6, _7, _8, _9, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8, _9), Id) + +#define G_TYPED_KERNEL_HELPER_10(Class, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10), Id) + +/** + * Declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) + * for more details. + * + * @param Class type name for this operation. + */ +#define G_TYPED_KERNEL(Class, ...) __WRAP_VAARGS(GET_G_TYPED_KERNEL(__VA_ARGS__, \ + G_TYPED_KERNEL_HELPER_10, \ + G_TYPED_KERNEL_HELPER_9, \ + G_TYPED_KERNEL_HELPER_8, \ + G_TYPED_KERNEL_HELPER_7, \ + G_TYPED_KERNEL_HELPER_6, \ + G_TYPED_KERNEL_HELPER_5, \ + G_TYPED_KERNEL_HELPER_4, \ + G_TYPED_KERNEL_HELPER_3, \ + G_TYPED_KERNEL_HELPER_2, \ + G_TYPED_KERNEL_HELPER)(Class, __VA_ARGS__)) \ + +/** + * Declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) for more details. + * + * @deprecated This macro is deprecated in favor of `G_TYPED_KERNEL` that is used for declaring any + * G-API Operation. + * + * @param Class type name for this operation. + */ +#define G_TYPED_KERNEL_M G_TYPED_KERNEL + +#define G_API_OP G_TYPED_KERNEL +#define G_API_OP_M G_API_OP + +namespace cv +{ +namespace gapi +{ + // Prework: model "Device" API before it gets to G-API headers. + // FIXME: Don't mix with internal Backends class! + /// @private + class GAPI_EXPORTS GBackend + { + public: + class Priv; + + // TODO: make it template (call `new` within??) + GBackend(); + explicit GBackend(std::shared_ptr &&p); + + Priv& priv(); + const Priv& priv() const; + std::size_t hash() const; + + bool operator== (const GBackend &rhs) const; + + private: + std::shared_ptr m_priv; + }; + + inline bool operator != (const GBackend &lhs, const GBackend &rhs) + { + return !(lhs == rhs); + } +} // namespace gapi +} // namespace cv + +namespace std +{ + template<> struct hash + { + std::size_t operator() (const cv::gapi::GBackend &b) const + { + return b.hash(); + } + }; +} // namespace std + + +namespace cv { +namespace gapi { + /// @private + class GFunctor + { + public: + virtual cv::GKernelImpl impl() const = 0; + virtual cv::gapi::GBackend backend() const = 0; + const char* id() const { return m_id; } + + virtual ~GFunctor() = default; + protected: + GFunctor(const char* id) : m_id(id) { }; + private: + const char* m_id; + }; + + /** \addtogroup gapi_compile_args + * @{ + */ + + // FIXME: Hide implementation + /** + * @brief A container class for heterogeneous kernel + * implementation collections and graph transformations. + * + * GKernelPackage is a special container class which stores kernel + * _implementations_ and graph _transformations_. Objects of this class + * are created and passed to cv::GComputation::compile() to specify + * which kernels to use and which transformations to apply in the + * compiled graph. GKernelPackage may contain kernels of + * different backends, e.g. be heterogeneous. + * + * The most easy way to create a kernel package is to use function + * cv::gapi::kernels(). This template functions takes kernel + * implementations in form of type list (variadic template) and + * generates a kernel package atop of that. + * + * Kernel packages can be also generated programmatically, starting + * with an empty package (created with the default constructor) + * and then by populating it with kernels via call to + * GKernelPackage::include(). Note this method is also a template + * one since G-API kernel and transformation implementations are _types_, + * not objects. + * + * Finally, two kernel packages can be combined into a new one + * with function cv::gapi::combine(). + */ + class GAPI_EXPORTS_W_SIMPLE GKernelPackage + { + + /// @private + using M = std::unordered_map>; + + /// @private + M m_id_kernels; + + /// @private + std::vector m_transformations; + + protected: + /// @private + // Remove ALL implementations of the given API (identified by ID) + void removeAPI(const std::string &id); + + /// @private + // Partial include() specialization for kernels + template + typename std::enable_if<(std::is_base_of::value), void>::type + includeHelper() + { + auto backend = KImpl::backend(); + auto kernel_id = KImpl::API::id(); + auto kernel_impl = GKernelImpl{KImpl::kernel(), &KImpl::API::getOutMeta}; + removeAPI(kernel_id); + + m_id_kernels[kernel_id] = std::make_pair(backend, kernel_impl); + } + + /// @private + // Partial include() specialization for transformations + template + typename std::enable_if<(std::is_base_of::value), void>::type + includeHelper() + { + m_transformations.emplace_back(TImpl::transformation()); + } + + public: + void include(const GFunctor& functor) + { + m_id_kernels[functor.id()] = std::make_pair(functor.backend(), functor.impl()); + } + /** + * @brief Returns total number of kernels + * in the package (across all backends included) + * + * @return a number of kernels in the package + */ + std::size_t size() const; + + /** + * @brief Returns vector of transformations included in the package + * + * @return vector of transformations included in the package + */ + const std::vector& get_transformations() const; + + /** + * @brief Returns vector of kernel ids included in the package + * + * @return vector of kernel ids included in the package + */ + std::vector get_kernel_ids() const; + + /** + * @brief Test if a particular kernel _implementation_ KImpl is + * included in this kernel package. + * + * @sa includesAPI() + * + * @note cannot be applied to transformations + * + * @return true if there is such kernel, false otherwise. + */ + template + bool includes() const + { + static_assert(std::is_base_of::value, + "includes() can be applied to kernels only"); + + auto kernel_it = m_id_kernels.find(KImpl::API::id()); + return kernel_it != m_id_kernels.end() && + kernel_it->second.first == KImpl::backend(); + } + + /** + * @brief Remove all kernels associated with the given backend + * from the package. + * + * Does nothing if there's no kernels of this backend in the package. + * + * @param backend backend which kernels to remove + */ + void remove(const GBackend& backend); + + /** + * @brief Remove all kernels implementing the given API from + * the package. + * + * Does nothing if there's no kernels implementing the given interface. + */ + template + void remove() + { + removeAPI(KAPI::id()); + } + + // FIXME: Rename to includes() and distinguish API/impl case by + // statically? + /** + * Check if package contains ANY implementation of a kernel API + * by API type. + */ + template + bool includesAPI() const + { + return includesAPI(KAPI::id()); + } + + /// @private + bool includesAPI(const std::string &id) const; + + // FIXME: The below comment is wrong, and who needs this function? + /** + * @brief Find a kernel (by its API) + * + * Returns implementation corresponding id. + * Throws if nothing found. + * + * @return Backend which hosts matching kernel implementation. + * + */ + template + GBackend lookup() const + { + return lookup(KAPI::id()).first; + } + + /// @private + std::pair + lookup(const std::string &id) const; + + // FIXME: No overwrites allowed? + /** + * @brief Put a new kernel implementation or a new transformation + * KImpl into the package. + */ + template + void include() + { + includeHelper(); + } + + /** + * @brief Adds a new kernel based on it's backend and id into the kernel package + * + * @param backend backend associated with the kernel + * @param kernel_id a name/id of the kernel + */ + void include(const cv::gapi::GBackend& backend, const std::string& kernel_id) + { + removeAPI(kernel_id); + m_id_kernels[kernel_id] = std::make_pair(backend, GKernelImpl{{}, {}}); + } + + /** + * @brief Lists all backends which are included into package + * + * @return vector of backends + */ + std::vector backends() const; + + // TODO: Doxygen bug -- it wants me to place this comment + // here, not below. + /** + * @brief Create a new package based on `lhs` and `rhs`. + * + * @param lhs "Left-hand-side" package in the process + * @param rhs "Right-hand-side" package in the process + * @return a new kernel package. + */ + friend GAPI_EXPORTS GKernelPackage combine(const GKernelPackage &lhs, + const GKernelPackage &rhs); + }; + + /** + * @brief Create a kernel package object containing kernels + * and transformations specified in variadic template argument. + * + * In G-API, kernel implementations and transformations are _types_. + * Every backend has its own kernel API (like GAPI_OCV_KERNEL() and + * GAPI_FLUID_KERNEL()) but all of that APIs define a new type for + * each kernel implementation. + * + * Use this function to pass kernel implementations (defined in + * either way) and transformations to the system. Example: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp kernels_snippet + * + * Note that kernels() itself is a function returning object, not + * a type, so having `()` at the end is important -- it must be a + * function call. + */ + template GKernelPackage kernels() + { + // FIXME: currently there is no check that transformations' signatures are unique + // and won't be any intersection in graph compilation stage + static_assert(cv::detail::all_unique::value, "Kernels API must be unique"); + + GKernelPackage pkg; + + // For those who wonder - below is a trick to call a number of + // methods based on parameter pack (zeroes just help hiding these + // calls into a sequence which helps to expand this parameter pack). + // Just note that `f(),a` always equals to `a` (with f() called!) + // and parentheses are used to hide function call in the expanded sequence. + // Leading 0 helps to handle case when KK is an empty list (kernels<>()). + int unused[] = { 0, (pkg.include(), 0)... }; + cv::util::suppress_unused_warning(unused); + return pkg; + }; + + template + GKernelPackage kernels(FF&... functors) + { + GKernelPackage pkg; + int unused[] = { 0, (pkg.include(functors), 0)... }; + cv::util::suppress_unused_warning(unused); + return pkg; + }; + + /** @} */ + + // FYI - this function is already commented above + GAPI_EXPORTS GKernelPackage combine(const GKernelPackage &lhs, + const GKernelPackage &rhs); + + /** + * @brief Combines multiple G-API kernel packages into one + * + * @overload + * + * This function successively combines the passed kernel packages using a right fold. + * Calling `combine(a, b, c)` is equal to `combine(a, combine(b, c))`. + * + * @return The resulting kernel package + */ + template + GKernelPackage combine(const GKernelPackage &a, const GKernelPackage &b, Ps&&... rest) + { + return combine(a, combine(b, rest...)); + } + + /** \addtogroup gapi_compile_args + * @{ + */ + /** + * @brief cv::use_only() is a special combinator which hints G-API to use only + * kernels specified in cv::GComputation::compile() (and not to extend kernels available by + * default with that package). + */ + struct GAPI_EXPORTS use_only + { + GKernelPackage pkg; + }; + /** @} */ + +} // namespace gapi + +namespace detail +{ + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.kernel_package"; } + }; + + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.use_only"; } + }; +} // namespace detail + +} // namespace cv + +#endif // OPENCV_GAPI_GKERNEL_HPP diff --git a/3rdparty/include/opencv2/gapi/gmat.hpp b/3rdparty/include/opencv2/gapi/gmat.hpp new file mode 100644 index 0000000000..7bea97bbc5 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gmat.hpp @@ -0,0 +1,279 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GMAT_HPP +#define OPENCV_GAPI_GMAT_HPP + +#include +#include // std::shared_ptr + +#include +#include // GShape + +#include + +// TODO GAPI_EXPORTS or so +namespace cv +{ +// Forward declaration; GNode and GOrigin are an internal +// (user-inaccessible) classes. +class GNode; +struct GOrigin; + +/** \addtogroup gapi_data_objects + * @{ + * + * @brief G-API data objects used to build G-API expressions. + * + * These objects do not own any particular data (except compile-time + * associated values like with cv::GScalar or `cv::GArray`) and are + * used only to construct graphs. + * + * Every graph in G-API starts and ends with data objects. + * + * Once constructed and compiled, G-API operates with regular host-side + * data instead. Refer to the below table to find the mapping between + * G-API and regular data types when passing input and output data + * structures to G-API: + * + * G-API data type | I/O data type + * ------------------ | ------------- + * cv::GMat | cv::Mat, cv::UMat, cv::RMat + * cv::GScalar | cv::Scalar + * `cv::GArray` | std::vector + * `cv::GOpaque` | T + * cv::GFrame | cv::MediaFrame + */ +/** + * @brief GMat class represents image or tensor data in the + * graph. + * + * GMat doesn't store any data itself, instead it describes a + * functional relationship between operations consuming and producing + * GMat objects. + * + * GMat is a virtual counterpart of Mat and UMat, but it + * doesn't mean G-API use Mat or UMat objects internally to represent + * GMat objects -- the internal data representation may be + * backend-specific or optimized out at all. + * + * @sa Mat, GMatDesc + */ +class GAPI_EXPORTS_W_SIMPLE GMat +{ +public: + /** + * @brief Constructs an empty GMat + * + * Normally, empty G-API data objects denote a starting point of + * the graph. When an empty GMat is assigned to a result of some + * operation, it obtains a functional link to this operation (and + * is not empty anymore). + */ + GAPI_WRAP GMat(); // Empty constructor + + /// @private + GMat(const GNode &n, std::size_t out); // Operation result constructor + /// @private + GOrigin& priv(); // Internal use only + /// @private + const GOrigin& priv() const; // Internal use only + +private: + std::shared_ptr m_priv; +}; + +class GAPI_EXPORTS GMatP : public GMat +{ +public: + using GMat::GMat; +}; + +class RMat; + +/** @} */ + +/** + * \addtogroup gapi_meta_args + * @{ + */ +struct GAPI_EXPORTS_W_SIMPLE GMatDesc +{ + // FIXME: Default initializers in C++14 + GAPI_PROP int depth; + GAPI_PROP int chan; + GAPI_PROP cv::Size size; // NB.: no multi-dimensional cases covered yet + GAPI_PROP bool planar; + GAPI_PROP std::vector dims; // FIXME: Maybe it's real questionable to have it here + + GAPI_WRAP GMatDesc(int d, int c, cv::Size s, bool p = false) + : depth(d), chan(c), size(s), planar(p) {} + + GAPI_WRAP GMatDesc(int d, const std::vector &dd) + : depth(d), chan(-1), size{-1,-1}, planar(false), dims(dd) {} + + GAPI_WRAP GMatDesc(int d, std::vector &&dd) + : depth(d), chan(-1), size{-1,-1}, planar(false), dims(std::move(dd)) {} + + GAPI_WRAP GMatDesc() : GMatDesc(-1, -1, {-1,-1}) {} + + inline bool operator== (const GMatDesc &rhs) const + { + return depth == rhs.depth + && chan == rhs.chan + && size == rhs.size + && planar == rhs.planar + && dims == rhs.dims; + } + + inline bool operator!= (const GMatDesc &rhs) const + { + return !(*this == rhs); + } + + bool isND() const { return !dims.empty(); } + + // Checks if the passed mat can be described by this descriptor + // (it handles the case when + // 1-channel mat can be reinterpreted as is (1-channel mat) + // and as a 3-channel planar mat with height divided by 3) + bool canDescribe(const cv::Mat& mat) const; + + bool canDescribe(const cv::RMat& mat) const; + + // Meta combinator: return a new GMatDesc which differs in size by delta + // (all other fields are taken unchanged from this GMatDesc) + // FIXME: a better name? + GAPI_WRAP GMatDesc withSizeDelta(cv::Size delta) const + { + GMatDesc desc(*this); + desc.size += delta; + return desc; + } + // Meta combinator: return a new GMatDesc which differs in size by delta + // (all other fields are taken unchanged from this GMatDesc) + // + // This is an overload. + GAPI_WRAP GMatDesc withSizeDelta(int dx, int dy) const + { + return withSizeDelta(cv::Size{dx,dy}); + } + + GAPI_WRAP GMatDesc withSize(cv::Size sz) const + { + GMatDesc desc(*this); + desc.size = sz; + return desc; + } + + // Meta combinator: return a new GMatDesc with specified data depth. + // (all other fields are taken unchanged from this GMatDesc) + GAPI_WRAP GMatDesc withDepth(int ddepth) const + { + GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1); + GMatDesc desc(*this); + if (ddepth != -1) desc.depth = ddepth; + return desc; + } + + // Meta combinator: return a new GMatDesc with specified data depth + // and number of channels. + // (all other fields are taken unchanged from this GMatDesc) + GAPI_WRAP GMatDesc withType(int ddepth, int dchan) const + { + GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1); + GMatDesc desc = withDepth(ddepth); + desc.chan = dchan; + return desc; + } + + // Meta combinator: return a new GMatDesc with planar flag set + // (no size changes are performed, only channel interpretation is changed + // (interleaved -> planar) + GAPI_WRAP GMatDesc asPlanar() const + { + GAPI_Assert(planar == false); + GMatDesc desc(*this); + desc.planar = true; + return desc; + } + + // Meta combinator: return a new GMatDesc + // reinterpreting 1-channel input as planar image + // (size height is divided by plane number) + GAPI_WRAP GMatDesc asPlanar(int planes) const + { + GAPI_Assert(planar == false); + GAPI_Assert(chan == 1); + GAPI_Assert(planes > 1); + GAPI_Assert(size.height % planes == 0); + GMatDesc desc(*this); + desc.size.height /= planes; + desc.chan = planes; + return desc.asPlanar(); + } + + // Meta combinator: return a new GMatDesc with planar flag set to false + // (no size changes are performed, only channel interpretation is changed + // (planar -> interleaved) + GAPI_WRAP GMatDesc asInterleaved() const + { + GAPI_Assert(planar == true); + GMatDesc desc(*this); + desc.planar = false; + return desc; + } +}; + +static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; } + +namespace gapi { namespace detail { +/** Checks GMatDesc fields if the passed matrix is a set of n-dimentional points. +@param in GMatDesc to check. +@param n expected dimensionality. +@return the amount of points. In case input matrix can't be described as vector of points +of expected dimensionality, returns -1. + */ +int checkVector(const GMatDesc& in, const size_t n); + +/** @overload + +Checks GMatDesc fields if the passed matrix can be described as a set of points of any +dimensionality. + +@return array of two elements in form of std::vector: the amount of points +and their calculated dimensionality. In case input matrix can't be described as vector of points, +returns {-1, -1}. + */ +std::vector checkVector(const GMatDesc& in); +}} // namespace gapi::detail + +#if !defined(GAPI_STANDALONE) +GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat); +#endif // !defined(GAPI_STANDALONE) + +//Fwd declarations +namespace gapi { namespace own { + class Mat; + GAPI_EXPORTS GMatDesc descr_of(const Mat &mat); +}}//gapi::own + +GAPI_EXPORTS GMatDesc descr_of(const RMat &mat); + +#if !defined(GAPI_STANDALONE) +GAPI_EXPORTS GMatDesc descr_of(const cv::Mat &mat); +#else +using gapi::own::descr_of; +#endif + +/** @} */ + +GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc); + +} // namespace cv + +#endif // OPENCV_GAPI_GMAT_HPP diff --git a/3rdparty/include/opencv2/gapi/gmetaarg.hpp b/3rdparty/include/opencv2/gapi/gmetaarg.hpp new file mode 100644 index 0000000000..f21182c19f --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gmetaarg.hpp @@ -0,0 +1,80 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GMETAARG_HPP +#define OPENCV_GAPI_GMETAARG_HPP + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +namespace cv +{ +// FIXME: Rename to GMeta? +// FIXME: user shouldn't deal with it - put to detail? +// GMetaArg is an union type over descriptions of G-types which can serve as +// GComputation's in/output slots. +// +// GMetaArg objects are passed as arguments to GComputation::compile() +// to specify which data a compiled computation should be specialized on. +// For manual compile(), user must supply this metadata, in case of apply() +// this metadata is taken from arguments computation should operate on. +// +// The first type (monostate) is equal to "uninitialized"/"unresolved" meta. +using GMetaArg = util::variant + < util::monostate + , GMatDesc + , GScalarDesc + , GArrayDesc + , GOpaqueDesc + , GFrameDesc + >; +GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const GMetaArg &); + +using GMetaArgs = std::vector; + +namespace detail +{ + // These traits are used by GComputation::compile() + + // FIXME: is_constructible doesn't work as variant doesn't do any SFINAE + // in its current template constructor + + template struct is_meta_descr : std::false_type {}; + template<> struct is_meta_descr : std::true_type {}; + template<> struct is_meta_descr : std::true_type {}; + template<> struct is_meta_descr : std::true_type {}; + template<> struct is_meta_descr : std::true_type {}; + + template + using are_meta_descrs = all_satisfy; + + template + using are_meta_descrs_but_last = all_satisfy::type>; + +} // namespace detail + +// Note: descr_of(std::vector<..>) returns a GArrayDesc, while +// descrs_of(std::vector<..>) returns an array of Meta args! +class UMat; +GAPI_EXPORTS cv::GMetaArgs descrs_of(const std::vector &vec); +GAPI_EXPORTS cv::GMetaArgs descrs_of(const std::vector &vec); +namespace gapi { namespace own { + GAPI_EXPORTS cv::GMetaArgs descrs_of(const std::vector &vec); +}} // namespace gapi::own + +} // namespace cv + +#endif // OPENCV_GAPI_GMETAARG_HPP diff --git a/3rdparty/include/opencv2/gapi/gopaque.hpp b/3rdparty/include/opencv2/gapi/gopaque.hpp new file mode 100644 index 0000000000..979a9db8c4 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gopaque.hpp @@ -0,0 +1,369 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GOPAQUE_HPP +#define OPENCV_GAPI_GOPAQUE_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include // OpaqueKind +#include // TypeHintBase + +namespace cv +{ +// Forward declaration; GNode and GOrigin are an internal +// (user-inaccessible) classes. +class GNode; +struct GOrigin; +template class GOpaque; + +/** + * \addtogroup gapi_meta_args + * @{ + */ +struct GAPI_EXPORTS_W_SIMPLE GOpaqueDesc +{ + // FIXME: Body + // FIXME: Also implement proper operator== then + bool operator== (const GOpaqueDesc&) const { return true; } +}; +template GOpaqueDesc descr_of(const U &) { return {};} +GAPI_EXPORTS_W inline GOpaqueDesc empty_gopaque_desc() {return {}; } +/** @} */ + +std::ostream& operator<<(std::ostream& os, const cv::GOpaqueDesc &desc); + +namespace detail +{ + // ConstructOpaque is a callback which stores information about T and is used by + // G-API runtime to construct an object in host memory (T remains opaque for G-API). + // ConstructOpaque is carried into G-API internals by GOpaqueU. + // Currently it is suitable for Host (CPU) plugins only, real offload may require + // more information for manual memory allocation on-device. + class OpaqueRef; + using ConstructOpaque = std::function; + + // FIXME: garray.hpp already contains hint classes (for actual T type verification), + // need to think where it can be moved (currently opaque uses it from garray) + + // This class strips type information from GOpaque and makes it usable + // in the G-API graph compiler (expression unrolling, graph generation, etc). + // Part of GProtoArg. + class GAPI_EXPORTS GOpaqueU + { + public: + GOpaqueU(const GNode &n, std::size_t out); // Operation result constructor + + template + bool holds() const; // Check if was created from GOpaque + + GOrigin& priv(); // Internal use only + const GOrigin& priv() const; // Internal use only + + protected: + GOpaqueU(); // Default constructor + template friend class cv::GOpaque; // (available for GOpaque only) + + void setConstructFcn(ConstructOpaque &&cv); // Store T-aware constructor + + template + void specifyType(); // Store type of initial GOpaque + + template + void storeKind(); + + void setKind(cv::detail::OpaqueKind); + + std::shared_ptr m_priv; + std::shared_ptr m_hint; + }; + + template + bool GOpaqueU::holds() const{ + GAPI_Assert(m_hint != nullptr); + using U = util::decay_t; + return dynamic_cast*>(m_hint.get()) != nullptr; + }; + + template + void GOpaqueU::specifyType(){ + m_hint.reset(new TypeHint>); + }; + + template + void GOpaqueU::storeKind(){ + // FIXME: Add assert here on cv::Mat and cv::Scalar? + setKind(cv::detail::GOpaqueTraits::kind); + }; + + // This class represents a typed object reference. + // Depending on origins, this reference may be either "just a" reference to + // an object created externally, OR actually own the underlying object + // (be value holder). + class BasicOpaqueRef + { + public: + cv::GOpaqueDesc m_desc; + virtual ~BasicOpaqueRef() {} + + virtual void mov(BasicOpaqueRef &ref) = 0; + virtual const void* ptr() const = 0; + virtual void set(const cv::util::any &a) = 0; + }; + + template class OpaqueRefT final: public BasicOpaqueRef + { + using empty_t = util::monostate; + using ro_ext_t = const T *; + using rw_ext_t = T *; + using rw_own_t = T ; + util::variant m_ref; + + inline bool isEmpty() const { return util::holds_alternative(m_ref); } + inline bool isROExt() const { return util::holds_alternative(m_ref); } + inline bool isRWExt() const { return util::holds_alternative(m_ref); } + inline bool isRWOwn() const { return util::holds_alternative(m_ref); } + + void init(const T* obj = nullptr) + { + if (obj) m_desc = cv::descr_of(*obj); + } + + public: + OpaqueRefT() { init(); } + virtual ~OpaqueRefT() {} + + explicit OpaqueRefT(const T& obj) : m_ref(&obj) { init(&obj); } + explicit OpaqueRefT( T& obj) : m_ref(&obj) { init(&obj); } + explicit OpaqueRefT( T&& obj) : m_ref(std::move(obj)) { init(&obj); } + + // Reset a OpaqueRefT. Called only for objects instantiated + // internally in G-API (e.g. temporary GOpaque's within a + // computation). Reset here means both initialization + // (creating an object) and reset (discarding its existing + // content before the next execution). Must never be called + // for external OpaqueRefTs. + void reset() + { + if (isEmpty()) + { + T empty_obj{}; + m_desc = cv::descr_of(empty_obj); + m_ref = std::move(empty_obj); + GAPI_Assert(isRWOwn()); + } + else if (isRWOwn()) + { + util::get(m_ref) = {}; + } + else GAPI_Assert(false); // shouldn't be called in *EXT modes + } + + // Obtain a WRITE reference to underlying object + // Used by CPU kernel API wrappers when a kernel execution frame + // is created + T& wref() + { + GAPI_Assert(isRWExt() || isRWOwn()); + if (isRWExt()) return *util::get(m_ref); + if (isRWOwn()) return util::get(m_ref); + util::throw_error(std::logic_error("Impossible happened")); + } + + // Obtain a READ reference to underlying object + // Used by CPU kernel API wrappers when a kernel execution frame + // is created + const T& rref() const + { + // ANY object can be accessed for reading, even if it declared for + // output. Example -- a GComputation from [in] to [out1,out2] + // where [out2] is a result of operation applied to [out1]: + // + // GComputation boundary + // . . . . . . . + // . . + // [in] ----> foo() ----> [out1] + // . . : + // . . . .:. . . + // . V . + // . bar() ---> [out2] + // . . . . . . . . . . . . + // + if (isROExt()) return *util::get(m_ref); + if (isRWExt()) return *util::get(m_ref); + if (isRWOwn()) return util::get(m_ref); + util::throw_error(std::logic_error("Impossible happened")); + } + + virtual void mov(BasicOpaqueRef &v) override { + OpaqueRefT *tv = dynamic_cast*>(&v); + GAPI_Assert(tv != nullptr); + wref() = std::move(tv->wref()); + } + + virtual const void* ptr() const override { return &rref(); } + + virtual void set(const cv::util::any &a) override { + wref() = util::any_cast(a); + } + }; + + // This class strips type information from OpaqueRefT<> and makes it usable + // in the G-API executables (carrying run-time data/information to kernels). + // Part of GRunArg. + // Its methods are typed proxies to OpaqueRefT. + // OpaqueRef maintains "reference" semantics so two copies of OpaqueRef refer + // to the same underlying object. + class OpaqueRef + { + std::shared_ptr m_ref; + cv::detail::OpaqueKind m_kind; + + template inline void check() const + { + GAPI_DbgAssert(dynamic_cast*>(m_ref.get()) != nullptr); + } + + public: + OpaqueRef() = default; + + template< + typename T, + typename = util::are_different_t + > + // FIXME: probably won't work with const object + explicit OpaqueRef(T&& obj) : + m_ref(new OpaqueRefT>(std::forward(obj))), + m_kind(GOpaqueTraits>::kind) {} + + cv::detail::OpaqueKind getKind() const + { + return m_kind; + } + + template void reset() + { + if (!m_ref) m_ref.reset(new OpaqueRefT()); + check(); + storeKind(); + static_cast&>(*m_ref).reset(); + } + + template + void storeKind() + { + m_kind = cv::detail::GOpaqueTraits::kind; + } + + template T& wref() + { + check(); + return static_cast&>(*m_ref).wref(); + } + + template const T& rref() const + { + check(); + return static_cast&>(*m_ref).rref(); + } + + void mov(OpaqueRef &v) + { + m_ref->mov(*v.m_ref); + } + + cv::GOpaqueDesc descr_of() const + { + return m_ref->m_desc; + } + + // May be used to uniquely identify this object internally + const void *ptr() const { return m_ref->ptr(); } + + // Introduced for in-graph meta handling + OpaqueRef& operator= (const cv::util::any &a) + { + m_ref->set(a); + return *this; + } + }; +} // namespace detail + +/** \addtogroup gapi_data_objects + * @{ + */ +/** + * @brief `cv::GOpaque` template class represents an object of + * class `T` in the graph. + * + * `cv::GOpaque` describes a functional relationship between operations + * consuming and producing object of class `T`. `cv::GOpaque` is + * designed to extend G-API with user-defined data types, which are + * often required with user-defined operations. G-API can't apply any + * optimizations to user-defined types since these types are opaque to + * the framework. However, there is a number of G-API operations + * declared with `cv::GOpaque` as a return type, + * e.g. cv::gapi::streaming::timestamp() or cv::gapi::streaming::size(). + * + * @sa `cv::GArray` + */ +template class GOpaque +{ +public: + // Host type (or Flat type) - the type this GOpaque is actually + // specified to. + /// @private + using HT = typename detail::flatten_g>::type; + + /** + * @brief Constructs an empty `cv::GOpaque` + * + * Normally, empty G-API data objects denote a starting point of + * the graph. When an empty `cv::GOpaque` is assigned to a result + * of some operation, it obtains a functional link to this + * operation (and is not empty anymore). + */ + GOpaque() { putDetails(); } // Empty constructor + + /// @private + explicit GOpaque(detail::GOpaqueU &&ref) // GOpaqueU-based constructor + : m_ref(ref) { putDetails(); } // (used by GCall, not for users) + + /// @private + detail::GOpaqueU strip() const { + return m_ref; + } + /// @private + static void Ctor(detail::OpaqueRef& ref) { + ref.reset(); + } +private: + void putDetails() { + m_ref.setConstructFcn(&Ctor); + m_ref.specifyType(); + m_ref.storeKind(); + } + + detail::GOpaqueU m_ref; +}; + +/** @} */ + +} // namespace cv + +#endif // OPENCV_GAPI_GOPAQUE_HPP diff --git a/3rdparty/include/opencv2/gapi/gproto.hpp b/3rdparty/include/opencv2/gapi/gproto.hpp new file mode 100644 index 0000000000..fbcccb38ea --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gproto.hpp @@ -0,0 +1,159 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GPROTO_HPP +#define OPENCV_GAPI_GPROTO_HPP + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +namespace cv { + +// FIXME: user shouldn't deal with it - put to detail? +// GProtoArg is an union type over G-types which can serve as +// GComputation's in/output slots. In other words, GProtoArg +// wraps any type which can serve as G-API exchange type. +// +// In Runtime, GProtoArgs are substituted with appropriate GRunArgs. +// +// GProtoArg objects are constructed in-place when user describes +// (captures) computations, user doesn't interact with these types +// directly. +using GProtoArg = util::variant + < GMat + , GMatP + , GFrame + , GScalar + , detail::GArrayU // instead of GArray + , detail::GOpaqueU // instead of GOpaque + >; + +using GProtoArgs = std::vector; + +namespace detail +{ +template inline GProtoArgs packArgs(Ts... args) +{ + return GProtoArgs{ GProtoArg(wrap_gapi_helper::wrap(args))... }; +} + +} + +template +struct GIOProtoArgs +{ +public: + // NB: Used by python wrapper + GIOProtoArgs() = default; + explicit GIOProtoArgs(const GProtoArgs& args) : m_args(args) {} + explicit GIOProtoArgs(GProtoArgs &&args) : m_args(std::move(args)) {} + + GProtoArgs m_args; + + // TODO: Think about the addition operator + /** + * @brief This operator allows to complement the proto vectors at runtime. + * + * It's an ordinary overload of addition assignment operator. + * + * Example of usage: + * @snippet dynamic_graph.cpp GIOProtoArgs usage + * + */ + template + friend GIOProtoArgs& operator += (GIOProtoArgs &lhs, const GIOProtoArgs &rhs); +}; + +template +cv::GIOProtoArgs& operator += (cv::GIOProtoArgs &lhs, const cv::GIOProtoArgs &rhs) +{ + lhs.m_args.reserve(lhs.m_args.size() + rhs.m_args.size()); + lhs.m_args.insert(lhs.m_args.end(), rhs.m_args.begin(), rhs.m_args.end()); + return lhs; +} + +struct In_Tag{}; +struct Out_Tag{}; + +using GProtoInputArgs = GIOProtoArgs; +using GProtoOutputArgs = GIOProtoArgs; + +// Perfect forwarding +template inline GProtoInputArgs GIn(Ts&&... ts) +{ + return GProtoInputArgs(detail::packArgs(std::forward(ts)...)); +} + +template inline GProtoOutputArgs GOut(Ts&&... ts) +{ + return GProtoOutputArgs(detail::packArgs(std::forward(ts)...)); +} + +namespace detail +{ + // Extract elements form tuple + // FIXME: Someday utilize a generic tuple_to_vec<> routine + template + static GProtoOutputArgs getGOut_impl(const std::tuple& ts, detail::Seq) + { + return GProtoOutputArgs{ detail::packArgs(std::get(ts)...)}; + } +} + +template inline GProtoOutputArgs GOut(const std::tuple& ts) +{ + // TODO: think of std::forward(ts) + return detail::getGOut_impl(ts, typename detail::MkSeq::type()); +} + +// Takes rvalue as input arg +template inline GProtoOutputArgs GOut(std::tuple&& ts) +{ + // TODO: think of std::forward(ts) + return detail::getGOut_impl(ts, typename detail::MkSeq::type()); +} + +// Extract run-time arguments from node origin +// Can be used to extract constant values associated with G-objects +// (like GScalar) at graph construction time +GRunArg value_of(const GOrigin &origin); + +// Transform run-time computation arguments into a collection of metadata +// extracted from that arguments +GMetaArg GAPI_EXPORTS descr_of(const GRunArg &arg ); +GMetaArgs GAPI_EXPORTS descr_of(const GRunArgs &args); + +// Transform run-time operation result argument into metadata extracted from that argument +// Used to compare the metadata, which generated at compile time with the metadata result operation in run time +GMetaArg GAPI_EXPORTS descr_of(const GRunArgP& argp); + +// Checks if run-time computation argument can be described by metadata +bool GAPI_EXPORTS can_describe(const GMetaArg& meta, const GRunArg& arg); +bool GAPI_EXPORTS can_describe(const GMetaArgs& metas, const GRunArgs& args); + +// Checks if run-time computation result argument can be described by metadata. +// Used to check if the metadata generated at compile time +// coincides with output arguments passed to computation in cpu and ocl backends +bool GAPI_EXPORTS can_describe(const GMetaArg& meta, const GRunArgP& argp); + +// Validates input arguments +void GAPI_EXPORTS validate_input_arg(const GRunArg& arg); +void GAPI_EXPORTS validate_input_args(const GRunArgs& args); + +} // namespace cv + +#endif // OPENCV_GAPI_GPROTO_HPP diff --git a/3rdparty/include/opencv2/gapi/gpu/core.hpp b/3rdparty/include/opencv2/gapi/gpu/core.hpp new file mode 100644 index 0000000000..a7ee59577c --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gpu/core.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GPU_CORE_API_HPP +#define OPENCV_GAPI_GPU_CORE_API_HPP +/** @file +* @deprecated Use instead. +*/ + +#include + +namespace cv { +namespace gapi { +namespace core { +namespace gpu { + using namespace ocl; +} // namespace gpu +} // namespace core +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_GPU_CORE_API_HPP diff --git a/3rdparty/include/opencv2/gapi/gpu/ggpukernel.hpp b/3rdparty/include/opencv2/gapi/gpu/ggpukernel.hpp new file mode 100644 index 0000000000..b52c21de6b --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gpu/ggpukernel.hpp @@ -0,0 +1,18 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GGPUKERNEL_HPP +#define OPENCV_GAPI_GGPUKERNEL_HPP +/** @file +* @deprecated Use instead. +*/ + +#include +#define GAPI_GPU_KERNEL GAPI_OCL_KERNEL + + +#endif // OPENCV_GAPI_GGPUKERNEL_HPP diff --git a/3rdparty/include/opencv2/gapi/gpu/imgproc.hpp b/3rdparty/include/opencv2/gapi/gpu/imgproc.hpp new file mode 100644 index 0000000000..b0df7ae331 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gpu/imgproc.hpp @@ -0,0 +1,28 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GPU_IMGPROC_API_HPP +#define OPENCV_GAPI_GPU_IMGPROC_API_HPP +/** @file +* @deprecated Use instead. +*/ + +#include + + +namespace cv { +namespace gapi { +namespace imgproc { +namespace gpu { + using namespace ocl; +} // namespace gpu +} // namespace imgproc +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_GPU_IMGPROC_API_HPP diff --git a/3rdparty/include/opencv2/gapi/gscalar.hpp b/3rdparty/include/opencv2/gapi/gscalar.hpp new file mode 100644 index 0000000000..c6edc33b75 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gscalar.hpp @@ -0,0 +1,140 @@ +// This file is part of OpenCV project. + +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GSCALAR_HPP +#define OPENCV_GAPI_GSCALAR_HPP + +#include + +#include +#include // GShape +#include + +namespace cv +{ +// Forward declaration; GNode and GOrigin are an internal +// (user-inaccessible) classes. +class GNode; +struct GOrigin; + +/** \addtogroup gapi_data_objects + * @{ + */ +/** + * @brief GScalar class represents cv::Scalar data in the graph. + * + * GScalar may be associated with a cv::Scalar value, which becomes + * its constant value bound in graph compile time. cv::GScalar describes a + * functional relationship between operations consuming and producing + * GScalar objects. + * + * GScalar is a virtual counterpart of cv::Scalar, which is usually used + * to represent the GScalar data in G-API during the execution. + * + * @sa Scalar + */ +class GAPI_EXPORTS_W_SIMPLE GScalar +{ +public: + /** + * @brief Constructs an empty GScalar + * + * Normally, empty G-API data objects denote a starting point of + * the graph. When an empty GScalar is assigned to a result of some + * operation, it obtains a functional link to this operation (and + * is not empty anymore). + */ + GAPI_WRAP GScalar(); + + /** + * @brief Constructs a value-initialized GScalar + * + * In contrast with GMat (which can be either an explicit graph input + * or a result of some operation), GScalars may have their values + * be associated at graph construction time. It is useful when + * some operation has a GScalar input which doesn't change during + * the program execution, and is set only once. In this case, + * there is no need to declare such GScalar as a graph input. + * + * @note The value of GScalar may be overwritten by assigning some + * other GScalar to the object using `operator=` -- on the + * assigment, the old GScalar value is discarded. + * + * @param s a cv::Scalar value to associate with this GScalar object. + */ + explicit GScalar(const cv::Scalar& s); + + /** + * @overload + * @brief Constructs a value-initialized GScalar + * + * @param s a cv::Scalar value to associate with this GScalar object. + */ + explicit GScalar(cv::Scalar&& s); // Constant value move-constructor from cv::Scalar + + /** + * @overload + * @brief Constructs a value-initialized GScalar + * + * @param v0 A `double` value to associate with this GScalar. Note + * that only the first component of a four-component cv::Scalar is + * set to this value, with others remain zeros. + * + * This constructor overload is not marked `explicit` and can be + * used in G-API expression code like this: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp gscalar_implicit + * + * Here operator+(GMat,GScalar) is used to wrap cv::gapi::addC() + * and a value-initialized GScalar is created on the fly. + * + * @overload + */ + GScalar(double v0); // Constant value constructor from double + + /// @private + GScalar(const GNode &n, std::size_t out); // Operation result constructor + /// @private + GOrigin& priv(); // Internal use only + /// @private + const GOrigin& priv() const; // Internal use only + +private: + std::shared_ptr m_priv; +}; + +/** @} */ + +/** + * \addtogroup gapi_meta_args + * @{ + */ +struct GAPI_EXPORTS_W_SIMPLE GScalarDesc +{ + // NB.: right now it is empty + + inline bool operator== (const GScalarDesc &) const + { + return true; // NB: implement this method if GScalar meta appears + } + + inline bool operator!= (const GScalarDesc &rhs) const + { + return !(*this == rhs); + } +}; + +GAPI_EXPORTS_W inline GScalarDesc empty_scalar_desc() { return GScalarDesc(); } + +GAPI_EXPORTS GScalarDesc descr_of(const cv::Scalar &scalar); + +std::ostream& operator<<(std::ostream& os, const cv::GScalarDesc &desc); + +} // namespace cv + +#endif // OPENCV_GAPI_GSCALAR_HPP diff --git a/3rdparty/include/opencv2/gapi/gstreaming.hpp b/3rdparty/include/opencv2/gapi/gstreaming.hpp new file mode 100644 index 0000000000..50abe69f87 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gstreaming.hpp @@ -0,0 +1,418 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GSTREAMING_COMPILED_HPP +#define OPENCV_GAPI_GSTREAMING_COMPILED_HPP + +#include +#include + +#include +#include +#include +#include +#include + +namespace cv { + +template using optional = cv::util::optional; + +namespace detail { +template struct wref_spec { + using type = T; +}; +template struct wref_spec > { + using type = T; +}; + +template +struct OptRef { + struct OptHolder { + virtual void mov(RefHolder &h) = 0; + virtual void reset() = 0; + virtual ~OptHolder() = default; + using Ptr = std::shared_ptr; + }; + template struct Holder final: OptHolder { + std::reference_wrapper > m_opt_ref; + + explicit Holder(cv::optional& opt) : m_opt_ref(std::ref(opt)) { + } + virtual void mov(RefHolder &h) override { + using U = typename wref_spec::type; + m_opt_ref.get() = cv::util::make_optional(std::move(h.template wref())); + } + virtual void reset() override { + m_opt_ref.get().reset(); + } + }; + template + explicit OptRef(cv::optional& t) : m_opt{new Holder(t)} {} + void mov(RefHolder &h) { m_opt->mov(h); } + void reset() { m_opt->reset();} +private: + typename OptHolder::Ptr m_opt; +}; +using OptionalVectorRef = OptRef; +using OptionalOpaqueRef = OptRef; +} // namespace detail + +// TODO: Keep it in sync with GRunArgP (derive the type automatically?) +using GOptRunArgP = util::variant< + optional*, + optional*, + optional*, + cv::detail::OptionalVectorRef, + cv::detail::OptionalOpaqueRef +>; +using GOptRunArgsP = std::vector; + +using GOptRunArg = util::variant< + optional, + optional, + optional, + optional, + optional +>; +using GOptRunArgs = std::vector; + +namespace detail { + +template inline GOptRunArgP wrap_opt_arg(optional& arg) { + // By default, T goes to an OpaqueRef. All other types are specialized + return GOptRunArgP{OptionalOpaqueRef(arg)}; +} + +template inline GOptRunArgP wrap_opt_arg(optional >& arg) { + return GOptRunArgP{OptionalVectorRef(arg)}; +} + +template<> inline GOptRunArgP wrap_opt_arg(optional &m) { + return GOptRunArgP{&m}; +} + +template<> inline GOptRunArgP wrap_opt_arg(optional &s) { + return GOptRunArgP{&s}; +} + +} // namespace detail + +// Now cv::gout() may produce an empty vector (see "dynamic graphs"), so +// there may be a conflict between these two. State here that Opt version +// _must_ have at least one input for this overload +template +inline GOptRunArgsP gout(optional&arg, optional&... args) +{ + return GOptRunArgsP{ detail::wrap_opt_arg(arg), detail::wrap_opt_arg(args)... }; +} + +/** + * \addtogroup gapi_main_classes + * @{ + */ +/** + * @brief Represents a computation (graph) compiled for streaming. + * + * This class represents a product of graph compilation (calling + * cv::GComputation::compileStreaming()). Objects of this class + * actually do stream processing, and the whole pipeline execution + * complexity is incapsulated into objects of this class. Execution + * model has two levels: at the very top, the execution of a + * heterogeneous graph is aggressively pipelined; at the very bottom + * the execution of every internal block is determined by its + * associated backend. Backends are selected based on kernel packages + * passed via compilation arguments ( see @ref gapi_compile_args, + * GNetworkPackage, GKernelPackage for details). + * + * GStreamingCompiled objects have a "player" semantics -- there are + * methods like start() and stop(). GStreamingCompiled has a full + * control over a videostream and so is stateful. You need to specify the + * input stream data using setSource() and then call start() to + * actually start processing. After that, use pull() or try_pull() to + * obtain next processed data frame from the graph in a blocking or + * non-blocking way, respectively. + * + * Currently a single GStreamingCompiled can process only one video + * streat at time. Produce multiple GStreamingCompiled objects to run the + * same graph on multiple video streams. + * + * @sa GCompiled + */ +class GAPI_EXPORTS_W_SIMPLE GStreamingCompiled +{ +public: + class GAPI_EXPORTS Priv; + GAPI_WRAP GStreamingCompiled(); + + // FIXME: More overloads? + /** + * @brief Specify the input data to GStreamingCompiled for + * processing, a generic version. + * + * Use gin() to create an input parameter vector. + * + * Input vectors must have the same number of elements as defined + * in the cv::GComputation protocol (at the moment of its + * construction). Shapes of elements also must conform to protocol + * (e.g. cv::Mat needs to be passed where cv::GMat has been + * declared as input, and so on). Run-time exception is generated + * on type mismatch. + * + * In contrast with regular GCompiled, user can also pass an + * object of type GVideoCapture for a GMat parameter of the parent + * GComputation. The compiled pipeline will start fetching data + * from that GVideoCapture and feeding it into the + * pipeline. Pipeline stops when a GVideoCapture marks end of the + * stream (or when stop() is called). + * + * Passing a regular Mat for a GMat parameter makes it "infinite" + * source -- pipeline may run forever feeding with this Mat until + * stopped explicitly. + * + * Currently only a single GVideoCapture is supported as input. If + * the parent GComputation is declared with multiple input GMat's, + * one of those can be specified as GVideoCapture but all others + * must be regular Mat objects. + * + * Throws if pipeline is already running. Use stop() and then + * setSource() to run the graph on a new video stream. + * + * @note This method is not thread-safe (with respect to the user + * side) at the moment. Protect the access if + * start()/stop()/setSource() may be called on the same object in + * multiple threads in your application. + * + * @param ins vector of inputs to process. + * @sa gin + */ + void setSource(GRunArgs &&ins); + + /// @private -- Exclude this function from OpenCV documentation + GAPI_WRAP void setSource(const cv::detail::ExtractArgsCallback& callback); + + /** + * @brief Specify an input video stream for a single-input + * computation pipeline. + * + * Throws if pipeline is already running. Use stop() and then + * setSource() to run the graph on a new video stream. + * + * @overload + * @param s a shared pointer to IStreamSource representing the + * input video stream. + */ + void setSource(const gapi::wip::IStreamSource::Ptr& s); + + /** + * @brief Constructs and specifies an input video stream for a + * single-input computation pipeline with the given parameters. + * + * Throws if pipeline is already running. Use stop() and then + * setSource() to run the graph on a new video stream. + * + * @overload + * @param args arguments used to contruct and initialize a stream + * source. + */ + template + void setSource(Args&&... args) { + setSource(cv::gapi::wip::make_src(std::forward(args)...)); + } + + /** + * @brief Start the pipeline execution. + * + * Use pull()/try_pull() to obtain data. Throws an exception if + * a video source was not specified. + * + * setSource() must be called first, even if the pipeline has been + * working already and then stopped (explicitly via stop() or due + * stream completion) + * + * @note This method is not thread-safe (with respect to the user + * side) at the moment. Protect the access if + * start()/stop()/setSource() may be called on the same object in + * multiple threads in your application. + */ + GAPI_WRAP void start(); + + /** + * @brief Get the next processed frame from the pipeline. + * + * Use gout() to create an output parameter vector. + * + * Output vectors must have the same number of elements as defined + * in the cv::GComputation protocol (at the moment of its + * construction). Shapes of elements also must conform to protocol + * (e.g. cv::Mat needs to be passed where cv::GMat has been + * declared as output, and so on). Run-time exception is generated + * on type mismatch. + * + * This method writes new data into objects passed via output + * vector. If there is no data ready yet, this method blocks. Use + * try_pull() if you need a non-blocking version. + * + * @param outs vector of output parameters to obtain. + * @return true if next result has been obtained, + * false marks end of the stream. + */ + bool pull(cv::GRunArgsP &&outs); + + // NB: Used from python + /// @private -- Exclude this function from OpenCV documentation + GAPI_WRAP std::tuple> pull(); + + /** + * @brief Get some next available data from the pipeline. + * + * This method takes a vector of cv::optional object. An object is + * assigned to some value if this value is available (ready) at + * the time of the call, and resets the object to empty() if it is + * not. + * + * This is a blocking method which guarantees that some data has + * been written to the output vector on return. + * + * Using this method only makes sense if the graph has + * desynchronized parts (see cv::gapi::desync). If there is no + * desynchronized parts in the graph, the behavior of this + * method is identical to the regular pull() (all data objects are + * produced synchronously in the output vector). + * + * Use gout() to create an output parameter vector. + * + * Output vectors must have the same number of elements as defined + * in the cv::GComputation protocol (at the moment of its + * construction). Shapes of elements also must conform to protocol + * (e.g. cv::optional needs to be passed where cv::GMat + * has been declared as output, and so on). Run-time exception is + * generated on type mismatch. + * + * This method writes new data into objects passed via output + * vector. If there is no data ready yet, this method blocks. Use + * try_pull() if you need a non-blocking version. + * + * @param outs vector of output parameters to obtain. + * @return true if next result has been obtained, + * false marks end of the stream. + * + * @sa cv::gapi::desync + */ + bool pull(cv::GOptRunArgsP &&outs); + + /** + * @brief Try to get the next processed frame from the pipeline. + * + * Use gout() to create an output parameter vector. + * + * This method writes new data into objects passed via output + * vector. If there is no data ready yet, the output vector + * remains unchanged and false is returned. + * + * @return true if data has been obtained, and false if it was + * not. Note: false here doesn't mark the end of the stream. + */ + bool try_pull(cv::GRunArgsP &&outs); + + /** + * @brief Stop (abort) processing the pipeline. + * + * Note - it is not pause but a complete stop. Calling start() + * will cause G-API to start processing the stream from the early beginning. + * + * Throws if the pipeline is not running. + */ + GAPI_WRAP void stop(); + + /** + * @brief Test if the pipeline is running. + * + * @note This method is not thread-safe (with respect to the user + * side) at the moment. Protect the access if + * start()/stop()/setSource() may be called on the same object in + * multiple threads in your application. + * + * @return true if the current stream is not over yet. + */ + GAPI_WRAP bool running() const; + + /// @private + Priv& priv(); + + /** + * @brief Check if compiled object is valid (non-empty) + * + * @return true if the object is runnable (valid), false otherwise + */ + explicit operator bool () const; + + /** + * @brief Vector of metadata this graph was compiled for. + * + * @return Unless _reshape_ is not supported, return value is the + * same vector which was passed to cv::GComputation::compile() to + * produce this compiled object. Otherwise, it is the latest + * metadata vector passed to reshape() (if that call was + * successful). + */ + const GMetaArgs& metas() const; // Meta passed to compile() + + /** + * @brief Vector of metadata descriptions of graph outputs + * + * @return vector with formats/resolutions of graph's output + * objects, auto-inferred from input metadata vector by + * operations which form this computation. + * + * @note GCompiled objects produced from the same + * cv::GComputiation graph with different input metas may return + * different values in this vector. + */ + const GMetaArgs& outMetas() const; + +protected: + /// @private + std::shared_ptr m_priv; +}; +/** @} */ + +namespace gapi { + +/** + * @brief This namespace contains G-API functions, structures, and + * symbols related to the Streaming execution mode. + * + * Some of the operations defined in this namespace (e.g. size(), + * BGR(), etc.) can be used in the traditional execution mode too. + */ +namespace streaming { +/** + * @brief Specify queue capacity for streaming execution. + * + * In the streaming mode the pipeline steps are connected with queues + * and this compile argument controls every queue's size. + */ +struct GAPI_EXPORTS queue_capacity +{ + explicit queue_capacity(size_t cap = 1) : capacity(cap) { }; + size_t capacity; +}; +/** @} */ +} // namespace streaming +} // namespace gapi + +namespace detail +{ +template<> struct CompileArgTag +{ + static const char* tag() { return "gapi.queue_capacity"; } +}; +} + +} + +#endif // OPENCV_GAPI_GSTREAMING_COMPILED_HPP diff --git a/3rdparty/include/opencv2/gapi/gtransform.hpp b/3rdparty/include/opencv2/gapi/gtransform.hpp new file mode 100644 index 0000000000..5d1b91b517 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gtransform.hpp @@ -0,0 +1,103 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_GTRANSFORM_HPP +#define OPENCV_GAPI_GTRANSFORM_HPP + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace cv +{ + +struct GAPI_EXPORTS GTransform +{ + // FIXME: consider another simplified + // class instead of GComputation + using F = std::function; + + std::string description; + F pattern; + F substitute; + + GTransform(const std::string& d, const F &p, const F &s) : description(d), pattern(p), substitute(s){}; +}; + +namespace detail +{ + +template +struct TransHelper; + +template +struct TransHelper, Out> +{ + template + static GComputation invoke(Callable f, Seq, Seq) + { + const std::tuple ins; + const auto r = tuple_wrap_helper::get(f(std::get(ins)...)); + return GComputation(cv::GIn(std::get(ins)...), + cv::GOut(std::get(r)...)); + } + + static GComputation get_pattern() + { + return invoke(K::pattern, typename MkSeq::type(), + typename MkSeq::type>::value>::type()); + } + static GComputation get_substitute() + { + return invoke(K::substitute, typename MkSeq::type(), + typename MkSeq::type>::value>::type()); + } +}; +} // namespace detail + +template +class GTransformImpl; + +template +class GTransformImpl> : public cv::detail::TransHelper, R>, + public cv::detail::TransformTag +{ +public: + // FIXME: currently there is no check that transformations' signatures are unique + // and won't be any intersection in graph compilation stage + using API = K; + + static GTransform transformation() + { + return GTransform(K::descr(), &K::get_pattern, &K::get_substitute); + } +}; +} // namespace cv + +#define G_DESCR_HELPER_CLASS(Class) Class##DescrHelper + +#define G_DESCR_HELPER_BODY(Class, Descr) \ + namespace detail \ + { \ + struct G_DESCR_HELPER_CLASS(Class) \ + { \ + static constexpr const char *descr() { return Descr; }; \ + }; \ + } + +#define GAPI_TRANSFORM(Class, API, Descr) \ + G_DESCR_HELPER_BODY(Class, Descr) \ + struct Class final : public cv::GTransformImpl, \ + public detail::G_DESCR_HELPER_CLASS(Class) + +#endif // OPENCV_GAPI_GTRANSFORM_HPP diff --git a/3rdparty/include/opencv2/gapi/gtype_traits.hpp b/3rdparty/include/opencv2/gapi/gtype_traits.hpp new file mode 100644 index 0000000000..0b11b18485 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gtype_traits.hpp @@ -0,0 +1,233 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GTYPE_TRAITS_HPP +#define OPENCV_GAPI_GTYPE_TRAITS_HPP + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace cv +{ +namespace detail +{ + // FIXME: These traits and enum and possible numerous switch(kind) + // block may be replaced with a special Handler object or with + // a double dispatch + enum class ArgKind: int + { + OPAQUE_VAL, // Unknown, generic, opaque-to-GAPI data type - STATIC + // Note: OPAQUE is sometimes defined in Win sys headers +#if !defined(OPAQUE) && !defined(CV_DOXYGEN) + OPAQUE = OPAQUE_VAL, // deprecated value used for compatibility, use OPAQUE_VAL instead +#endif + GOBJREF, // reference to object + GMAT, // a cv::GMat + GMATP, // a cv::GMatP + GFRAME, // a cv::GFrame + GSCALAR, // a cv::GScalar + GARRAY, // a cv::GArrayU (note - exactly GArrayU, not GArray!) + GOPAQUE, // a cv::GOpaqueU (note - exactly GOpaqueU, not GOpaque!) + }; + + template + constexpr const char* meta_to_string() noexcept; + template<> + constexpr const char* meta_to_string() noexcept { return "GMatDesc"; } + template<> + constexpr const char* meta_to_string() noexcept { return "GScalarDesc"; } + template<> + constexpr const char* meta_to_string() noexcept { return "GArrayDesc"; } + template<> + constexpr const char* meta_to_string() noexcept { return "GOpaqueDesc"; } + template<> + constexpr const char* meta_to_string() noexcept { return "GFrameDesc";} + + // Describe G-API types (G-types) with traits. Mostly used by + // cv::GArg to store meta information about types passed into + // operation arguments. Please note that cv::GComputation is + // defined on GProtoArgs, not GArgs! + template struct GTypeTraits; + template struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::OPAQUE_VAL; + static constexpr const OpaqueKind op_kind = OpaqueKind::CV_UNKNOWN; + }; + template<> struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::GMAT; + static constexpr const GShape shape = GShape::GMAT; + static constexpr const OpaqueKind op_kind = OpaqueKind::CV_UNKNOWN; + }; + template<> struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::GMATP; + static constexpr const GShape shape = GShape::GMAT; + static constexpr const OpaqueKind op_kind = OpaqueKind::CV_UNKNOWN; + }; + template<> struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::GFRAME; + static constexpr const GShape shape = GShape::GFRAME; + static constexpr const OpaqueKind op_kind = OpaqueKind::CV_UNKNOWN; + }; + template<> struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::GSCALAR; + static constexpr const GShape shape = GShape::GSCALAR; + static constexpr const OpaqueKind op_kind = OpaqueKind::CV_UNKNOWN; + }; + template struct GTypeTraits > + { + static constexpr const ArgKind kind = ArgKind::GARRAY; + static constexpr const GShape shape = GShape::GARRAY; + static constexpr const OpaqueKind op_kind = GOpaqueTraits::kind; + using host_type = std::vector; + using strip_type = cv::detail::VectorRef; + static cv::detail::GArrayU wrap_value(const cv::GArray &t) { return t.strip();} + static cv::detail::VectorRef wrap_in (const std::vector &t) { return detail::VectorRef(t); } + static cv::detail::VectorRef wrap_out ( std::vector &t) { return detail::VectorRef(t); } + }; + template struct GTypeTraits > + { + static constexpr const ArgKind kind = ArgKind::GOPAQUE; + static constexpr const GShape shape = GShape::GOPAQUE; + static constexpr const OpaqueKind op_kind = GOpaqueTraits::kind; + using host_type = T; + using strip_type = cv::detail::OpaqueRef; + static cv::detail::GOpaqueU wrap_value(const cv::GOpaque &t) { return t.strip();} + static cv::detail::OpaqueRef wrap_in (const T &t) { return detail::OpaqueRef(t); } + static cv::detail::OpaqueRef wrap_out ( T &t) { return detail::OpaqueRef(t); } + }; + + // Tests if Trait for type T requires extra marshalling ("custom wrap") or not. + // If Traits has wrap_value() defined, it does. + template struct has_custom_wrap + { + template class check; + template static std::true_type test(check::wrap_value)> *); + template static std::false_type test(...); + using type = decltype(test(nullptr)); + static const constexpr bool value = std::is_same(nullptr))>::value; + }; + + // Resolve a Host type back to its associated G-Type. + // FIXME: Probably it can be avoided + // FIXME: GMatP is not present here. + // (Actually these traits is used only to check + // if associated G-type has custom wrap functions + // and GMat behavior is correct for GMatP) + template struct GTypeOf; +#if !defined(GAPI_STANDALONE) + template<> struct GTypeOf { using type = cv::GMat; }; +#endif // !defined(GAPI_STANDALONE) + template<> struct GTypeOf { using type = cv::GMat; }; + template<> struct GTypeOf { using type = cv::GMat; }; + template<> struct GTypeOf { using type = cv::GScalar; }; + template struct GTypeOf > { using type = cv::GArray; }; + template struct GTypeOf { using type = cv::GOpaque;}; + template<> struct GTypeOf { using type = cv::GFrame; }; + // FIXME: This is not quite correct since IStreamSource may produce not only Mat but also Scalar + // and vector data. TODO: Extend the type dispatching on these types too. + template<> struct GTypeOf { using type = cv::GMat;}; + template using g_type_of_t = typename GTypeOf::type; + + // Marshalling helper for G-types and its Host types. Helps G-API + // to store G types in internal generic containers for further + // processing. Implements the following callbacks: + // + // * wrap() - converts user-facing G-type into an internal one + // for internal storage. + // Used when G-API operation is instantiated (G::on(), + // etc) during expressing a pipeline. Mostly returns input + // value "as is" except the case when G-type is a template. For + // template G-classes, calls custom wrap() from Traits. + // The value returned by wrap() is then wrapped into GArg() and + // stored in G-API metadata. + // + // Example: + // - cv::GMat arguments are passed as-is. + // - integers, pointers, STL containers, user types are passed as-is. + // - cv::GArray is converted to cv::GArrayU. + // + // * wrap_in() / wrap_out() - convert Host type associated with + // G-type to internal representation type. + // + // - For "simple" (non-template) G-types, returns value as-is. + // Example: cv::GMat has host type cv::Mat, when user passes a + // cv::Mat, system stores it internally as cv::Mat. + // + // - For "complex" (template) G-types, utilizes custom + // wrap_in()/wrap_out() as described in Traits. + // Example: cv::GArray has host type std::vector, when + // user passes a std::vector, system stores it + // internally as VectorRef (with stripped away). + template struct WrapValue + { + static auto wrap(const T& t) -> + typename std::remove_reference::type + { + return static_cast::type>(t); + } + + template static U wrap_in (const U &u) { return u; } + template static U* wrap_out(U &u) { return &u; } + }; + template struct WrapValue::value>::type> + { + static auto wrap(const T& t) -> decltype(GTypeTraits::wrap_value(t)) + { + return GTypeTraits::wrap_value(t); + } + template static auto wrap_in (const U &u) -> typename GTypeTraits::strip_type + { + return GTypeTraits::wrap_in(u); + } + template static auto wrap_out(U &u) -> typename GTypeTraits::strip_type + { + return GTypeTraits::wrap_out(u); + } + }; + + template using wrap_gapi_helper = WrapValue::type>; + template using wrap_host_helper = WrapValue >::type>; + +// Union type for various user-defined type constructors (GArray, +// GOpaque, etc) +// +// TODO: Replace construct-only API with a more generic one (probably +// with bits of introspection) +// +// Not required for non-user-defined types (GMat, GScalar, etc) +using HostCtor = util::variant + < util::monostate + , detail::ConstructVec + , detail::ConstructOpaque + >; + +template struct GObtainCtor { + static HostCtor get() { return HostCtor{}; } +}; +template struct GObtainCtor > { + static HostCtor get() { return HostCtor{ConstructVec{&GArray::VCtor}}; }; +}; +template struct GObtainCtor > { + static HostCtor get() { return HostCtor{ConstructOpaque{&GOpaque::Ctor}}; }; +}; +} // namespace detail +} // namespace cv + +#endif // OPENCV_GAPI_GTYPE_TRAITS_HPP diff --git a/3rdparty/include/opencv2/gapi/gtyped.hpp b/3rdparty/include/opencv2/gapi/gtyped.hpp new file mode 100644 index 0000000000..27d9777944 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/gtyped.hpp @@ -0,0 +1,247 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GTYPED_HPP +#define OPENCV_GAPI_GTYPED_HPP +#if !defined(GAPI_STANDALONE) + +#include + +#include +#include +#include +#include + +namespace cv { + +namespace detail +{ + // FIXME: How to prevent coolhackers from extending it by their own types? + // FIXME: ...Should we care? + template struct ProtoToParam; + template<> struct ProtoToParam { using type = cv::Mat; }; + template<> struct ProtoToParam { using type = cv::Scalar; }; + template struct ProtoToParam > { using type = std::vector; }; + template<> struct ProtoToParam> { using type = std::vector; }; + template struct ProtoToParam > { using type = U; }; + template using ProtoToParamT = typename ProtoToParam::type; + + template struct ProtoToMeta; + template<> struct ProtoToMeta { using type = cv::GMatDesc; }; + template<> struct ProtoToMeta { using type = cv::GScalarDesc; }; + template struct ProtoToMeta > { using type = cv::GArrayDesc; }; + template struct ProtoToMeta > { using type = cv::GOpaqueDesc; }; + template<> struct ProtoToMeta { using type = cv::GFrameDesc; }; + template using ProtoToMetaT = typename ProtoToMeta::type; + + //workaround for MSVC 19.0 bug + template + auto make_default()->decltype(T{}) {return {};} +}; // detail + +/** + * @brief This class is a typed wrapper over a regular GComputation. + * + * `std::function<>`-like template parameter specifies the graph + * signature so methods so the object's constructor, methods like + * `apply()` and the derived `GCompiledT::operator()` also become + * typed. + * + * There is no need to use cv::gin() or cv::gout() modifiers with + * objects of this class. Instead, all input arguments are followed + * by all output arguments in the order from the template argument + * signature. + * + * Refer to the following example. Regular (untyped) code is written this way: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp Untyped_Example + * + * Here: + * + * - cv::GComputation object is created with a lambda constructor + * where it is defined as a two-input, one-output graph. + * + * - Its method `apply()` in fact takes arbitrary number of arguments + * (as vectors) so user can pass wrong number of inputs/outputs + * here. C++ compiler wouldn't notice that since the cv::GComputation + * API is polymorphic, and only a run-time error will be generated. + * + * Now the same code written with typed API: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp Typed_Example + * + * The key difference is: + * + * - Now the constructor lambda *must take* parameters and *must + * return* values as defined in the `GComputationT<>` signature. + * - Its method `apply()` does not require any extra specifiers to + * separate input arguments from the output ones + * - A `GCompiledT` (compilation product) takes input/output + * arguments with no extra specifiers as well. + */ +template class GComputationT; + +// Single return value implementation +template class GComputationT +{ +public: + typedef std::function Gen; + + class GCompiledT + { + private: + friend class GComputationT; + + cv::GCompiled m_comp; + + explicit GCompiledT(const cv::GCompiled &comp) : m_comp(comp) {} + + public: + GCompiledT() {} + + void operator()(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT &outArg) + { + m_comp(cv::gin(inArgs...), cv::gout(outArg)); + } + + explicit operator bool() const + { + return static_cast(m_comp); + } + }; + +private: + typedef std::pair Captured; + + Captured capture(const Gen& g, Args... args) + { + return Captured(g(args...), cv::GIn(args...)); + } + + Captured m_capture; + cv::GComputation m_comp; + +public: + GComputationT(const Gen &generator) + : m_capture(capture(generator, detail::make_default()...)) + , m_comp(cv::GProtoInputArgs(std::move(m_capture.second)), + cv::GOut(m_capture.first)) + { + } + + void apply(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT &outArg, + GCompileArgs &&args) + { + m_comp.apply(cv::gin(inArgs...), cv::gout(outArg), std::move(args)); + } + + void apply(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT &outArg) + { + apply(inArgs..., outArg, GCompileArgs()); + } + + + GCompiledT compile(detail::ProtoToMetaT... inDescs) + { + GMetaArgs inMetas = { GMetaArg(inDescs)... }; + return GCompiledT(m_comp.compile(std::move(inMetas), GCompileArgs())); + } + + GCompiledT compile(detail::ProtoToMetaT... inDescs, GCompileArgs &&args) + { + GMetaArgs inMetas = { GMetaArg(inDescs)... }; + return GCompiledT(m_comp.compile(std::move(inMetas), std::move(args))); + } +}; + +// Multiple (fixed) return value implementation. FIXME: How to avoid copy-paste? +template class GComputationT(Args...)> +{ +public: + typedef std::function(Args...)> Gen; + + class GCompiledT + { + private: + friend class GComputationT(Args...)>; + + cv::GCompiled m_comp; + explicit GCompiledT(const cv::GCompiled &comp) : m_comp(comp) {} + + public: + GCompiledT() {} + + void operator()(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT&... outArgs) + { + m_comp(cv::gin(inArgs...), cv::gout(outArgs...)); + } + + explicit operator bool() const + { + return static_cast(m_comp); + } + }; + +private: + typedef std::pair Captured; + + template + Captured capture(GProtoArgs &&args, const std::tuple &rr, detail::Seq) + { + return Captured(cv::GOut(std::get(rr)...).m_args, args); + } + + Captured capture(const Gen& g, Args... args) + { + return capture(cv::GIn(args...).m_args, g(args...), typename detail::MkSeq::type()); + } + + Captured m_capture; + cv::GComputation m_comp; + +public: + GComputationT(const Gen &generator) + : m_capture(capture(generator, detail::make_default()...)) + , m_comp(cv::GProtoInputArgs(std::move(m_capture.second)), + cv::GProtoOutputArgs(std::move(m_capture.first))) + { + } + + void apply(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT&... outArgs, + GCompileArgs &&args) + { + m_comp.apply(cv::gin(inArgs...), cv::gout(outArgs...), std::move(args)); + } + + void apply(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT&... outArgs) + { + apply(inArgs..., outArgs..., GCompileArgs()); + } + + + GCompiledT compile(detail::ProtoToMetaT... inDescs) + { + GMetaArgs inMetas = { GMetaArg(inDescs)... }; + return GCompiledT(m_comp.compile(std::move(inMetas), GCompileArgs())); + } + + GCompiledT compile(detail::ProtoToMetaT... inDescs, GCompileArgs &&args) + { + GMetaArgs inMetas = { GMetaArg(inDescs)... }; + return GCompiledT(m_comp.compile(std::move(inMetas), std::move(args))); + } +}; + +} // namespace cv +#endif // !defined(GAPI_STANDALONE) +#endif // OPENCV_GAPI_GTYPED_HPP diff --git a/3rdparty/include/opencv2/gapi/imgproc.hpp b/3rdparty/include/opencv2/gapi/imgproc.hpp new file mode 100644 index 0000000000..5c4c6f7031 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/imgproc.hpp @@ -0,0 +1,1682 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_IMGPROC_HPP +#define OPENCV_GAPI_IMGPROC_HPP + +#include + +#include // std::tuple + +#include +#include +#include + + +/** \defgroup gapi_imgproc G-API Image processing functionality +@{ + @defgroup gapi_filters Graph API: Image filters + @defgroup gapi_colorconvert Graph API: Converting image from one color space to another + @defgroup gapi_feature Graph API: Image Feature Detection + @defgroup gapi_shape Graph API: Image Structural Analysis and Shape Descriptors +@} + */ + +namespace { +void validateFindingContoursMeta(const int depth, const int chan, const int mode) +{ + GAPI_Assert(chan == 1); + switch (mode) + { + case cv::RETR_CCOMP: + GAPI_Assert(depth == CV_8U || depth == CV_32S); + break; + case cv::RETR_FLOODFILL: + GAPI_Assert(depth == CV_32S); + break; + default: + GAPI_Assert(depth == CV_8U); + break; + } +} +} // anonymous namespace + +namespace cv { namespace gapi { + +/** + * @brief This namespace contains G-API Operation Types for OpenCV + * ImgProc module functionality. + */ +namespace imgproc { + using GMat2 = std::tuple; + using GMat3 = std::tuple; // FIXME: how to avoid this? + using GFindContoursOutput = std::tuple>,GArray>; + + G_TYPED_KERNEL(GFilter2D, ,"org.opencv.imgproc.filters.filter2D") { + static GMatDesc outMeta(GMatDesc in, int ddepth, Mat, Point, Scalar, int, Scalar) { + return in.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GSepFilter, , "org.opencv.imgproc.filters.sepfilter") { + static GMatDesc outMeta(GMatDesc in, int ddepth, Mat, Mat, Point, Scalar, int, Scalar) { + return in.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GBoxFilter, , "org.opencv.imgproc.filters.boxfilter") { + static GMatDesc outMeta(GMatDesc in, int ddepth, Size, Point, bool, int, Scalar) { + return in.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GBlur, , "org.opencv.imgproc.filters.blur"){ + static GMatDesc outMeta(GMatDesc in, Size, Point, int, Scalar) { + return in; + } + }; + + G_TYPED_KERNEL(GGaussBlur, , "org.opencv.imgproc.filters.gaussianBlur") { + static GMatDesc outMeta(GMatDesc in, Size, double, double, int, Scalar) { + return in; + } + }; + + G_TYPED_KERNEL(GMedianBlur, , "org.opencv.imgproc.filters.medianBlur") { + static GMatDesc outMeta(GMatDesc in, int) { + return in; + } + }; + + G_TYPED_KERNEL(GErode, , "org.opencv.imgproc.filters.erode") { + static GMatDesc outMeta(GMatDesc in, Mat, Point, int, int, Scalar) { + return in; + } + }; + + G_TYPED_KERNEL(GDilate, , "org.opencv.imgproc.filters.dilate") { + static GMatDesc outMeta(GMatDesc in, Mat, Point, int, int, Scalar) { + return in; + } + }; + + G_TYPED_KERNEL(GMorphologyEx, , + "org.opencv.imgproc.filters.morphologyEx") { + static GMatDesc outMeta(const GMatDesc &in, MorphTypes, Mat, Point, int, + BorderTypes, Scalar) { + return in; + } + }; + + G_TYPED_KERNEL(GSobel, , "org.opencv.imgproc.filters.sobel") { + static GMatDesc outMeta(GMatDesc in, int ddepth, int, int, int, double, double, int, Scalar) { + return in.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL_M(GSobelXY, , "org.opencv.imgproc.filters.sobelxy") { + static std::tuple outMeta(GMatDesc in, int ddepth, int, int, double, double, int, Scalar) { + return std::make_tuple(in.withDepth(ddepth), in.withDepth(ddepth)); + } + }; + + G_TYPED_KERNEL(GLaplacian, , + "org.opencv.imgproc.filters.laplacian") { + static GMatDesc outMeta(GMatDesc in, int ddepth, int, double, double, int) { + return in.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GBilateralFilter, , + "org.opencv.imgproc.filters.bilateralfilter") { + static GMatDesc outMeta(GMatDesc in, int, double, double, int) { + return in; + } + }; + + G_TYPED_KERNEL(GEqHist, , "org.opencv.imgproc.equalizeHist"){ + static GMatDesc outMeta(GMatDesc in) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GCanny, , "org.opencv.imgproc.feature.canny"){ + static GMatDesc outMeta(GMatDesc in, double, double, int, bool) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GGoodFeatures, + (GMat,int,double,double,Mat,int,bool,double)>, + "org.opencv.imgproc.feature.goodFeaturesToTrack") { + static GArrayDesc outMeta(GMatDesc, int, double, double, const Mat&, int, bool, double) { + return empty_array_desc(); + } + }; + + using RetrMode = RetrievalModes; + using ContMethod = ContourApproximationModes; + G_TYPED_KERNEL(GFindContours, >(GMat,RetrMode,ContMethod,GOpaque)>, + "org.opencv.imgproc.shape.findContours") + { + static GArrayDesc outMeta(GMatDesc in, RetrMode mode, ContMethod, GOpaqueDesc) + { + validateFindingContoursMeta(in.depth, in.chan, mode); + return empty_array_desc(); + } + }; + + // FIXME oc: make default value offset = Point() + G_TYPED_KERNEL(GFindContoursNoOffset, >(GMat,RetrMode,ContMethod)>, + "org.opencv.imgproc.shape.findContoursNoOffset") + { + static GArrayDesc outMeta(GMatDesc in, RetrMode mode, ContMethod) + { + validateFindingContoursMeta(in.depth, in.chan, mode); + return empty_array_desc(); + } + }; + + G_TYPED_KERNEL(GFindContoursH,)>, + "org.opencv.imgproc.shape.findContoursH") + { + static std::tuple + outMeta(GMatDesc in, RetrMode mode, ContMethod, GOpaqueDesc) + { + validateFindingContoursMeta(in.depth, in.chan, mode); + return std::make_tuple(empty_array_desc(), empty_array_desc()); + } + }; + + // FIXME oc: make default value offset = Point() + G_TYPED_KERNEL(GFindContoursHNoOffset,, + "org.opencv.imgproc.shape.findContoursHNoOffset") + { + static std::tuple + outMeta(GMatDesc in, RetrMode mode, ContMethod) + { + validateFindingContoursMeta(in.depth, in.chan, mode); + return std::make_tuple(empty_array_desc(), empty_array_desc()); + } + }; + + G_TYPED_KERNEL(GBoundingRectMat, (GMat)>, + "org.opencv.imgproc.shape.boundingRectMat") { + static GOpaqueDesc outMeta(GMatDesc in) { + if (in.depth == CV_8U) + { + GAPI_Assert(in.chan == 1); + } + else + { + GAPI_Assert (in.depth == CV_32S || in.depth == CV_32F); + int amount = detail::checkVector(in, 2u); + GAPI_Assert(amount != -1 && + "Input Mat can't be described as vector of 2-dimentional points"); + } + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GBoundingRectVector32S, (GArray)>, + "org.opencv.imgproc.shape.boundingRectVector32S") { + static GOpaqueDesc outMeta(GArrayDesc) { + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GBoundingRectVector32F, (GArray)>, + "org.opencv.imgproc.shape.boundingRectVector32F") { + static GOpaqueDesc outMeta(GArrayDesc) { + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GFitLine2DMat, (GMat,DistanceTypes,double,double,double)>, + "org.opencv.imgproc.shape.fitLine2DMat") { + static GOpaqueDesc outMeta(GMatDesc in,DistanceTypes,double,double,double) { + int amount = detail::checkVector(in, 2u); + GAPI_Assert(amount != -1 && + "Input Mat can't be described as vector of 2-dimentional points"); + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GFitLine2DVector32S, + (GArray,DistanceTypes,double,double,double)>, + "org.opencv.imgproc.shape.fitLine2DVector32S") { + static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) { + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GFitLine2DVector32F, + (GArray,DistanceTypes,double,double,double)>, + "org.opencv.imgproc.shape.fitLine2DVector32F") { + static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) { + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GFitLine2DVector64F, + (GArray,DistanceTypes,double,double,double)>, + "org.opencv.imgproc.shape.fitLine2DVector64F") { + static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) { + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GFitLine3DMat, (GMat,DistanceTypes,double,double,double)>, + "org.opencv.imgproc.shape.fitLine3DMat") { + static GOpaqueDesc outMeta(GMatDesc in,int,double,double,double) { + int amount = detail::checkVector(in, 3u); + GAPI_Assert(amount != -1 && + "Input Mat can't be described as vector of 3-dimentional points"); + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GFitLine3DVector32S, + (GArray,DistanceTypes,double,double,double)>, + "org.opencv.imgproc.shape.fitLine3DVector32S") { + static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) { + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GFitLine3DVector32F, + (GArray,DistanceTypes,double,double,double)>, + "org.opencv.imgproc.shape.fitLine3DVector32F") { + static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) { + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GFitLine3DVector64F, + (GArray,DistanceTypes,double,double,double)>, + "org.opencv.imgproc.shape.fitLine3DVector64F") { + static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) { + return empty_gopaque_desc(); + } + }; + + G_TYPED_KERNEL(GBGR2RGB, , "org.opencv.imgproc.colorconvert.bgr2rgb") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GRGB2YUV, , "org.opencv.imgproc.colorconvert.rgb2yuv") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GYUV2RGB, , "org.opencv.imgproc.colorconvert.yuv2rgb") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GBGR2I420, , "org.opencv.imgproc.colorconvert.bgr2i420") { + static GMatDesc outMeta(GMatDesc in) { + GAPI_Assert(in.depth == CV_8U); + GAPI_Assert(in.chan == 3); + GAPI_Assert(in.size.height % 2 == 0); + return in.withType(in.depth, 1).withSize(Size(in.size.width, in.size.height * 3 / 2)); + } + }; + + G_TYPED_KERNEL(GRGB2I420, , "org.opencv.imgproc.colorconvert.rgb2i420") { + static GMatDesc outMeta(GMatDesc in) { + GAPI_Assert(in.depth == CV_8U); + GAPI_Assert(in.chan == 3); + GAPI_Assert(in.size.height % 2 == 0); + return in.withType(in.depth, 1).withSize(Size(in.size.width, in.size.height * 3 / 2)); + } + }; + + G_TYPED_KERNEL(GI4202BGR, , "org.opencv.imgproc.colorconvert.i4202bgr") { + static GMatDesc outMeta(GMatDesc in) { + GAPI_Assert(in.depth == CV_8U); + GAPI_Assert(in.chan == 1); + GAPI_Assert(in.size.height % 3 == 0); + return in.withType(in.depth, 3).withSize(Size(in.size.width, in.size.height * 2 / 3)); + } + }; + + G_TYPED_KERNEL(GI4202RGB, , "org.opencv.imgproc.colorconvert.i4202rgb") { + static GMatDesc outMeta(GMatDesc in) { + GAPI_Assert(in.depth == CV_8U); + GAPI_Assert(in.chan == 1); + GAPI_Assert(in.size.height % 3 == 0); + return in.withType(in.depth, 3).withSize(Size(in.size.width, in.size.height * 2 / 3)); + } + }; + + G_TYPED_KERNEL(GNV12toRGB, , "org.opencv.imgproc.colorconvert.nv12torgb") { + static GMatDesc outMeta(GMatDesc in_y, GMatDesc in_uv) { + GAPI_Assert(in_y.chan == 1); + GAPI_Assert(in_uv.chan == 2); + GAPI_Assert(in_y.depth == CV_8U); + GAPI_Assert(in_uv.depth == CV_8U); + // UV size should be aligned with Y + GAPI_Assert(in_y.size.width == 2 * in_uv.size.width); + GAPI_Assert(in_y.size.height == 2 * in_uv.size.height); + return in_y.withType(CV_8U, 3); // type will be CV_8UC3; + } + }; + + G_TYPED_KERNEL(GNV12toBGR, , "org.opencv.imgproc.colorconvert.nv12tobgr") { + static GMatDesc outMeta(GMatDesc in_y, GMatDesc in_uv) { + GAPI_Assert(in_y.chan == 1); + GAPI_Assert(in_uv.chan == 2); + GAPI_Assert(in_y.depth == CV_8U); + GAPI_Assert(in_uv.depth == CV_8U); + // UV size should be aligned with Y + GAPI_Assert(in_y.size.width == 2 * in_uv.size.width); + GAPI_Assert(in_y.size.height == 2 * in_uv.size.height); + return in_y.withType(CV_8U, 3); // type will be CV_8UC3; + } + }; + + G_TYPED_KERNEL(GRGB2Lab, , "org.opencv.imgproc.colorconvert.rgb2lab") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GBGR2LUV, , "org.opencv.imgproc.colorconvert.bgr2luv") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GLUV2BGR, , "org.opencv.imgproc.colorconvert.luv2bgr") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GYUV2BGR, , "org.opencv.imgproc.colorconvert.yuv2bgr") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GBGR2YUV, , "org.opencv.imgproc.colorconvert.bgr2yuv") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GRGB2Gray, , "org.opencv.imgproc.colorconvert.rgb2gray") { + static GMatDesc outMeta(GMatDesc in) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GRGB2GrayCustom, , "org.opencv.imgproc.colorconvert.rgb2graycustom") { + static GMatDesc outMeta(GMatDesc in, float, float, float) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GBGR2Gray, , "org.opencv.imgproc.colorconvert.bgr2gray") { + static GMatDesc outMeta(GMatDesc in) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GBayerGR2RGB, , "org.opencv.imgproc.colorconvert.bayergr2rgb") { + static cv::GMatDesc outMeta(cv::GMatDesc in) { + return in.withType(CV_8U, 3); + } + }; + + G_TYPED_KERNEL(GRGB2HSV, , "org.opencv.imgproc.colorconvert.rgb2hsv") { + static cv::GMatDesc outMeta(cv::GMatDesc in) { + return in; + } + }; + + G_TYPED_KERNEL(GRGB2YUV422, , "org.opencv.imgproc.colorconvert.rgb2yuv422") { + static cv::GMatDesc outMeta(cv::GMatDesc in) { + GAPI_Assert(in.depth == CV_8U); + GAPI_Assert(in.chan == 3); + return in.withType(in.depth, 2); + } + }; + + G_TYPED_KERNEL(GNV12toRGBp, , "org.opencv.imgproc.colorconvert.nv12torgbp") { + static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) { + GAPI_Assert(inY.depth == CV_8U); + GAPI_Assert(inUV.depth == CV_8U); + GAPI_Assert(inY.chan == 1); + GAPI_Assert(inY.planar == false); + GAPI_Assert(inUV.chan == 2); + GAPI_Assert(inUV.planar == false); + GAPI_Assert(inY.size.width == 2 * inUV.size.width); + GAPI_Assert(inY.size.height == 2 * inUV.size.height); + return inY.withType(CV_8U, 3).asPlanar(); + } + }; + + G_TYPED_KERNEL(GNV12toGray, , "org.opencv.imgproc.colorconvert.nv12togray") { + static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) { + GAPI_Assert(inY.depth == CV_8U); + GAPI_Assert(inUV.depth == CV_8U); + GAPI_Assert(inY.chan == 1); + GAPI_Assert(inY.planar == false); + GAPI_Assert(inUV.chan == 2); + GAPI_Assert(inUV.planar == false); + + GAPI_Assert(inY.size.width == 2 * inUV.size.width); + GAPI_Assert(inY.size.height == 2 * inUV.size.height); + return inY.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GNV12toBGRp, , "org.opencv.imgproc.colorconvert.nv12tobgrp") { + static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) { + GAPI_Assert(inY.depth == CV_8U); + GAPI_Assert(inUV.depth == CV_8U); + GAPI_Assert(inY.chan == 1); + GAPI_Assert(inY.planar == false); + GAPI_Assert(inUV.chan == 2); + GAPI_Assert(inUV.planar == false); + GAPI_Assert(inY.size.width == 2 * inUV.size.width); + GAPI_Assert(inY.size.height == 2 * inUV.size.height); + return inY.withType(CV_8U, 3).asPlanar(); + } + }; + +} //namespace imgproc + +//! @addtogroup gapi_filters +//! @{ +/** @brief Applies a separable linear filter to a matrix(image). + +The function applies a separable linear filter to the matrix. That is, first, every row of src is +filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D +kernel kernelY. The final result is returned. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note + - In case of floating-point computation, rounding to nearest even is procedeed +if hardware supports it (if not - to nearest value). + - Function textual ID is "org.opencv.imgproc.filters.sepfilter" +@param src Source image. +@param ddepth desired depth of the destination image (the following combinations of src.depth() and ddepth are supported: + + src.depth() = CV_8U, ddepth = -1/CV_16S/CV_32F/CV_64F + src.depth() = CV_16U/CV_16S, ddepth = -1/CV_32F/CV_64F + src.depth() = CV_32F, ddepth = -1/CV_32F/CV_64F + src.depth() = CV_64F, ddepth = -1/CV_64F + +when ddepth=-1, the output image will have the same depth as the source) +@param kernelX Coefficients for filtering each row. +@param kernelY Coefficients for filtering each column. +@param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor +is at the kernel center. +@param delta Value added to the filtered results before storing them. +@param borderType Pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa boxFilter, gaussianBlur, medianBlur + */ +GAPI_EXPORTS GMat sepFilter(const GMat& src, int ddepth, const Mat& kernelX, const Mat& kernelY, const Point& anchor /*FIXME: = Point(-1,-1)*/, + const Scalar& delta /*FIXME = GScalar(0)*/, int borderType = BORDER_DEFAULT, + const Scalar& borderValue = Scalar(0)); + +/** @brief Convolves an image with the kernel. + +The function applies an arbitrary linear filter to an image. When +the aperture is partially outside the image, the function interpolates outlier pixel values +according to the specified border mode. + +The function does actually compute correlation, not the convolution: + +\f[\texttt{dst} (x,y) = \sum _{ \substack{0\leq x' < \texttt{kernel.cols}\\{0\leq y' < \texttt{kernel.rows}}}} \texttt{kernel} (x',y')* \texttt{src} (x+x'- \texttt{anchor.x} ,y+y'- \texttt{anchor.y} )\f] + +That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip +the kernel using flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows - +anchor.y - 1)`. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same size and number of channels an input image. +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.filter2D" + +@param src input image. +@param ddepth desired depth of the destination image +@param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point +matrix; if you want to apply different kernels to different channels, split the image into +separate color planes using split and process them individually. +@param anchor anchor of the kernel that indicates the relative position of a filtered point within +the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor +is at the kernel center. +@param delta optional value added to the filtered pixels before storing them in dst. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa sepFilter + */ +GAPI_EXPORTS GMat filter2D(const GMat& src, int ddepth, const Mat& kernel, const Point& anchor = Point(-1,-1), const Scalar& delta = Scalar(0), + int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0)); + + +/** @brief Blurs an image using the box filter. + +The function smooths an image using the kernel: + +\f[\texttt{K} = \alpha \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \end{bmatrix}\f] + +where + +\f[\alpha = \begin{cases} \frac{1}{\texttt{ksize.width*ksize.height}} & \texttt{when } \texttt{normalize=true} \\1 & \texttt{otherwise} \end{cases}\f] + +Unnormalized box filter is useful for computing various integral characteristics over each pixel +neighborhood, such as covariance matrices of image derivatives (used in dense optical flow +algorithms, and so on). If you need to compute pixel sums over variable-size windows, use cv::integral. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.boxfilter" + +@param src Source image. +@param dtype the output image depth (-1 to set the input image data type). +@param ksize blurring kernel size. +@param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor +is at the kernel center. +@param normalize flag, specifying whether the kernel is normalized by its area or not. +@param borderType Pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa sepFilter, gaussianBlur, medianBlur, integral + */ +GAPI_EXPORTS GMat boxFilter(const GMat& src, int dtype, const Size& ksize, const Point& anchor = Point(-1,-1), + bool normalize = true, int borderType = BORDER_DEFAULT, + const Scalar& borderValue = Scalar(0)); + +/** @brief Blurs an image using the normalized box filter. + +The function smooths an image using the kernel: + +\f[\texttt{K} = \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \end{bmatrix}\f] + +The call `blur(src, ksize, anchor, borderType)` is equivalent to `boxFilter(src, src.type(), ksize, anchor, +true, borderType)`. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.blur" + +@param src Source image. +@param ksize blurring kernel size. +@param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel +center. +@param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa boxFilter, bilateralFilter, GaussianBlur, medianBlur + */ +GAPI_EXPORTS GMat blur(const GMat& src, const Size& ksize, const Point& anchor = Point(-1,-1), + int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0)); + + +//GAPI_EXPORTS_W void blur( InputArray src, OutputArray dst, + // Size ksize, Point anchor = Point(-1,-1), + // int borderType = BORDER_DEFAULT ); + + +/** @brief Blurs an image using a Gaussian filter. + +The function filter2Ds the source image with the specified Gaussian kernel. +Output image must have the same type and number of channels an input image. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.gaussianBlur" + +@param src input image; +@param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be +positive and odd. Or, they can be zero's and then they are computed from sigma. +@param sigmaX Gaussian kernel standard deviation in X direction. +@param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be +equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height, +respectively (see cv::getGaussianKernel for details); to fully control the result regardless of +possible future modifications of all this semantics, it is recommended to specify all of ksize, +sigmaX, and sigmaY. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa sepFilter, boxFilter, medianBlur + */ +GAPI_EXPORTS GMat gaussianBlur(const GMat& src, const Size& ksize, double sigmaX, double sigmaY = 0, + int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0)); + +/** @brief Blurs an image using the median filter. + +The function smoothes an image using the median filter with the \f$\texttt{ksize} \times +\texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently. +Output image must have the same type, size, and number of channels as the input image. +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. +The median filter uses cv::BORDER_REPLICATE internally to cope with border pixels, see cv::BorderTypes + - Function textual ID is "org.opencv.imgproc.filters.medianBlur" + +@param src input matrix (image) +@param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ... +@sa boxFilter, gaussianBlur + */ +GAPI_EXPORTS_W GMat medianBlur(const GMat& src, int ksize); + +/** @brief Erodes an image by using a specific structuring element. + +The function erodes the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the minimum is taken: + +\f[\texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +Erosion can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.erode" + +@param src input image +@param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular +structuring element is used. Kernel can be created using getStructuringElement. +@param anchor position of the anchor within the element; default value (-1, -1) means that the +anchor is at the element center. +@param iterations number of times erosion is applied. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of a constant border +@sa dilate, morphologyEx + */ +GAPI_EXPORTS GMat erode(const GMat& src, const Mat& kernel, const Point& anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue()); + +/** @brief Erodes an image by using 3 by 3 rectangular structuring element. + +The function erodes the source image using the rectangular structuring element with rectangle center as an anchor. +Erosion can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.erode" + +@param src input image +@param iterations number of times erosion is applied. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of a constant border +@sa erode, dilate3x3 + */ +GAPI_EXPORTS GMat erode3x3(const GMat& src, int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue()); + +/** @brief Dilates an image by using a specific structuring element. + +The function dilates the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the maximum is taken: +\f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +Dilation can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.dilate" + +@param src input image. +@param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular +structuring element is used. Kernel can be created using getStructuringElement +@param anchor position of the anchor within the element; default value (-1, -1) means that the +anchor is at the element center. +@param iterations number of times dilation is applied. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of a constant border +@sa erode, morphologyEx, getStructuringElement + */ +GAPI_EXPORTS GMat dilate(const GMat& src, const Mat& kernel, const Point& anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue()); + +/** @brief Dilates an image by using 3 by 3 rectangular structuring element. + +The function dilates the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the maximum is taken: +\f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +Dilation can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.dilate" + +@param src input image. +@param iterations number of times dilation is applied. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of a constant border +@sa dilate, erode3x3 + */ + +GAPI_EXPORTS GMat dilate3x3(const GMat& src, int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue()); + +/** @brief Performs advanced morphological transformations. + +The function can perform advanced morphological transformations using an erosion and dilation as +basic operations. + +Any of the operations can be done in-place. In case of multi-channel images, each channel is +processed independently. + +@note + - Function textual ID is "org.opencv.imgproc.filters.morphologyEx" + - The number of iterations is the number of times erosion or dilatation operation will be +applied. For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to +apply successively: erode -> erode -> dilate -> dilate +(and not erode -> dilate -> erode -> dilate). + +@param src Input image. +@param op Type of a morphological operation, see #MorphTypes +@param kernel Structuring element. It can be created using #getStructuringElement. +@param anchor Anchor position within the element. Both negative values mean that the anchor is at +the kernel center. +@param iterations Number of times erosion and dilation are applied. +@param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported. +@param borderValue Border value in case of a constant border. The default value has a special +meaning. +@sa dilate, erode, getStructuringElement + */ +GAPI_EXPORTS GMat morphologyEx(const GMat &src, const MorphTypes op, const Mat &kernel, + const Point &anchor = Point(-1,-1), + const int iterations = 1, + const BorderTypes borderType = BORDER_CONSTANT, + const Scalar &borderValue = morphologyDefaultBorderValue()); + +/** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. + +In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to +calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$ +kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first +or the second x- or y- derivatives. + +There is also the special value `ksize = FILTER_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr +filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is + +\f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f] + +for the x-derivative, or transposed for the y-derivative. + +The function calculates an image derivative by convolving the image with the appropriate kernel: + +\f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f] + +The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less +resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) +or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first +case corresponds to a kernel of: + +\f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f] + +The second case corresponds to a kernel of: + +\f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f] + +@note + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.sobel" + +@param src input image. +@param ddepth output image depth, see @ref filter_depths "combinations"; in the case of + 8-bit input images it will result in truncated derivatives. +@param dx order of the derivative x. +@param dy order of the derivative y. +@param ksize size of the extended Sobel kernel; it must be odd. +@param scale optional scale factor for the computed derivative values; by default, no scaling is +applied (see cv::getDerivKernels for details). +@param delta optional delta value that is added to the results prior to storing them in dst. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa filter2D, gaussianBlur, cartToPolar + */ +GAPI_EXPORTS GMat Sobel(const GMat& src, int ddepth, int dx, int dy, int ksize = 3, + double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT, + const Scalar& borderValue = Scalar(0)); + +/** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. + +In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to +calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$ +kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first +or the second x- or y- derivatives. + +There is also the special value `ksize = FILTER_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr +filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is + +\f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f] + +for the x-derivative, or transposed for the y-derivative. + +The function calculates an image derivative by convolving the image with the appropriate kernel: + +\f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f] + +The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less +resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) +or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first +case corresponds to a kernel of: + +\f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f] + +The second case corresponds to a kernel of: + +\f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f] + +@note + - First returned matrix correspons to dx derivative while the second one to dy. + - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + - Function textual ID is "org.opencv.imgproc.filters.sobelxy" + +@param src input image. +@param ddepth output image depth, see @ref filter_depths "combinations"; in the case of + 8-bit input images it will result in truncated derivatives. +@param order order of the derivatives. +@param ksize size of the extended Sobel kernel; it must be odd. +@param scale optional scale factor for the computed derivative values; by default, no scaling is +applied (see cv::getDerivKernels for details). +@param delta optional delta value that is added to the results prior to storing them in dst. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa filter2D, gaussianBlur, cartToPolar + */ +GAPI_EXPORTS std::tuple SobelXY(const GMat& src, int ddepth, int order, int ksize = 3, + double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT, + const Scalar& borderValue = Scalar(0)); + +/** @brief Calculates the Laplacian of an image. + +The function calculates the Laplacian of the source image by adding up the second x and y +derivatives calculated using the Sobel operator: + +\f[\texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}\f] + +This is done when `ksize > 1`. When `ksize == 1`, the Laplacian is computed by filtering the image +with the following \f$3 \times 3\f$ aperture: + +\f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f] + +@note Function textual ID is "org.opencv.imgproc.filters.laplacian" + +@param src Source image. +@param ddepth Desired depth of the destination image. +@param ksize Aperture size used to compute the second-derivative filters. See #getDerivKernels for +details. The size must be positive and odd. +@param scale Optional scale factor for the computed Laplacian values. By default, no scaling is +applied. See #getDerivKernels for details. +@param delta Optional delta value that is added to the results prior to storing them in dst . +@param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported. +@return Destination image of the same size and the same number of channels as src. +@sa Sobel, Scharr + */ +GAPI_EXPORTS GMat Laplacian(const GMat& src, int ddepth, int ksize = 1, + double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT); + +/** @brief Applies the bilateral filter to an image. + +The function applies bilateral filtering to the input image, as described in +http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html +bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is +very slow compared to most filters. + +_Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (\< +10), the filter will not have much effect, whereas if they are large (\> 150), they will have a very +strong effect, making the image look "cartoonish". + +_Filter size_: Large filters (d \> 5) are very slow, so it is recommended to use d=5 for real-time +applications, and perhaps d=9 for offline applications that need heavy noise filtering. + +This filter does not work inplace. + +@note Function textual ID is "org.opencv.imgproc.filters.bilateralfilter" + +@param src Source 8-bit or floating-point, 1-channel or 3-channel image. +@param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, +it is computed from sigmaSpace. +@param sigmaColor Filter sigma in the color space. A larger value of the parameter means that +farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting +in larger areas of semi-equal color. +@param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that +farther pixels will influence each other as long as their colors are close enough (see sigmaColor +). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is +proportional to sigmaSpace. +@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes +@return Destination image of the same size and type as src. + */ +GAPI_EXPORTS GMat bilateralFilter(const GMat& src, int d, double sigmaColor, double sigmaSpace, + int borderType = BORDER_DEFAULT); + +//! @} gapi_filters + +//! @addtogroup gapi_feature +//! @{ +/** @brief Finds edges in an image using the Canny algorithm. + +The function finds edges in the input image and marks them in the output map edges using the +Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The +largest value is used to find initial segments of strong edges. See + + +@note Function textual ID is "org.opencv.imgproc.feature.canny" + +@param image 8-bit input image. +@param threshold1 first threshold for the hysteresis procedure. +@param threshold2 second threshold for the hysteresis procedure. +@param apertureSize aperture size for the Sobel operator. +@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm +\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude ( +L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough ( +L2gradient=false ). + */ +GAPI_EXPORTS GMat Canny(const GMat& image, double threshold1, double threshold2, + int apertureSize = 3, bool L2gradient = false); + +/** @brief Determines strong corners on an image. + +The function finds the most prominent corners in the image or in the specified image region, as +described in @cite Shi94 + +- Function calculates the corner quality measure at every source image pixel using the + #cornerMinEigenVal or #cornerHarris . +- Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are + retained). +- The corners with the minimal eigenvalue less than + \f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected. +- The remaining corners are sorted by the quality measure in the descending order. +- Function throws away each corner for which there is a stronger corner at a distance less than + maxDistance. + +The function can be used to initialize a point-based tracker of an object. + +@note + - If the function is called with different values A and B of the parameter qualityLevel , and +A \> B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector +with qualityLevel=B . + - Function textual ID is "org.opencv.imgproc.feature.goodFeaturesToTrack" + +@param image Input 8-bit or floating-point 32-bit, single-channel image. +@param maxCorners Maximum number of corners to return. If there are more corners than are found, +the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set +and all detected corners are returned. +@param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The +parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue +(see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the +quality measure less than the product are rejected. For example, if the best corner has the +quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure +less than 15 are rejected. +@param minDistance Minimum possible Euclidean distance between the returned corners. +@param mask Optional region of interest. If the image is not empty (it needs to have the type +CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected. +@param blockSize Size of an average block for computing a derivative covariation matrix over each +pixel neighborhood. See cornerEigenValsAndVecs . +@param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris) +or #cornerMinEigenVal. +@param k Free parameter of the Harris detector. + +@return vector of detected corners. + */ +GAPI_EXPORTS_W GArray goodFeaturesToTrack(const GMat &image, + int maxCorners, + double qualityLevel, + double minDistance, + const Mat &mask = Mat(), + int blockSize = 3, + bool useHarrisDetector = false, + double k = 0.04); + +/** @brief Equalizes the histogram of a grayscale image. + +//! @} gapi_feature + +The function equalizes the histogram of the input image using the following algorithm: + +- Calculate the histogram \f$H\f$ for src . +- Normalize the histogram so that the sum of histogram bins is 255. +- Compute the integral of the histogram: +\f[H'_i = \sum _{0 \le j < i} H(j)\f] +- Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$ + +The algorithm normalizes the brightness and increases the contrast of the image. +@note + - The returned image is of the same size and type as input. + - Function textual ID is "org.opencv.imgproc.equalizeHist" + +@param src Source 8-bit single channel image. + */ +GAPI_EXPORTS GMat equalizeHist(const GMat& src); + +//! @addtogroup gapi_shape +//! @{ +/** @brief Finds contours in a binary image. + +The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . +The contours are a useful tool for shape analysis and object detection and recognition. +See squares.cpp in the OpenCV sample directory. + +@note Function textual ID is "org.opencv.imgproc.shape.findContours" + +@param src Input gray-scale image @ref CV_8UC1. Non-zero pixels are treated as 1's. Zero +pixels remain 0's, so the image is treated as binary . You can use #compare, #inRange, #threshold , +#adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one. +If mode equals to #RETR_CCOMP, the input can also be a 32-bit integer +image of labels ( @ref CV_32SC1 ). If #RETR_FLOODFILL then @ref CV_32SC1 is supported only. +@param mode Contour retrieval mode, see #RetrievalModes +@param method Contour approximation method, see #ContourApproximationModes +@param offset Optional offset by which every contour point is shifted. This is useful if the +contours are extracted from the image ROI and then they should be analyzed in the whole image +context. + +@return GArray of detected contours. Each contour is stored as a GArray of points. + */ +GAPI_EXPORTS GArray> +findContours(const GMat &src, const RetrievalModes mode, const ContourApproximationModes method, + const GOpaque &offset); + +// FIXME oc: make default value offset = Point() +/** @overload +@note Function textual ID is "org.opencv.imgproc.shape.findContoursNoOffset" + */ +GAPI_EXPORTS GArray> +findContours(const GMat &src, const RetrievalModes mode, const ContourApproximationModes method); + +/** @brief Finds contours and their hierarchy in a binary image. + +The function retrieves contours from the binary image using the algorithm @cite Suzuki85 +and calculates their hierarchy. +The contours are a useful tool for shape analysis and object detection and recognition. +See squares.cpp in the OpenCV sample directory. + +@note Function textual ID is "org.opencv.imgproc.shape.findContoursH" + +@param src Input gray-scale image @ref CV_8UC1. Non-zero pixels are treated as 1's. Zero +pixels remain 0's, so the image is treated as binary . You can use #compare, #inRange, #threshold , +#adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one. +If mode equals to #RETR_CCOMP, the input can also be a 32-bit integer +image of labels ( @ref CV_32SC1 ). If #RETR_FLOODFILL -- @ref CV_32SC1 supports only. +@param mode Contour retrieval mode, see #RetrievalModes +@param method Contour approximation method, see #ContourApproximationModes +@param offset Optional offset by which every contour point is shifted. This is useful if the +contours are extracted from the image ROI and then they should be analyzed in the whole image +context. + +@return + - GArray of detected contours. Each contour is stored as a GArray of points. + - Optional output GArray of cv::Vec4i, containing information about the image topology. +It has as many elements as the number of contours. For each i-th contour contours[i], the elements +hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based +indices in contours of the next and previous contours at the same hierarchical level, the first +child contour and the parent contour, respectively. If for the contour i there are no next, +previous, parent, or nested contours, the corresponding elements of hierarchy[i] will be negative. + */ +GAPI_EXPORTS std::tuple>,GArray> +findContoursH(const GMat &src, const RetrievalModes mode, const ContourApproximationModes method, + const GOpaque &offset); + +// FIXME oc: make default value offset = Point() +/** @overload +@note Function textual ID is "org.opencv.imgproc.shape.findContoursHNoOffset" + */ +GAPI_EXPORTS std::tuple>,GArray> +findContoursH(const GMat &src, const RetrievalModes mode, const ContourApproximationModes method); + +/** @brief Calculates the up-right bounding rectangle of a point set or non-zero pixels +of gray-scale image. + +The function calculates and returns the minimal up-right bounding rectangle for the specified +point set or non-zero pixels of gray-scale image. + +@note + - Function textual ID is "org.opencv.imgproc.shape.boundingRectMat" + - In case of a 2D points' set given, Mat should be 2-dimensional, have a single row or column +if there are 2 channels, or have 2 columns if there is a single channel. Mat should have either +@ref CV_32S or @ref CV_32F depth + +@param src Input gray-scale image @ref CV_8UC1; or input set of @ref CV_32S or @ref CV_32F +2D points stored in Mat. + */ +GAPI_EXPORTS_W GOpaque boundingRect(const GMat& src); + +/** @overload + +Calculates the up-right bounding rectangle of a point set. + +@note Function textual ID is "org.opencv.imgproc.shape.boundingRectVector32S" + +@param src Input 2D point set, stored in std::vector. + */ +GAPI_EXPORTS_W GOpaque boundingRect(const GArray& src); + +/** @overload + +Calculates the up-right bounding rectangle of a point set. + +@note Function textual ID is "org.opencv.imgproc.shape.boundingRectVector32F" + +@param src Input 2D point set, stored in std::vector. + */ +GAPI_EXPORTS GOpaque boundingRect(const GArray& src); + +/** @brief Fits a line to a 2D point set. + +The function fits a line to a 2D point set by minimizing \f$\sum_i \rho(r_i)\f$ where +\f$r_i\f$ is a distance between the \f$i^{th}\f$ point, the line and \f$\rho(r)\f$ is a distance +function, one of the following: +- DIST_L2 +\f[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\f] +- DIST_L1 +\f[\rho (r) = r\f] +- DIST_L12 +\f[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f] +- DIST_FAIR +\f[\rho \left (r \right ) = C^2 \cdot \left ( \frac{r}{C} - \log{\left(1 + \frac{r}{C}\right)} \right ) \quad \text{where} \quad C=1.3998\f] +- DIST_WELSCH +\f[\rho \left (r \right ) = \frac{C^2}{2} \cdot \left ( 1 - \exp{\left(-\left(\frac{r}{C}\right)^2\right)} \right ) \quad \text{where} \quad C=2.9846\f] +- DIST_HUBER +\f[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f] + +The algorithm is based on the M-estimator ( ) technique +that iteratively fits the line using the weighted least-squares algorithm. After each iteration the +weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ . + +@note + - Function textual ID is "org.opencv.imgproc.shape.fitLine2DMat" + - In case of an N-dimentional points' set given, Mat should be 2-dimensional, have a single row +or column if there are N channels, or have N columns if there is a single channel. + +@param src Input set of 2D points stored in one of possible containers: Mat, +std::vector, std::vector, std::vector. +@param distType Distance used by the M-estimator, see #DistanceTypes. @ref DIST_USER +and @ref DIST_C are not suppored. +@param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value +is chosen. +@param reps Sufficient accuracy for the radius (distance between the coordinate origin and the +line). 1.0 would be a good default value for reps. If it is 0, a default value is chosen. +@param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for aeps. +If it is 0, a default value is chosen. + +@return Output line parameters: a vector of 4 elements (like Vec4f) - (vx, vy, x0, y0), +where (vx, vy) is a normalized vector collinear to the line and (x0, y0) is a point on the line. + */ +GAPI_EXPORTS GOpaque fitLine2D(const GMat& src, const DistanceTypes distType, + const double param = 0., const double reps = 0., + const double aeps = 0.); + +/** @overload + +@note Function textual ID is "org.opencv.imgproc.shape.fitLine2DVector32S" + + */ +GAPI_EXPORTS GOpaque fitLine2D(const GArray& src, const DistanceTypes distType, + const double param = 0., const double reps = 0., + const double aeps = 0.); + +/** @overload + +@note Function textual ID is "org.opencv.imgproc.shape.fitLine2DVector32F" + + */ +GAPI_EXPORTS GOpaque fitLine2D(const GArray& src, const DistanceTypes distType, + const double param = 0., const double reps = 0., + const double aeps = 0.); + +/** @overload + +@note Function textual ID is "org.opencv.imgproc.shape.fitLine2DVector64F" + + */ +GAPI_EXPORTS GOpaque fitLine2D(const GArray& src, const DistanceTypes distType, + const double param = 0., const double reps = 0., + const double aeps = 0.); + +/** @brief Fits a line to a 3D point set. + +The function fits a line to a 3D point set by minimizing \f$\sum_i \rho(r_i)\f$ where +\f$r_i\f$ is a distance between the \f$i^{th}\f$ point, the line and \f$\rho(r)\f$ is a distance +function, one of the following: +- DIST_L2 +\f[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\f] +- DIST_L1 +\f[\rho (r) = r\f] +- DIST_L12 +\f[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f] +- DIST_FAIR +\f[\rho \left (r \right ) = C^2 \cdot \left ( \frac{r}{C} - \log{\left(1 + \frac{r}{C}\right)} \right ) \quad \text{where} \quad C=1.3998\f] +- DIST_WELSCH +\f[\rho \left (r \right ) = \frac{C^2}{2} \cdot \left ( 1 - \exp{\left(-\left(\frac{r}{C}\right)^2\right)} \right ) \quad \text{where} \quad C=2.9846\f] +- DIST_HUBER +\f[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f] + +The algorithm is based on the M-estimator ( ) technique +that iteratively fits the line using the weighted least-squares algorithm. After each iteration the +weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ . + +@note + - Function textual ID is "org.opencv.imgproc.shape.fitLine3DMat" + - In case of an N-dimentional points' set given, Mat should be 2-dimensional, have a single row +or column if there are N channels, or have N columns if there is a single channel. + +@param src Input set of 3D points stored in one of possible containers: Mat, +std::vector, std::vector, std::vector. +@param distType Distance used by the M-estimator, see #DistanceTypes. @ref DIST_USER +and @ref DIST_C are not suppored. +@param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value +is chosen. +@param reps Sufficient accuracy for the radius (distance between the coordinate origin and the +line). 1.0 would be a good default value for reps. If it is 0, a default value is chosen. +@param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for aeps. +If it is 0, a default value is chosen. + +@return Output line parameters: a vector of 6 elements (like Vec6f) - (vx, vy, vz, x0, y0, z0), +where (vx, vy, vz) is a normalized vector collinear to the line and (x0, y0, z0) is a point on +the line. + */ +GAPI_EXPORTS GOpaque fitLine3D(const GMat& src, const DistanceTypes distType, + const double param = 0., const double reps = 0., + const double aeps = 0.); + +/** @overload + +@note Function textual ID is "org.opencv.imgproc.shape.fitLine3DVector32S" + + */ +GAPI_EXPORTS GOpaque fitLine3D(const GArray& src, const DistanceTypes distType, + const double param = 0., const double reps = 0., + const double aeps = 0.); + +/** @overload + +@note Function textual ID is "org.opencv.imgproc.shape.fitLine3DVector32F" + + */ +GAPI_EXPORTS GOpaque fitLine3D(const GArray& src, const DistanceTypes distType, + const double param = 0., const double reps = 0., + const double aeps = 0.); + +/** @overload + +@note Function textual ID is "org.opencv.imgproc.shape.fitLine3DVector64F" + + */ +GAPI_EXPORTS GOpaque fitLine3D(const GArray& src, const DistanceTypes distType, + const double param = 0., const double reps = 0., + const double aeps = 0.); + +//! @} gapi_shape + +//! @addtogroup gapi_colorconvert +//! @{ +/** @brief Converts an image from BGR color space to RGB color space. + +The function converts an input image from BGR color space to RGB. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image is 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2rgb" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa RGB2BGR +*/ +GAPI_EXPORTS_W GMat BGR2RGB(const GMat& src); + +/** @brief Converts an image from RGB color space to gray-scaled. + +The conventional ranges for R, G, and B channel values are 0 to 255. +Resulting gray color value computed as +\f[\texttt{dst} (I)= \texttt{0.299} * \texttt{src}(I).R + \texttt{0.587} * \texttt{src}(I).G + \texttt{0.114} * \texttt{src}(I).B \f] + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2gray" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1. +@sa RGB2YUV + */ +GAPI_EXPORTS_W GMat RGB2Gray(const GMat& src); + +/** @overload +Resulting gray color value computed as +\f[\texttt{dst} (I)= \texttt{rY} * \texttt{src}(I).R + \texttt{gY} * \texttt{src}(I).G + \texttt{bY} * \texttt{src}(I).B \f] + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2graycustom" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1. +@param rY float multiplier for R channel. +@param gY float multiplier for G channel. +@param bY float multiplier for B channel. +@sa RGB2YUV + */ +GAPI_EXPORTS GMat RGB2Gray(const GMat& src, float rY, float gY, float bY); + +/** @brief Converts an image from BGR color space to gray-scaled. + +The conventional ranges for B, G, and R channel values are 0 to 255. +Resulting gray color value computed as +\f[\texttt{dst} (I)= \texttt{0.114} * \texttt{src}(I).B + \texttt{0.587} * \texttt{src}(I).G + \texttt{0.299} * \texttt{src}(I).R \f] + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2gray" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1. +@sa BGR2LUV + */ +GAPI_EXPORTS GMat BGR2Gray(const GMat& src); + +/** @brief Converts an image from RGB color space to YUV color space. + +The function converts an input image from RGB color space to YUV. +The conventional ranges for R, G, and B channel values are 0 to 255. + +In case of linear transformations, the range does not matter. But in case of a non-linear +transformation, an input RGB image should be normalized to the proper value range to get the correct +results, like here, at RGB \f$\rightarrow\f$ Y\*u\*v\* transformation. +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2yuv" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa YUV2RGB, RGB2Lab +*/ +GAPI_EXPORTS GMat RGB2YUV(const GMat& src); + +/** @brief Converts an image from BGR color space to I420 color space. + +The function converts an input image from BGR color space to I420. +The conventional ranges for R, G, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 1-channel image. @ref CV_8UC1. +Width of I420 output image must be the same as width of input image. +Height of I420 output image must be equal 3/2 from height of input image. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2i420" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa I4202BGR +*/ +GAPI_EXPORTS GMat BGR2I420(const GMat& src); + +/** @brief Converts an image from RGB color space to I420 color space. + +The function converts an input image from RGB color space to I420. +The conventional ranges for R, G, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 1-channel image. @ref CV_8UC1. +Width of I420 output image must be the same as width of input image. +Height of I420 output image must be equal 3/2 from height of input image. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2i420" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa I4202RGB +*/ +GAPI_EXPORTS GMat RGB2I420(const GMat& src); + +/** @brief Converts an image from I420 color space to BGR color space. + +The function converts an input image from I420 color space to BGR. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image. @ref CV_8UC3. +Width of BGR output image must be the same as width of input image. +Height of BGR output image must be equal 2/3 from height of input image. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.i4202bgr" + +@param src input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@sa BGR2I420 +*/ +GAPI_EXPORTS GMat I4202BGR(const GMat& src); + +/** @brief Converts an image from I420 color space to BGR color space. + +The function converts an input image from I420 color space to BGR. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image. @ref CV_8UC3. +Width of RGB output image must be the same as width of input image. +Height of RGB output image must be equal 2/3 from height of input image. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.i4202rgb" + +@param src input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@sa RGB2I420 +*/ +GAPI_EXPORTS GMat I4202RGB(const GMat& src); + +/** @brief Converts an image from BGR color space to LUV color space. + +The function converts an input image from BGR color space to LUV. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2luv" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa RGB2Lab, RGB2LUV +*/ +GAPI_EXPORTS GMat BGR2LUV(const GMat& src); + +/** @brief Converts an image from LUV color space to BGR color space. + +The function converts an input image from LUV color space to BGR. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.luv2bgr" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa BGR2LUV +*/ +GAPI_EXPORTS GMat LUV2BGR(const GMat& src); + +/** @brief Converts an image from YUV color space to BGR color space. + +The function converts an input image from YUV color space to BGR. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.yuv2bgr" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa BGR2YUV +*/ +GAPI_EXPORTS GMat YUV2BGR(const GMat& src); + +/** @brief Converts an image from BGR color space to YUV color space. + +The function converts an input image from BGR color space to YUV. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2yuv" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa YUV2BGR +*/ +GAPI_EXPORTS GMat BGR2YUV(const GMat& src); + +/** @brief Converts an image from RGB color space to Lab color space. + +The function converts an input image from BGR color space to Lab. +The conventional ranges for R, G, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC1. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2lab" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1. +@sa RGB2YUV, RGB2LUV +*/ +GAPI_EXPORTS GMat RGB2Lab(const GMat& src); + +/** @brief Converts an image from YUV color space to RGB. +The function converts an input image from YUV color space to RGB. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.yuv2rgb" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. + +@sa RGB2Lab, RGB2YUV +*/ +GAPI_EXPORTS GMat YUV2RGB(const GMat& src); + +/** @brief Converts an image from NV12 (YUV420p) color space to RGB. +The function converts an input image from NV12 color space to RGB. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgb" + +@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2. + +@sa YUV2RGB, NV12toBGR +*/ +GAPI_EXPORTS GMat NV12toRGB(const GMat& src_y, const GMat& src_uv); + +/** @brief Converts an image from NV12 (YUV420p) color space to gray-scaled. +The function converts an input image from NV12 color space to gray-scaled. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned 1-channel image @ref CV_8UC1. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12togray" + +@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2. + +@sa YUV2RGB, NV12toBGR +*/ +GAPI_EXPORTS GMat NV12toGray(const GMat& src_y, const GMat& src_uv); + +/** @brief Converts an image from NV12 (YUV420p) color space to BGR. +The function converts an input image from NV12 color space to RGB. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12tobgr" + +@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2. + +@sa YUV2BGR, NV12toRGB +*/ +GAPI_EXPORTS GMat NV12toBGR(const GMat& src_y, const GMat& src_uv); + +/** @brief Converts an image from BayerGR color space to RGB. +The function converts an input image from BayerGR color space to RGB. +The conventional ranges for G, R, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bayergr2rgb" + +@param src_gr input image: 8-bit unsigned 1-channel image @ref CV_8UC1. + +@sa YUV2BGR, NV12toRGB +*/ +GAPI_EXPORTS GMat BayerGR2RGB(const GMat& src_gr); + +/** @brief Converts an image from RGB color space to HSV. +The function converts an input image from RGB color space to HSV. +The conventional ranges for R, G, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2hsv" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. + +@sa YUV2BGR, NV12toRGB +*/ +GAPI_EXPORTS GMat RGB2HSV(const GMat& src); + +/** @brief Converts an image from RGB color space to YUV422. +The function converts an input image from RGB color space to YUV422. +The conventional ranges for R, G, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 2-channel image @ref CV_8UC2. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2yuv422" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. + +@sa YUV2BGR, NV12toRGB +*/ +GAPI_EXPORTS GMat RGB2YUV422(const GMat& src); + +/** @brief Converts an image from NV12 (YUV420p) color space to RGB. +The function converts an input image from NV12 color space to RGB. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned planar 3-channel image @ref CV_8UC1. +Planar image memory layout is three planes laying in the memory contiguously, +so the image height should be plane_height*plane_number, +image type is @ref CV_8UC1. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgbp" + +@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2. + +@sa YUV2RGB, NV12toBGRp, NV12toRGB +*/ +GAPI_EXPORTS GMatP NV12toRGBp(const GMat &src_y, const GMat &src_uv); + +/** @brief Converts an image from NV12 (YUV420p) color space to BGR. +The function converts an input image from NV12 color space to BGR. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned planar 3-channel image @ref CV_8UC1. +Planar image memory layout is three planes laying in the memory contiguously, +so the image height should be plane_height*plane_number, +image type is @ref CV_8UC1. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgbp" + +@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2. + +@sa YUV2RGB, NV12toRGBp, NV12toBGR +*/ +GAPI_EXPORTS GMatP NV12toBGRp(const GMat &src_y, const GMat &src_uv); + +//! @} gapi_colorconvert +} //namespace gapi +} //namespace cv + +#endif // OPENCV_GAPI_IMGPROC_HPP diff --git a/3rdparty/include/opencv2/gapi/infer.hpp b/3rdparty/include/opencv2/gapi/infer.hpp new file mode 100644 index 0000000000..807c82d31f --- /dev/null +++ b/3rdparty/include/opencv2/gapi/infer.hpp @@ -0,0 +1,714 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019-2021 Intel Corporation + + +#ifndef OPENCV_GAPI_INFER_HPP +#define OPENCV_GAPI_INFER_HPP + +// FIXME: Inference API is currently only available in full mode +#if !defined(GAPI_STANDALONE) + +#include +#include // string +#include // tuple +#include // is_same, false_type + +#include // all_satisfy +#include // any<> +#include // GKernelType[M], GBackend +#include // GArg +#include // CompileArgTag +#include // GMetaArg + +namespace cv { + +template class GNetworkType; + +namespace detail { + +// Infer /////////////////////////////////////////////////////////////////////// +template +struct accepted_infer_types { + static constexpr const auto value = + std::is_same::type, cv::GMat>::value + || std::is_same::type, cv::GFrame>::value; +}; + +template +using valid_infer_types = all_satisfy; + +// Infer2 ////////////////////////////////////////////////////////////////////// + +template +struct valid_infer2_types; + +// Terminal case 1 (50/50 success) +template +struct valid_infer2_types< std::tuple, std::tuple > { + // By default, Nets are limited to GMat argument types only + // for infer2, every GMat argument may translate to either + // GArray or GArray. GArray<> part is stripped + // already at this point. + static constexpr const auto value = + std::is_same::type, cv::GMat>::value + || std::is_same::type, cv::Rect>::value; +}; + +// Terminal case 2 (100% failure) +template +struct valid_infer2_types< std::tuple<>, std::tuple > + : public std::false_type { +}; + +// Terminal case 3 (100% failure) +template +struct valid_infer2_types< std::tuple, std::tuple<> > + : public std::false_type { +}; + +// Recursion -- generic +template +struct valid_infer2_types< std::tuple, std::tuple > { + static constexpr const auto value = + valid_infer2_types< std::tuple, std::tuple >::value + && valid_infer2_types< std::tuple, std::tuple >::value; +}; + +// Struct stores network input/output names. +// Used by infer +struct InOutInfo +{ + std::vector in_names; + std::vector out_names; +}; + +template +class GInferOutputsTyped +{ +public: + GInferOutputsTyped() = default; + GInferOutputsTyped(std::shared_ptr call) + : m_priv(std::make_shared(std::move(call))) + { + } + + OutT at(const std::string& name) + { + auto it = m_priv->blobs.find(name); + if (it == m_priv->blobs.end()) { + // FIXME: Avoid modifying GKernel + auto shape = cv::detail::GTypeTraits::shape; + m_priv->call->kernel().outShapes.push_back(shape); + m_priv->call->kernel().outCtors.emplace_back(cv::detail::GObtainCtor::get()); + auto out_idx = static_cast(m_priv->blobs.size()); + it = m_priv->blobs.emplace(name, + cv::detail::Yield::yield(*(m_priv->call), out_idx)).first; + m_priv->info->out_names.push_back(name); + } + return it->second; + } +private: + struct Priv + { + Priv(std::shared_ptr c) + : call(std::move(c)), info(cv::util::any_cast(&call->params())) + { + } + + std::shared_ptr call; + InOutInfo* info = nullptr; + std::unordered_map blobs; + }; + + std::shared_ptr m_priv; +}; + +template +class GInferInputsTyped +{ +public: + GInferInputsTyped() + : m_priv(std::make_shared()) + { + } + + template + GInferInputsTyped& setInput(const std::string& name, U in) + { + m_priv->blobs.emplace(std::piecewise_construct, + std::forward_as_tuple(name), + std::forward_as_tuple(in)); + return *this; + } + + using StorageT = cv::util::variant; + StorageT& operator[](const std::string& name) { + return m_priv->blobs[name]; + } + + using Map = std::unordered_map; + const Map& getBlobs() const { + return m_priv->blobs; + } + +private: + struct Priv + { + std::unordered_map blobs; + }; + + std::shared_ptr m_priv; +}; + +template +std::shared_ptr makeCall(const std::string &tag, + std::vector &&args, + std::vector &&names, + cv::GKinds &&kinds) { + auto call = std::make_shared(GKernel{ + InferT::id(), + tag, + InferT::getOutMeta, + {}, // outShape will be filled later + std::move(kinds), + {}, // outCtors will be filled later + }); + + call->setArgs(std::move(args)); + call->params() = cv::detail::InOutInfo{std::move(names), {}}; + + return call; +} + +} // namespace detail + +// TODO: maybe tuple_wrap_helper from util.hpp may help with this. +// Multiple-return-value network definition (specialized base class) +template +class GNetworkType(Args...)> > +{ +public: + using InArgs = std::tuple; + using OutArgs = std::tuple; + + using Result = OutArgs; + using API = std::function; + + using ResultL = std::tuple< cv::GArray... >; +}; + +// Single-return-value network definition (specialized base class) +template +class GNetworkType > +{ +public: + using InArgs = std::tuple; + using OutArgs = std::tuple; + + using Result = R; + using API = std::function; + + using ResultL = cv::GArray; +}; + +// InferAPI: Accepts either GMat or GFrame for very individual network's input +template +struct InferAPI { + using type = typename std::enable_if + < detail::valid_infer_types::value + && std::tuple_size::value == sizeof...(Ts) + , std::function + >::type; +}; + +// InferAPIRoi: Accepts a rectangle and either GMat or GFrame +template +struct InferAPIRoi { + using type = typename std::enable_if + < detail::valid_infer_types::value + && std::tuple_size::value == 1u + , std::function, T)> + >::type; +}; + +// InferAPIList: Accepts a list of rectangles and list of GMat/GFrames; +// crops every input. +template +struct InferAPIList { + using type = typename std::enable_if + < detail::valid_infer_types::value + && std::tuple_size::value == sizeof...(Ts) + , std::function, Ts...)> + >::type; +}; + +// APIList2 is also template to allow different calling options +// (GArray vs GArray per input) +template +struct InferAPIList2 { + using type = typename std::enable_if + < detail::valid_infer_types::value && + cv::detail::valid_infer2_types< typename Net::InArgs + , std::tuple >::value, + std::function...)> + >::type; +}; + +// Base "Infer" kernel. Note - for whatever network, kernel ID +// is always the same. Different inference calls are distinguished by +// network _tag_ (an extra field in GCall) +// +// getOutMeta is a stub callback collected by G-API kernel subsystem +// automatically. This is a rare case when this callback is defined by +// a particular backend, not by a network itself. +struct GInferBase { + static constexpr const char * id() { + return "org.opencv.dnn.infer"; // Universal stub + } + static GMetaArgs getOutMeta(const GMetaArgs &, const GArgs &) { + return GMetaArgs{}; // One more universal stub + } +}; + +// Base "InferROI" kernel. +// All notes from "Infer" kernel apply here as well. +struct GInferROIBase { + static constexpr const char * id() { + return "org.opencv.dnn.infer-roi"; // Universal stub + } + static GMetaArgs getOutMeta(const GMetaArgs &, const GArgs &) { + return GMetaArgs{}; // One more universal stub + } +}; + +// Base "Infer list" kernel. +// All notes from "Infer" kernel apply here as well. +struct GInferListBase { + static constexpr const char * id() { + return "org.opencv.dnn.infer-roi-list-1"; // Universal stub + } + static GMetaArgs getOutMeta(const GMetaArgs &, const GArgs &) { + return GMetaArgs{}; // One more universal stub + } +}; + +// Base "Infer list 2" kernel. +// All notes from "Infer" kernel apply here as well. +struct GInferList2Base { + static constexpr const char * id() { + return "org.opencv.dnn.infer-roi-list-2"; // Universal stub + } + static GMetaArgs getOutMeta(const GMetaArgs &, const GArgs &) { + return GMetaArgs{}; // One more universal stub + } +}; + +// A generic inference kernel. API (::on()) is fully defined by the Net +// template parameter. +// Acts as a regular kernel in graph (via KernelTypeMedium). +template +struct GInfer final + : public GInferBase + , public detail::KernelTypeMedium< GInfer + , typename InferAPI::type > { + using GInferBase::getOutMeta; // FIXME: name lookup conflict workaround? + + static constexpr const char* tag() { return Net::tag(); } +}; + +// A specific roi-inference kernel. API (::on()) is fixed here and +// verified against Net. +template +struct GInferROI final + : public GInferROIBase + , public detail::KernelTypeMedium< GInferROI + , typename InferAPIRoi::type > { + using GInferROIBase::getOutMeta; // FIXME: name lookup conflict workaround? + + static constexpr const char* tag() { return Net::tag(); } +}; + + +// A generic roi-list inference kernel. API (::on()) is derived from +// the Net template parameter (see more in infer<> overload). +template +struct GInferList final + : public GInferListBase + , public detail::KernelTypeMedium< GInferList + , typename InferAPIList::type > { + using GInferListBase::getOutMeta; // FIXME: name lookup conflict workaround? + + static constexpr const char* tag() { return Net::tag(); } +}; + +// An even more generic roi-list inference kernel. API (::on()) is +// derived from the Net template parameter (see more in infer<> +// overload). +// Takes an extra variadic template list to reflect how this network +// was called (with Rects or GMats as array parameters) +template +struct GInferList2 final + : public GInferList2Base + , public detail::KernelTypeMedium< GInferList2 + , typename InferAPIList2::type > { + using GInferList2Base::getOutMeta; // FIXME: name lookup conflict workaround? + + static constexpr const char* tag() { return Net::tag(); } +}; + +/** + * @brief G-API object used to collect network inputs + */ +using GInferInputs = cv::detail::GInferInputsTyped; + +/** + * @brief G-API object used to collect the list of network inputs + */ +using GInferListInputs = cv::detail::GInferInputsTyped, cv::GArray>; + +/** + * @brief G-API object used to collect network outputs + */ +using GInferOutputs = cv::detail::GInferOutputsTyped; + +/** + * @brief G-API object used to collect the list of network outputs + */ +using GInferListOutputs = cv::detail::GInferOutputsTyped>; + +namespace detail { +void inline unpackBlobs(const cv::GInferInputs::Map& blobs, + std::vector& args, + std::vector& names, + cv::GKinds& kinds) +{ + for (auto&& p : blobs) { + names.emplace_back(p.first); + switch (p.second.index()) { + case cv::GInferInputs::StorageT::index_of(): + args.emplace_back(cv::util::get(p.second)); + kinds.emplace_back(cv::detail::OpaqueKind::CV_MAT); + break; + case cv::GInferInputs::StorageT::index_of(): + args.emplace_back(cv::util::get(p.second)); + kinds.emplace_back(cv::detail::OpaqueKind::CV_UNKNOWN); + break; + default: + GAPI_Assert(false); + } + } +} + +template +struct InferROITraits; + +template <> +struct InferROITraits +{ + using outType = cv::GInferOutputs; + using inType = cv::GOpaque; +}; + +template <> +struct InferROITraits +{ + using outType = cv::GInferListOutputs; + using inType = cv::GArray; +}; + +template +typename InferROITraits::outType +inferGenericROI(const std::string& tag, + const typename InferROITraits::inType& in, + const cv::GInferInputs& inputs) +{ + std::vector args; + std::vector names; + cv::GKinds kinds; + + args.emplace_back(in); + kinds.emplace_back(cv::detail::OpaqueKind::CV_RECT); + + unpackBlobs(inputs.getBlobs(), args, names, kinds); + + auto call = cv::detail::makeCall(tag, + std::move(args), + std::move(names), + std::move(kinds)); + + return {std::move(call)}; +} + +} // namespace detail +} // namespace cv + +// FIXME: Probably the signature makes a function/tuple/function round-trip +#define G_API_NET(Class, API, Tag) \ + struct Class final: public cv::GNetworkType { \ + static constexpr const char * tag() { return Tag; } \ + } + +namespace cv { +namespace gapi { + +/** @brief Calculates response for the specified network (template + * parameter) for the specified region in the source image. + * Currently expects a single-input network only. + * + * @tparam A network type defined with G_API_NET() macro. + * @param in input image where to take ROI from. + * @param roi an object describing the region of interest + * in the source image. May be calculated in the same graph dynamically. + * @return an object of return type as defined in G_API_NET(). + * If a network has multiple return values (defined with a tuple), a tuple of + * objects of appropriate type is returned. + * @sa G_API_NET() + */ +template +typename Net::Result infer(cv::GOpaque roi, T in) { + return GInferROI::on(roi, in); +} + +/** @brief Calculates responses for the specified network (template + * parameter) for every region in the source image. + * + * @tparam A network type defined with G_API_NET() macro. + * @param roi a list of rectangles describing regions of interest + * in the source image. Usually an output of object detector or tracker. + * @param args network's input parameters as specified in G_API_NET() macro. + * NOTE: verified to work reliably with 1-input topologies only. + * @return a list of objects of return type as defined in G_API_NET(). + * If a network has multiple return values (defined with a tuple), a tuple of + * GArray<> objects is returned with the appropriate types inside. + * @sa G_API_NET() + */ +template +typename Net::ResultL infer(cv::GArray roi, Args&&... args) { + return GInferList::on(roi, std::forward(args)...); +} + +/** @brief Calculates responses for the specified network (template + * parameter) for every region in the source image, extended version. + * + * @tparam A network type defined with G_API_NET() macro. + * @param image A source image containing regions of interest + * @param args GArray<> objects of cv::Rect or cv::GMat, one per every + * network input: + * - If a cv::GArray is passed, the appropriate + * regions are taken from `image` and preprocessed to this particular + * network input; + * - If a cv::GArray is passed, the underlying data traited + * as tensor (no automatic preprocessing happen). + * @return a list of objects of return type as defined in G_API_NET(). + * If a network has multiple return values (defined with a tuple), a tuple of + * GArray<> objects is returned with the appropriate types inside. + * @sa G_API_NET() + */ + +template +typename Net::ResultL infer2(T image, cv::GArray... args) { + // FIXME: Declared as "2" because in the current form it steals + // overloads from the regular infer + return GInferList2::on(image, args...); +} + +/** + * @brief Calculates response for the specified network (template + * parameter) given the input data. + * + * @tparam A network type defined with G_API_NET() macro. + * @param args network's input parameters as specified in G_API_NET() macro. + * @return an object of return type as defined in G_API_NET(). + * If a network has multiple return values (defined with a tuple), a tuple of + * objects of appropriate type is returned. + * @sa G_API_NET() + */ +template +typename Net::Result infer(Args&&... args) { + return GInfer::on(std::forward(args)...); +} + +/** + * @brief Generic network type: input and output layers are configured dynamically at runtime + * + * Unlike the network types defined with G_API_NET macro, this one + * doesn't fix number of network inputs and outputs at the compilation stage + * thus providing user with an opportunity to program them in runtime. + */ +struct Generic { }; + +/** + * @brief Calculates response for generic network + * + * @param tag a network tag + * @param inputs networks's inputs + * @return a GInferOutputs + */ +template cv::GInferOutputs +infer(const std::string& tag, const cv::GInferInputs& inputs) +{ + std::vector args; + std::vector names; + cv::GKinds kinds; + + cv::detail::unpackBlobs(inputs.getBlobs(), args, names, kinds); + + auto call = cv::detail::makeCall(tag, + std::move(args), + std::move(names), + std::move(kinds)); + + return cv::GInferOutputs{std::move(call)}; +} + +/** @brief Calculates response for the generic network + * for the specified region in the source image. + * Currently expects a single-input network only. + * + * @param tag a network tag + * @param roi a an object describing the region of interest + * in the source image. May be calculated in the same graph dynamically. + * @param inputs networks's inputs + * @return a cv::GInferOutputs + */ +template cv::GInferOutputs +infer(const std::string& tag, const cv::GOpaque& roi, const cv::GInferInputs& inputs) +{ + return cv::detail::inferGenericROI(tag, roi, inputs); +} + +/** @brief Calculates responses for the specified network + * for every region in the source image. + * + * @param tag a network tag + * @param rois a list of rectangles describing regions of interest + * in the source image. Usually an output of object detector or tracker. + * @param inputs networks's inputs + * @return a cv::GInferListOutputs + */ +template cv::GInferListOutputs +infer(const std::string& tag, const cv::GArray& rois, const cv::GInferInputs& inputs) +{ + return cv::detail::inferGenericROI(tag, rois, inputs); +} + +/** @brief Calculates responses for the specified network + * for every region in the source image, extended version. + * + * @param tag a network tag + * @param in a source image containing regions of interest. + * @param inputs networks's inputs + * @return a cv::GInferListOutputs + */ +template +typename std::enable_if::value, cv::GInferListOutputs>::type +infer2(const std::string& tag, + const Input& in, + const cv::GInferListInputs& inputs) +{ + std::vector args; + std::vector names; + cv::GKinds kinds; + + args.emplace_back(in); + auto k = cv::detail::GOpaqueTraits::kind; + kinds.emplace_back(k); + + for (auto&& p : inputs.getBlobs()) { + names.emplace_back(p.first); + switch (p.second.index()) { + case cv::GInferListInputs::StorageT::index_of>(): + args.emplace_back(cv::util::get>(p.second)); + kinds.emplace_back(cv::detail::OpaqueKind::CV_MAT); + break; + case cv::GInferListInputs::StorageT::index_of>(): + args.emplace_back(cv::util::get>(p.second)); + kinds.emplace_back(cv::detail::OpaqueKind::CV_RECT); + break; + default: + GAPI_Assert(false); + } + } + + auto call = cv::detail::makeCall(tag, + std::move(args), + std::move(names), + std::move(kinds)); + + return cv::GInferListOutputs{std::move(call)}; +} + +} // namespace gapi +} // namespace cv + +#endif // GAPI_STANDALONE + +namespace cv { +namespace gapi { + +// Note: the below code _is_ part of STANDALONE build, +// just to make our compiler code compileable. + +// A type-erased form of network parameters. +// Similar to how a type-erased GKernel is represented and used. +/// @private +struct GAPI_EXPORTS_W_SIMPLE GNetParam { + std::string tag; // FIXME: const? + GBackend backend; // Specifies the execution model + util::any params; // Backend-interpreted parameter structure +}; + +/** \addtogroup gapi_compile_args + * @{ + */ +/** + * @brief A container class for network configurations. Similar to + * GKernelPackage. Use cv::gapi::networks() to construct this object. + * + * @sa cv::gapi::networks + */ +struct GAPI_EXPORTS_W_SIMPLE GNetPackage { + GAPI_WRAP GNetPackage() = default; + GAPI_WRAP explicit GNetPackage(std::vector nets); + explicit GNetPackage(std::initializer_list ii); + std::vector backends() const; + std::vector networks; +}; +/** @} gapi_compile_args */ +} // namespace gapi + +namespace detail { +template +gapi::GNetParam strip(T&& t) { + return gapi::GNetParam { t.tag() + , t.backend() + , t.params() + }; +} + +template<> struct CompileArgTag { + static const char* tag() { return "gapi.net_package"; } +}; + +} // namespace cv::detail + +namespace gapi { +template +cv::gapi::GNetPackage networks(Args&&... args) { + return cv::gapi::GNetPackage({ cv::detail::strip(args)... }); +} + +inline cv::gapi::GNetPackage& operator += ( cv::gapi::GNetPackage& lhs, + const cv::gapi::GNetPackage& rhs) { + lhs.networks.reserve(lhs.networks.size() + rhs.networks.size()); + lhs.networks.insert(lhs.networks.end(), rhs.networks.begin(), rhs.networks.end()); + return lhs; +} + +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_INFER_HPP diff --git a/3rdparty/include/opencv2/gapi/infer/bindings_ie.hpp b/3rdparty/include/opencv2/gapi/infer/bindings_ie.hpp new file mode 100644 index 0000000000..fdd4128b1a --- /dev/null +++ b/3rdparty/include/opencv2/gapi/infer/bindings_ie.hpp @@ -0,0 +1,56 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + +#ifndef OPENCV_GAPI_INFER_BINDINGS_IE_HPP +#define OPENCV_GAPI_INFER_BINDINGS_IE_HPP + +#include +#include "opencv2/gapi/own/exports.hpp" // GAPI_EXPORTS +#include // GKernelPackage +#include // Params + +#include + +namespace cv { +namespace gapi { +namespace ie { + +// NB: Used by python wrapper +// This class can be marked as SIMPLE, because it's implemented as pimpl +class GAPI_EXPORTS_W_SIMPLE PyParams { +public: + PyParams() = default; + + PyParams(const std::string &tag, + const std::string &model, + const std::string &weights, + const std::string &device); + + PyParams(const std::string &tag, + const std::string &model, + const std::string &device); + + GBackend backend() const; + std::string tag() const; + cv::util::any params() const; + +private: + std::shared_ptr> m_priv; +}; + +GAPI_EXPORTS_W PyParams params(const std::string &tag, + const std::string &model, + const std::string &weights, + const std::string &device); + +GAPI_EXPORTS_W PyParams params(const std::string &tag, + const std::string &model, + const std::string &device); +} // namespace ie +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_INFER_BINDINGS_IE_HPP diff --git a/3rdparty/include/opencv2/gapi/infer/ie.hpp b/3rdparty/include/opencv2/gapi/infer/ie.hpp new file mode 100644 index 0000000000..2be739e518 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/infer/ie.hpp @@ -0,0 +1,453 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019-2021 Intel Corporation + +#ifndef OPENCV_GAPI_INFER_IE_HPP +#define OPENCV_GAPI_INFER_IE_HPP + +#include +#include +#include +#include +#include // tuple, tuple_size +#include + +#include +#include + +#include // GAPI_EXPORTS +#include // GKernelPackage +#include // Generic + +namespace cv { +namespace gapi { +// FIXME: introduce a new sub-namespace for NN? + +/** + * @brief This namespace contains G-API OpenVINO backend functions, + * structures, and symbols. + */ +namespace ie { + +GAPI_EXPORTS cv::gapi::GBackend backend(); + +/** + * Specifies how G-API and IE should trait input data + * + * In OpenCV, the same cv::Mat is used to represent both + * image and tensor data. Sometimes those are hardly distinguishable, + * so this extra parameter is used to give G-API a hint. + * + * This hint controls how G-API reinterprets the data when converting + * it to IE Blob format (and which layout/etc is assigned to this data). + */ +enum class TraitAs: int +{ + TENSOR, //!< G-API traits an associated cv::Mat as a raw tensor and passes dimensions as-is + IMAGE //!< G-API traits an associated cv::Mat as an image so creates an "image" blob (NCHW/NHWC, etc) +}; + +using IEConfig = std::map; + +namespace detail { +struct ParamDesc { + std::string model_path; + std::string weights_path; + std::string device_id; + + std::vector input_names; + std::vector output_names; + + using ConstInput = std::pair; + std::unordered_map const_inputs; + + std::size_t num_in; + std::size_t num_out; + + enum class Kind {Load, Import}; + Kind kind; + bool is_generic; + IEConfig config; + + std::map> reshape_table; + std::unordered_set layer_names_to_reshape; + + // NB: Number of asyncrhonious infer requests + size_t nireq; + + // NB: An optional config to setup RemoteContext for IE + cv::util::any context_config; +}; +} // namespace detail + +// FIXME: this is probably a shared (reusable) thing +template +struct PortCfg { + using In = std::array + < std::string + , std::tuple_size::value >; + using Out = std::array + < std::string + , std::tuple_size::value >; +}; + +/** + * @brief This structure provides functions + * that fill inference parameters for "OpenVINO Toolkit" model. + */ +template class Params { +public: + /** @brief Class constructor. + + Constructs Params based on model information and specifies default values for other + inference description parameters. Model is loaded and compiled using "OpenVINO Toolkit". + + @param model Path to topology IR (.xml file). + @param weights Path to weights (.bin file). + @param device target device to use. + */ + Params(const std::string &model, + const std::string &weights, + const std::string &device) + : desc{ model, weights, device, {}, {}, {} + , std::tuple_size::value // num_in + , std::tuple_size::value // num_out + , detail::ParamDesc::Kind::Load + , false + , {} + , {} + , {} + , 1u + , {}} { + }; + + /** @overload + Use this constructor to work with pre-compiled network. + Model is imported from a pre-compiled blob. + + @param model Path to model. + @param device target device to use. + */ + Params(const std::string &model, + const std::string &device) + : desc{ model, {}, device, {}, {}, {} + , std::tuple_size::value // num_in + , std::tuple_size::value // num_out + , detail::ParamDesc::Kind::Import + , false + , {} + , {} + , {} + , 1u + , {}} { + }; + + /** @brief Specifies sequence of network input layers names for inference. + + The function is used to associate cv::gapi::infer<> inputs with the model inputs. + Number of names has to match the number of network inputs as defined in G_API_NET(). + In case a network has only single input layer, there is no need to specify name manually. + + @param layer_names std::array where N is the number of inputs + as defined in the @ref G_API_NET. Contains names of input layers. + @return reference to this parameter structure. + */ + Params& cfgInputLayers(const typename PortCfg::In &layer_names) { + desc.input_names.clear(); + desc.input_names.reserve(layer_names.size()); + std::copy(layer_names.begin(), layer_names.end(), + std::back_inserter(desc.input_names)); + return *this; + } + + /** @brief Specifies sequence of network output layers names for inference. + + The function is used to associate cv::gapi::infer<> outputs with the model outputs. + Number of names has to match the number of network outputs as defined in G_API_NET(). + In case a network has only single output layer, there is no need to specify name manually. + + @param layer_names std::array where N is the number of outputs + as defined in the @ref G_API_NET. Contains names of output layers. + @return reference to this parameter structure. + */ + Params& cfgOutputLayers(const typename PortCfg::Out &layer_names) { + desc.output_names.clear(); + desc.output_names.reserve(layer_names.size()); + std::copy(layer_names.begin(), layer_names.end(), + std::back_inserter(desc.output_names)); + return *this; + } + + /** @brief Specifies a constant input. + + The function is used to set a constant input. This input has to be + a preprocessed tensor if its type is TENSOR. Need to provide name of the + network layer which will receive provided data. + + @param layer_name Name of network layer. + @param data cv::Mat that contains data which will be associated with network layer. + @param hint Input type @sa cv::gapi::ie::TraitAs. + @return reference to this parameter structure. + */ + Params& constInput(const std::string &layer_name, + const cv::Mat &data, + TraitAs hint = TraitAs::TENSOR) { + desc.const_inputs[layer_name] = {data, hint}; + return *this; + } + + /** @brief Specifies OpenVINO plugin configuration. + + The function is used to set configuration for OpenVINO plugin. Some parameters + can be different for each plugin. Please follow https://docs.openvinotoolkit.org/latest/index.html + to check information about specific plugin. + + @param cfg Map of pairs: (config parameter name, config parameter value). + @return reference to this parameter structure. + */ + Params& pluginConfig(const IEConfig& cfg) { + desc.config = cfg; + return *this; + } + + /** @overload + Function with a rvalue parameter. + + @param cfg rvalue map of pairs: (config parameter name, config parameter value). + @return reference to this parameter structure. + */ + Params& pluginConfig(IEConfig&& cfg) { + desc.config = std::move(cfg); + return *this; + } + + /** @brief Specifies configuration for RemoteContext in InferenceEngine. + + When RemoteContext is configured the backend imports the networks using the context. + It also expects cv::MediaFrames to be actually remote, to operate with blobs via the context. + + @param ctx_cfg cv::util::any value which holds InferenceEngine::ParamMap. + @return reference to this parameter structure. + */ + Params& cfgContextParams(const cv::util::any& ctx_cfg) { + desc.context_config = ctx_cfg; + return *this; + } + + /** @overload + Function with an rvalue parameter. + + @param ctx_cfg cv::util::any value which holds InferenceEngine::ParamMap. + @return reference to this parameter structure. + */ + Params& cfgContextParams(cv::util::any&& ctx_cfg) { + desc.context_config = std::move(ctx_cfg); + return *this; + } + + /** @brief Specifies number of asynchronous inference requests. + + @param nireq Number of inference asynchronous requests. + @return reference to this parameter structure. + */ + Params& cfgNumRequests(size_t nireq) { + GAPI_Assert(nireq > 0 && "Number of infer requests must be greater than zero!"); + desc.nireq = nireq; + return *this; + } + + /** @brief Specifies new input shapes for the network inputs. + + The function is used to specify new input shapes for the network inputs. + Follow https://docs.openvinotoolkit.org/latest/classInferenceEngine_1_1networkNetwork.html + for additional information. + + @param reshape_table Map of pairs: name of corresponding data and its dimension. + @return reference to this parameter structure. + */ + Params& cfgInputReshape(const std::map>& reshape_table) { + desc.reshape_table = reshape_table; + return *this; + } + + /** @overload */ + Params& cfgInputReshape(std::map>&& reshape_table) { + desc.reshape_table = std::move(reshape_table); + return *this; + } + + /** @overload + + @param layer_name Name of layer. + @param layer_dims New dimensions for this layer. + @return reference to this parameter structure. + */ + Params& cfgInputReshape(const std::string& layer_name, const std::vector& layer_dims) { + desc.reshape_table.emplace(layer_name, layer_dims); + return *this; + } + + /** @overload */ + Params& cfgInputReshape(std::string&& layer_name, std::vector&& layer_dims) { + desc.reshape_table.emplace(layer_name, layer_dims); + return *this; + } + + /** @overload + + @param layer_names set of names of network layers that will be used for network reshape. + @return reference to this parameter structure. + */ + Params& cfgInputReshape(const std::unordered_set& layer_names) { + desc.layer_names_to_reshape = layer_names; + return *this; + } + + /** @overload + + @param layer_names rvalue set of the selected layers will be reshaped automatically + its input image size. + @return reference to this parameter structure. + */ + Params& cfgInputReshape(std::unordered_set&& layer_names) { + desc.layer_names_to_reshape = std::move(layer_names); + return *this; + } + + // BEGIN(G-API's network parametrization API) + GBackend backend() const { return cv::gapi::ie::backend(); } + std::string tag() const { return Net::tag(); } + cv::util::any params() const { return { desc }; } + // END(G-API's network parametrization API) + +protected: + detail::ParamDesc desc; +}; + +/* +* @brief This structure provides functions for generic network type that +* fill inference parameters. +* @see struct Generic +*/ +template<> +class Params { +public: + /** @brief Class constructor. + + Constructs Params based on model information and sets default values for other + inference description parameters. Model is loaded and compiled using OpenVINO Toolkit. + + @param tag string tag of the network for which these parameters are intended. + @param model path to topology IR (.xml file). + @param weights path to weights (.bin file). + @param device target device to use. + */ + Params(const std::string &tag, + const std::string &model, + const std::string &weights, + const std::string &device) + : desc{ model, weights, device, {}, {}, {}, 0u, 0u, + detail::ParamDesc::Kind::Load, true, {}, {}, {}, 1u, + {}}, + m_tag(tag) { + }; + + /** @overload + + This constructor for pre-compiled networks. Model is imported from pre-compiled + blob. + + @param tag string tag of the network for which these parameters are intended. + @param model path to model. + @param device target device to use. + */ + Params(const std::string &tag, + const std::string &model, + const std::string &device) + : desc{ model, {}, device, {}, {}, {}, 0u, 0u, + detail::ParamDesc::Kind::Import, true, {}, {}, {}, 1u, + {}}, + m_tag(tag) { + }; + + /** @see ie::Params::pluginConfig. */ + Params& pluginConfig(const IEConfig& cfg) { + desc.config = cfg; + return *this; + } + + /** @overload */ + Params& pluginConfig(IEConfig&& cfg) { + desc.config = std::move(cfg); + return *this; + } + + /** @see ie::Params::constInput. */ + Params& constInput(const std::string &layer_name, + const cv::Mat &data, + TraitAs hint = TraitAs::TENSOR) { + desc.const_inputs[layer_name] = {data, hint}; + return *this; + } + + /** @see ie::Params::cfgNumRequests. */ + Params& cfgNumRequests(size_t nireq) { + GAPI_Assert(nireq > 0 && "Number of infer requests must be greater than zero!"); + desc.nireq = nireq; + return *this; + } + + /** @see ie::Params::cfgInputReshape */ + Params& cfgInputReshape(const std::map>&reshape_table) { + desc.reshape_table = reshape_table; + return *this; + } + + /** @overload */ + Params& cfgInputReshape(std::map> && reshape_table) { + desc.reshape_table = std::move(reshape_table); + return *this; + } + + /** @overload */ + Params& cfgInputReshape(std::string && layer_name, std::vector && layer_dims) { + desc.reshape_table.emplace(layer_name, layer_dims); + return *this; + } + + /** @overload */ + Params& cfgInputReshape(const std::string & layer_name, const std::vector&layer_dims) { + desc.reshape_table.emplace(layer_name, layer_dims); + return *this; + } + + /** @overload */ + Params& cfgInputReshape(std::unordered_set && layer_names) { + desc.layer_names_to_reshape = std::move(layer_names); + return *this; + } + + /** @overload */ + Params& cfgInputReshape(const std::unordered_set&layer_names) { + desc.layer_names_to_reshape = layer_names; + return *this; + } + + // BEGIN(G-API's network parametrization API) + GBackend backend() const { return cv::gapi::ie::backend(); } + std::string tag() const { return m_tag; } + cv::util::any params() const { return { desc }; } + // END(G-API's network parametrization API) + +protected: + detail::ParamDesc desc; + std::string m_tag; +}; + +} // namespace ie +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_INFER_IE_HPP diff --git a/3rdparty/include/opencv2/gapi/infer/onnx.hpp b/3rdparty/include/opencv2/gapi/infer/onnx.hpp new file mode 100644 index 0000000000..bb5ef6c59e --- /dev/null +++ b/3rdparty/include/opencv2/gapi/infer/onnx.hpp @@ -0,0 +1,284 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020-2021 Intel Corporation + +#ifndef OPENCV_GAPI_INFER_ONNX_HPP +#define OPENCV_GAPI_INFER_ONNX_HPP + +#include +#include +#include +#include // tuple, tuple_size + +#include +#include + +#include // GAPI_EXPORTS +#include // GKernelPackage + +namespace cv { +namespace gapi { + +/** + * @brief This namespace contains G-API ONNX Runtime backend functions, structures, and symbols. + */ +namespace onnx { + +GAPI_EXPORTS cv::gapi::GBackend backend(); + +enum class TraitAs: int { + TENSOR, //!< G-API traits an associated cv::Mat as a raw tensor + // and passes dimensions as-is + IMAGE //!< G-API traits an associated cv::Mat as an image so + // creates an "image" blob (NCHW/NHWC, etc) +}; + +using PostProc = std::function &, + std::unordered_map &)>; + +namespace detail { +/** +* @brief This structure contains description of inference parameters +* which is specific to ONNX models. +*/ +struct ParamDesc { + std::string model_path; //!< Path to model. + + // NB: nun_* may differ from topology's real input/output port numbers + // (e.g. topology's partial execution) + std::size_t num_in; //!< How many inputs are defined in the operation + std::size_t num_out; //!< How many outputs are defined in the operation + + // NB: Here order follows the `Net` API + std::vector input_names; //!< Names of input network layers. + std::vector output_names; //!< Names of output network layers. + + using ConstInput = std::pair; + std::unordered_map const_inputs; //!< Map with pair of name of network layer and ConstInput which will be associated with this. + + std::vector mean; //!< Mean values for preprocessing. + std::vector stdev; //!< Standard deviation values for preprocessing. + + std::vector out_metas; //!< Out meta information about your output (type, dimension). + PostProc custom_post_proc; //!< Post processing function. + + std::vector normalize; //!< Vector of bool values that enabled or disabled normalize of input data. + + std::vector names_to_remap; //!< Names of output layers that will be processed in PostProc function. +}; +} // namespace detail + +template +struct PortCfg { + using In = std::array + < std::string + , std::tuple_size::value >; + using Out = std::array + < std::string + , std::tuple_size::value >; + using NormCoefs = std::array + < cv::Scalar + , std::tuple_size::value >; + using Normalize = std::array + < bool + , std::tuple_size::value >; +}; + +/** + * Contains description of inference parameters and kit of functions that + * fill this parameters. + */ +template class Params { +public: + /** @brief Class constructor. + + Constructs Params based on model information and sets default values for other + inference description parameters. + + @param model Path to model (.onnx file). + */ + Params(const std::string &model) { + desc.model_path = model; + desc.num_in = std::tuple_size::value; + desc.num_out = std::tuple_size::value; + }; + + /** @brief Specifies sequence of network input layers names for inference. + + The function is used to associate data of graph inputs with input layers of + network topology. Number of names has to match the number of network inputs. If a network + has only one input layer, there is no need to call it as the layer is + associated with input automatically but this doesn't prevent you from + doing it yourself. Count of names has to match to number of network inputs. + + @param layer_names std::array where N is the number of inputs + as defined in the @ref G_API_NET. Contains names of input layers. + @return the reference on modified object. + */ + Params& cfgInputLayers(const typename PortCfg::In &layer_names) { + desc.input_names.assign(layer_names.begin(), layer_names.end()); + return *this; + } + + /** @brief Specifies sequence of output layers names for inference. + + The function is used to associate data of graph outputs with output layers of + network topology. If a network has only one output layer, there is no need to call it + as the layer is associated with ouput automatically but this doesn't prevent + you from doing it yourself. Count of names has to match to number of network + outputs or you can set your own output but for this case you have to + additionally use @ref cfgPostProc function. + + @param layer_names std::array where N is the number of outputs + as defined in the @ref G_API_NET. Contains names of output layers. + @return the reference on modified object. + */ + Params& cfgOutputLayers(const typename PortCfg::Out &layer_names) { + desc.output_names.assign(layer_names.begin(), layer_names.end()); + return *this; + } + + /** @brief Sets a constant input. + + The function is used to set constant input. This input has to be + a prepared tensor since preprocessing is disabled for this case. You should + provide name of network layer which will receive provided data. + + @param layer_name Name of network layer. + @param data cv::Mat that contains data which will be associated with network layer. + @param hint Type of input (TENSOR). + @return the reference on modified object. + */ + Params& constInput(const std::string &layer_name, + const cv::Mat &data, + TraitAs hint = TraitAs::TENSOR) { + desc.const_inputs[layer_name] = {data, hint}; + return *this; + } + + /** @brief Specifies mean value and standard deviation for preprocessing. + + The function is used to set mean value and standard deviation for preprocessing + of input data. + + @param m std::array where N is the number of inputs + as defined in the @ref G_API_NET. Contains mean values. + @param s std::array where N is the number of inputs + as defined in the @ref G_API_NET. Contains standard deviation values. + @return the reference on modified object. + */ + Params& cfgMeanStd(const typename PortCfg::NormCoefs &m, + const typename PortCfg::NormCoefs &s) { + desc.mean.assign(m.begin(), m.end()); + desc.stdev.assign(s.begin(), s.end()); + return *this; + } + + /** @brief Configures graph output and provides the post processing function from user. + + The function is used when you work with networks with dynamic outputs. + Since we can't know dimensions of inference result needs provide them for + construction of graph output. This dimensions can differ from inference result. + So you have to provide @ref PostProc function that gets information from inference + result and fill output which is constructed by dimensions from out_metas. + + @param out_metas Out meta information about your output (type, dimension). + @param remap_function Post processing function, which has two parameters. First is onnx + result, second is graph output. Both parameters is std::map that contain pair of + layer's name and cv::Mat. + @return the reference on modified object. + */ + Params& cfgPostProc(const std::vector &out_metas, + const PostProc &remap_function) { + desc.out_metas = out_metas; + desc.custom_post_proc = remap_function; + return *this; + } + + /** @overload + Function with a rvalue parameters. + + @param out_metas rvalue out meta information about your output (type, dimension). + @param remap_function rvalue post processing function, which has two parameters. First is onnx + result, second is graph output. Both parameters is std::map that contain pair of + layer's name and cv::Mat. + @return the reference on modified object. + */ + Params& cfgPostProc(std::vector &&out_metas, + PostProc &&remap_function) { + desc.out_metas = std::move(out_metas); + desc.custom_post_proc = std::move(remap_function); + return *this; + } + + /** @overload + The function has additional parameter names_to_remap. This parameter provides + information about output layers which will be used for inference and post + processing function. + + @param out_metas Out meta information. + @param remap_function Post processing function. + @param names_to_remap Names of output layers. network's inference will + be done on these layers. Inference's result will be processed in post processing + function using these names. + @return the reference on modified object. + */ + Params& cfgPostProc(const std::vector &out_metas, + const PostProc &remap_function, + const std::vector &names_to_remap) { + desc.out_metas = out_metas; + desc.custom_post_proc = remap_function; + desc.names_to_remap = names_to_remap; + return *this; + } + + /** @overload + Function with a rvalue parameters and additional parameter names_to_remap. + + @param out_metas rvalue out meta information. + @param remap_function rvalue post processing function. + @param names_to_remap rvalue names of output layers. network's inference will + be done on these layers. Inference's result will be processed in post processing + function using these names. + @return the reference on modified object. + */ + Params& cfgPostProc(std::vector &&out_metas, + PostProc &&remap_function, + std::vector &&names_to_remap) { + desc.out_metas = std::move(out_metas); + desc.custom_post_proc = std::move(remap_function); + desc.names_to_remap = std::move(names_to_remap); + return *this; + } + + /** @brief Specifies normalize parameter for preprocessing. + + The function is used to set normalize parameter for preprocessing of input data. + + @param normalizations std::array where N is the number of inputs + as defined in the @ref G_API_NET. Сontains bool values that enabled or disabled + normalize of input data. + @return the reference on modified object. + */ + Params& cfgNormalize(const typename PortCfg::Normalize &normalizations) { + desc.normalize.assign(normalizations.begin(), normalizations.end()); + return *this; + } + + // BEGIN(G-API's network parametrization API) + GBackend backend() const { return cv::gapi::onnx::backend(); } + std::string tag() const { return Net::tag(); } + cv::util::any params() const { return { desc }; } + // END(G-API's network parametrization API) + +protected: + detail::ParamDesc desc; +}; + +} // namespace onnx +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_INFER_HPP diff --git a/3rdparty/include/opencv2/gapi/infer/parsers.hpp b/3rdparty/include/opencv2/gapi/infer/parsers.hpp new file mode 100644 index 0000000000..c7308dd39f --- /dev/null +++ b/3rdparty/include/opencv2/gapi/infer/parsers.hpp @@ -0,0 +1,138 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + + +#ifndef OPENCV_GAPI_PARSERS_HPP +#define OPENCV_GAPI_PARSERS_HPP + +#include // std::tuple + +#include +#include + +namespace cv { namespace gapi { +namespace nn { +namespace parsers { + using GRects = GArray; + using GDetections = std::tuple, GArray>; + + G_TYPED_KERNEL(GParseSSDBL, , float, int)>, + "org.opencv.nn.parsers.parseSSD_BL") { + static std::tuple outMeta(const GMatDesc&, const GOpaqueDesc&, float, int) { + return std::make_tuple(empty_array_desc(), empty_array_desc()); + } + }; + + G_TYPED_KERNEL(GParseSSD, , float, bool, bool)>, + "org.opencv.nn.parsers.parseSSD") { + static GArrayDesc outMeta(const GMatDesc&, const GOpaqueDesc&, float, bool, bool) { + return empty_array_desc(); + } + }; + + G_TYPED_KERNEL(GParseYolo, , float, float, std::vector)>, + "org.opencv.nn.parsers.parseYolo") { + static std::tuple outMeta(const GMatDesc&, const GOpaqueDesc&, + float, float, const std::vector&) { + return std::make_tuple(empty_array_desc(), empty_array_desc()); + } + static const std::vector& defaultAnchors() { + static std::vector anchors { + 0.57273f, 0.677385f, 1.87446f, 2.06253f, 3.33843f, 5.47434f, 7.88282f, 3.52778f, 9.77052f, 9.16828f + }; + return anchors; + } + }; +} // namespace parsers +} // namespace nn + +/** @brief Parses output of SSD network. + +Extracts detection information (box, confidence, label) from SSD output and +filters it by given confidence and label. + +@note Function textual ID is "org.opencv.nn.parsers.parseSSD_BL" + +@param in Input CV_32F tensor with {1,1,N,7} dimensions. +@param inSz Size to project detected boxes to (size of the input image). +@param confidenceThreshold If confidence of the +detection is smaller than confidence threshold, detection is rejected. +@param filterLabel If provided (!= -1), only detections with +given label will get to the output. +@return a tuple with a vector of detected boxes and a vector of appropriate labels. +*/ +GAPI_EXPORTS_W std::tuple, GArray> parseSSD(const GMat& in, + const GOpaque& inSz, + const float confidenceThreshold = 0.5f, + const int filterLabel = -1); + +/** @brief Parses output of SSD network. + +Extracts detection information (box, confidence) from SSD output and +filters it by given confidence and by going out of bounds. + +@note Function textual ID is "org.opencv.nn.parsers.parseSSD" + +@param in Input CV_32F tensor with {1,1,N,7} dimensions. +@param inSz Size to project detected boxes to (size of the input image). +@param confidenceThreshold If confidence of the +detection is smaller than confidence threshold, detection is rejected. +@param alignmentToSquare If provided true, bounding boxes are extended to squares. +The center of the rectangle remains unchanged, the side of the square is +the larger side of the rectangle. +@param filterOutOfBounds If provided true, out-of-frame boxes are filtered. +@return a vector of detected bounding boxes. +*/ +GAPI_EXPORTS_W GArray parseSSD(const GMat& in, + const GOpaque& inSz, + const float confidenceThreshold, + const bool alignmentToSquare, + const bool filterOutOfBounds); + +/** @brief Parses output of Yolo network. + +Extracts detection information (box, confidence, label) from Yolo output, +filters it by given confidence and performs non-maximum supression for overlapping boxes. + +@note Function textual ID is "org.opencv.nn.parsers.parseYolo" + +@param in Input CV_32F tensor with {1,13,13,N} dimensions, N should satisfy: +\f[\texttt{N} = (\texttt{num_classes} + \texttt{5}) * \texttt{5},\f] +where num_classes - a number of classes Yolo network was trained with. +@param inSz Size to project detected boxes to (size of the input image). +@param confidenceThreshold If confidence of the +detection is smaller than confidence threshold, detection is rejected. +@param nmsThreshold Non-maximum supression threshold which controls minimum +relative box intersection area required for rejecting the box with a smaller confidence. +If 1.f, nms is not performed and no boxes are rejected. +@param anchors Anchors Yolo network was trained with. +@note The default anchor values are specified for YOLO v2 Tiny as described in Intel Open Model Zoo +documentation. +@return a tuple with a vector of detected boxes and a vector of appropriate labels. +*/ +GAPI_EXPORTS_W std::tuple, GArray> parseYolo(const GMat& in, + const GOpaque& inSz, + const float confidenceThreshold = 0.5f, + const float nmsThreshold = 0.5f, + const std::vector& anchors + = nn::parsers::GParseYolo::defaultAnchors()); + +} // namespace gapi +} // namespace cv + +// Reimport parseSSD & parseYolo under their initial namespace +namespace cv { +namespace gapi { +namespace streaming { + +using cv::gapi::parseSSD; +using cv::gapi::parseYolo; + +} // namespace streaming +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_PARSERS_HPP diff --git a/3rdparty/include/opencv2/gapi/media.hpp b/3rdparty/include/opencv2/gapi/media.hpp new file mode 100644 index 0000000000..aa7d6d6a1f --- /dev/null +++ b/3rdparty/include/opencv2/gapi/media.hpp @@ -0,0 +1,229 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + +#ifndef OPENCV_GAPI_MEDIA_HPP +#define OPENCV_GAPI_MEDIA_HPP + +#include // unique_ptr<>, shared_ptr<> +#include // array<> +#include // function<> +#include // forward<>() + +#include +#include + +namespace cv { + +/** \addtogroup gapi_data_structures + * @{ + * + * @brief Extra G-API data structures used to pass input/output data + * to the graph for processing. + */ +/** + * @brief cv::MediaFrame class represents an image/media frame + * obtained from an external source. + * + * cv::MediaFrame represents image data as specified in + * cv::MediaFormat. cv::MediaFrame is designed to be a thin wrapper over some + * external memory of buffer; the class itself provides an uniform + * interface over such types of memory. cv::MediaFrame wraps data from + * a camera driver or from a media codec and provides an abstraction + * layer over this memory to G-API. MediaFrame defines a compact interface + * to access and manage the underlying data; the implementation is + * fully defined by the associated Adapter (which is usually + * user-defined). + * + * @sa cv::RMat + */ +class GAPI_EXPORTS MediaFrame { +public: + /// This enum defines different types of cv::MediaFrame provided + /// access to the underlying data. Note that different flags can't + /// be combined in this version. + enum class Access { + R, ///< Access data for reading + W, ///< Access data for writing + }; + class IAdapter; + class View; + using AdapterPtr = std::unique_ptr; + + /** + * @brief Constructs an empty MediaFrame + * + * The constructed object has no any data associated with it. + */ + MediaFrame(); + + /** + * @brief Constructs a MediaFrame with the given + * Adapter. MediaFrame takes ownership over the passed adapter. + * + * @param p an unique pointer to instance of IAdapter derived class. + */ + explicit MediaFrame(AdapterPtr &&p); + + /** + * @overload + * @brief Constructs a MediaFrame with the given parameters for + * the Adapter. The adapter of type `T` is costructed on the fly. + * + * @param args list of arguments to construct an adapter of type + * `T`. + */ + template static cv::MediaFrame Create(Args&&... args); + + /** + * @brief Obtain access to the underlying data with the given + * mode. + * + * Depending on the associated Adapter and the data wrapped, this + * method may be cheap (e.g., the underlying memory is local) or + * costly (if the underlying memory is external or device + * memory). + * + * @param mode an access mode flag + * @return a MediaFrame::View object. The views should be handled + * carefully, refer to the MediaFrame::View documentation for details. + */ + View access(Access mode) const; + + /** + * @brief Returns a media frame descriptor -- the information + * about the media format, dimensions, etc. + * @return a cv::GFrameDesc + */ + cv::GFrameDesc desc() const; + + // FIXME: design a better solution + // Should be used only if the actual adapter provides implementation + /// @private -- exclude from the OpenCV documentation for now. + cv::util::any blobParams() const; + + /** + * @brief Casts and returns the associated MediaFrame adapter to + * the particular adapter type `T`, returns nullptr if the type is + * different. + * + * This method may be useful if the adapter type is known by the + * caller, and some lower level access to the memory is required. + * Depending on the memory type, it may be more efficient than + * access(). + * + * @return a pointer to the adapter object, nullptr if the adapter + * type is different. + */ + template T* get() const { + static_assert(std::is_base_of::value, + "T is not derived from cv::MediaFrame::IAdapter!"); + auto* adapter = getAdapter(); + GAPI_Assert(adapter != nullptr); + return dynamic_cast(adapter); + } + +private: + struct Priv; + std::shared_ptr m; + IAdapter* getAdapter() const; +}; + +template +inline cv::MediaFrame cv::MediaFrame::Create(Args&&... args) { + std::unique_ptr ptr(new T(std::forward(args)...)); + return cv::MediaFrame(std::move(ptr)); +} + +/** + * @brief Provides access to the MediaFrame's underlying data. + * + * This object contains the necessary information to access the pixel + * data of the associated MediaFrame: arrays of pointers and strides + * (distance between every plane row, in bytes) for every image + * plane, as defined in cv::MediaFormat. + * There may be up to four image planes in MediaFrame. + * + * Depending on the MediaFrame::Access flag passed in + * MediaFrame::access(), a MediaFrame::View may be read- or + * write-only. + * + * Depending on the MediaFrame::IAdapter implementation associated + * with the parent MediaFrame, writing to memory with + * MediaFrame::Access::R flag may have no effect or lead to + * undefined behavior. Same applies to reading the memory with + * MediaFrame::Access::W flag -- again, depending on the IAdapter + * implementation, the host-side buffer the view provides access to + * may have no current data stored in (so in-place editing of the + * buffer contents may not be possible). + * + * MediaFrame::View objects must be handled carefully, as an external + * resource associated with MediaFrame may be locked for the time the + * MediaFrame::View object exists. Obtaining MediaFrame::View should + * be seen as "map" and destroying it as "unmap" in the "map/unmap" + * idiom (applicable to OpenCL, device memory, remote + * memory). + * + * When a MediaFrame buffer is accessed for writing, and the memory + * under MediaFrame::View::Ptrs is altered, the data synchronization + * of a host-side and device/remote buffer is not guaranteed until the + * MediaFrame::View is destroyed. In other words, the real data on the + * device or in a remote target may be updated at the MediaFrame::View + * destruction only -- but it depends on the associated + * MediaFrame::IAdapter implementation. + */ +class GAPI_EXPORTS MediaFrame::View final { +public: + static constexpr const size_t MAX_PLANES = 4; + using Ptrs = std::array; + using Strides = std::array; // in bytes + using Callback = std::function; + + /// @private + View(Ptrs&& ptrs, Strides&& strs, Callback &&cb = [](){}); + + /// @private + View(const View&) = delete; + + /// @private + View(View&&) = default; + + /// @private + View& operator = (const View&) = delete; + + ~View(); + + Ptrs ptr; ///< Array of image plane pointers + Strides stride; ///< Array of image plane strides, in bytes. + +private: + Callback m_cb; +}; + +/** + * @brief An interface class for MediaFrame data adapters. + * + * Implement this interface to wrap media data in the MediaFrame. It + * makes sense to implement this class if there is a custom + * cv::gapi::wip::IStreamSource defined -- in this case, a stream + * source can produce MediaFrame objects with this adapter and the + * media data may be passed to graph without any copy. For example, a + * GStreamer-based stream source can implement an adapter over + * `GstBuffer` and G-API will transparently use it in the graph. + */ +class GAPI_EXPORTS MediaFrame::IAdapter { +public: + virtual ~IAdapter() = 0; + virtual cv::GFrameDesc meta() const = 0; + virtual MediaFrame::View access(MediaFrame::Access) = 0; + // FIXME: design a better solution + // The default implementation does nothing + virtual cv::util::any blobParams() const; +}; +/** @} */ + +} //namespace cv + +#endif // OPENCV_GAPI_MEDIA_HPP diff --git a/3rdparty/include/opencv2/gapi/ocl/core.hpp b/3rdparty/include/opencv2/gapi/ocl/core.hpp new file mode 100644 index 0000000000..6c7587096c --- /dev/null +++ b/3rdparty/include/opencv2/gapi/ocl/core.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OCL_CORE_API_HPP +#define OPENCV_GAPI_OCL_CORE_API_HPP + +#include // GAPI_EXPORTS +#include // GKernelPackage + +namespace cv { +namespace gapi { +namespace core { +namespace ocl { + + GAPI_EXPORTS_W cv::gapi::GKernelPackage kernels(); + +} // namespace ocl +} // namespace core +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_OCL_CORE_API_HPP diff --git a/3rdparty/include/opencv2/gapi/ocl/goclkernel.hpp b/3rdparty/include/opencv2/gapi/ocl/goclkernel.hpp new file mode 100644 index 0000000000..6a2f1df769 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/ocl/goclkernel.hpp @@ -0,0 +1,249 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GOCLKERNEL_HPP +#define OPENCV_GAPI_GOCLKERNEL_HPP + +#include +#include +#include +#include + +#include +#include +#include +#include + +// FIXME: namespace scheme for backends? +namespace cv { + +namespace gimpl +{ + // Forward-declare an internal class + class GOCLExecutable; +} // namespace gimpl + +namespace gapi +{ +/** + * @brief This namespace contains G-API OpenCL backend functions, structures, and symbols. + */ +namespace ocl +{ + /** + * \addtogroup gapi_std_backends G-API Standard Backends + * @{ + */ + /** + * @brief Get a reference to OCL backend. + * + * At the moment, the OCL backend is built atop of OpenCV + * "Transparent API" (T-API), see cv::UMat for details. + * + * @sa gapi_std_backends + */ + GAPI_EXPORTS cv::gapi::GBackend backend(); + /** @} */ +} // namespace ocl +} // namespace gapi + + +// Represents arguments which are passed to a wrapped OCL function +// FIXME: put into detail? +class GAPI_EXPORTS GOCLContext +{ +public: + // Generic accessor API + template + const T& inArg(int input) { return m_args.at(input).get(); } + + // Syntax sugar + const cv::UMat& inMat(int input); + cv::UMat& outMatR(int output); // FIXME: Avoid cv::Mat m = ctx.outMatR() + + const cv::Scalar& inVal(int input); + cv::Scalar& outValR(int output); // FIXME: Avoid cv::Scalar s = ctx.outValR() + template std::vector& outVecR(int output) // FIXME: the same issue + { + return outVecRef(output).wref(); + } + template T& outOpaqueR(int output) // FIXME: the same issue + { + return outOpaqueRef(output).wref(); + } + +protected: + detail::VectorRef& outVecRef(int output); + detail::OpaqueRef& outOpaqueRef(int output); + + std::vector m_args; + std::unordered_map m_results; + + + friend class gimpl::GOCLExecutable; +}; + +class GAPI_EXPORTS GOCLKernel +{ +public: + // This function is kernel's execution entry point (does the processing work) + using F = std::function; + + GOCLKernel(); + explicit GOCLKernel(const F& f); + + void apply(GOCLContext &ctx); + +protected: + F m_f; +}; + +// FIXME: This is an ugly ad-hoc implementation. TODO: refactor + +namespace detail +{ +template struct ocl_get_in; +template<> struct ocl_get_in +{ + static cv::UMat get(GOCLContext &ctx, int idx) { return ctx.inMat(idx); } +}; +template<> struct ocl_get_in +{ + static cv::Scalar get(GOCLContext &ctx, int idx) { return ctx.inVal(idx); } +}; +template struct ocl_get_in > +{ + static const std::vector& get(GOCLContext &ctx, int idx) { return ctx.inArg(idx).rref(); } +}; +template struct ocl_get_in > +{ + static const U& get(GOCLContext &ctx, int idx) { return ctx.inArg(idx).rref(); } +}; +template struct ocl_get_in +{ + static T get(GOCLContext &ctx, int idx) { return ctx.inArg(idx); } +}; + +struct tracked_cv_umat{ + //TODO Think if T - API could reallocate UMat to a proper size - how do we handle this ? + //tracked_cv_umat(cv::UMat& m) : r{(m)}, original_data{m.getMat(ACCESS_RW).data} {} + tracked_cv_umat(cv::UMat& m) : r(m), original_data{ nullptr } {} + cv::UMat &r; // FIXME: It was a value (not a reference) before. + // Actually OCL backend should allocate its internal data! + uchar* original_data; + + operator cv::UMat& (){ return r;} + void validate() const{ + //if (r.getMat(ACCESS_RW).data != original_data) + //{ + // util::throw_error + // (std::logic_error + // ("OpenCV kernel output parameter was reallocated. \n" + // "Incorrect meta data was provided ?")); + //} + + } +}; + +template +void postprocess_ocl(Outputs&... outs) +{ + struct + { + void operator()(tracked_cv_umat* bm) { bm->validate(); } + void operator()(...) { } + + } validate; + //dummy array to unfold parameter pack + int dummy[] = { 0, (validate(&outs), 0)... }; + cv::util::suppress_unused_warning(dummy); +} + +template struct ocl_get_out; +template<> struct ocl_get_out +{ + static tracked_cv_umat get(GOCLContext &ctx, int idx) + { + auto& r = ctx.outMatR(idx); + return{ r }; + } +}; +template<> struct ocl_get_out +{ + static cv::Scalar& get(GOCLContext &ctx, int idx) + { + return ctx.outValR(idx); + } +}; +template struct ocl_get_out > +{ + static std::vector& get(GOCLContext &ctx, int idx) { return ctx.outVecR(idx); } +}; +template struct ocl_get_out > +{ + static U& get(GOCLContext &ctx, int idx) { return ctx.outOpaqueR(idx); } +}; + +template +struct OCLCallHelper; + +// FIXME: probably can be simplified with std::apply or analogue. +template +struct OCLCallHelper, std::tuple > +{ + template + struct call_and_postprocess + { + template + static void call(Inputs&&... ins, Outputs&&... outs) + { + //not using a std::forward on outs is deliberate in order to + //cause compilation error, by trying to bind rvalue references to lvalue references + Impl::run(std::forward(ins)..., outs...); + + postprocess_ocl(outs...); + } + }; + + template + static void call_impl(GOCLContext &ctx, detail::Seq, detail::Seq) + { + //TODO: Make sure that OpenCV kernels do not reallocate memory for output parameters + //by comparing it's state (data ptr) before and after the call. + //Convert own::Scalar to cv::Scalar before call kernel and run kernel + //convert cv::Scalar to own::Scalar after call kernel and write back results + call_and_postprocess::get(ctx, IIs))...>::call(ocl_get_in::get(ctx, IIs)..., ocl_get_out::get(ctx, OIs)...); + } + + static void call(GOCLContext &ctx) + { + call_impl(ctx, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } +}; + +} // namespace detail + +template +class GOCLKernelImpl: public cv::detail::OCLCallHelper, + public cv::detail::KernelTag +{ + using P = detail::OCLCallHelper; + +public: + using API = K; + + static cv::gapi::GBackend backend() { return cv::gapi::ocl::backend(); } + static cv::GOCLKernel kernel() { return GOCLKernel(&P::call); } +}; + +#define GAPI_OCL_KERNEL(Name, API) struct Name: public cv::GOCLKernelImpl + +} // namespace cv + +#endif // OPENCV_GAPI_GOCLKERNEL_HPP diff --git a/3rdparty/include/opencv2/gapi/ocl/imgproc.hpp b/3rdparty/include/opencv2/gapi/ocl/imgproc.hpp new file mode 100644 index 0000000000..1bb5911b18 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/ocl/imgproc.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OCL_IMGPROC_API_HPP +#define OPENCV_GAPI_OCL_IMGPROC_API_HPP + +#include // GAPI_EXPORTS +#include // GKernelPackage + +namespace cv { +namespace gapi { +namespace imgproc { +namespace ocl { + + GAPI_EXPORTS GKernelPackage kernels(); + +} // namespace ocl +} // namespace imgproc +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_OCL_IMGPROC_API_HPP diff --git a/3rdparty/include/opencv2/gapi/opencv_includes.hpp b/3rdparty/include/opencv2/gapi/opencv_includes.hpp new file mode 100644 index 0000000000..08b2d6ed02 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/opencv_includes.hpp @@ -0,0 +1,33 @@ +// This file is part of OpenCV project. + +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OPENCV_INCLUDES_HPP +#define OPENCV_GAPI_OPENCV_INCLUDES_HPP + +#if !defined(GAPI_STANDALONE) +# include +# include +# include +# include +#else // Without OpenCV +# include +# include // cv::gapi::own::Rect/Size/Point +# include // cv::gapi::own::Scalar +# include +// replacement of cv's structures: +namespace cv { + using Rect = gapi::own::Rect; + using Size = gapi::own::Size; + using Point = gapi::own::Point; + using Point2f = gapi::own::Point2f; + using Scalar = gapi::own::Scalar; + using Mat = gapi::own::Mat; +} // namespace cv +#endif // !defined(GAPI_STANDALONE) + +#endif // OPENCV_GAPI_OPENCV_INCLUDES_HPP diff --git a/3rdparty/include/opencv2/gapi/operators.hpp b/3rdparty/include/opencv2/gapi/operators.hpp new file mode 100644 index 0000000000..6794b44b6e --- /dev/null +++ b/3rdparty/include/opencv2/gapi/operators.hpp @@ -0,0 +1,70 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OPERATORS_HPP +#define OPENCV_GAPI_OPERATORS_HPP + +#include +#include + +namespace cv +{ +GAPI_EXPORTS cv::GMat operator+(const cv::GMat& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator+(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator+(const cv::GScalar& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator-(const cv::GMat& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator-(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator-(const cv::GScalar& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator*(const cv::GMat& lhs, float rhs); +GAPI_EXPORTS cv::GMat operator*(float lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator*(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator*(const cv::GScalar& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator/(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator/(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator/(const cv::GMat& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator&(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator|(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator^(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator~(const cv::GMat& lhs); + +GAPI_EXPORTS cv::GMat operator&(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator|(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator^(const cv::GScalar& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator&(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator|(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator^(const cv::GMat& lhs, const cv::GScalar& rhs); + +GAPI_EXPORTS cv::GMat operator>(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator>=(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator<(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator<=(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator==(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator!=(const cv::GMat& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator>(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator>=(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator<(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator<=(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator==(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator!=(const cv::GMat& lhs, const cv::GScalar& rhs); + +GAPI_EXPORTS cv::GMat operator>(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator>=(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator<(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator<=(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator==(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator!=(const cv::GScalar& lhs, const cv::GMat& rhs); +} // cv + +#endif // OPENCV_GAPI_OPERATORS_HPP diff --git a/3rdparty/include/opencv2/gapi/own/assert.hpp b/3rdparty/include/opencv2/gapi/own/assert.hpp new file mode 100644 index 0000000000..d50543fdac --- /dev/null +++ b/3rdparty/include/opencv2/gapi/own/assert.hpp @@ -0,0 +1,55 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_ASSERT_HPP +#define OPENCV_GAPI_OWN_ASSERT_HPP + +#include + +#define GAPI_DbgAssertNoOp(expr) { \ + constexpr bool _assert_tmp = false && (expr); \ + cv::util::suppress_unused_warning(_assert_tmp); \ +} + +#if !defined(GAPI_STANDALONE) +#include +#define GAPI_Assert CV_Assert + +#if defined _DEBUG || defined CV_STATIC_ANALYSIS +# define GAPI_DbgAssert CV_DbgAssert +#else +# define GAPI_DbgAssert(expr) GAPI_DbgAssertNoOp(expr) +#endif + +#else +#include +#include +#include + +namespace detail +{ + [[noreturn]] inline void assert_abort(const char* str, int line, const char* file, const char* func) + { + std::stringstream ss; + ss << file << ":" << line << ": Assertion " << str << " in function " << func << " failed\n"; + cv::util::throw_error(std::logic_error(ss.str())); + } +} + +#define GAPI_Assert(expr) \ +{ if (!(expr)) ::detail::assert_abort(#expr, __LINE__, __FILE__, __func__); } + + +#ifdef NDEBUG +# define GAPI_DbgAssert(expr) GAPI_DbgAssertNoOp(expr) +#else +# define GAPI_DbgAssert(expr) GAPI_Assert(expr) +#endif + +#endif // GAPI_STANDALONE + +#endif // OPENCV_GAPI_OWN_ASSERT_HPP diff --git a/3rdparty/include/opencv2/gapi/own/convert.hpp b/3rdparty/include/opencv2/gapi/own/convert.hpp new file mode 100644 index 0000000000..1a8ecd8bc6 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/own/convert.hpp @@ -0,0 +1,55 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_CONVERT_HPP +#define OPENCV_GAPI_OWN_CONVERT_HPP + +#if !defined(GAPI_STANDALONE) + +#include +#include + +namespace cv +{ + template + std::vector to_own(const cv::MatSize &sz) { + std::vector result(sz.dims()); + for (int i = 0; i < sz.dims(); i++) { + // Note: cv::MatSize is not iterable + result[i] = static_cast(sz[i]); + } + return result; + } + + cv::gapi::own::Mat to_own(Mat&&) = delete; + + inline cv::gapi::own::Mat to_own(Mat const& m) { + return (m.dims == 2) + ? cv::gapi::own::Mat{m.rows, m.cols, m.type(), m.data, m.step} + : cv::gapi::own::Mat{to_own(m.size), m.type(), m.data}; + }; + +namespace gapi +{ +namespace own +{ + + inline cv::Mat to_ocv(Mat const& m) { + return m.dims.empty() + ? cv::Mat{m.rows, m.cols, m.type(), m.data, m.step} + : cv::Mat{m.dims, m.type(), m.data}; + } + + cv::Mat to_ocv(Mat&&) = delete; + +} // namespace own +} // namespace gapi +} // namespace cv + +#endif // !defined(GAPI_STANDALONE) + +#endif // OPENCV_GAPI_OWN_CONVERT_HPP diff --git a/3rdparty/include/opencv2/gapi/own/cvdefs.hpp b/3rdparty/include/opencv2/gapi/own/cvdefs.hpp new file mode 100644 index 0000000000..9ec0f89ed8 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/own/cvdefs.hpp @@ -0,0 +1,149 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_CV_DEFS_HPP +#define OPENCV_GAPI_CV_DEFS_HPP + +#if defined(GAPI_STANDALONE) +// Simulate OpenCV definitions taken from various +// OpenCV interface headers if G-API is built in a +// standalone mode. + +// interface.h: + +typedef unsigned char uchar; +typedef char schar; + +typedef unsigned short ushort; + +#define CV_CN_MAX 512 +#define CV_CN_SHIFT 3 +#define CV_DEPTH_MAX (1 << CV_CN_SHIFT) + + +#define CV_8U 0 +#define CV_8S 1 +#define CV_16U 2 +#define CV_16S 3 +#define CV_32S 4 +#define CV_32F 5 +#define CV_64F 6 +#define CV_USRTYPE1 7 + +#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) +#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) + +#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) +#define CV_MAKE_TYPE CV_MAKETYPE + +#define CV_8UC1 CV_MAKETYPE(CV_8U,1) +#define CV_8UC2 CV_MAKETYPE(CV_8U,2) +#define CV_8UC3 CV_MAKETYPE(CV_8U,3) +#define CV_8UC4 CV_MAKETYPE(CV_8U,4) +#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) + +#define CV_8SC1 CV_MAKETYPE(CV_8S,1) +#define CV_8SC2 CV_MAKETYPE(CV_8S,2) +#define CV_8SC3 CV_MAKETYPE(CV_8S,3) +#define CV_8SC4 CV_MAKETYPE(CV_8S,4) +#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) + +#define CV_16UC1 CV_MAKETYPE(CV_16U,1) +#define CV_16UC2 CV_MAKETYPE(CV_16U,2) +#define CV_16UC3 CV_MAKETYPE(CV_16U,3) +#define CV_16UC4 CV_MAKETYPE(CV_16U,4) +#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) + +#define CV_16SC1 CV_MAKETYPE(CV_16S,1) +#define CV_16SC2 CV_MAKETYPE(CV_16S,2) +#define CV_16SC3 CV_MAKETYPE(CV_16S,3) +#define CV_16SC4 CV_MAKETYPE(CV_16S,4) +#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) + +#define CV_32SC1 CV_MAKETYPE(CV_32S,1) +#define CV_32SC2 CV_MAKETYPE(CV_32S,2) +#define CV_32SC3 CV_MAKETYPE(CV_32S,3) +#define CV_32SC4 CV_MAKETYPE(CV_32S,4) +#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) + +#define CV_32FC1 CV_MAKETYPE(CV_32F,1) +#define CV_32FC2 CV_MAKETYPE(CV_32F,2) +#define CV_32FC3 CV_MAKETYPE(CV_32F,3) +#define CV_32FC4 CV_MAKETYPE(CV_32F,4) +#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) + +#define CV_64FC1 CV_MAKETYPE(CV_64F,1) +#define CV_64FC2 CV_MAKETYPE(CV_64F,2) +#define CV_64FC3 CV_MAKETYPE(CV_64F,3) +#define CV_64FC4 CV_MAKETYPE(CV_64F,4) +#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) + +// cvdef.h: + +#define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT) +#define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1) +#define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1) +#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) +#define CV_MAT_CONT_FLAG_SHIFT 14 +#define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT) +#define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG) +#define CV_IS_CONT_MAT CV_IS_MAT_CONT +#define CV_SUBMAT_FLAG_SHIFT 15 +#define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT) +#define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG) + +///** Size of each channel item, +// 0x8442211 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ +//#define CV_ELEM_SIZE1(type) \ +// ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15) + +#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) + +/** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */ +#define CV_ELEM_SIZE(type) \ + (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3)) + +#ifndef CV_OVERRIDE +# define CV_OVERRIDE override +#endif + +// base.h: +namespace cv +{ +enum BorderTypes { + BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i` + BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh` + BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb` + BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg` + BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba` + BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno` + + BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_ISOLATED = 16 //!< do not look outside of ROI +}; +// imgproc.hpp: +enum InterpolationFlags{ + INTER_NEAREST = 0, + INTER_LINEAR = 1, + INTER_CUBIC = 2, + INTER_AREA = 3, + INTER_LANCZOS4 = 4, + INTER_LINEAR_EXACT = 5, + INTER_MAX = 7, +}; +} // namespace cv + +static inline int cvFloor( double value ) +{ + int i = (int)value; + return i - (i > value); +} + +#endif // defined(GAPI_STANDALONE) + +#endif // OPENCV_GAPI_CV_DEFS_HPP diff --git a/3rdparty/include/opencv2/gapi/own/exports.hpp b/3rdparty/include/opencv2/gapi/own/exports.hpp new file mode 100644 index 0000000000..c36f4003d0 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/own/exports.hpp @@ -0,0 +1,42 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_TYPES_HPP +#define OPENCV_GAPI_OWN_TYPES_HPP + +# if defined(__OPENCV_BUILD) +# include +# define GAPI_EXPORTS CV_EXPORTS + /* special informative macros for wrapper generators */ +# define GAPI_PROP CV_PROP +# define GAPI_PROP_RW CV_PROP_RW +# define GAPI_WRAP CV_WRAP +# define GAPI_EXPORTS_W_SIMPLE CV_EXPORTS_W_SIMPLE +# define GAPI_EXPORTS_W CV_EXPORTS_W +# else +# define GAPI_PROP +# define GAPI_PROP_RW +# define GAPI_WRAP +# define GAPI_EXPORTS +# define GAPI_EXPORTS_W_SIMPLE +# define GAPI_EXPORTS_W + +#if 0 // Note: the following version currently is not needed for non-OpenCV build +# if defined _WIN32 +# define GAPI_EXPORTS __declspec(dllexport) +# elif defined __GNUC__ && __GNUC__ >= 4 +# define GAPI_EXPORTS __attribute__ ((visibility ("default"))) +# endif + +# ifndef GAPI_EXPORTS +# define GAPI_EXPORTS +# endif +#endif + +# endif + +#endif // OPENCV_GAPI_OWN_TYPES_HPP diff --git a/3rdparty/include/opencv2/gapi/own/mat.hpp b/3rdparty/include/opencv2/gapi/own/mat.hpp new file mode 100644 index 0000000000..ce9c0bf362 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/own/mat.hpp @@ -0,0 +1,354 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_MAT_HPP +#define OPENCV_GAPI_OWN_MAT_HPP + +#include +#include +#include +#include +#include + +#include //std::shared_ptr +#include //std::memcpy +#include //std::accumulate +#include +#include + +namespace cv { namespace gapi { namespace own { + namespace detail { + template + void assign_row(void* ptr, int cols, Scalar const& s) + { + auto p = static_cast(ptr); + for (int c = 0; c < cols; c++) + { + for (int ch = 0; ch < channels; ch++) + { + p[c * channels + ch] = saturate(s[ch], roundd); + } + } + } + + inline size_t default_step(int type, int cols) + { + return CV_ELEM_SIZE(type) * cols; + } + //Matrix header, i.e. fields that are unique to each Mat object. + //Devoted class is needed to implement custom behavior on move (erasing state of moved from object) + struct MatHeader{ + enum { AUTO_STEP = 0}; + enum { TYPE_MASK = 0x00000FFF }; + + MatHeader() = default; + + MatHeader(int _rows, int _cols, int type, void* _data, size_t _step) + : flags((type & TYPE_MASK)), rows(_rows), cols(_cols), data((uchar*)_data), step(_step == AUTO_STEP ? detail::default_step(type, _cols) : _step) + {} + + MatHeader(const std::vector &_dims, int type, void* _data) + : flags((type & TYPE_MASK)), data((uchar*)_data), step(0), dims(_dims) + {} + + MatHeader(const MatHeader& ) = default; + MatHeader(MatHeader&& src) : MatHeader(src) // reuse copy constructor here + { + MatHeader empty; //give it a name to call copy(not move) assignment below + src = empty; + } + MatHeader& operator=(const MatHeader& ) = default; + MatHeader& operator=(MatHeader&& src) + { + *this = src; //calling a copy assignment here, not move one + MatHeader empty; //give it a name to call copy(not move) assignment below + src = empty; + return *this; + } + /*! includes several bit-fields: + - depth + - number of channels + */ + int flags = 0; + + //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions + int rows = 0, cols = 0; + //! pointer to the data + uchar* data = nullptr; + size_t step = 0; + //! dimensions (ND-case) + std::vector dims; + }; + } // namespace detail + //concise version of cv::Mat suitable for GAPI needs (used when no dependence on OpenCV is required) + class Mat : public detail::MatHeader{ + public: + + Mat() = default; + + /** @overload + @param _rows Number of rows in a 2D array. + @param _cols Number of columns in a 2D array. + @param _type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param _data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param _step Number of bytes each matrix row occupies. The value should include the padding bytes at + the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed + and the actual step is calculated as cols*elemSize(). See Mat::elemSize. + */ + Mat(int _rows, int _cols, int _type, void* _data, size_t _step = AUTO_STEP) + : MatHeader (_rows, _cols, _type, _data, _step) + {} + + Mat(const std::vector &_dims, int _type, void* _data) + : MatHeader (_dims, _type, _data) + {} + + Mat(std::vector &&_dims, int _type, void* _data) + : MatHeader (std::move(_dims), _type, _data) + {} + + Mat(Mat const& src, const Rect& roi ) + : Mat(src) + { + rows = roi.height; + cols = roi.width; + data = ptr(roi.y, roi.x); + } + + Mat(Mat const& ) = default; + Mat(Mat&& ) = default; + + Mat& operator=(Mat const& ) = default; + Mat& operator=(Mat&& ) = default; + + /** @brief Sets all or some of the array elements to the specified value. + @param s Assigned scalar converted to the actual array type. + */ + Mat& operator = (const Scalar& s) + { + constexpr unsigned max_channels = 4; //Scalar can't fit more than 4 + using func_p_t = void (*)(void*, int, Scalar const&); + using detail::assign_row; + #define TABLE_ENTRY(type) {assign_row, assign_row, assign_row, assign_row} + static constexpr func_p_t func_tbl[][max_channels] = { + TABLE_ENTRY(uchar), + TABLE_ENTRY(schar), + TABLE_ENTRY(ushort), + TABLE_ENTRY(short), + TABLE_ENTRY(int), + TABLE_ENTRY(float), + TABLE_ENTRY(double) + }; + #undef TABLE_ENTRY + + static_assert(CV_8U == 0 && CV_8S == 1 && CV_16U == 2 && CV_16S == 3 + && CV_32S == 4 && CV_32F == 5 && CV_64F == 6, + "OCV type ids used as indexes to array, thus exact numbers are important!" + ); + + const auto depth = static_cast(this->depth()); + GAPI_Assert(depth < sizeof(func_tbl)/sizeof(func_tbl[0])); + + if (dims.empty()) + { + const auto channels = static_cast(this->channels()); + GAPI_Assert(channels <= max_channels); + + auto* f = func_tbl[depth][channels - 1]; + for (int r = 0; r < rows; ++r) + { + (*f)(static_cast(ptr(r)), cols, s ); + } + } + else + { + auto* f = func_tbl[depth][0]; + // FIXME: better to refactor assign_row to use std::size_t by default + (*f)(static_cast(data), static_cast(total()), s); + } + return *this; + } + + /** @brief Returns the matrix element size in bytes. + + The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 , + the method returns 3\*sizeof(short) or 6. + */ + size_t elemSize() const + { + return CV_ELEM_SIZE(type()); + } + /** @brief Returns the type of a matrix element. + + The method returns a matrix element type. This is an identifier compatible with the CvMat type + system, like CV_16SC3 or 16-bit signed 3-channel array, and so on. + */ + int type() const {return CV_MAT_TYPE(flags);} + + /** @brief Returns the depth of a matrix element. + + The method returns the identifier of the matrix element depth (the type of each individual channel). + For example, for a 16-bit signed element array, the method returns CV_16S . A complete list of + matrix types contains the following values: + - CV_8U - 8-bit unsigned integers ( 0..255 ) + - CV_8S - 8-bit signed integers ( -128..127 ) + - CV_16U - 16-bit unsigned integers ( 0..65535 ) + - CV_16S - 16-bit signed integers ( -32768..32767 ) + - CV_32S - 32-bit signed integers ( -2147483648..2147483647 ) + - CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN ) + - CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN ) + */ + int depth() const {return CV_MAT_DEPTH(flags);} + + /** @brief Returns the number of matrix channels. + + The method returns the number of matrix channels. + If matrix is N-dimensional, -1 is returned. + */ + int channels() const {return dims.empty() ? CV_MAT_CN(flags) : -1;} + + /** + @param _rows New number of rows. + @param _cols New number of columns. + @param _type New matrix type. + */ + void create(int _rows, int _cols, int _type) + { + create(Size{_cols, _rows}, _type); + } + /** @overload + @param _size Alternative new matrix size specification: Size(cols, rows) + @param _type New matrix type. + */ + void create(Size _size, int _type) + { + GAPI_Assert(_size.height >= 0 && _size.width >= 0); + if (_size != Size{cols, rows} ) + { + Mat tmp{_size.height, _size.width, _type, nullptr}; + tmp.memory.reset(new uchar[ tmp.step * tmp.rows], [](uchar * p){delete[] p;}); + tmp.data = tmp.memory.get(); + + *this = std::move(tmp); + } + } + + void create(const std::vector &_dims, int _type) + { + // FIXME: make a proper reallocation-on-demands + // WARNING: no tensor views, so no strides + Mat tmp{_dims, _type, nullptr}; + // FIXME: this accumulate duplicates a lot + const auto sz = std::accumulate(_dims.begin(), _dims.end(), 1, std::multiplies()); + tmp.memory.reset(new uchar[CV_ELEM_SIZE(_type)*sz], [](uchar * p){delete[] p;}); + tmp.data = tmp.memory.get(); + *this = std::move(tmp); + } + + /** @brief Creates a full copy of the matrix and the underlying data. + + The method creates a full copy of the matrix. The original step[] is not taken into account. + So, the copy has a continuous buffer occupying total() * elemSize() bytes. + */ + Mat clone() const + { + Mat m; + copyTo(m); + return m; + } + + /** @brief Copies the matrix to another one. + + The method copies the matrix data to another matrix. Before copying the data, the method invokes : + @code + m.create(this->size(), this->type()); + @endcode + so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the + function does not handle the case of a partial overlap between the source and the destination + matrices. + */ + void copyTo(Mat& dst) const + { + if (dims.empty()) + { + dst.create(rows, cols, type()); + for (int r = 0; r < rows; ++r) + { + std::copy_n(ptr(r), detail::default_step(type(),cols), dst.ptr(r)); + } + } + else + { + dst.create(dims, depth()); + std::copy_n(data, total()*elemSize(), data); + } + } + + /** @brief Returns true if the array has no elements. + + The method returns true if Mat::total() is 0 or if Mat::data is NULL. Because of pop_back() and + resize() methods `M.total() == 0` does not imply that `M.data == NULL`. + */ + bool empty() const + { + return data == 0 || total() == 0; + } + + /** @brief Returns the total number of array elements. + + The method returns the number of array elements (a number of pixels if the array represents an + image). + */ + size_t total() const + { + return dims.empty() + ? (static_cast(rows) * cols) + : std::accumulate(dims.begin(), dims.end(), static_cast(1), std::multiplies()); + } + + /** @overload + @param roi Extracted submatrix specified as a rectangle. + */ + Mat operator()( const Rect& roi ) const + { + return Mat{*this, roi}; + } + + + /** @brief Returns a pointer to the specified matrix row. + + The methods return `uchar*` or typed pointer to the specified matrix row. See the sample in + Mat::isContinuous to know how to use these methods. + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + uchar* ptr(int row, int col = 0) + { + return const_cast(const_cast(this)->ptr(row,col)); + } + /** @overload */ + const uchar* ptr(int row, int col = 0) const + { + return data + step * row + CV_ELEM_SIZE(type()) * col; + } + + + private: + //actual memory allocated for storage, or nullptr if object is non owning view to over memory + std::shared_ptr memory; + }; + +} //namespace own +} //namespace gapi +} //namespace cv + +#endif /* OPENCV_GAPI_OWN_MAT_HPP */ diff --git a/3rdparty/include/opencv2/gapi/own/saturate.hpp b/3rdparty/include/opencv2/gapi/own/saturate.hpp new file mode 100644 index 0000000000..5b232479ea --- /dev/null +++ b/3rdparty/include/opencv2/gapi/own/saturate.hpp @@ -0,0 +1,90 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_SATURATE_HPP +#define OPENCV_GAPI_OWN_SATURATE_HPP + +#include + +#include +#include + +#include + +namespace cv { namespace gapi { namespace own { +//----------------------------- +// +// Numeric cast with saturation +// +//----------------------------- + +template +static inline DST saturate(SRC x) +{ + // only integral types please! + GAPI_DbgAssert(std::is_integral::value && + std::is_integral::value); + + if (std::is_same::value) + return static_cast(x); + + if (sizeof(DST) > sizeof(SRC)) + return static_cast(x); + + // compiler must recognize this saturation, + // so compile saturate(a + b) with adds + // instruction (e.g.: _mm_adds_epi16 if x86) + return x < std::numeric_limits::min()? + std::numeric_limits::min(): + x > std::numeric_limits::max()? + std::numeric_limits::max(): + static_cast(x); +} + +// Note, that OpenCV rounds differently: +// - like std::round() for add, subtract +// - like std::rint() for multiply, divide +template +static inline DST saturate(SRC x, R round) +{ + if (std::is_floating_point::value) + { + return static_cast(x); + } + else if (std::is_integral::value) + { + GAPI_DbgAssert(std::is_integral::value && + std::is_integral::value); + return saturate(x); + } + else + { + GAPI_DbgAssert(std::is_integral::value && + std::is_floating_point::value); +#ifdef _WIN32 +// Suppress warning about converting x to floating-point +// Note that x is already floating-point at this point +#pragma warning(disable: 4244) +#endif + int ix = static_cast(round(x)); +#ifdef _WIN32 +#pragma warning(default: 4244) +#endif + return saturate(ix); + } +} + +// explicit suffix 'd' for double type +inline double ceild(double x) { return ceil(x); } +inline double floord(double x) { return floor(x); } +inline double roundd(double x) { return round(x); } +inline double rintd(double x) { return rint(x); } + +} //namespace own +} //namespace gapi +} //namespace cv +#endif /* OPENCV_GAPI_OWN_SATURATE_HPP */ diff --git a/3rdparty/include/opencv2/gapi/own/scalar.hpp b/3rdparty/include/opencv2/gapi/own/scalar.hpp new file mode 100644 index 0000000000..bda91c83b5 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/own/scalar.hpp @@ -0,0 +1,47 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GAPI_OWN_SCALAR_HPP +#define OPENCV_GAPI_GAPI_OWN_SCALAR_HPP + +#include + +namespace cv +{ +namespace gapi +{ +namespace own +{ + +class GAPI_EXPORTS Scalar +{ +public: + Scalar() = default; + explicit Scalar(double v0) { val[0] = v0; }; + Scalar(double v0, double v1, double v2 = 0, double v3 = 0) + : val{v0, v1, v2, v3} + { + } + + const double& operator[](int i) const { return val[i]; } + double& operator[](int i) { return val[i]; } + + static Scalar all(double v0) { return Scalar(v0, v0, v0, v0); } + + double val[4] = {0}; +}; + +inline bool operator==(const Scalar& lhs, const Scalar& rhs) +{ + return std::equal(std::begin(lhs.val), std::end(lhs.val), std::begin(rhs.val)); +} + +} // namespace own +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_GAPI_OWN_SCALAR_HPP diff --git a/3rdparty/include/opencv2/gapi/own/types.hpp b/3rdparty/include/opencv2/gapi/own/types.hpp new file mode 100644 index 0000000000..53bb867e32 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/own/types.hpp @@ -0,0 +1,150 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_TYPES_HPP +#define OPENCV_GAPI_TYPES_HPP + +#include // std::max, std::min +#include + +namespace cv +{ +namespace gapi +{ + +/** + * @brief This namespace contains G-API own data structures used in + * its standalone mode build. + */ +namespace own +{ + +class Point +{ +public: + Point() = default; + Point(int _x, int _y) : x(_x), y(_y) {}; + + int x = 0; + int y = 0; +}; + +class Point2f +{ +public: + Point2f() = default; + Point2f(float _x, float _y) : x(_x), y(_y) {}; + + float x = 0.f; + float y = 0.f; +}; + +class Rect +{ +public: + Rect() = default; + Rect(int _x, int _y, int _width, int _height) : x(_x), y(_y), width(_width), height(_height) {}; +#if !defined(GAPI_STANDALONE) + Rect(const cv::Rect& other) : x(other.x), y(other.y), width(other.width), height(other.height) {}; + inline Rect& operator=(const cv::Rect& other) + { + x = other.x; + y = other.x; + width = other.width; + height = other.height; + return *this; + } +#endif // !defined(GAPI_STANDALONE) + + int x = 0; //!< x coordinate of the top-left corner + int y = 0; //!< y coordinate of the top-left corner + int width = 0; //!< width of the rectangle + int height = 0; //!< height of the rectangle +}; + +inline bool operator==(const Rect& lhs, const Rect& rhs) +{ + return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height; +} + +inline bool operator!=(const Rect& lhs, const Rect& rhs) +{ + return !(lhs == rhs); +} + +inline Rect& operator&=(Rect& lhs, const Rect& rhs) +{ + int x1 = std::max(lhs.x, rhs.x); + int y1 = std::max(lhs.y, rhs.y); + lhs.width = std::min(lhs.x + lhs.width, rhs.x + rhs.width) - x1; + lhs.height = std::min(lhs.y + lhs.height, rhs.y + rhs.height) - y1; + lhs.x = x1; + lhs.y = y1; + if( lhs.width <= 0 || lhs.height <= 0 ) + lhs = Rect(); + return lhs; +} + +inline const Rect operator&(const Rect& lhs, const Rect& rhs) +{ + Rect result = lhs; + return result &= rhs; +} + +inline std::ostream& operator<<(std::ostream& o, const Rect& rect) +{ + return o << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]"; +} + +class Size +{ +public: + Size() = default; + Size(int _width, int _height) : width(_width), height(_height) {}; +#if !defined(GAPI_STANDALONE) + Size(const cv::Size& other) : width(other.width), height(other.height) {}; + inline Size& operator=(const cv::Size& rhs) + { + width = rhs.width; + height = rhs.height; + return *this; + } +#endif // !defined(GAPI_STANDALONE) + + int width = 0; + int height = 0; +}; + +inline Size& operator+=(Size& lhs, const Size& rhs) +{ + lhs.width += rhs.width; + lhs.height += rhs.height; + return lhs; +} + +inline bool operator==(const Size& lhs, const Size& rhs) +{ + return lhs.width == rhs.width && lhs.height == rhs.height; +} + +inline bool operator!=(const Size& lhs, const Size& rhs) +{ + return !(lhs == rhs); +} + + +inline std::ostream& operator<<(std::ostream& o, const Size& s) +{ + o << "[" << s.width << " x " << s.height << "]"; + return o; +} + +} // namespace own +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_TYPES_HPP diff --git a/3rdparty/include/opencv2/gapi/plaidml/core.hpp b/3rdparty/include/opencv2/gapi/plaidml/core.hpp new file mode 100644 index 0000000000..3c63fed93d --- /dev/null +++ b/3rdparty/include/opencv2/gapi/plaidml/core.hpp @@ -0,0 +1,20 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + + +#ifndef OPENCV_GAPI_PLAIDML_CORE_HPP +#define OPENCV_GAPI_PLAIDML_CORE_HPP + +#include // GKernelPackage +#include // GAPI_EXPORTS + +namespace cv { namespace gapi { namespace core { namespace plaidml { + +GAPI_EXPORTS cv::gapi::GKernelPackage kernels(); + +}}}} + +#endif // OPENCV_GAPI_PLAIDML_CORE_HPP diff --git a/3rdparty/include/opencv2/gapi/plaidml/gplaidmlkernel.hpp b/3rdparty/include/opencv2/gapi/plaidml/gplaidmlkernel.hpp new file mode 100644 index 0000000000..7ce00cfa35 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/plaidml/gplaidmlkernel.hpp @@ -0,0 +1,140 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation +// + + +#ifndef OPENCV_GAPI_GPLAIDMLKERNEL_HPP +#define OPENCV_GAPI_GPLAIDMLKERNEL_HPP + +#include +#include + +namespace plaidml +{ +namespace edsl +{ + class Tensor; +} // namespace edsl +} // namespace plaidml + +namespace cv +{ +namespace gapi +{ +namespace plaidml +{ + +GAPI_EXPORTS cv::gapi::GBackend backend(); + +} // namespace plaidml +} // namespace gapi + +struct GPlaidMLContext +{ + // Generic accessor API + template + const T& inArg(int input) { return m_args.at(input).get(); } + + // Syntax sugar + const plaidml::edsl::Tensor& inTensor(int input) + { + return inArg(input); + } + + plaidml::edsl::Tensor& outTensor(int output) + { + return *(m_results.at(output).get()); + } + + std::vector m_args; + std::unordered_map m_results; +}; + +class GAPI_EXPORTS GPlaidMLKernel +{ +public: + using F = std::function; + + GPlaidMLKernel() = default; + explicit GPlaidMLKernel(const F& f) : m_f(f) {}; + + void apply(GPlaidMLContext &ctx) const + { + GAPI_Assert(m_f); + m_f(ctx); + } + +protected: + F m_f; +}; + + +namespace detail +{ + +template struct plaidml_get_in; +template<> struct plaidml_get_in +{ + static const plaidml::edsl::Tensor& get(GPlaidMLContext& ctx, int idx) + { + return ctx.inTensor(idx); + } +}; + +template struct plaidml_get_in +{ + static T get(GPlaidMLContext &ctx, int idx) { return ctx.inArg(idx); } +}; + +template struct plaidml_get_out; +template<> struct plaidml_get_out +{ + static plaidml::edsl::Tensor& get(GPlaidMLContext& ctx, int idx) + { + return ctx.outTensor(idx); + } +}; + +template +struct PlaidMLCallHelper; + +template +struct PlaidMLCallHelper, std::tuple > +{ + template + static void call_impl(GPlaidMLContext &ctx, detail::Seq, detail::Seq) + { + Impl::run(plaidml_get_in::get(ctx, IIs)..., plaidml_get_out::get(ctx, OIs)...); + } + + static void call(GPlaidMLContext& ctx) + { + call_impl(ctx, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } +}; + +} // namespace detail + +template +class GPlaidMLKernelImpl: public cv::detail::PlaidMLCallHelper, + public cv::detail::KernelTag +{ + using P = detail::PlaidMLCallHelper; + +public: + using API = K; + + static cv::gapi::GBackend backend() { return cv::gapi::plaidml::backend(); } + static cv::GPlaidMLKernel kernel() { return GPlaidMLKernel(&P::call); } +}; + +#define GAPI_PLAIDML_KERNEL(Name, API) struct Name: public cv::GPlaidMLKernelImpl + +} // namespace cv + +#endif // OPENCV_GAPI_GPLAIDMLKERNEL_HPP diff --git a/3rdparty/include/opencv2/gapi/plaidml/plaidml.hpp b/3rdparty/include/opencv2/gapi/plaidml/plaidml.hpp new file mode 100644 index 0000000000..3207a8cb2e --- /dev/null +++ b/3rdparty/include/opencv2/gapi/plaidml/plaidml.hpp @@ -0,0 +1,53 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + + +#ifndef OPENCV_GAPI_PLAIDML_PLAIDML_HPP +#define OPENCV_GAPI_PLAIDML_PLAIDML_HPP + +#include +#include // CompileArgTag + +namespace cv +{ +namespace gapi +{ + +/** + * @brief This namespace contains G-API PlaidML backend functions, + * structures, and symbols. + */ +namespace plaidml +{ + +/** \addtogroup gapi_compile_args + * @{ + */ +/** + * @brief This structure represents the basic parameters for the experimental + * PlaidML backend. + */ +struct config +{ + std::string dev_id; //!< Device ID. Refer to PlaidML documentation for details. + std::string trg_id; //!< Target ID. Refer to PlaidML documentation for details. +}; +/** @} gapi_compile_args */ + +} // namespace plaidml +} // namespace gapi + +namespace detail +{ + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.plaidml.config"; } + }; +} // namespace detail + +} // namespace cv + +#endif // OPENCV_GAPI_PLAIDML_PLAIDML_HPP diff --git a/3rdparty/include/opencv2/gapi/python/python.hpp b/3rdparty/include/opencv2/gapi/python/python.hpp new file mode 100644 index 0000000000..0e20bbbb59 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/python/python.hpp @@ -0,0 +1,67 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2021 Intel Corporation + + +#ifndef OPENCV_GAPI_PYTHON_API_HPP +#define OPENCV_GAPI_PYTHON_API_HPP + +#include // GKernelPackage +#include // GAPI_EXPORTS + +namespace cv { +namespace gapi { + +/** + * @brief This namespace contains G-API Python backend functions, + * structures, and symbols. + * + * This functionality is required to enable G-API custom operations + * and kernels when using G-API from Python, no need to use it in the + * C++ form. + */ +namespace python { + +GAPI_EXPORTS cv::gapi::GBackend backend(); + +struct GPythonContext +{ + const cv::GArgs &ins; + const cv::GMetaArgs &in_metas; + const cv::GTypesInfo &out_info; +}; + +using Impl = std::function; + +class GAPI_EXPORTS GPythonKernel +{ +public: + GPythonKernel() = default; + GPythonKernel(Impl run); + + cv::GRunArgs operator()(const GPythonContext& ctx); +private: + Impl m_run; +}; + +class GAPI_EXPORTS GPythonFunctor : public cv::gapi::GFunctor +{ +public: + using Meta = cv::GKernel::M; + + GPythonFunctor(const char* id, const Meta &meta, const Impl& impl); + + GKernelImpl impl() const override; + gapi::GBackend backend() const override; + +private: + GKernelImpl impl_; +}; + +} // namespace python +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_PYTHON_API_HPP diff --git a/3rdparty/include/opencv2/gapi/render.hpp b/3rdparty/include/opencv2/gapi/render.hpp new file mode 100644 index 0000000000..52e55b0d80 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/render.hpp @@ -0,0 +1,14 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_RENDER_ROOT_HPP +#define OPENCV_GAPI_RENDER_ROOT_HPP + +// This file is just a shortcut to render/render.hpp + +#include + +#endif // OPENCV_GAPI_RENDER_ROOT_HPP diff --git a/3rdparty/include/opencv2/gapi/render/render.hpp b/3rdparty/include/opencv2/gapi/render/render.hpp new file mode 100644 index 0000000000..5375412224 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/render/render.hpp @@ -0,0 +1,196 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2020 Intel Corporation + + +#ifndef OPENCV_GAPI_RENDER_HPP +#define OPENCV_GAPI_RENDER_HPP + +#include + +#include + +/** \defgroup gapi_draw G-API Drawing and composition functionality + * @{ + * + * @brief Functions for in-graph drawing. + * + * @note This is a Work in Progress functionality and APIs may + * change in the future releases. + * + * G-API can do some in-graph drawing with a generic operations and a + * set of [rendering primitives](@ref gapi_draw_prims). + * In contrast with traditional OpenCV, in G-API user need to form a + * *rendering list* of primitives to draw. This list can be built + * manually or generated within a graph. This list is passed to + * [special operations or functions](@ref gapi_draw_api) where all + * primitives are interpreted and applied to the image. + * + * For example, in a complex pipeline a list of detected objects + * can be translated in-graph to a list of cv::gapi::wip::draw::Rect + * primitives to highlight those with bounding boxes, or a list of + * detected faces can be translated in-graph to a list of + * cv::gapi::wip::draw::Mosaic primitives to hide sensitive content + * or protect privacy. + * + * Like any other operations, rendering in G-API can be reimplemented + * by different backends. Currently only an OpenCV-based backend is + * available. + * + * In addition to the graph-level operations, there are also regular + * (immediate) OpenCV-like functions are available -- see + * cv::gapi::wip::draw::render(). These functions are just wrappers + * over regular G-API and build the rendering graphs on the fly, so + * take compilation arguments as parameters. + * + * Currently this API is more machine-oriented than human-oriented. + * The main purpose is to translate a set of domain-specific objects + * to a list of primitives to draw. For example, in order to generate + * a picture like this: + * + * ![](modules/gapi/doc/pics/render_example.png) + * + * Rendering list needs to be generated as follows: + * + * @include modules/gapi/samples/draw_example.cpp + * + * @defgroup gapi_draw_prims Drawing primitives + * @defgroup gapi_draw_api Drawing operations and functions + * @} + */ + +namespace cv +{ +namespace gapi +{ +namespace wip +{ +namespace draw +{ + +using GMat2 = std::tuple; +using GMatDesc2 = std::tuple; + +//! @addtogroup gapi_draw_api +//! @{ +/** @brief The function renders on the input image passed drawing primitivies + +@param bgr input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@param prims vector of drawing primitivies +@param args graph compile time parameters +*/ +void GAPI_EXPORTS_W render(cv::Mat& bgr, + const Prims& prims, + cv::GCompileArgs&& args = {}); + +/** @brief The function renders on two NV12 planes passed drawing primitivies + +@param y_plane input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param uv_plane input image: 8-bit unsigned 2-channel image @ref CV_8UC2. +@param prims vector of drawing primitivies +@param args graph compile time parameters +*/ +void GAPI_EXPORTS_W render(cv::Mat& y_plane, + cv::Mat& uv_plane, + const Prims& prims, + cv::GCompileArgs&& args = {}); + +/** @brief The function renders on the input media frame passed drawing primitivies + +@param frame input Media Frame : @ref cv::MediaFrame. +@param prims vector of drawing primitivies +@param args graph compile time parameters +*/ +void GAPI_EXPORTS render(cv::MediaFrame& frame, + const Prims& prims, + cv::GCompileArgs&& args = {}); + + +G_TYPED_KERNEL_M(GRenderNV12, )>, "org.opencv.render.nv12") +{ + static GMatDesc2 outMeta(GMatDesc y_plane, GMatDesc uv_plane, GArrayDesc) + { + return std::make_tuple(y_plane, uv_plane); + } +}; + +G_TYPED_KERNEL(GRenderBGR, )>, "org.opencv.render.bgr") +{ + static GMatDesc outMeta(GMatDesc bgr, GArrayDesc) + { + return bgr; + } +}; + +G_TYPED_KERNEL(GRenderFrame, )>, "org.opencv.render.frame") +{ + static GFrameDesc outMeta(GFrameDesc desc, GArrayDesc) + { + return desc; + } +}; + +/** @brief Renders on 3 channels input + +Output image must be 8-bit unsigned planar 3-channel image + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3 +@param prims draw primitives +*/ +GAPI_EXPORTS_W GMat render3ch(const GMat& src, const GArray& prims); + +/** @brief Renders on two planes + +Output y image must be 8-bit unsigned planar 1-channel image @ref CV_8UC1 +uv image must be 8-bit unsigned planar 2-channel image @ref CV_8UC2 + +@param y input image: 8-bit unsigned 1-channel image @ref CV_8UC1 +@param uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2 +@param prims draw primitives +*/ +GAPI_EXPORTS_W GMat2 renderNV12(const GMat& y, + const GMat& uv, + const GArray& prims); + +/** @brief Renders Media Frame + +Output media frame frame cv::MediaFrame + +@param m_frame input image: cv::MediaFrame @ref cv::MediaFrame +@param prims draw primitives +*/ +GAPI_EXPORTS GFrame renderFrame(const GFrame& m_frame, + const GArray& prims); + +//! @} gapi_draw_api + +} // namespace draw +} // namespace wip + +/** + * @brief This namespace contains G-API CPU rendering backend functions, + * structures, and symbols. See @ref gapi_draw for details. + */ +namespace render +{ +namespace ocv +{ + GAPI_EXPORTS_W cv::gapi::GKernelPackage kernels(); + +} // namespace ocv +} // namespace render +} // namespace gapi + +namespace detail +{ + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.freetype_font"; } + }; +} // namespace detail + +} // namespace cv + +#endif // OPENCV_GAPI_RENDER_HPP diff --git a/3rdparty/include/opencv2/gapi/render/render_types.hpp b/3rdparty/include/opencv2/gapi/render/render_types.hpp new file mode 100644 index 0000000000..6d70e3a877 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/render/render_types.hpp @@ -0,0 +1,359 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + + +#ifndef OPENCV_GAPI_RENDER_TYPES_HPP +#define OPENCV_GAPI_RENDER_TYPES_HPP + +#include +#include + +#include +#include +#include + +namespace cv +{ +namespace gapi +{ +namespace wip +{ +namespace draw +{ + +/** + * @brief This structure specifies which FreeType font to use by FText primitives. + */ +struct freetype_font +{ + /*@{*/ + std::string path; //!< The path to the font file (.ttf) + /*@{*/ +}; + +//! @addtogroup gapi_draw_prims +//! @{ +/** + * @brief This structure represents a text string to draw. + * + * Parameters match cv::putText(). + */ +struct GAPI_EXPORTS_W_SIMPLE Text +{ + /** + * @brief Text constructor + * + * @param text_ The text string to be drawn + * @param org_ The bottom-left corner of the text string in the image + * @param ff_ The font type, see #HersheyFonts + * @param fs_ The font scale factor that is multiplied by the font-specific base size + * @param color_ The text color + * @param thick_ The thickness of the lines used to draw a text + * @param lt_ The line type. See #LineTypes + * @param bottom_left_origin_ When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner + */ + GAPI_WRAP + Text(const std::string& text_, + const cv::Point& org_, + int ff_, + double fs_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = 8, + bool bottom_left_origin_ = false) : + text(text_), org(org_), ff(ff_), fs(fs_), + color(color_), thick(thick_), lt(lt_), bottom_left_origin(bottom_left_origin_) + { + } + + GAPI_WRAP + Text() = default; + + /*@{*/ + GAPI_PROP_RW std::string text; //!< The text string to be drawn + GAPI_PROP_RW cv::Point org; //!< The bottom-left corner of the text string in the image + GAPI_PROP_RW int ff; //!< The font type, see #HersheyFonts + GAPI_PROP_RW double fs; //!< The font scale factor that is multiplied by the font-specific base size + GAPI_PROP_RW cv::Scalar color; //!< The text color + GAPI_PROP_RW int thick; //!< The thickness of the lines used to draw a text + GAPI_PROP_RW int lt; //!< The line type. See #LineTypes + GAPI_PROP_RW bool bottom_left_origin; //!< When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner + /*@{*/ +}; + +/** + * @brief This structure represents a text string to draw using + * FreeType renderer. + * + * If OpenCV is built without FreeType support, this primitive will + * fail at the execution stage. + */ +struct FText +{ + /** + * @brief FText constructor + * + * @param text_ The text string to be drawn + * @param org_ The bottom-left corner of the text string in the image + * @param fh_ The height of text + * @param color_ The text color + */ + FText(const std::wstring& text_, + const cv::Point& org_, + int fh_, + const cv::Scalar& color_) : + text(text_), org(org_), fh(fh_), color(color_) + { + } + + FText() = default; + + /*@{*/ + std::wstring text; //!< The text string to be drawn + cv::Point org; //!< The bottom-left corner of the text string in the image + int fh; //!< The height of text + cv::Scalar color; //!< The text color + /*@{*/ +}; + +/** + * @brief This structure represents a rectangle to draw. + * + * Parameters match cv::rectangle(). + */ +struct GAPI_EXPORTS_W_SIMPLE Rect +{ + /** + * @brief Rect constructor + * + * @param rect_ Coordinates of the rectangle + * @param color_ The bottom-left corner of the text string in the image + * @param thick_ The thickness of lines that make up the rectangle. Negative values, like #FILLED, mean that the function has to draw a filled rectangle + * @param lt_ The type of the line. See #LineTypes + * @param shift_ The number of fractional bits in the point coordinates + */ + Rect(const cv::Rect& rect_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = 8, + int shift_ = 0) : + rect(rect_), color(color_), thick(thick_), lt(lt_), shift(shift_) + { + } + + GAPI_WRAP + Rect() = default; + + /*@{*/ + GAPI_PROP_RW cv::Rect rect; //!< Coordinates of the rectangle + GAPI_PROP_RW cv::Scalar color; //!< The rectangle color or brightness (grayscale image) + GAPI_PROP_RW int thick; //!< The thickness of lines that make up the rectangle. Negative values, like #FILLED, mean that the function has to draw a filled rectangle + GAPI_PROP_RW int lt; //!< The type of the line. See #LineTypes + GAPI_PROP_RW int shift; //!< The number of fractional bits in the point coordinates + /*@{*/ +}; + +/** + * @brief This structure represents a circle to draw. + * + * Parameters match cv::circle(). + */ +struct GAPI_EXPORTS_W_SIMPLE Circle +{ + /** + * @brief Circle constructor + * + * @param center_ The center of the circle + * @param radius_ The radius of the circle + * @param color_ The color of the circle + * @param thick_ The thickness of the circle outline, if positive. Negative values, like #FILLED, mean that a filled circle is to be drawn + * @param lt_ The Type of the circle boundary. See #LineTypes + * @param shift_ The Number of fractional bits in the coordinates of the center and in the radius value + */ + GAPI_WRAP + Circle(const cv::Point& center_, + int radius_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = 8, + int shift_ = 0) : + center(center_), radius(radius_), color(color_), thick(thick_), lt(lt_), shift(shift_) + { + } + + GAPI_WRAP + Circle() = default; + + /*@{*/ + GAPI_PROP_RW cv::Point center; //!< The center of the circle + GAPI_PROP_RW int radius; //!< The radius of the circle + GAPI_PROP_RW cv::Scalar color; //!< The color of the circle + GAPI_PROP_RW int thick; //!< The thickness of the circle outline, if positive. Negative values, like #FILLED, mean that a filled circle is to be drawn + GAPI_PROP_RW int lt; //!< The Type of the circle boundary. See #LineTypes + GAPI_PROP_RW int shift; //!< The Number of fractional bits in the coordinates of the center and in the radius value + /*@{*/ +}; + +/** + * @brief This structure represents a line to draw. + * + * Parameters match cv::line(). + */ +struct GAPI_EXPORTS_W_SIMPLE Line +{ + /** + * @brief Line constructor + * + * @param pt1_ The first point of the line segment + * @param pt2_ The second point of the line segment + * @param color_ The line color + * @param thick_ The thickness of line + * @param lt_ The Type of the line. See #LineTypes + * @param shift_ The number of fractional bits in the point coordinates + */ + GAPI_WRAP + Line(const cv::Point& pt1_, + const cv::Point& pt2_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = 8, + int shift_ = 0) : + pt1(pt1_), pt2(pt2_), color(color_), thick(thick_), lt(lt_), shift(shift_) + { + } + + GAPI_WRAP + Line() = default; + + /*@{*/ + GAPI_PROP_RW cv::Point pt1; //!< The first point of the line segment + GAPI_PROP_RW cv::Point pt2; //!< The second point of the line segment + GAPI_PROP_RW cv::Scalar color; //!< The line color + GAPI_PROP_RW int thick; //!< The thickness of line + GAPI_PROP_RW int lt; //!< The Type of the line. See #LineTypes + GAPI_PROP_RW int shift; //!< The number of fractional bits in the point coordinates + /*@{*/ +}; + +/** + * @brief This structure represents a mosaicing operation. + * + * Mosaicing is a very basic method to obfuscate regions in the image. + */ +struct GAPI_EXPORTS_W_SIMPLE Mosaic +{ + /** + * @brief Mosaic constructor + * + * @param mos_ Coordinates of the mosaic + * @param cellSz_ Cell size (same for X, Y) + * @param decim_ Decimation (0 stands for no decimation) + */ + Mosaic(const cv::Rect& mos_, + int cellSz_, + int decim_) : + mos(mos_), cellSz(cellSz_), decim(decim_) + { + } + + GAPI_WRAP + Mosaic() : cellSz(0), decim(0) {} + + /*@{*/ + GAPI_PROP_RW cv::Rect mos; //!< Coordinates of the mosaic + GAPI_PROP_RW int cellSz; //!< Cell size (same for X, Y) + GAPI_PROP_RW int decim; //!< Decimation (0 stands for no decimation) + /*@{*/ +}; + +/** + * @brief This structure represents an image to draw. + * + * Image is blended on a frame using the specified mask. + */ +struct GAPI_EXPORTS_W_SIMPLE Image +{ + /** + * @brief Mosaic constructor + * + * @param org_ The bottom-left corner of the image + * @param img_ Image to draw + * @param alpha_ Alpha channel for image to draw (same size and number of channels) + */ + GAPI_WRAP + Image(const cv::Point& org_, + const cv::Mat& img_, + const cv::Mat& alpha_) : + org(org_), img(img_), alpha(alpha_) + { + } + + GAPI_WRAP + Image() = default; + + /*@{*/ + GAPI_PROP_RW cv::Point org; //!< The bottom-left corner of the image + GAPI_PROP_RW cv::Mat img; //!< Image to draw + GAPI_PROP_RW cv::Mat alpha; //!< Alpha channel for image to draw (same size and number of channels) + /*@{*/ +}; + +/** + * @brief This structure represents a polygon to draw. + */ +struct GAPI_EXPORTS_W_SIMPLE Poly +{ + /** + * @brief Mosaic constructor + * + * @param points_ Points to connect + * @param color_ The line color + * @param thick_ The thickness of line + * @param lt_ The Type of the line. See #LineTypes + * @param shift_ The number of fractional bits in the point coordinate + */ + GAPI_WRAP + Poly(const std::vector& points_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = 8, + int shift_ = 0) : + points(points_), color(color_), thick(thick_), lt(lt_), shift(shift_) + { + } + + GAPI_WRAP + Poly() = default; + + /*@{*/ + GAPI_PROP_RW std::vector points; //!< Points to connect + GAPI_PROP_RW cv::Scalar color; //!< The line color + GAPI_PROP_RW int thick; //!< The thickness of line + GAPI_PROP_RW int lt; //!< The Type of the line. See #LineTypes + GAPI_PROP_RW int shift; //!< The number of fractional bits in the point coordinate + /*@{*/ +}; + +using Prim = util::variant + < Text + , FText + , Rect + , Circle + , Line + , Mosaic + , Image + , Poly + >; + +using Prims = std::vector; +//! @} gapi_draw_prims + +} // namespace draw +} // namespace wip +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_RENDER_TYPES_HPP diff --git a/3rdparty/include/opencv2/gapi/rmat.hpp b/3rdparty/include/opencv2/gapi/rmat.hpp new file mode 100644 index 0000000000..cc27f48664 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/rmat.hpp @@ -0,0 +1,156 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + +#ifndef OPENCV_GAPI_RMAT_HPP +#define OPENCV_GAPI_RMAT_HPP + +#include +#include + +// Forward declaration +namespace cv { +namespace gapi { +namespace s11n { + struct IOStream; + struct IIStream; +} // namespace s11n +} // namespace gapi +} // namespace cv + +namespace cv { + +// "Remote Mat", a general class which provides an abstraction layer over the data +// storage and placement (host, remote device etc) and allows to access this data. +// +// The device specific implementation is hidden in the RMat::Adapter class +// +// The basic flow is the following: +// * Backend which is aware of the remote device: +// - Implements own AdapterT class which is derived from RMat::Adapter +// - Wraps device memory into RMat via make_rmat utility function: +// cv::RMat rmat = cv::make_rmat(args); +// +// * End user: +// - Writes the code which works with RMats without any knowledge of the remote device: +// void func(const cv::RMat& in_rmat, cv::RMat& out_rmat) { +// // Fetch input data from the device, get mapped memory for output +// cv::RMat::View in_view = in_rmat.access(Access::R); +// cv::RMat::View out_view = out_rmat.access(Access::W); +// performCalculations(in_view, out_view); +// // data from out_view is transferred to the device when out_view is destroyed +// } +/** \addtogroup gapi_data_structures + * @{ + */ +class GAPI_EXPORTS RMat +{ +public: + // A lightweight wrapper on image data: + // - Doesn't own the memory; + // - Doesn't implement copy semantics (it's assumed that a view is created each time + // wrapped data is being accessed); + // - Has an optional callback which is called when the view is destroyed. + class GAPI_EXPORTS View + { + public: + using DestroyCallback = std::function; + using stepsT = std::vector; + + View() = default; + View(const GMatDesc& desc, uchar* data, const stepsT& steps = {}, DestroyCallback&& cb = nullptr); + View(const GMatDesc& desc, uchar* data, size_t step, DestroyCallback&& cb = nullptr); + + View(const View&) = delete; + View& operator=(const View&) = delete; + View(View&&) = default; + View& operator=(View&& v); + ~View() { if (m_cb) m_cb(); } + + cv::Size size() const { return m_desc.size; } + const std::vector& dims() const { return m_desc.dims; } + int cols() const { return m_desc.size.width; } + int rows() const { return m_desc.size.height; } + int type() const; + int depth() const { return m_desc.depth; } + int chan() const { return m_desc.chan; } + size_t elemSize() const { return CV_ELEM_SIZE(type()); } + + template T* ptr(int y = 0) { + return reinterpret_cast(m_data + step()*y); + } + template const T* ptr(int y = 0) const { + return reinterpret_cast(m_data + step()*y); + } + template T* ptr(int y, int x) { + return reinterpret_cast(m_data + step()*y + step(1)*x); + } + template const T* ptr(int y, int x) const { + return reinterpret_cast(m_data + step()*y + step(1)*x); + } + size_t step(size_t i = 0) const { GAPI_DbgAssert(i; + + RMat() = default; + RMat(AdapterP&& a) : m_adapter(std::move(a)) {} + GMatDesc desc() const { return m_adapter->desc(); } + + // Note: When accessed for write there is no guarantee that returned view + // will contain actual snapshot of the mapped device memory + // (no guarantee that fetch from a device is performed). The only + // guaranty is that when the view is destroyed, its data will be + // transferred to the device + View access(Access a) const { return m_adapter->access(a); } + + // Cast underlying RMat adapter to the particular adapter type, + // return nullptr if underlying type is different + template T* get() const + { + static_assert(std::is_base_of::value, "T is not derived from Adapter!"); + GAPI_Assert(m_adapter != nullptr); + return dynamic_cast(m_adapter.get()); + } + + void serialize(cv::gapi::s11n::IOStream& os) const { + m_adapter->serialize(os); + } + +private: + AdapterP m_adapter = nullptr; +}; + +template +RMat make_rmat(Ts&&... args) { return { std::make_shared(std::forward(args)...) }; } +/** @} */ + +} //namespace cv + +#endif /* OPENCV_GAPI_RMAT_HPP */ diff --git a/3rdparty/include/opencv2/gapi/s11n.hpp b/3rdparty/include/opencv2/gapi/s11n.hpp new file mode 100644 index 0000000000..5a64410e5a --- /dev/null +++ b/3rdparty/include/opencv2/gapi/s11n.hpp @@ -0,0 +1,373 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020-2021 Intel Corporation + +#ifndef OPENCV_GAPI_S11N_HPP +#define OPENCV_GAPI_S11N_HPP + +#include +#include +#include +#include +#include +#include + +namespace cv { +namespace gapi { + +namespace detail { + GAPI_EXPORTS cv::GComputation getGraph(const std::vector &p); + + GAPI_EXPORTS cv::GMetaArgs getMetaArgs(const std::vector &p); + + GAPI_EXPORTS cv::GRunArgs getRunArgs(const std::vector &p); + + GAPI_EXPORTS std::vector getVectorOfStrings(const std::vector &p); + + template + cv::GCompileArgs getCompileArgs(const std::vector &p); + + template + cv::GRunArgs getRunArgsWithRMats(const std::vector &p); +} // namespace detail + +GAPI_EXPORTS std::vector serialize(const cv::GComputation &c); +//namespace{ + +template static inline +T deserialize(const std::vector &p); + +//} //ananymous namespace + +GAPI_EXPORTS std::vector serialize(const cv::GCompileArgs&); +GAPI_EXPORTS std::vector serialize(const cv::GMetaArgs&); +GAPI_EXPORTS std::vector serialize(const cv::GRunArgs&); +GAPI_EXPORTS std::vector serialize(const std::vector&); + +template<> inline +cv::GComputation deserialize(const std::vector &p) { + return detail::getGraph(p); +} + +template<> inline +cv::GMetaArgs deserialize(const std::vector &p) { + return detail::getMetaArgs(p); +} + +template<> inline +cv::GRunArgs deserialize(const std::vector &p) { + return detail::getRunArgs(p); +} + +template<> inline +std::vector deserialize(const std::vector &p) { + return detail::getVectorOfStrings(p); +} + +template inline +typename std::enable_if::value, GCompileArgs>:: +type deserialize(const std::vector &p) { + return detail::getCompileArgs(p); +} + +template inline +typename std::enable_if::value, GRunArgs>:: +type deserialize(const std::vector &p) { + return detail::getRunArgsWithRMats(p); +} +} // namespace gapi +} // namespace cv + +namespace cv { +namespace gapi { +namespace s11n { +struct GAPI_EXPORTS IOStream { + virtual ~IOStream() = default; + // Define the native support for basic C++ types at the API level: + virtual IOStream& operator<< (bool) = 0; + virtual IOStream& operator<< (char) = 0; + virtual IOStream& operator<< (unsigned char) = 0; + virtual IOStream& operator<< (short) = 0; + virtual IOStream& operator<< (unsigned short) = 0; + virtual IOStream& operator<< (int) = 0; + virtual IOStream& operator<< (uint32_t) = 0; + virtual IOStream& operator<< (uint64_t) = 0; + virtual IOStream& operator<< (float) = 0; + virtual IOStream& operator<< (double) = 0; + virtual IOStream& operator<< (const std::string&) = 0; +}; + +struct GAPI_EXPORTS IIStream { + virtual ~IIStream() = default; + virtual IIStream& operator>> (bool &) = 0; + virtual IIStream& operator>> (std::vector::reference) = 0; + virtual IIStream& operator>> (char &) = 0; + virtual IIStream& operator>> (unsigned char &) = 0; + virtual IIStream& operator>> (short &) = 0; + virtual IIStream& operator>> (unsigned short &) = 0; + virtual IIStream& operator>> (int &) = 0; + virtual IIStream& operator>> (float &) = 0; + virtual IIStream& operator>> (double &) = 0; + virtual IIStream& operator >> (uint32_t &) = 0; + virtual IIStream& operator >> (uint64_t &) = 0; + virtual IIStream& operator>> (std::string &) = 0; +}; + +namespace detail { +GAPI_EXPORTS std::unique_ptr getInStream(const std::vector &p); +} // namespace detail + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// S11N operators +// Note: operators for basic types are defined in IIStream/IOStream + +// OpenCV types //////////////////////////////////////////////////////////////// + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::Point &pt); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::Point &pt); + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::Point2f &pt); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::Point2f &pt); + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::Size &sz); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::Size &sz); + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::Rect &rc); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::Rect &rc); + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::Scalar &s); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::Scalar &s); + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::Mat &m); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::Mat &m); + +// FIXME: for GRunArgs serailization +#if !defined(GAPI_STANDALONE) +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::UMat &); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::UMat &); +#endif // !defined(GAPI_STANDALONE) + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::RMat &r); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::RMat &r); + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::IStreamSource::Ptr &); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::IStreamSource::Ptr &); + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::detail::VectorRef &); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::detail::VectorRef &); + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::detail::OpaqueRef &); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::detail::OpaqueRef &); + +GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::MediaFrame &); +GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::MediaFrame &); + +// Generic STL types //////////////////////////////////////////////////////////////// +template +IOStream& operator<< (IOStream& os, const std::map &m) { + const uint32_t sz = static_cast(m.size()); + os << sz; + for (const auto& it : m) os << it.first << it.second; + return os; +} +template +IIStream& operator>> (IIStream& is, std::map &m) { + m.clear(); + uint32_t sz = 0u; + is >> sz; + for (std::size_t i = 0; i < sz; ++i) { + K k{}; + V v{}; + is >> k >> v; + m[k] = v; + } + return is; +} +template +IOStream& operator<< (IOStream& os, const std::unordered_map &m) { + const uint32_t sz = static_cast(m.size()); + os << sz; + for (auto &&it : m) os << it.first << it.second; + return os; +} +template +IIStream& operator>> (IIStream& is, std::unordered_map &m) { + m.clear(); + uint32_t sz = 0u; + is >> sz; + for (std::size_t i = 0; i < sz; ++i) { + K k{}; + V v{}; + is >> k >> v; + m[k] = v; + } + return is; +} +template +IOStream& operator<< (IOStream& os, const std::vector &ts) { + const uint32_t sz = static_cast(ts.size()); + os << sz; + for (auto &&v : ts) os << v; + return os; +} +template +IIStream& operator>> (IIStream& is, std::vector &ts) { + uint32_t sz = 0u; + is >> sz; + if (sz == 0u) { + ts.clear(); + } + else { + ts.resize(sz); + for (std::size_t i = 0; i < sz; ++i) is >> ts[i]; + } + return is; +} + +// Generic: variant serialization +namespace detail { +template +IOStream& put_v(IOStream&, const V&, std::size_t) { + GAPI_Assert(false && "variant>>: requested index is invalid"); +}; +template +IOStream& put_v(IOStream& os, const V& v, std::size_t x) { + return (x == 0u) + ? os << cv::util::get(v) + : put_v(os, v, x-1); +} +template +IIStream& get_v(IIStream&, V&, std::size_t, std::size_t) { + GAPI_Assert(false && "variant<<: requested index is invalid"); +} +template +IIStream& get_v(IIStream& is, V& v, std::size_t i, std::size_t gi) { + if (i == gi) { + X x{}; + is >> x; + v = V{std::move(x)}; + return is; + } else return get_v(is, v, i+1, gi); +} +} // namespace detail + +template +IOStream& operator<< (IOStream& os, const cv::util::variant &v) { + os << static_cast(v.index()); + return detail::put_v, Ts...>(os, v, v.index()); +} +template +IIStream& operator>> (IIStream& is, cv::util::variant &v) { + int idx = -1; + is >> idx; + GAPI_Assert(idx >= 0 && idx < (int)sizeof...(Ts)); + return detail::get_v, Ts...>(is, v, 0u, idx); +} + +// FIXME: consider a better solution +template +void getRunArgByIdx (IIStream& is, cv::util::variant &v, uint32_t idx) { + is = detail::get_v, Ts...>(is, v, 0u, idx); +} +} // namespace s11n + +namespace detail +{ +template struct try_deserialize_comparg; + +template<> struct try_deserialize_comparg> { +static cv::util::optional exec(const std::string&, cv::gapi::s11n::IIStream&) { + return { }; + } +}; + +template +struct try_deserialize_comparg> { +static cv::util::optional exec(const std::string& tag, cv::gapi::s11n::IIStream& is) { + if (tag == cv::detail::CompileArgTag::tag()) { + static_assert(cv::gapi::s11n::detail::has_S11N_spec::value, + "cv::gapi::deserialize expects Types to have S11N " + "specializations with deserialization callbacks!"); + return cv::util::optional( + GCompileArg { cv::gapi::s11n::detail::S11N::deserialize(is) }); + } + return try_deserialize_comparg>::exec(tag, is); +} +}; + +template struct deserialize_runarg; + +template +struct deserialize_runarg { +static GRunArg exec(cv::gapi::s11n::IIStream& is, uint32_t idx) { + if (idx == GRunArg::index_of()) { + auto ptr = std::make_shared(); + ptr->deserialize(is); + return GRunArg { RMat(std::move(ptr)) }; + } else { // non-RMat arg - use default deserialization + GRunArg arg; + getRunArgByIdx(is, arg, idx); + return arg; + } +} +}; + +template +inline cv::util::optional tryDeserializeCompArg(const std::string& tag, + const std::vector& sArg) { + std::unique_ptr pArgIs = cv::gapi::s11n::detail::getInStream(sArg); + return try_deserialize_comparg>::exec(tag, *pArgIs); +} + +template +cv::GCompileArgs getCompileArgs(const std::vector &sArgs) { + cv::GCompileArgs args; + + std::unique_ptr pIs = cv::gapi::s11n::detail::getInStream(sArgs); + cv::gapi::s11n::IIStream& is = *pIs; + + uint32_t sz = 0; + is >> sz; + for (uint32_t i = 0; i < sz; ++i) { + std::string tag; + is >> tag; + + std::vector sArg; + is >> sArg; + + cv::util::optional dArg = + cv::gapi::detail::tryDeserializeCompArg(tag, sArg); + + if (dArg.has_value()) + { + args.push_back(dArg.value()); + } + } + + return args; +} + +template +cv::GRunArgs getRunArgsWithRMats(const std::vector &p) { + std::unique_ptr pIs = cv::gapi::s11n::detail::getInStream(p); + cv::gapi::s11n::IIStream& is = *pIs; + cv::GRunArgs args; + + uint32_t sz = 0; + is >> sz; + for (uint32_t i = 0; i < sz; ++i) { + uint32_t idx = 0; + is >> idx; + args.push_back(cv::gapi::detail::deserialize_runarg::exec(is, idx)); + } + + return args; +} +} // namespace detail +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_S11N_HPP diff --git a/3rdparty/include/opencv2/gapi/s11n/base.hpp b/3rdparty/include/opencv2/gapi/s11n/base.hpp new file mode 100644 index 0000000000..b8ec8cfaff --- /dev/null +++ b/3rdparty/include/opencv2/gapi/s11n/base.hpp @@ -0,0 +1,51 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + +#ifndef OPENCV_GAPI_S11N_BASE_HPP +#define OPENCV_GAPI_S11N_BASE_HPP + +#include +#include + +namespace cv { +namespace gapi { + +/** + * @brief This namespace contains G-API serialization and + * deserialization functions and data structures. + */ +namespace s11n { +struct IOStream; +struct IIStream; + +namespace detail { + +struct NotImplemented { +}; + +// The default S11N for custom types is NotImplemented +// Don't! sublass from NotImplemented if you actually implement S11N. +template +struct S11N: public NotImplemented { + static void serialize(IOStream &, const T &) { + GAPI_Assert(false && "No serialization routine is provided!"); + } + static T deserialize(IIStream &) { + GAPI_Assert(false && "No deserialization routine is provided!"); + } +}; + +template struct has_S11N_spec { + static constexpr bool value = !std::is_base_of::type>>::value; +}; + +} // namespace detail +} // namespace s11n +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_S11N_BASE_HPP diff --git a/3rdparty/include/opencv2/gapi/stereo.hpp b/3rdparty/include/opencv2/gapi/stereo.hpp new file mode 100644 index 0000000000..dcf8f4d260 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/stereo.hpp @@ -0,0 +1,85 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distereoibution and at http://opencv.org/license.html. +// +// Copyright (C) 2021 Intel Corporation + +#ifndef OPENCV_GAPI_STEREO_HPP +#define OPENCV_GAPI_STEREO_HPP + +#include +#include +#include + +namespace cv { +namespace gapi { + +/** + * The enum specified format of result that you get from @ref cv::gapi::stereo. + */ +enum class StereoOutputFormat { + DEPTH_FLOAT16, ///< Floating point 16 bit value, CV_16FC1. + ///< This identifier is deprecated, use DEPTH_16F instead. + DEPTH_FLOAT32, ///< Floating point 32 bit value, CV_32FC1 + ///< This identifier is deprecated, use DEPTH_16F instead. + DISPARITY_FIXED16_11_5, ///< 16 bit signed: first bit for sign, + ///< 10 bits for integer part, + ///< 5 bits for fractional part. + ///< This identifier is deprecated, + ///< use DISPARITY_16Q_10_5 instead. + DISPARITY_FIXED16_12_4, ///< 16 bit signed: first bit for sign, + ///< 11 bits for integer part, + ///< 4 bits for fractional part. + ///< This identifier is deprecated, + ///< use DISPARITY_16Q_11_4 instead. + DEPTH_16F = DEPTH_FLOAT16, ///< Same as DEPTH_FLOAT16 + DEPTH_32F = DEPTH_FLOAT32, ///< Same as DEPTH_FLOAT32 + DISPARITY_16Q_10_5 = DISPARITY_FIXED16_11_5, ///< Same as DISPARITY_FIXED16_11_5 + DISPARITY_16Q_11_4 = DISPARITY_FIXED16_12_4 ///< Same as DISPARITY_FIXED16_12_4 +}; + + +/** + * @brief This namespace contains G-API Operation Types for Stereo and + * related functionality. + */ +namespace calib3d { + +G_TYPED_KERNEL(GStereo, , "org.opencv.stereo") { + static GMatDesc outMeta(const GMatDesc &left, const GMatDesc &right, const StereoOutputFormat of) { + GAPI_Assert(left.chan == 1); + GAPI_Assert(left.depth == CV_8U); + + GAPI_Assert(right.chan == 1); + GAPI_Assert(right.depth == CV_8U); + + switch(of) { + case StereoOutputFormat::DEPTH_FLOAT16: + return left.withDepth(CV_16FC1); + case StereoOutputFormat::DEPTH_FLOAT32: + return left.withDepth(CV_32FC1); + case StereoOutputFormat::DISPARITY_FIXED16_11_5: + case StereoOutputFormat::DISPARITY_FIXED16_12_4: + return left.withDepth(CV_16SC1); + default: + GAPI_Assert(false && "Unknown output format!"); + } + } +}; + +} // namespace calib3d + +/** @brief Computes disparity/depth map for the specified stereo-pair. +The function computes disparity or depth map depending on passed StereoOutputFormat argument. + +@param left 8-bit single-channel left image of @ref CV_8UC1 type. +@param right 8-bit single-channel right image of @ref CV_8UC1 type. +@param of enum to specified output kind: depth or disparity and corresponding type +*/ +GAPI_EXPORTS GMat stereo(const GMat& left, + const GMat& right, + const StereoOutputFormat of = StereoOutputFormat::DEPTH_FLOAT32); +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_STEREO_HPP diff --git a/3rdparty/include/opencv2/gapi/streaming/cap.hpp b/3rdparty/include/opencv2/gapi/streaming/cap.hpp new file mode 100644 index 0000000000..aad6af618c --- /dev/null +++ b/3rdparty/include/opencv2/gapi/streaming/cap.hpp @@ -0,0 +1,126 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_STREAMING_CAP_HPP +#define OPENCV_GAPI_STREAMING_CAP_HPP + +/** + * YOUR ATTENTION PLEASE! + * + * This is a header-only implementation of cv::VideoCapture-based + * Stream source. It is not built by default with G-API as G-API + * doesn't depend on videoio module. + * + * If you want to use it in your application, please make sure + * videioio is available in your OpenCV package and is linked to your + * application. + * + * Note for developers: please don't put videoio dependency in G-API + * because of this file. + */ +#include + +#include +#include +#include + +namespace cv { +namespace gapi { +namespace wip { + +/** + * @brief OpenCV's VideoCapture-based streaming source. + * + * This class implements IStreamSource interface. + * Its constructor takes the same parameters as cv::VideoCapture does. + * + * Please make sure that videoio OpenCV module is available before using + * this in your application (G-API doesn't depend on it directly). + * + * @note stream sources are passed to G-API via shared pointers, so + * please gapi::make_src<> to create objects and ptr() to pass a + * GCaptureSource to cv::gin(). + */ +class GCaptureSource: public IStreamSource +{ +public: + explicit GCaptureSource(int id) : cap(id) { prep(); } + explicit GCaptureSource(const std::string &path) : cap(path) { prep(); } + + // TODO: Add more constructor overloads to make it + // fully compatible with VideoCapture's interface. + +protected: + cv::VideoCapture cap; + cv::Mat first; + bool first_pulled = false; + int64_t counter = 0; + + void prep() + { + // Prepare first frame to report its meta to engine + // when needed + GAPI_Assert(first.empty()); + cv::Mat tmp; + if (!cap.read(tmp)) + { + GAPI_Assert(false && "Couldn't grab the very first frame"); + } + // NOTE: Some decode/media VideoCapture backends continue + // owning the video buffer under cv::Mat so in order to + // process it safely in a highly concurrent pipeline, clone() + // is the only right way. + first = tmp.clone(); + } + + virtual bool pull(cv::gapi::wip::Data &data) override + { + if (!first_pulled) + { + GAPI_Assert(!first.empty()); + first_pulled = true; + data = first; // no need to clone here since it was cloned already + } + else + { + if (!cap.isOpened()) return false; + + cv::Mat frame; + if (!cap.read(frame)) + { + // end-of-stream happened + return false; + } + // Same reason to clone as in prep() + data = frame.clone(); + } + // Tag data with seq_id/ts + const auto now = std::chrono::system_clock::now(); + const auto dur = std::chrono::duration_cast + (now.time_since_epoch()); + data.meta[cv::gapi::streaming::meta_tag::timestamp] = int64_t{dur.count()}; + data.meta[cv::gapi::streaming::meta_tag::seq_id] = int64_t{counter++}; + return true; + } + + virtual GMetaArg descr_of() const override + { + GAPI_Assert(!first.empty()); + return cv::GMetaArg{cv::descr_of(first)}; + } +}; + +// NB: Overload for using from python +GAPI_EXPORTS_W cv::Ptr inline make_capture_src(const std::string& path) +{ + return make_src(path); +} + +} // namespace wip +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_STREAMING_CAP_HPP diff --git a/3rdparty/include/opencv2/gapi/streaming/desync.hpp b/3rdparty/include/opencv2/gapi/streaming/desync.hpp new file mode 100644 index 0000000000..86de279fe9 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/streaming/desync.hpp @@ -0,0 +1,84 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GSTREAMING_DESYNC_HPP +#define OPENCV_GAPI_GSTREAMING_DESYNC_HPP + +#include + +#include +#include +#include +#include +#include + +namespace cv { +namespace gapi { +namespace streaming { + +namespace detail { +struct GDesync { + static const char *id() { + return "org.opencv.streaming.desync"; + } + + // An universal yield for desync. + // Yields output objects according to the input Types... + // Reuses gkernel machinery. + // FIXME: This function can be generic and declared in gkernel.hpp + // (it is there already, but a part of GKernelType[M] + template + static std::tuple yield(cv::GCall &call, cv::detail::Seq) { + return std::make_tuple(cv::detail::Yield::yield(call, IIs)...); + } +}; + +template +G desync(const G &g) { + cv::GKernel k{ + GDesync::id() // kernel id + , "" // kernel tag + , [](const GMetaArgs &a, const GArgs &) {return a;} // outMeta callback + , {cv::detail::GTypeTraits::shape} // output Shape + , {cv::detail::GTypeTraits::op_kind} // input data kinds + , {cv::detail::GObtainCtor::get()} // output template ctors + }; + cv::GCall call(std::move(k)); + call.pass(g); + return std::get<0>(GDesync::yield(call, cv::detail::MkSeq<1>::type())); +} +} // namespace detail + +/** + * @brief Starts a desynchronized branch in the graph. + * + * This operation takes a single G-API data object and returns a + * graph-level "duplicate" of this object. + * + * Operations which use this data object can be desynchronized + * from the rest of the graph. + * + * This operation has no effect when a GComputation is compiled with + * regular cv::GComputation::compile(), since cv::GCompiled objects + * always produce their full output vectors. + * + * This operation only makes sense when a GComputation is compiled in + * straming mode with cv::GComputation::compileStreaming(). If this + * operation is used and there are desynchronized outputs, the user + * should use a special version of cv::GStreamingCompiled::pull() + * which produces an array of cv::util::optional<> objects. + * + * @note This feature is highly experimental now and is currently + * limited to a single GMat argument only. + */ +GAPI_EXPORTS GMat desync(const GMat &g); + +} // namespace streaming +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_GSTREAMING_DESYNC_HPP diff --git a/3rdparty/include/opencv2/gapi/streaming/format.hpp b/3rdparty/include/opencv2/gapi/streaming/format.hpp new file mode 100644 index 0000000000..f7c3bd457d --- /dev/null +++ b/3rdparty/include/opencv2/gapi/streaming/format.hpp @@ -0,0 +1,94 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + +#ifndef OPENCV_GAPI_GSTREAMING_FORMAT_HPP +#define OPENCV_GAPI_GSTREAMING_FORMAT_HPP + +#include // GKernelPackage + +namespace cv { +namespace gapi { +namespace streaming { + +GAPI_EXPORTS cv::gapi::GKernelPackage kernels(); + +G_API_OP(GBGR, , "org.opencv.streaming.BGR") +{ + static GMatDesc outMeta(const GFrameDesc& in) { return GMatDesc{CV_8U, 3, in.size}; } +}; + +G_API_OP(GY, , "org.opencv.streaming.Y") { + static GMatDesc outMeta(const GFrameDesc& frameDesc) { + return GMatDesc { CV_8U, 1, frameDesc.size , false }; + } +}; + +G_API_OP(GUV, , "org.opencv.streaming.UV") { + static GMatDesc outMeta(const GFrameDesc& frameDesc) { + return GMatDesc { CV_8U, 2, cv::Size(frameDesc.size.width / 2, frameDesc.size.height / 2), + false }; + } +}; + +/** @brief Gets bgr plane from input frame + +@note Function textual ID is "org.opencv.streaming.BGR" + +@param in Input frame +@return Image in BGR format +*/ +GAPI_EXPORTS cv::GMat BGR(const cv::GFrame& in); + +/** @brief Extracts Y plane from media frame. + +Output image is 8-bit 1-channel image of @ref CV_8UC1. + +@note Function textual ID is "org.opencv.streaming.Y" + +@param frame input media frame. +*/ +GAPI_EXPORTS GMat Y(const cv::GFrame& frame); + +/** @brief Extracts UV plane from media frame. + +Output image is 8-bit 2-channel image of @ref CV_8UC2. + +@note Function textual ID is "org.opencv.streaming.UV" + +@param frame input media frame. +*/ +GAPI_EXPORTS GMat UV(const cv::GFrame& frame); +} // namespace streaming + +//! @addtogroup gapi_transform +//! @{ +/** @brief Makes a copy of the input image. Note that this copy may be not real +(no actual data copied). Use this function to maintain graph contracts, +e.g when graph's input needs to be passed directly to output, like in Streaming mode. + +@note Function textual ID is "org.opencv.streaming.copy" + +@param in Input image +@return Copy of the input +*/ +GAPI_EXPORTS_W GMat copy(const GMat& in); + +/** @brief Makes a copy of the input frame. Note that this copy may be not real +(no actual data copied). Use this function to maintain graph contracts, +e.g when graph's input needs to be passed directly to output, like in Streaming mode. + +@note Function textual ID is "org.opencv.streaming.copy" + +@param in Input frame +@return Copy of the input +*/ +GAPI_EXPORTS GFrame copy(const GFrame& in); +//! @} gapi_transform + +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_GSTREAMING_FORMAT_HPP diff --git a/3rdparty/include/opencv2/gapi/streaming/meta.hpp b/3rdparty/include/opencv2/gapi/streaming/meta.hpp new file mode 100644 index 0000000000..cbcfc3aa37 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/streaming/meta.hpp @@ -0,0 +1,79 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + + +#ifndef OPENCV_GAPI_GSTREAMING_META_HPP +#define OPENCV_GAPI_GSTREAMING_META_HPP + +#include +#include +#include +#include + +namespace cv { +namespace gapi { +namespace streaming { + +// FIXME: the name is debatable +namespace meta_tag { +static constexpr const char * timestamp = "org.opencv.gapi.meta.timestamp"; +static constexpr const char * seq_id = "org.opencv.gapi.meta.seq_id"; +} // namespace meta_tag + +namespace detail { +struct GMeta { + static const char *id() { + return "org.opencv.streaming.meta"; + } + // A universal yield for meta(), same as in GDesync + template + static std::tuple yield(cv::GCall &call, cv::detail::Seq) { + return std::make_tuple(cv::detail::Yield::yield(call, IIs)...); + } + // Also a universal outMeta stub here + static GMetaArgs getOutMeta(const GMetaArgs &args, const GArgs &) { + return args; + } +}; +} // namespace detail + +template +cv::GOpaque meta(G g, const std::string &tag) { + using O = cv::GOpaque; + cv::GKernel k{ + detail::GMeta::id() // kernel id + , tag // kernel tag. Use meta tag here + , &detail::GMeta::getOutMeta // outMeta callback + , {cv::detail::GTypeTraits::shape} // output Shape + , {cv::detail::GTypeTraits::op_kind} // input data kinds + , {cv::detail::GObtainCtor::get()} // output template ctors + }; + cv::GCall call(std::move(k)); + call.pass(g); + return std::get<0>(detail::GMeta::yield(call, cv::detail::MkSeq<1>::type())); +} + +template +cv::GOpaque timestamp(G g) { + return meta(g, meta_tag::timestamp); +} + +template +cv::GOpaque seq_id(G g) { + return meta(g, meta_tag::seq_id); +} + +template +cv::GOpaque seqNo(G g) { + // Old name, compatibility only + return seq_id(g); +} + +} // namespace streaming +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_GSTREAMING_META_HPP diff --git a/3rdparty/include/opencv2/gapi/streaming/source.hpp b/3rdparty/include/opencv2/gapi/streaming/source.hpp new file mode 100644 index 0000000000..6597cad8f8 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/streaming/source.hpp @@ -0,0 +1,62 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_STREAMING_SOURCE_HPP +#define OPENCV_GAPI_STREAMING_SOURCE_HPP + +#include // shared_ptr +#include // is_base_of + +#include // GMetaArg + + +namespace cv { +namespace gapi { +namespace wip { + struct Data; // "forward-declaration" of GRunArg + +/** + * @brief Abstract streaming pipeline source. + * + * Implement this interface if you want customize the way how data is + * streaming into GStreamingCompiled. + * + * Objects implementing this interface can be passed to + * GStreamingCompiled using setSource() with cv::gin(). Regular + * compiled graphs (GCompiled) don't support input objects of this + * type. + * + * Default cv::VideoCapture-based implementation is available, see + * cv::gapi::wip::GCaptureSource. + * + * @note stream sources are passed to G-API via shared pointers, so + * please use ptr() when passing a IStreamSource implementation to + * cv::gin(). + */ +class IStreamSource: public std::enable_shared_from_this +{ +public: + using Ptr = std::shared_ptr; + Ptr ptr() { return shared_from_this(); } + virtual bool pull(Data &data) = 0; + virtual GMetaArg descr_of() const = 0; + virtual ~IStreamSource() = default; +}; + +template +IStreamSource::Ptr inline make_src(Args&&... args) +{ + static_assert(std::is_base_of::value, + "T must implement the cv::gapi::IStreamSource interface!"); + auto src_ptr = std::make_shared(std::forward(args)...); + return src_ptr->ptr(); +} + +} // namespace wip +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_STREAMING_SOURCE_HPP diff --git a/3rdparty/include/opencv2/gapi/streaming/sync.hpp b/3rdparty/include/opencv2/gapi/streaming/sync.hpp new file mode 100644 index 0000000000..5801e6f00a --- /dev/null +++ b/3rdparty/include/opencv2/gapi/streaming/sync.hpp @@ -0,0 +1,30 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2021 Intel Corporation + +#ifndef OPENCV_GAPI_STREAMING_SYNC_HPP +#define OPENCV_GAPI_STREAMING_SYNC_HPP + +namespace cv { +namespace gapi { +namespace streaming { + +enum class sync_policy { + dont_sync, + drop +}; + +} // namespace streaming +} // namespace gapi + +namespace detail { + template<> struct CompileArgTag { + static const char* tag() { return "gapi.streaming.sync_policy"; } + }; + +} // namespace detail +} // namespace cv + +#endif // OPENCV_GAPI_STREAMING_SYNC_HPP diff --git a/3rdparty/include/opencv2/gapi/util/any.hpp b/3rdparty/include/opencv2/gapi/util/any.hpp new file mode 100644 index 0000000000..5f97e95b08 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/util/any.hpp @@ -0,0 +1,186 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_ANY_HPP +#define OPENCV_GAPI_UTIL_ANY_HPP + +#include +#include +#include +#include + +#include + +#if defined(_MSC_VER) + // disable MSVC warning on "multiple copy constructors specified" +# pragma warning(disable: 4521) +#endif + +namespace cv +{ + +namespace internal +{ + template + T down_cast(Source operand) + { +#if defined(__GXX_RTTI) || defined(_CPPRTTI) + return dynamic_cast(operand); +#else + #warning used static cast instead of dynamic because RTTI is disabled + return static_cast(operand); +#endif + } +} + +namespace util +{ + class bad_any_cast : public std::bad_cast + { + public: + virtual const char* what() const noexcept override + { + return "Bad any cast"; + } + }; + + //modeled against C++17 std::any + + class any + { + private: + struct holder; + using holder_ptr = std::unique_ptr; + struct holder + { + virtual holder_ptr clone() = 0; + virtual ~holder() = default; + }; + + template + struct holder_impl : holder + { + value_t v; + template + holder_impl(arg_t&& a) : v(std::forward(a)) {} + holder_ptr clone() override { return holder_ptr(new holder_impl (v));} + }; + + holder_ptr hldr; + public: + template + any(value_t&& arg) : hldr(new holder_impl::type>( std::forward(arg))) {} + + any(any const& src) : hldr( src.hldr ? src.hldr->clone() : nullptr) {} + //simple hack in order not to write enable_if for the template constructor + any(any & src) : any (const_cast(src)) {} + + any() = default; + any(any&& ) = default; + + any& operator=(any&&) = default; + + any& operator=(any const& src) + { + any copy(src); + swap(*this, copy); + return *this; + } + + template + friend value_t* any_cast(any* operand); + + template + friend const value_t* any_cast(const any* operand); + + template + friend value_t& unsafe_any_cast(any& operand); + + template + friend const value_t& unsafe_any_cast(const any& operand); + + friend void swap(any & lhs, any& rhs) + { + swap(lhs.hldr, rhs.hldr); + } + + }; + + template + value_t* any_cast(any* operand) + { + auto casted = internal::down_cast::type> *>(operand->hldr.get()); + if (casted){ + return & (casted->v); + } + return nullptr; + } + + template + const value_t* any_cast(const any* operand) + { + auto casted = internal::down_cast::type> *>(operand->hldr.get()); + if (casted){ + return & (casted->v); + } + return nullptr; + } + + template + value_t& any_cast(any& operand) + { + auto ptr = any_cast(&operand); + if (ptr) + { + return *ptr; + } + + throw_error(bad_any_cast()); + } + + + template + const value_t& any_cast(const any& operand) + { + auto ptr = any_cast(&operand); + if (ptr) + { + return *ptr; + } + + throw_error(bad_any_cast()); + } + + template + inline value_t& unsafe_any_cast(any& operand) + { +#ifdef DEBUG + return any_cast(operand); +#else + return static_cast::type> *>(operand.hldr.get())->v; +#endif + } + + template + inline const value_t& unsafe_any_cast(const any& operand) + { +#ifdef DEBUG + return any_cast(operand); +#else + return static_cast::type> *>(operand.hldr.get())->v; +#endif + } + +} // namespace util +} // namespace cv + +#if defined(_MSC_VER) + // Enable "multiple copy constructors specified" back +# pragma warning(default: 4521) +#endif + +#endif // OPENCV_GAPI_UTIL_ANY_HPP diff --git a/3rdparty/include/opencv2/gapi/util/compiler_hints.hpp b/3rdparty/include/opencv2/gapi/util/compiler_hints.hpp new file mode 100644 index 0000000000..a41a97145d --- /dev/null +++ b/3rdparty/include/opencv2/gapi/util/compiler_hints.hpp @@ -0,0 +1,19 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + +#ifndef OPENCV_GAPI_UTIL_COMPILER_HINTS_HPP +#define OPENCV_GAPI_UTIL_COMPILER_HINTS_HPP + +namespace cv +{ +namespace util +{ + //! Utility template function to prevent "unused" warnings by various compilers. + template void suppress_unused_warning( const T& ) {} +} // namespace util +} // namespace cv + +#endif /* OPENCV_GAPI_UTIL_COMPILER_HINTS_HPP */ diff --git a/3rdparty/include/opencv2/gapi/util/copy_through_move.hpp b/3rdparty/include/opencv2/gapi/util/copy_through_move.hpp new file mode 100644 index 0000000000..1a1121eb21 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/util/copy_through_move.hpp @@ -0,0 +1,34 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + +#ifndef OPENCV_GAPI_UTIL_COPY_THROUGH_MOVE_HPP +#define OPENCV_GAPI_UTIL_COPY_THROUGH_MOVE_HPP + +#include //decay_t + +namespace cv +{ +namespace util +{ + //This is a tool to move initialize captures of a lambda in C++11 + template + struct copy_through_move_t{ + T value; + const T& get() const {return value;} + T& get() {return value;} + copy_through_move_t(T&& g) : value(std::move(g)) {} + copy_through_move_t(copy_through_move_t&&) = default; + copy_through_move_t(copy_through_move_t const& lhs) : copy_through_move_t(std::move(const_cast(lhs))) {} + }; + + template + copy_through_move_t> copy_through_move(T&& t){ + return std::forward(t); + } +} // namespace util +} // namespace cv + +#endif /* OPENCV_GAPI_UTIL_COPY_THROUGH_MOVE_HPP */ diff --git a/3rdparty/include/opencv2/gapi/util/optional.hpp b/3rdparty/include/opencv2/gapi/util/optional.hpp new file mode 100644 index 0000000000..6c8ceebbda --- /dev/null +++ b/3rdparty/include/opencv2/gapi/util/optional.hpp @@ -0,0 +1,178 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_OPTIONAL_HPP +#define OPENCV_GAPI_UTIL_OPTIONAL_HPP + +#include + +// A poor man's `optional` implementation, incompletely modeled against C++17 spec. +namespace cv +{ +namespace util +{ + class bad_optional_access: public std::exception + { + public: + virtual const char *what() const noexcept override + { + return "Bad optional access"; + } + }; + + // TODO: nullopt_t + + // Interface /////////////////////////////////////////////////////////////// + template class optional + { + public: + // Constructors + // NB.: there were issues with Clang 3.8 when =default() was used + // instead {} + optional() {}; + optional(const optional&) = default; + explicit optional(T&&) noexcept; + explicit optional(const T&) noexcept; + optional(optional&&) noexcept; + // TODO: optional(nullopt_t) noexcept; + // TODO: optional(const optional &) + // TODO: optional(optional &&) + // TODO: optional(Args&&...) + // TODO: optional(initializer_list) + // TODO: optional(U&& value); + + // Assignment + optional& operator=(const optional&) = default; + optional& operator=(optional&&); + + // Observers + T* operator-> (); + const T* operator-> () const; + T& operator* (); + const T& operator* () const; + // TODO: && versions + + operator bool() const noexcept; + bool has_value() const noexcept; + + T& value(); + const T& value() const; + // TODO: && versions + + template + T value_or(U &&default_value) const; + + void swap(optional &other) noexcept; + void reset() noexcept; + // TODO: emplace + + // TODO: operator==, !=, <, <=, >, >= + + private: + struct nothing {}; + util::variant m_holder; + }; + + template + optional::type> make_optional(T&& value); + + // TODO: Args... and initializer_list versions + + // Implementation ////////////////////////////////////////////////////////// + template optional::optional(T &&v) noexcept + : m_holder(std::move(v)) + { + } + + template optional::optional(const T &v) noexcept + : m_holder(v) + { + } + + template optional::optional(optional&& rhs) noexcept + : m_holder(std::move(rhs.m_holder)) + { + rhs.reset(); + } + + template optional& optional::operator=(optional&& rhs) + { + m_holder = std::move(rhs.m_holder); + rhs.reset(); + return *this; + } + + template T* optional::operator-> () + { + return & *(*this); + } + + template const T* optional::operator-> () const + { + return & *(*this); + } + + template T& optional::operator* () + { + return this->value(); + } + + template const T& optional::operator* () const + { + return this->value(); + } + + template optional::operator bool() const noexcept + { + return this->has_value(); + } + + template bool optional::has_value() const noexcept + { + return util::holds_alternative(m_holder); + } + + template T& optional::value() + { + if (!this->has_value()) + throw_error(bad_optional_access()); + return util::get(m_holder); + } + + template const T& optional::value() const + { + if (!this->has_value()) + throw_error(bad_optional_access()); + return util::get(m_holder); + } + + template + template T optional::value_or(U &&default_value) const + { + return (this->has_value() ? this->value() : T(default_value)); + } + + template void optional::swap(optional &other) noexcept + { + m_holder.swap(other.m_holder); + } + + template void optional::reset() noexcept + { + if (this->has_value()) + m_holder = nothing{}; + } + + template + optional::type> make_optional(T&& value) + { + return optional::type>(std::forward(value)); + } +} // namespace util +} // namespace cv + +#endif // OPENCV_GAPI_UTIL_OPTIONAL_HPP diff --git a/3rdparty/include/opencv2/gapi/util/throw.hpp b/3rdparty/include/opencv2/gapi/util/throw.hpp new file mode 100644 index 0000000000..689bf583cf --- /dev/null +++ b/3rdparty/include/opencv2/gapi/util/throw.hpp @@ -0,0 +1,36 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_THROW_HPP +#define OPENCV_GAPI_UTIL_THROW_HPP + +#include // std::forward + +#if !defined(__EXCEPTIONS) +#include +#include +#endif + +namespace cv +{ +namespace util +{ +template +[[noreturn]] void throw_error(ExceptionType &&e) +{ +#if defined(__EXCEPTIONS) || defined(_CPPUNWIND) + throw std::forward(e); +#else + fprintf(stderr, "An exception thrown! %s\n" , e.what()); + fflush(stderr); + abort(); +#endif +} +} // namespace util +} // namespace cv + +#endif // OPENCV_GAPI_UTIL_THROW_HPP diff --git a/3rdparty/include/opencv2/gapi/util/type_traits.hpp b/3rdparty/include/opencv2/gapi/util/type_traits.hpp new file mode 100644 index 0000000000..637f18460b --- /dev/null +++ b/3rdparty/include/opencv2/gapi/util/type_traits.hpp @@ -0,0 +1,31 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_TYPE_TRAITS_HPP +#define OPENCV_GAPI_UTIL_TYPE_TRAITS_HPP + +#include + +namespace cv +{ +namespace util +{ + //these are C++14 parts of type_traits : + template< bool B, class T = void > + using enable_if_t = typename std::enable_if::type; + + template + using decay_t = typename std::decay::type; + + //this is not part of C++14 but still, of pretty common usage + template + using are_different_t = enable_if_t< !std::is_same, decay_t>::value, V>; + +} // namespace cv +} // namespace util + +#endif // OPENCV_GAPI_UTIL_TYPE_TRAITS_HPP diff --git a/3rdparty/include/opencv2/gapi/util/util.hpp b/3rdparty/include/opencv2/gapi/util/util.hpp new file mode 100644 index 0000000000..afcf5596fd --- /dev/null +++ b/3rdparty/include/opencv2/gapi/util/util.hpp @@ -0,0 +1,124 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_HPP +#define OPENCV_GAPI_UTIL_HPP + +#include + +// \cond HIDDEN_SYMBOLS +// This header file contains some generic utility functions which are +// used in other G-API Public API headers. +// +// PLEASE don't put any stuff here if it is NOT used in public API headers! + +namespace cv +{ +namespace detail +{ + // Recursive integer sequence type, useful for enumerating elements of + // template parameter packs. + template struct Seq { using next = Seq; }; + template struct MkSeq { using type = typename MkSeq::type::next; }; + template<> struct MkSeq<0>{ using type = Seq<>; }; + + // Checks if elements of variadic template satisfy the given Predicate. + // Implemented via tuple, with an interface to accept plain type lists + template class, typename, typename...> struct all_satisfy; + + template class F, typename T, typename... Ts> + struct all_satisfy > + { + static const constexpr bool value = F::value + && all_satisfy >::value; + }; + template class F, typename T> + struct all_satisfy > + { + static const constexpr bool value = F::value; + }; + + template class F, typename T, typename... Ts> + struct all_satisfy: public all_satisfy > {}; + + // Permute given tuple type C with given integer sequence II + // Sequence may be less than tuple C size. + template struct permute_tuple; + + template + struct permute_tuple > + { + using type = std::tuple< typename std::tuple_element::type... >; + }; + + // Given T..., generates a type sequence of sizeof...(T)-1 elements + // which is T... without its last element + // Implemented via tuple, with an interface to accept plain type lists + template struct all_but_last; + + template + struct all_but_last > + { + using C = std::tuple; + using S = typename MkSeq::value - 1>::type; + using type = typename permute_tuple::type; + }; + + template + struct all_but_last: public all_but_last > {}; + + template + using all_but_last_t = typename all_but_last::type; + + // NB.: This is here because there's no constexpr std::max in C++11 + template struct max_of_t + { + static constexpr const std::size_t rest = max_of_t::value; + static constexpr const std::size_t value = rest > S0 ? rest : S0; + }; + template struct max_of_t + { + static constexpr const std::size_t value = S; + }; + + template + struct contains : std::false_type{}; + + template + struct contains : std::integral_constant::value || + contains::value> {}; + template + struct contains> : std::integral_constant::value> {}; + + template + struct all_unique : std::true_type{}; + + template + struct all_unique : std::integral_constant::value && + all_unique::value> {}; + + template + struct tuple_wrap_helper; + + template struct tuple_wrap_helper + { + using type = std::tuple; + static type get(T&& obj) { return std::make_tuple(std::move(obj)); } + }; + + template + struct tuple_wrap_helper> + { + using type = std::tuple; + static type get(std::tuple&& objs) { return std::forward>(objs); } + }; +} // namespace detail +} // namespace cv + +// \endcond + +#endif // OPENCV_GAPI_UTIL_HPP diff --git a/3rdparty/include/opencv2/gapi/util/variant.hpp b/3rdparty/include/opencv2/gapi/util/variant.hpp new file mode 100644 index 0000000000..71a06d2dcf --- /dev/null +++ b/3rdparty/include/opencv2/gapi/util/variant.hpp @@ -0,0 +1,434 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_VARIANT_HPP +#define OPENCV_GAPI_UTIL_VARIANT_HPP + +#include +#include + +#include +#include // max_of_t +#include + +// A poor man's `variant` implementation, incompletely modeled against C++17 spec. +namespace cv +{ +namespace util +{ + namespace detail + { + template + struct type_list_index_helper + { + static const constexpr bool is_same = std::is_same::value; + static const constexpr std::size_t value = + std::conditional, type_list_index_helper>::type::value; + }; + + template + struct type_list_index_helper + { + static_assert(std::is_same::value, "Type not found"); + static const constexpr std::size_t value = I; + }; + } + + template + struct type_list_index + { + static const constexpr std::size_t value = detail::type_list_index_helper<0, Target, Types...>::value; + }; + + class bad_variant_access: public std::exception + { + public: + virtual const char *what() const noexcept override + { + return "Bad variant access"; + } + }; + + // Interface /////////////////////////////////////////////////////////////// + struct monostate {}; + inline bool operator==(const util::monostate&, const util::monostate&) + { + return true; + } + + template // FIXME: no references, arrays, and void + class variant + { + // FIXME: Replace with std::aligned_union after gcc4.8 support is dropped + static constexpr const std::size_t S = cv::detail::max_of_t::value; + static constexpr const std::size_t A = cv::detail::max_of_t::value; + using Memory = typename std::aligned_storage::type[1]; + + template struct cctr_h { + static void help(Memory memory, const Memory from) { + new (memory) T(*reinterpret_cast(from)); + } + }; + + template struct mctr_h { + static void help(Memory memory, void *pval) { + new (memory) T(std::move(*reinterpret_cast(pval))); + } + }; + + //FIXME: unify with cctr_h and mctr_h + template struct cnvrt_ctor_h { + static void help(Memory memory, void* from) { + using util::decay_t; + new (memory) decay_t(std::forward(*reinterpret_cast*>(from))); + } + }; + + template struct copy_h { + static void help(Memory to, const Memory from) { + *reinterpret_cast(to) = *reinterpret_cast(from); + } + }; + + template struct move_h { + static void help(Memory to, Memory from) { + *reinterpret_cast(to) = std::move(*reinterpret_cast(from)); + } + }; + + //FIXME: unify with copy_h and move_h + template struct cnvrt_assign_h { + static void help(Memory to, void* from) { + using util::decay_t; + *reinterpret_cast*>(to) = std::forward(*reinterpret_cast*>(from)); + } + }; + + template struct swap_h { + static void help(Memory to, Memory from) { + std::swap(*reinterpret_cast(to), *reinterpret_cast(from)); + } + }; + + template struct dtor_h { + static void help(Memory memory) { + (void) memory; // MSCV warning + reinterpret_cast(memory)->~T(); + } + }; + + template struct equal_h { + static bool help(const Memory lhs, const Memory rhs) { + const T& t_lhs = *reinterpret_cast(lhs); + const T& t_rhs = *reinterpret_cast(rhs); + return t_lhs == t_rhs; + } + }; + + typedef void (*CCtr) (Memory, const Memory); // Copy c-tor (variant) + typedef void (*MCtr) (Memory, void*); // Generic move c-tor + typedef void (*Copy) (Memory, const Memory); // Copy assignment + typedef void (*Move) (Memory, Memory); // Move assignment + + typedef void (*Swap) (Memory, Memory); // Swap + typedef void (*Dtor) (Memory); // Destructor + + using cnvrt_assgn_t = void (*) (Memory, void*); // Converting assignment (via std::forward) + using cnvrt_ctor_t = void (*) (Memory, void*); // Converting constructor (via std::forward) + + typedef bool (*Equal)(const Memory, const Memory); // Equality test (external) + + static constexpr std::array cctrs(){ return {{(&cctr_h::help)...}};} + static constexpr std::array mctrs(){ return {{(&mctr_h::help)...}};} + static constexpr std::array cpyrs(){ return {{(©_h::help)...}};} + static constexpr std::array mvers(){ return {{(&move_h::help)...}};} + static constexpr std::array swprs(){ return {{(&swap_h::help)...}};} + static constexpr std::array dtors(){ return {{(&dtor_h::help)...}};} + + template + struct conditional_ref : std::conditional::type&, typename std::remove_reference::type > {}; + + template + using conditional_ref_t = typename conditional_ref::type; + + + template + static constexpr std::array cnvrt_assgnrs(){ + return {{(&cnvrt_assign_h>::help)...}}; + } + + template + static constexpr std::array cnvrt_ctors(){ + return {{(&cnvrt_ctor_h>::help)...}}; + } + + std::size_t m_index = 0; + + protected: + template friend T& get(variant &v); + template friend const T& get(const variant &v); + template friend T* get_if(variant *v) noexcept; + template friend const T* get_if(const variant *v) noexcept; + + template friend bool operator==(const variant &lhs, + const variant &rhs); + Memory memory; + + public: + // Constructors + variant() noexcept; + variant(const variant& other); + variant(variant&& other) noexcept; + // are_different_t is a SFINAE trick to avoid variant(T &&t) with T=variant + // for some reason, this version is called instead of variant(variant&& o) when + // variant is used in STL containers (examples: vector assignment). + template< + typename T, + typename = util::are_different_t + > + explicit variant(T&& t); + // template explicit variant(Args&&... args); + // FIXME: other constructors + + // Destructor + ~variant(); + + // Assignment + variant& operator=(const variant& rhs); + variant& operator=(variant &&rhs) noexcept; + + // SFINAE trick to avoid operator=(T&&) with T=variant<>, see comment above + template< + typename T, + typename = util::are_different_t + > + variant& operator=(T&& t) noexcept; + + // Observers + std::size_t index() const noexcept; + // FIXME: valueless_by_exception() + + // Modifiers + // FIXME: emplace() + void swap(variant &rhs) noexcept; + + // Non-C++17x! + template static constexpr std::size_t index_of(); + }; + + // FIMXE: visit + template + T* get_if(util::variant* v) noexcept; + + template + const T* get_if(const util::variant* v) noexcept; + + template + T& get(util::variant &v); + + template + const T& get(const util::variant &v); + + template + bool holds_alternative(const util::variant &v) noexcept; + + // FIXME: T&&, const TT&& versions. + + // Implementation ////////////////////////////////////////////////////////// + template + variant::variant() noexcept + { + typedef typename std::tuple_element<0, std::tuple >::type TFirst; + new (memory) TFirst(); + } + + template + variant::variant(const variant &other) + : m_index(other.m_index) + { + (cctrs()[m_index])(memory, other.memory); + } + + template + variant::variant(variant &&other) noexcept + : m_index(other.m_index) + { + (mctrs()[m_index])(memory, other.memory); + } + + template + template + variant::variant(T&& t) + : m_index(util::type_list_index, Ts...>::value) + { + const constexpr bool is_lvalue_arg = std::is_lvalue_reference::value; + (cnvrt_ctors()[m_index])(memory, const_cast *>(&t)); + } + + template + variant::~variant() + { + (dtors()[m_index])(memory); + } + + template + variant& variant::operator=(const variant &rhs) + { + if (m_index != rhs.m_index) + { + (dtors()[ m_index])(memory); + (cctrs()[rhs.m_index])(memory, rhs.memory); + m_index = rhs.m_index; + } + else + { + (cpyrs()[rhs.m_index])(memory, rhs.memory); + } + return *this; + } + + template + variant& variant::operator=(variant &&rhs) noexcept + { + if (m_index != rhs.m_index) + { + (dtors()[ m_index])(memory); + (mctrs()[rhs.m_index])(memory, rhs.memory); + m_index = rhs.m_index; + } + else + { + (mvers()[rhs.m_index])(memory, rhs.memory); + } + return *this; + } + + template + template + variant& variant::operator=(T&& t) noexcept + { + using decayed_t = util::decay_t; + // FIXME: No version with implicit type conversion available! + const constexpr std::size_t t_index = + util::type_list_index::value; + + const constexpr bool is_lvalue_arg = std::is_lvalue_reference::value; + + if (t_index != m_index) + { + (dtors()[m_index])(memory); + (cnvrt_ctors()[t_index])(memory, &t); + m_index = t_index; + } + else + { + (cnvrt_assgnrs()[m_index])(memory, &t); + } + return *this; + + } + + template + std::size_t util::variant::index() const noexcept + { + return m_index; + } + + template + void variant::swap(variant &rhs) noexcept + { + if (m_index == rhs.index()) + { + (swprs()[m_index](memory, rhs.memory)); + } + else + { + variant tmp(std::move(*this)); + *this = std::move(rhs); + rhs = std::move(tmp); + } + } + + template + template + constexpr std::size_t variant::index_of() + { + return util::type_list_index::value; // FIXME: tests! + } + + template + T* get_if(util::variant* v) noexcept + { + const constexpr std::size_t t_index = + util::type_list_index::value; + + if (v && v->index() == t_index) + return (T*)(&v->memory); // workaround for ICC 2019 + // original code: return reinterpret_cast(v.memory); + return nullptr; + } + + template + const T* get_if(const util::variant* v) noexcept + { + const constexpr std::size_t t_index = + util::type_list_index::value; + + if (v && v->index() == t_index) + return (const T*)(&v->memory); // workaround for ICC 2019 + // original code: return reinterpret_cast(v.memory); + return nullptr; + } + + template + T& get(util::variant &v) + { + if (auto* p = get_if(&v)) + return *p; + else + throw_error(bad_variant_access()); + } + + template + const T& get(const util::variant &v) + { + if (auto* p = get_if(&v)) + return *p; + else + throw_error(bad_variant_access()); + } + + template + bool holds_alternative(const util::variant &v) noexcept + { + return v.index() == util::variant::template index_of(); + } + + template bool operator==(const variant &lhs, + const variant &rhs) + { + using V = variant; + + // Instantiate table only here since it requires operator== for + // should have operator== only if this one is used, not in general + static const std::array eqs = { + {(&V::template equal_h::help)...} + }; + if (lhs.index() != rhs.index()) + return false; + return (eqs[lhs.index()])(lhs.memory, rhs.memory); + } + + template bool operator!=(const variant &lhs, + const variant &rhs) + { + return !(lhs == rhs); + } +} // namespace cv +} // namespace util + +#endif // OPENCV_GAPI_UTIL_VARIANT_HPP diff --git a/3rdparty/include/opencv2/gapi/video.hpp b/3rdparty/include/opencv2/gapi/video.hpp new file mode 100644 index 0000000000..4dcc1d4182 --- /dev/null +++ b/3rdparty/include/opencv2/gapi/video.hpp @@ -0,0 +1,364 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2020 Intel Corporation + +#ifndef OPENCV_GAPI_VIDEO_HPP +#define OPENCV_GAPI_VIDEO_HPP + +#include // std::tuple + +#include + + +/** \defgroup gapi_video G-API Video processing functionality + */ + +namespace cv { namespace gapi { + +/** @brief Structure for the Kalman filter's initialization parameters.*/ + +struct GAPI_EXPORTS KalmanParams +{ + // initial state + + //! corrected state (x(k)): x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) + Mat state; + //! posteriori error estimate covariance matrix (P(k)): P(k)=(I-K(k)*H)*P'(k) + Mat errorCov; + + // dynamic system description + + //! state transition matrix (A) + Mat transitionMatrix; + //! measurement matrix (H) + Mat measurementMatrix; + //! process noise covariance matrix (Q) + Mat processNoiseCov; + //! measurement noise covariance matrix (R) + Mat measurementNoiseCov; + //! control matrix (B) (Optional: not used if there's no control) + Mat controlMatrix; +}; + +/** + * @brief This namespace contains G-API Operations and functions for + * video-oriented algorithms, like optical flow and background subtraction. + */ +namespace video +{ +using GBuildPyrOutput = std::tuple, GScalar>; + +using GOptFlowLKOutput = std::tuple, + cv::GArray, + cv::GArray>; + +G_TYPED_KERNEL(GBuildOptFlowPyramid, , + "org.opencv.video.buildOpticalFlowPyramid") +{ + static std::tuple + outMeta(GMatDesc,const Size&,GScalarDesc,bool,int,int,bool) + { + return std::make_tuple(empty_array_desc(), empty_scalar_desc()); + } +}; + +G_TYPED_KERNEL(GCalcOptFlowLK, + ,cv::GArray,Size, + GScalar,TermCriteria,int,double)>, + "org.opencv.video.calcOpticalFlowPyrLK") +{ + static std::tuple outMeta(GMatDesc,GMatDesc,GArrayDesc, + GArrayDesc,const Size&,GScalarDesc, + const TermCriteria&,int,double) + { + return std::make_tuple(empty_array_desc(), empty_array_desc(), empty_array_desc()); + } + +}; + +G_TYPED_KERNEL(GCalcOptFlowLKForPyr, + ,cv::GArray, + cv::GArray,cv::GArray,Size,GScalar, + TermCriteria,int,double)>, + "org.opencv.video.calcOpticalFlowPyrLKForPyr") +{ + static std::tuple outMeta(GArrayDesc,GArrayDesc, + GArrayDesc,GArrayDesc, + const Size&,GScalarDesc, + const TermCriteria&,int,double) + { + return std::make_tuple(empty_array_desc(), empty_array_desc(), empty_array_desc()); + } +}; + +enum BackgroundSubtractorType +{ + TYPE_BS_MOG2, + TYPE_BS_KNN +}; + +/** @brief Structure for the Background Subtractor operation's initialization parameters.*/ + +struct BackgroundSubtractorParams +{ + //! Type of the Background Subtractor operation. + BackgroundSubtractorType operation = TYPE_BS_MOG2; + + //! Length of the history. + int history = 500; + + //! For MOG2: Threshold on the squared Mahalanobis distance between the pixel + //! and the model to decide whether a pixel is well described by + //! the background model. + //! For KNN: Threshold on the squared distance between the pixel and the sample + //! to decide whether a pixel is close to that sample. + double threshold = 16; + + //! If true, the algorithm will detect shadows and mark them. + bool detectShadows = true; + + //! The value between 0 and 1 that indicates how fast + //! the background model is learnt. + //! Negative parameter value makes the algorithm use some automatically + //! chosen learning rate. + double learningRate = -1; + + //! default constructor + BackgroundSubtractorParams() {} + + /** Full constructor + @param op MOG2/KNN Background Subtractor type. + @param histLength Length of the history. + @param thrshld For MOG2: Threshold on the squared Mahalanobis distance between + the pixel and the model to decide whether a pixel is well described by the background model. + For KNN: Threshold on the squared distance between the pixel and the sample to decide + whether a pixel is close to that sample. + @param detect If true, the algorithm will detect shadows and mark them. It decreases the + speed a bit, so if you do not need this feature, set the parameter to false. + @param lRate The value between 0 and 1 that indicates how fast the background model is learnt. + Negative parameter value makes the algorithm to use some automatically chosen learning rate. + */ + BackgroundSubtractorParams(BackgroundSubtractorType op, int histLength, + double thrshld, bool detect, double lRate) : operation(op), + history(histLength), + threshold(thrshld), + detectShadows(detect), + learningRate(lRate){} +}; + +G_TYPED_KERNEL(GBackgroundSubtractor, , + "org.opencv.video.BackgroundSubtractor") +{ + static GMatDesc outMeta(const GMatDesc& in, const BackgroundSubtractorParams& bsParams) + { + GAPI_Assert(bsParams.history >= 0); + GAPI_Assert(bsParams.learningRate <= 1); + return in.withType(CV_8U, 1); + } +}; + +void checkParams(const cv::gapi::KalmanParams& kfParams, + const cv::GMatDesc& measurement, const cv::GMatDesc& control = {}); + +G_TYPED_KERNEL(GKalmanFilter, , GMat, KalmanParams)>, + "org.opencv.video.KalmanFilter") +{ + static GMatDesc outMeta(const GMatDesc& measurement, const GOpaqueDesc&, + const GMatDesc& control, const KalmanParams& kfParams) + { + checkParams(kfParams, measurement, control); + return measurement.withSize(Size(1, kfParams.transitionMatrix.rows)); + } +}; + +G_TYPED_KERNEL(GKalmanFilterNoControl, , KalmanParams)>, "org.opencv.video.KalmanFilterNoControl") +{ + static GMatDesc outMeta(const GMatDesc& measurement, const GOpaqueDesc&, const KalmanParams& kfParams) + { + checkParams(kfParams, measurement); + return measurement.withSize(Size(1, kfParams.transitionMatrix.rows)); + } +}; +} //namespace video + +//! @addtogroup gapi_video +//! @{ +/** @brief Constructs the image pyramid which can be passed to calcOpticalFlowPyrLK. + +@note Function textual ID is "org.opencv.video.buildOpticalFlowPyramid" + +@param img 8-bit input image. +@param winSize window size of optical flow algorithm. Must be not less than winSize + argument of calcOpticalFlowPyrLK. It is needed to calculate required + padding for pyramid levels. +@param maxLevel 0-based maximal pyramid level number. +@param withDerivatives set to precompute gradients for the every pyramid level. If pyramid is + constructed without the gradients then calcOpticalFlowPyrLK will calculate + them internally. +@param pyrBorder the border mode for pyramid layers. +@param derivBorder the border mode for gradients. +@param tryReuseInputImage put ROI of input image into the pyramid if possible. You can pass false + to force data copying. + +@return + - output pyramid. + - number of levels in constructed pyramid. Can be less than maxLevel. + */ +GAPI_EXPORTS std::tuple, GScalar> +buildOpticalFlowPyramid(const GMat &img, + const Size &winSize, + const GScalar &maxLevel, + bool withDerivatives = true, + int pyrBorder = BORDER_REFLECT_101, + int derivBorder = BORDER_CONSTANT, + bool tryReuseInputImage = true); + +/** @brief Calculates an optical flow for a sparse feature set using the iterative Lucas-Kanade +method with pyramids. + +See @cite Bouguet00 . + +@note Function textual ID is "org.opencv.video.calcOpticalFlowPyrLK" + +@param prevImg first 8-bit input image (GMat) or pyramid (GArray) constructed by +buildOpticalFlowPyramid. +@param nextImg second input image (GMat) or pyramid (GArray) of the same size and the same +type as prevImg. +@param prevPts GArray of 2D points for which the flow needs to be found; point coordinates must be +single-precision floating-point numbers. +@param predPts GArray of 2D points initial for the flow search; make sense only when +OPTFLOW_USE_INITIAL_FLOW flag is passed; in that case the vector must have the same size as in +the input. +@param winSize size of the search window at each pyramid level. +@param maxLevel 0-based maximal pyramid level number; if set to 0, pyramids are not used (single +level), if set to 1, two levels are used, and so on; if pyramids are passed to input then +algorithm will use as many levels as pyramids have but no more than maxLevel. +@param criteria parameter, specifying the termination criteria of the iterative search algorithm +(after the specified maximum number of iterations criteria.maxCount or when the search window +moves by less than criteria.epsilon). +@param flags operation flags: + - **OPTFLOW_USE_INITIAL_FLOW** uses initial estimations, stored in nextPts; if the flag is + not set, then prevPts is copied to nextPts and is considered the initial estimate. + - **OPTFLOW_LK_GET_MIN_EIGENVALS** use minimum eigen values as an error measure (see + minEigThreshold description); if the flag is not set, then L1 distance between patches + around the original and a moved point, divided by number of pixels in a window, is used as a + error measure. +@param minEigThresh the algorithm calculates the minimum eigen value of a 2x2 normal matrix of +optical flow equations (this matrix is called a spatial gradient matrix in @cite Bouguet00), divided +by number of pixels in a window; if this value is less than minEigThreshold, then a corresponding +feature is filtered out and its flow is not processed, so it allows to remove bad points and get a +performance boost. + +@return + - GArray of 2D points (with single-precision floating-point coordinates) +containing the calculated new positions of input features in the second image. + - status GArray (of unsigned chars); each element of the vector is set to 1 if +the flow for the corresponding features has been found, otherwise, it is set to 0. + - GArray of errors (doubles); each element of the vector is set to an error for the +corresponding feature, type of the error measure can be set in flags parameter; if the flow wasn't +found then the error is not defined (use the status parameter to find such cases). + */ +GAPI_EXPORTS std::tuple, GArray, GArray> +calcOpticalFlowPyrLK(const GMat &prevImg, + const GMat &nextImg, + const GArray &prevPts, + const GArray &predPts, + const Size &winSize = Size(21, 21), + const GScalar &maxLevel = 3, + const TermCriteria &criteria = TermCriteria(TermCriteria::COUNT | + TermCriteria::EPS, + 30, 0.01), + int flags = 0, + double minEigThresh = 1e-4); + +/** +@overload +@note Function textual ID is "org.opencv.video.calcOpticalFlowPyrLKForPyr" +*/ +GAPI_EXPORTS std::tuple, GArray, GArray> +calcOpticalFlowPyrLK(const GArray &prevPyr, + const GArray &nextPyr, + const GArray &prevPts, + const GArray &predPts, + const Size &winSize = Size(21, 21), + const GScalar &maxLevel = 3, + const TermCriteria &criteria = TermCriteria(TermCriteria::COUNT | + TermCriteria::EPS, + 30, 0.01), + int flags = 0, + double minEigThresh = 1e-4); + +/** @brief Gaussian Mixture-based or K-nearest neighbours-based Background/Foreground Segmentation Algorithm. +The operation generates a foreground mask. + +@return Output image is foreground mask, i.e. 8-bit unsigned 1-channel (binary) matrix @ref CV_8UC1. + +@note Functional textual ID is "org.opencv.video.BackgroundSubtractor" + +@param src input image: Floating point frame is used without scaling and should be in range [0,255]. +@param bsParams Set of initialization parameters for Background Subtractor kernel. +*/ +GAPI_EXPORTS GMat BackgroundSubtractor(const GMat& src, const cv::gapi::video::BackgroundSubtractorParams& bsParams); + +/** @brief Standard Kalman filter algorithm . + +@note Functional textual ID is "org.opencv.video.KalmanFilter" + +@param measurement input matrix: 32-bit or 64-bit float 1-channel matrix containing measurements. +@param haveMeasurement dynamic input flag that indicates whether we get measurements +at a particular iteration . +@param control input matrix: 32-bit or 64-bit float 1-channel matrix contains control data +for changing dynamic system. +@param kfParams Set of initialization parameters for Kalman filter kernel. + +@return Output matrix is predicted or corrected state. They can be 32-bit or 64-bit float +1-channel matrix @ref CV_32FC1 or @ref CV_64FC1. + +@details If measurement matrix is given (haveMeasurements == true), corrected state will +be returned which corresponds to the pipeline +cv::KalmanFilter::predict(control) -> cv::KalmanFilter::correct(measurement). +Otherwise, predicted state will be returned which corresponds to the call of +cv::KalmanFilter::predict(control). +@sa cv::KalmanFilter +*/ +GAPI_EXPORTS GMat KalmanFilter(const GMat& measurement, const GOpaque& haveMeasurement, + const GMat& control, const cv::gapi::KalmanParams& kfParams); + +/** @overload +The case of Standard Kalman filter algorithm when there is no control in a dynamic system. +In this case the controlMatrix is empty and control vector is absent. + +@note Function textual ID is "org.opencv.video.KalmanFilterNoControl" + +@param measurement input matrix: 32-bit or 64-bit float 1-channel matrix containing measurements. +@param haveMeasurement dynamic input flag that indicates whether we get measurements +at a particular iteration. +@param kfParams Set of initialization parameters for Kalman filter kernel. + +@return Output matrix is predicted or corrected state. They can be 32-bit or 64-bit float +1-channel matrix @ref CV_32FC1 or @ref CV_64FC1. + +@sa cv::KalmanFilter + */ +GAPI_EXPORTS GMat KalmanFilter(const GMat& measurement, const GOpaque& haveMeasurement, + const cv::gapi::KalmanParams& kfParams); + +//! @} gapi_video +} //namespace gapi +} //namespace cv + + +namespace cv { namespace detail { +template<> struct CompileArgTag +{ + static const char* tag() + { + return "org.opencv.video.background_substractor_params"; + } +}; +} // namespace detail +} // namespace cv + +#endif // OPENCV_GAPI_VIDEO_HPP diff --git a/3rdparty/include/opencv2/hfs.hpp b/3rdparty/include/opencv2/hfs.hpp deleted file mode 100644 index 948f117c39..0000000000 --- a/3rdparty/include/opencv2/hfs.hpp +++ /dev/null @@ -1,153 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#include "opencv2/core.hpp" - -namespace cv { namespace hfs { - -/** @defgroup hfs Hierarchical Feature Selection for Efficient Image Segmentation - -The opencv hfs module contains an efficient algorithm to segment an image. -This module is implemented based on the paper Hierarchical Feature Selection for Efficient -Image Segmentation, ECCV 2016. The original project was developed by -Yun Liu(https://github.com/yun-liu/hfs). - - -Introduction to Hierarchical Feature Selection ----------------------------------------------- - - -This algorithm is executed in 3 stages: - -In the first stage, the algorithm uses SLIC (simple linear iterative clustering) algorithm -to obtain the superpixel of the input image. - -In the second stage, the algorithm view each superpixel as a node in the graph. -It will calculate a feature vector for each edge of the graph. It then calculates a weight -for each edge based on the feature vector and trained SVM parameters. After obtaining -weight for each edge, it will exploit EGB (Efficient Graph-based Image Segmentation) -algorithm to merge some nodes in the graph thus obtaining a coarser segmentation -After these operations, a post process will be executed to merge regions that are smaller -then a specific number of pixels into their nearby region. - -In the third stage, the algorithm exploits the similar mechanism to further merge -the small regions obtained in the second stage into even coarser segmentation. - -After these three stages, we can obtain the final segmentation of the image. -For further details about the algorithm, please refer to the original paper: -Hierarchical Feature Selection for Efficient Image Segmentation, ECCV 2016 - -*/ - -//! @addtogroup hfs -//! @{ -class CV_EXPORTS_W HfsSegment : public Algorithm { -public: - -/** @brief: set and get the parameter segEgbThresholdI. -* This parameter is used in the second stage mentioned above. -* It is a constant used to threshold weights of the edge when merging -* adjacent nodes when applying EGB algorithm. The segmentation result -* tends to have more regions remained if this value is large and vice versa. -*/ -CV_WRAP virtual void setSegEgbThresholdI(float c) = 0; -CV_WRAP virtual float getSegEgbThresholdI() = 0; - - -/** @brief: set and get the parameter minRegionSizeI. -* This parameter is used in the second stage -* mentioned above. After the EGB segmentation, regions that have fewer -* pixels then this parameter will be merged into it's adjacent region. -*/ -CV_WRAP virtual void setMinRegionSizeI(int n) = 0; -CV_WRAP virtual int getMinRegionSizeI() = 0; - - -/** @brief: set and get the parameter segEgbThresholdII. -* This parameter is used in the third stage -* mentioned above. It serves the same purpose as segEgbThresholdI. -* The segmentation result tends to have more regions remained if -* this value is large and vice versa. -*/ -CV_WRAP virtual void setSegEgbThresholdII(float c) = 0; -CV_WRAP virtual float getSegEgbThresholdII() = 0; - - -/** @brief: set and get the parameter minRegionSizeII. -* This parameter is used in the third stage -* mentioned above. It serves the same purpose as minRegionSizeI -*/ -CV_WRAP virtual void setMinRegionSizeII(int n) = 0; -CV_WRAP virtual int getMinRegionSizeII() = 0; - - -/** @brief: set and get the parameter spatialWeight. -* This parameter is used in the first stage -* mentioned above(the SLIC stage). It describes how important is the role -* of position when calculating the distance between each pixel and it's -* center. The exact formula to calculate the distance is -* \f$colorDistance + spatialWeight \times spatialDistance\f$. -* The segmentation result tends to have more local consistency -* if this value is larger. -*/ -CV_WRAP virtual void setSpatialWeight(float w) = 0; -CV_WRAP virtual float getSpatialWeight() = 0; - - -/** @brief: set and get the parameter slicSpixelSize. -* This parameter is used in the first stage mentioned -* above(the SLIC stage). It describes the size of each -* superpixel when initializing SLIC. Every superpixel -* approximately has \f$slicSpixelSize \times slicSpixelSize\f$ -* pixels in the beginning. -*/ -CV_WRAP virtual void setSlicSpixelSize(int n) = 0; -CV_WRAP virtual int getSlicSpixelSize() = 0; - - -/** @brief: set and get the parameter numSlicIter. -* This parameter is used in the first stage. It -* describes how many iteration to perform when executing SLIC. -*/ -CV_WRAP virtual void setNumSlicIter(int n) = 0; -CV_WRAP virtual int getNumSlicIter() = 0; - -/** @brief do segmentation gpu -* @param src: the input image -* @param ifDraw: if draw the image in the returned Mat. if this parameter is false, -* then the content of the returned Mat is a matrix of index, describing the region -* each pixel belongs to. And it's data type is CV_16U. If this parameter is true, -* then the returned Mat is a segmented picture, and color of each region is the -* average color of all pixels in that region. And it's data type is the same as -* the input image -*/ -CV_WRAP virtual Mat performSegmentGpu(InputArray src, bool ifDraw = true) = 0; - -/** @brief do segmentation with cpu -* This method is only implemented for reference. -* It is highly NOT recommanded to use it. -*/ -CV_WRAP virtual Mat performSegmentCpu(InputArray src, bool ifDraw = true) = 0; - -/** @brief: create a hfs object -* @param height: the height of the input image -* @param width: the width of the input image -* @param segEgbThresholdI: parameter segEgbThresholdI -* @param minRegionSizeI: parameter minRegionSizeI -* @param segEgbThresholdII: parameter segEgbThresholdII -* @param minRegionSizeII: parameter minRegionSizeII -* @param spatialWeight: parameter spatialWeight -* @param slicSpixelSize: parameter slicSpixelSize -* @param numSlicIter: parameter numSlicIter -*/ -CV_WRAP static Ptr create(int height, int width, - float segEgbThresholdI = 0.08f, int minRegionSizeI = 100, - float segEgbThresholdII = 0.28f, int minRegionSizeII = 200, - float spatialWeight = 0.6f, int slicSpixelSize = 8, int numSlicIter = 5); - -}; - -//! @} - -}} // namespace cv { namespace hfs { diff --git a/3rdparty/include/opencv2/highgui.hpp b/3rdparty/include/opencv2/highgui.hpp index 6a8c598720..cdab0ada78 100644 --- a/3rdparty/include/opencv2/highgui.hpp +++ b/3rdparty/include/opencv2/highgui.hpp @@ -202,7 +202,8 @@ enum WindowPropertyFlags { WND_PROP_ASPECT_RATIO = 2, //!< window's aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO). WND_PROP_OPENGL = 3, //!< opengl support. WND_PROP_VISIBLE = 4, //!< checks whether the window exists and is visible - WND_PROP_TOPMOST = 5 //!< property to toggle normal window being topmost or not + WND_PROP_TOPMOST = 5, //!< property to toggle normal window being topmost or not + WND_PROP_VSYNC = 6 //!< enable or disable VSYNC (in OpenGL mode) }; //! Mouse Events see cv::MouseCallback @@ -347,23 +348,34 @@ The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\le milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is running on your computer at that time. It returns the code of the pressed key or -1 if no key was -pressed before the specified time had elapsed. +pressed before the specified time had elapsed. To check for a key press but not wait for it, use +#pollKey. -@note +@note The functions #waitKey and #pollKey are the only methods in HighGUI that can fetch and handle +GUI events, so one of them needs to be called periodically for normal event processing unless +HighGUI is used within an environment that takes care of event processing. -This function is the only method in HighGUI that can fetch and handle events, so it needs to be -called periodically for normal event processing unless HighGUI is used within an environment that -takes care of event processing. - -@note - -The function only works if there is at least one HighGUI window created and the window is active. -If there are several HighGUI windows, any of them can be active. +@note The function only works if there is at least one HighGUI window created and the window is +active. If there are several HighGUI windows, any of them can be active. @param delay Delay in milliseconds. 0 is the special value that means "forever". */ CV_EXPORTS_W int waitKey(int delay = 0); +/** @brief Polls for a pressed key. + +The function pollKey polls for a key event without waiting. It returns the code of the pressed key +or -1 if no key was pressed since the last invocation. To wait until a key was pressed, use #waitKey. + +@note The functions #waitKey and #pollKey are the only methods in HighGUI that can fetch and handle +GUI events, so one of them needs to be called periodically for normal event processing unless +HighGUI is used within an environment that takes care of event processing. + +@note The function only works if there is at least one HighGUI window created and the window is +active. If there are several HighGUI windows, any of them can be active. + */ +CV_EXPORTS_W int pollKey(); + /** @brief Displays an image in the specified window. The function imshow displays an image in the specified window. If the window was created with the @@ -383,11 +395,12 @@ If the window was not created before this function, it is assumed creating a win If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow. -@note This function should be followed by cv::waitKey function which displays the image for specified -milliseconds. Otherwise, it won't display the image. For example, **waitKey(0)** will display the window -infinitely until any keypress (it is suitable for image display). **waitKey(25)** will display a frame -for 25 ms, after which display will be automatically closed. (If you put it in a loop to read -videos, it will display the video frame-by-frame) +@note This function should be followed by a call to cv::waitKey or cv::pollKey to perform GUI +housekeeping tasks that are necessary to actually show the given image and make the window respond +to mouse and keyboard events. Otherwise, it won't display the image and the window might lock up. +For example, **waitKey(0)** will display the window infinitely until any keypress (it is suitable +for image display). **waitKey(25)** will display a frame and wait approximately 25 ms for a key +press (suitable for displaying a video frame-by-frame). To remove the window, use cv::destroyWindow. @note @@ -544,7 +557,7 @@ displayed in the specified window winname. @note -[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar should be attached to the +[__Qt Backend Only__] winname can be empty if the trackbar should be attached to the control panel. Clicking the label of each trackbar enables editing the trackbar values manually. @@ -572,7 +585,7 @@ The function returns the current position of the specified trackbar. @note -[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control +[__Qt Backend Only__] winname can be empty if the trackbar is attached to the control panel. @param trackbarname Name of the trackbar. @@ -586,7 +599,7 @@ The function sets the position of the specified trackbar in the specified window @note -[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control +[__Qt Backend Only__] winname can be empty if the trackbar is attached to the control panel. @param trackbarname Name of the trackbar. @@ -601,7 +614,7 @@ The function sets the maximum position of the specified trackbar in the specifie @note -[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control +[__Qt Backend Only__] winname can be empty if the trackbar is attached to the control panel. @param trackbarname Name of the trackbar. @@ -616,7 +629,7 @@ The function sets the minimum position of the specified trackbar in the specifie @note -[__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control +[__Qt Backend Only__] winname can be empty if the trackbar is attached to the control panel. @param trackbarname Name of the trackbar. @@ -823,7 +836,7 @@ QT_NEW_BUTTONBAR flag is added to the type. See below various examples of the cv::createButton function call: : @code - createButton(NULL,callbackButton);//create a push button "button 0", that will call callbackButton. + createButton("",callbackButton);//create a push button "button 0", that will call callbackButton. createButton("button2",callbackButton,NULL,QT_CHECKBOX,0); createButton("button3",callbackButton,&value); createButton("button5",callbackButton1,NULL,QT_RADIOBOX); @@ -850,8 +863,4 @@ CV_EXPORTS int createButton( const String& bar_name, ButtonCallback on_change, } // cv -#ifndef DISABLE_OPENCV_24_COMPATIBILITY -#include "opencv2/highgui/highgui_c.h" -#endif - #endif diff --git a/3rdparty/include/opencv2/highgui/highgui_c.h b/3rdparty/include/opencv2/highgui/highgui_c.h index 35413139c7..5d20b9501e 100644 --- a/3rdparty/include/opencv2/highgui/highgui_c.h +++ b/3rdparty/include/opencv2/highgui/highgui_c.h @@ -44,12 +44,6 @@ #include "opencv2/core/core_c.h" #include "opencv2/imgproc/imgproc_c.h" -#ifdef HAVE_OPENCV_IMGCODECS -#include "opencv2/imgcodecs/imgcodecs_c.h" -#endif -#ifdef HAVE_OPENCV_VIDEOIO -#include "opencv2/videoio/videoio_c.h" -#endif #ifdef __cplusplus extern "C" { diff --git a/3rdparty/include/opencv2/img_hash.hpp b/3rdparty/include/opencv2/img_hash.hpp deleted file mode 100644 index 5e7a928462..0000000000 --- a/3rdparty/include/opencv2/img_hash.hpp +++ /dev/null @@ -1,78 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#ifndef OPENCV_IMG_HASH_H -#define OPENCV_IMG_HASH_H - -#include "opencv2/img_hash/average_hash.hpp" -#include "opencv2/img_hash/block_mean_hash.hpp" -#include "opencv2/img_hash/color_moment_hash.hpp" -#include "opencv2/img_hash/marr_hildreth_hash.hpp" -#include "opencv2/img_hash/phash.hpp" -#include "opencv2/img_hash/radial_variance_hash.hpp" - -/** -@defgroup img_hash The module brings implementations of different image hashing algorithms. - -Provide algorithms to extract the hash of images and fast way to figure out most similar images in -huge data set. - -Namespace for all functions is cv::img_hash. - -### Supported Algorithms - -- Average hash (also called Different hash) -- PHash (also called Perceptual hash) -- Marr Hildreth Hash -- Radial Variance Hash -- Block Mean Hash (modes 0 and 1) -- Color Moment Hash (this is the one and only hash algorithm resist to rotation attack(-90~90 degree)) - -You can study more about image hashing from following paper and websites: - -- "Implementation and benchmarking of perceptual image hash functions" @cite zauner2010implementation -- "Looks Like It" @cite lookslikeit - -### Code Example - -@include samples/hash_samples.cpp - -### Performance under different attacks - -![Performance chart](img_hash/doc/attack_performance.JPG) - -### Speed comparison with PHash library (100 images from ukbench) - -![Hash Computation chart](img_hash/doc/hash_computation_chart.JPG) -![Hash comparison chart](img_hash/doc/hash_comparison_chart.JPG) - -As you can see, hash computation speed of img_hash module outperform [PHash library](http://www.phash.org/) a lot. - -PS : I do not list out the comparison of Average hash, PHash and Color Moment hash, because I cannot -find them in PHash. - -### Motivation - -Collects useful image hash algorithms into opencv, so we do not need to rewrite them by ourselves -again and again or rely on another 3rd party library(ex : PHash library). BOVW or correlation -matching are good and robust, but they are very slow compare with image hash, if you need to deal -with large scale CBIR(content based image retrieval) problem, image hash is a more reasonable -solution. - -### More info - -You can learn more about img_hash modules from following links, these links show you how to find -similar image from ukbench dataset, provide thorough benchmark of different attacks(contrast, blur, -noise(gaussion,pepper and salt), jpeg compression, watermark, resize). - -* [Introduction to image hash module of opencv](http://qtandopencv.blogspot.my/2016/06/introduction-to-image-hash-module-of.html) -* [Speed up image hashing of opencv(img_hash) and introduce color moment hash](http://qtandopencv.blogspot.my/2016/06/speed-up-image-hashing-of-opencvimghash.html) - -### Contributors - -Tham Ngap Wei, thamngapwei@gmail.com - -*/ - -#endif // OPENCV_IMG_HASH_H diff --git a/3rdparty/include/opencv2/img_hash/average_hash.hpp b/3rdparty/include/opencv2/img_hash/average_hash.hpp deleted file mode 100644 index 1204441c3a..0000000000 --- a/3rdparty/include/opencv2/img_hash/average_hash.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#ifndef OPENCV_AVERAGE_HASH_HPP -#define OPENCV_AVERAGE_HASH_HPP - -#include "img_hash_base.hpp" - -namespace cv { -namespace img_hash { - -//! @addtogroup img_hash -//! @{ - -/** @brief Computes average hash value of the input image - -This is a fast image hashing algorithm, but only work on simple case. For more details, please -refer to @cite lookslikeit -*/ -class CV_EXPORTS_W AverageHash : public ImgHashBase -{ -public: - CV_WRAP static Ptr create(); -protected: - AverageHash() {} -}; - -/** @brief Calculates img_hash::AverageHash in one call -@param inputArr input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1. -@param outputArr Hash value of input, it will contain 16 hex decimal number, return type is CV_8U -*/ -CV_EXPORTS_W void averageHash(cv::InputArray inputArr, cv::OutputArray outputArr); - -//! @} - -}} // cv::img_hash:: - -#endif // OPENCV_AVERAGE_HASH_HPP diff --git a/3rdparty/include/opencv2/img_hash/block_mean_hash.hpp b/3rdparty/include/opencv2/img_hash/block_mean_hash.hpp deleted file mode 100644 index dbf2a5f861..0000000000 --- a/3rdparty/include/opencv2/img_hash/block_mean_hash.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#ifndef OPENCV_BLOCK_MEAN_HASH_HPP -#define OPENCV_BLOCK_MEAN_HASH_HPP - -#include "img_hash_base.hpp" - -namespace cv { -namespace img_hash { - -//! @addtogroup img_hash -//! @{ - -enum BlockMeanHashMode -{ - BLOCK_MEAN_HASH_MODE_0 = 0, //!< use fewer block and generate 16*16/8 uchar hash value - BLOCK_MEAN_HASH_MODE_1 = 1, //!< use block blocks(step sizes/2), generate 31*31/8 + 1 uchar hash value -}; - -/** @brief Image hash based on block mean. - -See @cite zauner2010implementation for details. -*/ -class CV_EXPORTS_W BlockMeanHash : public ImgHashBase -{ -public: - /** @brief Create BlockMeanHash object - @param mode the mode - */ - CV_WRAP void setMode(int mode); - CV_WRAP std::vector getMean() const; - CV_WRAP static Ptr create(int mode = BLOCK_MEAN_HASH_MODE_0); -protected: - BlockMeanHash() {} -}; - -/** @brief Computes block mean hash of the input image - @param inputArr input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1. - @param outputArr Hash value of input, it will contain 16 hex decimal number, return type is CV_8U - @param mode the mode -*/ -CV_EXPORTS_W void blockMeanHash(cv::InputArray inputArr, - cv::OutputArray outputArr, - int mode = BLOCK_MEAN_HASH_MODE_0); - -//! @} - -}} // cv::img_hash:: - -#endif // OPENCV_BLOCK_MEAN_HASH_HPP diff --git a/3rdparty/include/opencv2/img_hash/color_moment_hash.hpp b/3rdparty/include/opencv2/img_hash/color_moment_hash.hpp deleted file mode 100644 index d0a820bd9f..0000000000 --- a/3rdparty/include/opencv2/img_hash/color_moment_hash.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#ifndef OPENCV_COLOR_MOMENT_HASH_HPP -#define OPENCV_COLOR_MOMENT_HASH_HPP - -#include "img_hash_base.hpp" - -namespace cv { -namespace img_hash { - -//! @addtogroup img_hash -//! @{ - -/** @brief Image hash based on color moments. - -See @cite tang2012perceptual for details. -*/ -class CV_EXPORTS_W ColorMomentHash : public ImgHashBase -{ -public: - CV_WRAP static Ptr create(); -protected: - ColorMomentHash() {} -}; - -/** @brief Computes color moment hash of the input, the algorithm - is come from the paper "Perceptual Hashing for Color Images - Using Invariant Moments" - @param inputArr input image want to compute hash value, - type should be CV_8UC4, CV_8UC3 or CV_8UC1. - @param outputArr 42 hash values with type CV_64F(double) - */ -CV_EXPORTS_W void colorMomentHash(cv::InputArray inputArr, cv::OutputArray outputArr); - -//! @} - -}} // cv::img_hash:: - -#endif // OPENCV_COLOR_MOMENT_HASH_HPP diff --git a/3rdparty/include/opencv2/img_hash/img_hash_base.hpp b/3rdparty/include/opencv2/img_hash/img_hash_base.hpp deleted file mode 100644 index f0cc451ffd..0000000000 --- a/3rdparty/include/opencv2/img_hash/img_hash_base.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#ifndef OPENCV_IMG_HASH_BASE_HPP -#define OPENCV_IMG_HASH_BASE_HPP - -#include "opencv2/core.hpp" - -namespace cv { -namespace img_hash { - -//! @addtogroup img_hash -//! @{ - -/** @brief The base class for image hash algorithms - */ -class CV_EXPORTS_W ImgHashBase : public Algorithm -{ -public: - class ImgHashImpl; - - ~ImgHashBase(); - /** @brief Computes hash of the input image - @param inputArr input image want to compute hash value - @param outputArr hash of the image - */ - CV_WRAP void compute(cv::InputArray inputArr, cv::OutputArray outputArr); - /** @brief Compare the hash value between inOne and inTwo - @param hashOne Hash value one - @param hashTwo Hash value two - @return value indicate similarity between inOne and inTwo, the meaning - of the value vary from algorithms to algorithms - */ - CV_WRAP double compare(cv::InputArray hashOne, cv::InputArray hashTwo) const; -protected: - ImgHashBase(); -protected: - Ptr pImpl; -}; - -//! @} - -} } // cv::img_hash:: - -#endif // OPENCV_IMG_HASH_BASE_HPP diff --git a/3rdparty/include/opencv2/img_hash/marr_hildreth_hash.hpp b/3rdparty/include/opencv2/img_hash/marr_hildreth_hash.hpp deleted file mode 100644 index a9b04f9f9c..0000000000 --- a/3rdparty/include/opencv2/img_hash/marr_hildreth_hash.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#ifndef OPENCV_MARR_HILDRETH_HASH_HPP -#define OPENCV_MARR_HILDRETH_HASH_HPP - -#include "img_hash_base.hpp" - -namespace cv { -namespace img_hash { - -//! @addtogroup img_hash -//! @{ - -/** @brief Marr-Hildreth Operator Based Hash, slowest but more discriminative. - -See @cite zauner2010implementation for details. -*/ -class CV_EXPORTS_W MarrHildrethHash : public ImgHashBase -{ -public: - /** - * @brief self explain - */ - CV_WRAP float getAlpha() const; - - /** - * @brief self explain - */ - CV_WRAP float getScale() const; - - /** @brief Set Mh kernel parameters - @param alpha int scale factor for marr wavelet (default=2). - @param scale int level of scale factor (default = 1) - */ - CV_WRAP void setKernelParam(float alpha, float scale); - - /** - @param alpha int scale factor for marr wavelet (default=2). - @param scale int level of scale factor (default = 1) - */ - CV_WRAP static Ptr create(float alpha = 2.0f, float scale = 1.0f); -protected: - MarrHildrethHash() {} -}; - -/** @brief Computes average hash value of the input image - @param inputArr input image want to compute hash value, - type should be CV_8UC4, CV_8UC3, CV_8UC1. - @param outputArr Hash value of input, it will contain 16 hex - decimal number, return type is CV_8U - @param alpha int scale factor for marr wavelet (default=2). - @param scale int level of scale factor (default = 1) -*/ -CV_EXPORTS_W void marrHildrethHash(cv::InputArray inputArr, - cv::OutputArray outputArr, - float alpha = 2.0f, float scale = 1.0f); - -//! @} - -}} // cv::img_hash:: - -#endif // OPENCV_MARR_HILDRETH_HASH_HPP diff --git a/3rdparty/include/opencv2/img_hash/phash.hpp b/3rdparty/include/opencv2/img_hash/phash.hpp deleted file mode 100644 index d57cd6f3a8..0000000000 --- a/3rdparty/include/opencv2/img_hash/phash.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#ifndef OPENCV_PHASH_HPP -#define OPENCV_PHASH_HPP - -#include "img_hash_base.hpp" - -namespace cv { -namespace img_hash { - -//! @addtogroup img_hash -//! @{ - -/** @brief pHash - -Slower than average_hash, but tolerant of minor modifications - -This algorithm can combat more variation than averageHash, for more details please refer to @cite lookslikeit -*/ -class CV_EXPORTS_W PHash : public ImgHashBase -{ -public: - CV_WRAP static Ptr create(); -protected: - PHash() {} -}; - -/** @brief Computes pHash value of the input image - @param inputArr input image want to compute hash value, - type should be CV_8UC4, CV_8UC3, CV_8UC1. - @param outputArr Hash value of input, it will contain 8 uchar value -*/ -CV_EXPORTS_W void pHash(cv::InputArray inputArr, cv::OutputArray outputArr); - -//! @} - -} } // cv::img_hash:: - -#endif // OPENCV_PHASH_HPP diff --git a/3rdparty/include/opencv2/img_hash/radial_variance_hash.hpp b/3rdparty/include/opencv2/img_hash/radial_variance_hash.hpp deleted file mode 100644 index 455f2850eb..0000000000 --- a/3rdparty/include/opencv2/img_hash/radial_variance_hash.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// This file is part of OpenCV project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution and at http://opencv.org/license.html. - -#ifndef OPENCV_RADIAL_VARIANCE_HASH_HPP -#define OPENCV_RADIAL_VARIANCE_HASH_HPP - -#include "img_hash_base.hpp" - -namespace cv { -namespace img_hash { - -//! @addtogroup img_hash -//! @{ - - -/** @brief Image hash based on Radon transform. - -See @cite tang2012perceptual for details. -*/ -class CV_EXPORTS_W RadialVarianceHash : public ImgHashBase -{ -public: - CV_WRAP static Ptr create(double sigma = 1, int numOfAngleLine = 180); - - CV_WRAP int getNumOfAngleLine() const; - CV_WRAP double getSigma() const; - - CV_WRAP void setNumOfAngleLine(int value); - CV_WRAP void setSigma(double value); - - // internals - std::vector getFeatures(); - cv::Mat getHash(); - Mat getPixPerLine(Mat const &input); - Mat getProjection(); -protected: - RadialVarianceHash() {} -}; - -/** @brief Computes radial variance hash of the input image - @param inputArr input image want to compute hash value, - type should be CV_8UC4, CV_8UC3, CV_8UC1. - @param outputArr Hash value of input - @param sigma Gaussian kernel standard deviation - @param numOfAngleLine The number of angles to consider - */ -CV_EXPORTS_W void radialVarianceHash(cv::InputArray inputArr, - cv::OutputArray outputArr, - double sigma = 1, - int numOfAngleLine = 180); - - -//! @} - -}} // cv::img_hash:: - -#endif // OPENCV_RADIAL_VARIANCE_HASH_HPP diff --git a/3rdparty/include/opencv2/imgcodecs.hpp b/3rdparty/include/opencv2/imgcodecs.hpp index 7f6b24f0ff..d7ff9a178d 100644 --- a/3rdparty/include/opencv2/imgcodecs.hpp +++ b/3rdparty/include/opencv2/imgcodecs.hpp @@ -51,6 +51,7 @@ @defgroup imgcodecs_c C API @defgroup imgcodecs_flags Flags used for image file reading and writing @defgroup imgcodecs_ios iOS glue + @defgroup imgcodecs_macosx MacOS(OSX) glue @} */ @@ -94,12 +95,14 @@ enum ImwriteFlags { IMWRITE_PNG_BILEVEL = 18, //!< Binary level PNG, 0 or 1, default is 0. IMWRITE_PXM_BINARY = 32, //!< For PPM, PGM, or PBM, it can be a binary format flag, 0 or 1. Default value is 1. IMWRITE_EXR_TYPE = (3 << 4) + 0, /* 48 */ //!< override EXR storage type (FLOAT (FP32) is default) + IMWRITE_EXR_COMPRESSION = (3 << 4) + 1, /* 49 */ //!< override EXR compression type (ZIP_COMPRESSION = 3 is default) IMWRITE_WEBP_QUALITY = 64, //!< For WEBP, it can be a quality from 1 to 100 (the higher is the better). By default (without any parameter) and for quality above 100 the lossless compression is used. IMWRITE_PAM_TUPLETYPE = 128,//!< For PAM, sets the TUPLETYPE field to the corresponding string value that is defined for the format - IMWRITE_TIFF_RESUNIT = 256,//!< For TIFF, use to specify which DPI resolution unit to set; see libtiff documentation for valid values. - IMWRITE_TIFF_XDPI = 257,//!< For TIFF, use to specify the X direction DPI. - IMWRITE_TIFF_YDPI = 258, //!< For TIFF, use to specify the Y direction DPI. - IMWRITE_TIFF_COMPRESSION = 259 //!< For TIFF, use to specify the image compression scheme. See libtiff for integer constants corresponding to compression formats. Note, for images whose depth is CV_32F, only libtiff's SGILOG compression scheme is used. For other supported depths, the compression scheme can be specified by this flag; LZW compression is the default. + IMWRITE_TIFF_RESUNIT = 256,//!< For TIFF, use to specify which DPI resolution unit to set; see libtiff documentation for valid values + IMWRITE_TIFF_XDPI = 257,//!< For TIFF, use to specify the X direction DPI + IMWRITE_TIFF_YDPI = 258, //!< For TIFF, use to specify the Y direction DPI + IMWRITE_TIFF_COMPRESSION = 259, //!< For TIFF, use to specify the image compression scheme. See libtiff for integer constants corresponding to compression formats. Note, for images whose depth is CV_32F, only libtiff's SGILOG compression scheme is used. For other supported depths, the compression scheme can be specified by this flag; LZW compression is the default. + IMWRITE_JPEG2000_COMPRESSION_X1000 = 272 //!< For JPEG2000, use to specify the target compression rate (multiplied by 1000). The value can be from 0 to 1000. Default is 1000. }; enum ImwriteEXRTypeFlags { @@ -108,6 +111,19 @@ enum ImwriteEXRTypeFlags { IMWRITE_EXR_TYPE_FLOAT = 2 //!< store as FP32 (default) }; +enum ImwriteEXRCompressionFlags { + IMWRITE_EXR_COMPRESSION_NO = 0, //!< no compression + IMWRITE_EXR_COMPRESSION_RLE = 1, //!< run length encoding + IMWRITE_EXR_COMPRESSION_ZIPS = 2, //!< zlib compression, one scan line at a time + IMWRITE_EXR_COMPRESSION_ZIP = 3, //!< zlib compression, in blocks of 16 scan lines + IMWRITE_EXR_COMPRESSION_PIZ = 4, //!< piz-based wavelet compression + IMWRITE_EXR_COMPRESSION_PXR24 = 5, //!< lossy 24-bit float compression + IMWRITE_EXR_COMPRESSION_B44 = 6, //!< lossy 4-by-4 pixel block compression, fixed compression rate + IMWRITE_EXR_COMPRESSION_B44A = 7, //!< lossy 4-by-4 pixel block compression, flat fields are compressed more + IMWRITE_EXR_COMPRESSION_DWAA = 8, //!< lossy DCT based compression, in blocks of 32 scanlines. More efficient for partial buffer access. Supported since OpenEXR 2.2.0. + IMWRITE_EXR_COMPRESSION_DWAB = 9, //!< lossy DCT based compression, in blocks of 256 scanlines. More efficient space wise and faster to decode full frames than DWAA_COMPRESSION. Supported since OpenEXR 2.2.0. + }; + //! Imwrite PNG specific flags used to tune the compression algorithm. /** These flags will be modify the way of PNG image compression and will be passed to the underlying zlib processing stage. @@ -152,6 +168,7 @@ Currently, the following file formats are supported: - Portable Network Graphics - \*.png (see the *Note* section) - WebP - \*.webp (see the *Note* section) - Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported) +- PFM files - \*.pfm (see the *Note* section) - Sun rasters - \*.sr, \*.ras (always supported) - TIFF files - \*.tiff, \*.tif (see the *Note* section) - OpenEXR Image files - \*.exr (see the *Note* section) @@ -179,6 +196,7 @@ Currently, the following file formats are supported: - If EXIF information is embedded in the image file, the EXIF orientation will be taken into account and thus the image will be rotated accordingly except if the flags @ref IMREAD_IGNORE_ORIENTATION or @ref IMREAD_UNCHANGED are passed. +- Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image. - By default number of pixels must be less than 2^30. Limit can be set using system variable OPENCV_IO_MAX_IMAGE_PIXELS @@ -197,6 +215,26 @@ The function imreadmulti loads a multi-page image from the specified file into a */ CV_EXPORTS_W bool imreadmulti(const String& filename, CV_OUT std::vector& mats, int flags = IMREAD_ANYCOLOR); +/** @brief Loads a of images of a multi-page image from a file. + +The function imreadmulti loads a specified range from a multi-page image from the specified file into a vector of Mat objects. +@param filename Name of file to be loaded. +@param start Start index of the image to load +@param count Count number of images to load +@param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR. +@param mats A vector of Mat objects holding each page, if more than one. +@sa cv::imread +*/ +CV_EXPORTS_W bool imreadmulti(const String& filename, CV_OUT std::vector& mats, int start, int count, int flags = IMREAD_ANYCOLOR); + +/** @brief Returns the number of images inside the give file + +The function imcount will return the number of pages in a multi-page image, or 1 for single-page images +@param filename Name of file to be loaded. +@param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR. +*/ +CV_EXPORTS_W size_t imcount(const String& filename, int flags = IMREAD_ANYCOLOR); + /** @brief Saves an image to a specified file. The function imwrite saves the image to the specified file. The image format is chosen based on the @@ -205,13 +243,16 @@ single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function, with these exceptions: - 16-bit unsigned (CV_16U) images can be saved in the case of PNG, JPEG 2000, and TIFF formats -- 32-bit float (CV_32F) images can be saved in TIFF, OpenEXR, and Radiance HDR formats; 3-channel -(CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding (4 bytes per pixel) +- 32-bit float (CV_32F) images can be saved in PFM, TIFF, OpenEXR, and Radiance HDR formats; + 3-channel (CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding + (4 bytes per pixel) - PNG images with an alpha channel can be saved using this function. To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below). - Multiple images (vector of Mat) can be saved in TIFF format (see the code sample below). +If the image format is not supported, the image will be converted to 8-bit unsigned (CV_8U) and saved that way. + If the format, depth or channel order is different, use Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O functions to save the image to XML or YAML format. @@ -269,6 +310,19 @@ CV_EXPORTS_W bool imencode( const String& ext, InputArray img, CV_OUT std::vector& buf, const std::vector& params = std::vector()); +/** @brief Returns true if the specified image can be decoded by OpenCV + +@param filename File name of the image +*/ +CV_EXPORTS_W bool haveImageReader( const String& filename ); + +/** @brief Returns true if an image with the specified filename can be encoded by OpenCV + + @param filename File name of the image + */ +CV_EXPORTS_W bool haveImageWriter( const String& filename ); + + //! @} imgcodecs } // cv diff --git a/3rdparty/include/opencv2/imgcodecs/imgcodecs_c.h b/3rdparty/include/opencv2/imgcodecs/imgcodecs_c.h index c36dac3343..c78b3f72fa 100644 --- a/3rdparty/include/opencv2/imgcodecs/imgcodecs_c.h +++ b/3rdparty/include/opencv2/imgcodecs/imgcodecs_c.h @@ -1,149 +1 @@ -/*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. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_IMGCODECS_H -#define OPENCV_IMGCODECS_H - -#include "opencv2/core/core_c.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** @addtogroup imgcodecs_c - @{ - */ - -enum -{ -/* 8bit, color or not */ - CV_LOAD_IMAGE_UNCHANGED =-1, -/* 8bit, gray */ - CV_LOAD_IMAGE_GRAYSCALE =0, -/* ?, color */ - CV_LOAD_IMAGE_COLOR =1, -/* any depth, ? */ - CV_LOAD_IMAGE_ANYDEPTH =2, -/* ?, any color */ - CV_LOAD_IMAGE_ANYCOLOR =4, -/* ?, no rotate */ - CV_LOAD_IMAGE_IGNORE_ORIENTATION =128 -}; - -/* load image from file - iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED - overrides the other flags - using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED - unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit -*/ -CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); -CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); - -enum -{ - CV_IMWRITE_JPEG_QUALITY =1, - CV_IMWRITE_JPEG_PROGRESSIVE =2, - CV_IMWRITE_JPEG_OPTIMIZE =3, - CV_IMWRITE_JPEG_RST_INTERVAL =4, - CV_IMWRITE_JPEG_LUMA_QUALITY =5, - CV_IMWRITE_JPEG_CHROMA_QUALITY =6, - CV_IMWRITE_PNG_COMPRESSION =16, - CV_IMWRITE_PNG_STRATEGY =17, - CV_IMWRITE_PNG_BILEVEL =18, - CV_IMWRITE_PNG_STRATEGY_DEFAULT =0, - CV_IMWRITE_PNG_STRATEGY_FILTERED =1, - CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2, - CV_IMWRITE_PNG_STRATEGY_RLE =3, - CV_IMWRITE_PNG_STRATEGY_FIXED =4, - CV_IMWRITE_PXM_BINARY =32, - CV_IMWRITE_EXR_TYPE = 48, - CV_IMWRITE_WEBP_QUALITY =64, - CV_IMWRITE_PAM_TUPLETYPE = 128, - CV_IMWRITE_PAM_FORMAT_NULL = 0, - CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, - CV_IMWRITE_PAM_FORMAT_GRAYSCALE = 2, - CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, - CV_IMWRITE_PAM_FORMAT_RGB = 4, - CV_IMWRITE_PAM_FORMAT_RGB_ALPHA = 5, -}; - - - -/* save image to file */ -CVAPI(int) cvSaveImage( const char* filename, const CvArr* image, - const int* params CV_DEFAULT(0) ); - -/* decode image stored in the buffer */ -CVAPI(IplImage*) cvDecodeImage( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); -CVAPI(CvMat*) cvDecodeImageM( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); - -/* encode image and store the result as a byte vector (single-row 8uC1 matrix) */ -CVAPI(CvMat*) cvEncodeImage( const char* ext, const CvArr* image, - const int* params CV_DEFAULT(0) ); - -enum -{ - CV_CVTIMG_FLIP =1, - CV_CVTIMG_SWAP_RB =2 -}; - -/* utility function: convert one image to another with optional vertical flip */ -CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0)); - -CVAPI(int) cvHaveImageReader(const char* filename); -CVAPI(int) cvHaveImageWriter(const char* filename); - - -/****************************************************************************************\ -* Obsolete functions/synonyms * -\****************************************************************************************/ - -#define cvvLoadImage(name) cvLoadImage((name),1) -#define cvvSaveImage cvSaveImage -#define cvvConvertImage cvConvertImage - -/** @} imgcodecs_c */ - -#ifdef __cplusplus -} -#endif - -#endif // OPENCV_IMGCODECS_H +#error "This header with legacy C API declarations has been removed from OpenCV. Legacy constants are available from legacy/constants_c.h file." diff --git a/3rdparty/include/opencv2/imgcodecs/ios.h b/3rdparty/include/opencv2/imgcodecs/ios.h index a90c6d37a8..5f17218170 100644 --- a/3rdparty/include/opencv2/imgcodecs/ios.h +++ b/3rdparty/include/opencv2/imgcodecs/ios.h @@ -45,11 +45,13 @@ #import #import #import -#include "opencv2/core/core.hpp" +#include "opencv2/core.hpp" //! @addtogroup imgcodecs_ios //! @{ +CV_EXPORTS CGImageRef MatToCGImage(const cv::Mat& image) CF_RETURNS_RETAINED; +CV_EXPORTS void CGImageToMat(const CGImageRef image, cv::Mat& m, bool alphaExist = false); CV_EXPORTS UIImage* MatToUIImage(const cv::Mat& image); CV_EXPORTS void UIImageToMat(const UIImage* image, cv::Mat& m, bool alphaExist = false); diff --git a/3rdparty/include/opencv2/imgcodecs/legacy/constants_c.h b/3rdparty/include/opencv2/imgcodecs/legacy/constants_c.h new file mode 100644 index 0000000000..de7be4f74d --- /dev/null +++ b/3rdparty/include/opencv2/imgcodecs/legacy/constants_c.h @@ -0,0 +1,54 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_IMGCODECS_LEGACY_CONSTANTS_H +#define OPENCV_IMGCODECS_LEGACY_CONSTANTS_H + +/* duplicate of "ImreadModes" enumeration for better compatibility with OpenCV 3.x */ +enum +{ +/* 8bit, color or not */ + CV_LOAD_IMAGE_UNCHANGED =-1, +/* 8bit, gray */ + CV_LOAD_IMAGE_GRAYSCALE =0, +/* ?, color */ + CV_LOAD_IMAGE_COLOR =1, +/* any depth, ? */ + CV_LOAD_IMAGE_ANYDEPTH =2, +/* ?, any color */ + CV_LOAD_IMAGE_ANYCOLOR =4, +/* ?, no rotate */ + CV_LOAD_IMAGE_IGNORE_ORIENTATION =128 +}; + +/* duplicate of "ImwriteFlags" enumeration for better compatibility with OpenCV 3.x */ +enum +{ + CV_IMWRITE_JPEG_QUALITY =1, + CV_IMWRITE_JPEG_PROGRESSIVE =2, + CV_IMWRITE_JPEG_OPTIMIZE =3, + CV_IMWRITE_JPEG_RST_INTERVAL =4, + CV_IMWRITE_JPEG_LUMA_QUALITY =5, + CV_IMWRITE_JPEG_CHROMA_QUALITY =6, + CV_IMWRITE_PNG_COMPRESSION =16, + CV_IMWRITE_PNG_STRATEGY =17, + CV_IMWRITE_PNG_BILEVEL =18, + CV_IMWRITE_PNG_STRATEGY_DEFAULT =0, + CV_IMWRITE_PNG_STRATEGY_FILTERED =1, + CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2, + CV_IMWRITE_PNG_STRATEGY_RLE =3, + CV_IMWRITE_PNG_STRATEGY_FIXED =4, + CV_IMWRITE_PXM_BINARY =32, + CV_IMWRITE_EXR_TYPE = 48, + CV_IMWRITE_WEBP_QUALITY =64, + CV_IMWRITE_PAM_TUPLETYPE = 128, + CV_IMWRITE_PAM_FORMAT_NULL = 0, + CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, + CV_IMWRITE_PAM_FORMAT_GRAYSCALE = 2, + CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, + CV_IMWRITE_PAM_FORMAT_RGB = 4, + CV_IMWRITE_PAM_FORMAT_RGB_ALPHA = 5, +}; + +#endif // OPENCV_IMGCODECS_LEGACY_CONSTANTS_H diff --git a/3rdparty/include/opencv2/imgcodecs/macosx.h b/3rdparty/include/opencv2/imgcodecs/macosx.h new file mode 100644 index 0000000000..cfb0770700 --- /dev/null +++ b/3rdparty/include/opencv2/imgcodecs/macosx.h @@ -0,0 +1,20 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#if !defined(__APPLE__) || !defined(__MACH__) +#error This header should be used in macOS ObjC/Swift projects. +#endif + +#import +#include "opencv2/core.hpp" + +//! @addtogroup imgcodecs_macosx +//! @{ + +CV_EXPORTS CGImageRef MatToCGImage(const cv::Mat& image) CF_RETURNS_RETAINED; +CV_EXPORTS void CGImageToMat(const CGImageRef image, cv::Mat& m, bool alphaExist = false); +CV_EXPORTS NSImage* MatToNSImage(const cv::Mat& image); +CV_EXPORTS void NSImageToMat(const NSImage* image, cv::Mat& m, bool alphaExist = false); + +//! @} diff --git a/3rdparty/include/opencv2/imgproc.hpp b/3rdparty/include/opencv2/imgproc.hpp index 2739d28ff9..88c960747c 100644 --- a/3rdparty/include/opencv2/imgproc.hpp +++ b/3rdparty/include/opencv2/imgproc.hpp @@ -185,6 +185,7 @@ location of points on the plane, building special graphs (such as NNG,RNG), and @defgroup imgproc_motion Motion Analysis and Object Tracking @defgroup imgproc_feature Feature Detection @defgroup imgproc_object Object Detection + @defgroup imgproc_segmentation Image Segmentation @defgroup imgproc_c C API @defgroup imgproc_hal Hardware Acceleration Layer @{ @@ -204,6 +205,10 @@ namespace cv //! @addtogroup imgproc_filter //! @{ +enum SpecialFilter { + FILTER_SCHARR = -1 +}; + //! type of morphological operation enum MorphTypes{ MORPH_ERODE = 0, //!< see #erode @@ -336,12 +341,6 @@ enum AdaptiveThresholdTypes { ADAPTIVE_THRESH_GAUSSIAN_C = 1 }; -//! cv::undistort mode -enum UndistortTypes { - PROJ_SPHERICAL_ORTHO = 0, - PROJ_SPHERICAL_EQRECT = 1 - }; - //! class of the pixel in GrabCut algorithm enum GrabCutClasses { GC_BGD = 0, //!< an obvious background pixels @@ -406,9 +405,13 @@ enum ConnectedComponentsTypes { //! connected components algorithm enum ConnectedComponentsAlgorithmsTypes { - CCL_WU = 0, //!< SAUF @cite Wu2009 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity - CCL_DEFAULT = -1, //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity - CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity + CCL_DEFAULT = -1, //!< BBDT @cite Grana2010 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both BBDT and SAUF. + CCL_WU = 0, //!< SAUF @cite Wu2009 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for SAUF. + CCL_GRANA = 1, //!< BBDT @cite Grana2010 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both BBDT and SAUF. + CCL_BOLELLI = 2, //!< Spaghetti @cite Bolelli2019 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. + CCL_SAUF = 3, //!< Same as CCL_WU. It is preferable to use the flag with the name of the algorithm (CCL_SAUF) rather than the one with the name of the first author (CCL_WU). + CCL_BBDT = 4, //!< Same as CCL_GRANA. It is preferable to use the flag with the name of the algorithm (CCL_BBDT) rather than the one with the name of the first author (CCL_GRANA). + CCL_SPAGHETTI = 5, //!< Same as CCL_BOLELLI. It is preferable to use the flag with the name of the algorithm (CCL_SPAGHETTI) rather than the one with the name of the first author (CCL_BOLELLI). }; //! mode of the contour retrieval algorithm @@ -478,7 +481,8 @@ enum HoughModes { /** multi-scale variant of the classical Hough transform. The lines are encoded the same way as HOUGH_STANDARD. */ HOUGH_MULTI_SCALE = 2, - HOUGH_GRADIENT = 3 //!< basically *21HT*, described in @cite Yuen90 + HOUGH_GRADIENT = 3, //!< basically *21HT*, described in @cite Yuen90 + HOUGH_GRADIENT_ALT = 4, //!< variation of HOUGH_GRADIENT to get better accuracy }; //! Variants of Line Segment %Detector @@ -587,7 +591,7 @@ enum ColorConversionCodes { COLOR_YCrCb2BGR = 38, COLOR_YCrCb2RGB = 39, - COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions" + COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value) with H range 0..180 if 8 bit image, @ref color_convert_rgb_hsv "color conversions" COLOR_RGB2HSV = 41, COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions" @@ -595,27 +599,27 @@ enum ColorConversionCodes { COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions" COLOR_RGB2Luv = 51, - COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions" + COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation) with H range 0..180 if 8 bit image, @ref color_convert_rgb_hls "color conversions" COLOR_RGB2HLS = 53, - COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR + COLOR_HSV2BGR = 54, //!< backward conversions HSV to RGB/BGR with H range 0..180 if 8 bit image COLOR_HSV2RGB = 55, COLOR_Lab2BGR = 56, COLOR_Lab2RGB = 57, COLOR_Luv2BGR = 58, COLOR_Luv2RGB = 59, - COLOR_HLS2BGR = 60, + COLOR_HLS2BGR = 60, //!< backward conversions HLS to RGB/BGR with H range 0..180 if 8 bit image COLOR_HLS2RGB = 61, - COLOR_BGR2HSV_FULL = 66, + COLOR_BGR2HSV_FULL = 66, //!< convert RGB/BGR to HSV (hue saturation value) with H range 0..255 if 8 bit image, @ref color_convert_rgb_hsv "color conversions" COLOR_RGB2HSV_FULL = 67, - COLOR_BGR2HLS_FULL = 68, + COLOR_BGR2HLS_FULL = 68, //!< convert RGB/BGR to HLS (hue lightness saturation) with H range 0..255 if 8 bit image, @ref color_convert_rgb_hls "color conversions" COLOR_RGB2HLS_FULL = 69, - COLOR_HSV2BGR_FULL = 70, + COLOR_HSV2BGR_FULL = 70, //!< backward conversions HSV to RGB/BGR with H range 0..255 if 8 bit image COLOR_HSV2RGB_FULL = 71, - COLOR_HLS2BGR_FULL = 72, + COLOR_HLS2BGR_FULL = 72, //!< backward conversions HLS to RGB/BGR with H range 0..255 if 8 bit image COLOR_HLS2RGB_FULL = 73, COLOR_LBGR2Lab = 74, @@ -802,6 +806,45 @@ enum RectanglesIntersectTypes { INTERSECT_FULL = 2 //!< One of the rectangle is fully enclosed in the other }; +/** types of line +@ingroup imgproc_draw +*/ +enum LineTypes { + FILLED = -1, + LINE_4 = 4, //!< 4-connected line + LINE_8 = 8, //!< 8-connected line + LINE_AA = 16 //!< antialiased line +}; + +/** Only a subset of Hershey fonts are supported +@ingroup imgproc_draw +*/ +enum HersheyFonts { + FONT_HERSHEY_SIMPLEX = 0, //!< normal size sans-serif font + FONT_HERSHEY_PLAIN = 1, //!< small size sans-serif font + FONT_HERSHEY_DUPLEX = 2, //!< normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX) + FONT_HERSHEY_COMPLEX = 3, //!< normal size serif font + FONT_HERSHEY_TRIPLEX = 4, //!< normal size serif font (more complex than FONT_HERSHEY_COMPLEX) + FONT_HERSHEY_COMPLEX_SMALL = 5, //!< smaller version of FONT_HERSHEY_COMPLEX + FONT_HERSHEY_SCRIPT_SIMPLEX = 6, //!< hand-writing style font + FONT_HERSHEY_SCRIPT_COMPLEX = 7, //!< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX + FONT_ITALIC = 16 //!< flag for italic font +}; + +/** Possible set of marker types used for the cv::drawMarker function +@ingroup imgproc_draw +*/ +enum MarkerTypes +{ + MARKER_CROSS = 0, //!< A crosshair marker shape + MARKER_TILTED_CROSS = 1, //!< A 45 degree tilted crosshair marker shape + MARKER_STAR = 2, //!< A star marker shape, combination of cross and tilted cross + MARKER_DIAMOND = 3, //!< A diamond marker shape + MARKER_SQUARE = 4, //!< A square marker shape + MARKER_TRIANGLE_UP = 5, //!< An upwards pointing triangle marker shape + MARKER_TRIANGLE_DOWN = 6 //!< A downwards pointing triangle marker shape +}; + /** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform */ class CV_EXPORTS_W GeneralizedHough : public Algorithm @@ -1177,7 +1220,7 @@ protected: struct CV_EXPORTS Vertex { Vertex(); - Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0); + Vertex(Point2f pt, bool isvirtual, int firstEdge=0); bool isvirtual() const; bool isfree() const; @@ -1233,9 +1276,9 @@ public: ![image](pics/building_lsd.png) - @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use: + @param image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use: `lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);` - @param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where + @param lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly oriented depending on the gradient. @param width Vector of widths of the regions, where the lines are found. E.g. Width of line. @@ -1247,26 +1290,26 @@ public: - 1 corresponds to 0.1 mean false alarms This vector will be calculated only when the objects type is #LSD_REFINE_ADV. */ - CV_WRAP virtual void detect(InputArray _image, OutputArray _lines, + CV_WRAP virtual void detect(InputArray image, OutputArray lines, OutputArray width = noArray(), OutputArray prec = noArray(), OutputArray nfa = noArray()) = 0; /** @brief Draws the line segments on a given image. - @param _image The image, where the lines will be drawn. Should be bigger or equal to the image, + @param image The image, where the lines will be drawn. Should be bigger or equal to the image, where the lines were found. @param lines A vector of the lines that needed to be drawn. */ - CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0; + CV_WRAP virtual void drawSegments(InputOutputArray image, InputArray lines) = 0; /** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels. @param size The size of the image, where lines1 and lines2 were found. @param lines1 The first group of lines that needs to be drawn. It is visualized in blue color. @param lines2 The second group of lines. They visualized in red color. - @param _image Optional image, where the lines will be drawn. The image should be color(3-channel) + @param image Optional image, where the lines will be drawn. The image should be color(3-channel) in order for lines1 and lines2 to be drawn in the above mentioned colors. */ - CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0; + CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray image = noArray()) = 0; virtual ~LineSegmentDetector() { } }; @@ -1276,22 +1319,21 @@ public: The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want to edit those, as to tailor it for their own application. -@param _refine The way found lines will be refined, see #LineSegmentDetectorModes -@param _scale The scale of the image that will be used to find the lines. Range (0..1]. -@param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale. -@param _quant Bound to the quantization error on the gradient norm. -@param _ang_th Gradient angle tolerance in degrees. -@param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement -is chosen. -@param _density_th Minimal density of aligned region points in the enclosing rectangle. -@param _n_bins Number of bins in pseudo-ordering of gradient modulus. +@param refine The way found lines will be refined, see #LineSegmentDetectorModes +@param scale The scale of the image that will be used to find the lines. Range (0..1]. +@param sigma_scale Sigma for Gaussian filter. It is computed as sigma = sigma_scale/scale. +@param quant Bound to the quantization error on the gradient norm. +@param ang_th Gradient angle tolerance in degrees. +@param log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement is chosen. +@param density_th Minimal density of aligned region points in the enclosing rectangle. +@param n_bins Number of bins in pseudo-ordering of gradient modulus. @note Implementation has been removed due original code license conflict */ CV_EXPORTS_W Ptr createLineSegmentDetector( - int _refine = LSD_REFINE_STD, double _scale = 0.8, - double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, - double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024); + int refine = LSD_REFINE_STD, double scale = 0.8, + double sigma_scale = 0.6, double quant = 2.0, double ang_th = 22.5, + double log_eps = 0, double density_th = 0.7, int n_bins = 1024); //! @} imgproc_feature @@ -1321,14 +1363,14 @@ CV_EXPORTS_W Mat getGaussianKernel( int ksize, double sigma, int ktype = CV_64F /** @brief Returns filter coefficients for computing spatial image derivatives. The function computes and returns the filter coefficients for spatial image derivatives. When -`ksize=CV_SCHARR`, the Scharr \f$3 \times 3\f$ kernels are generated (see #Scharr). Otherwise, Sobel +`ksize=FILTER_SCHARR`, the Scharr \f$3 \times 3\f$ kernels are generated (see #Scharr). Otherwise, Sobel kernels are generated (see #Sobel). The filters are normally passed to #sepFilter2D or to @param kx Output matrix of row filter coefficients. It has the type ktype . @param ky Output matrix of column filter coefficients. It has the type ktype . @param dx Derivative order in respect of x. @param dy Derivative order in respect of y. -@param ksize Aperture size. It can be CV_SCHARR, 1, 3, 5, or 7. +@param ksize Aperture size. It can be FILTER_SCHARR, 1, 3, 5, or 7. @param normalize Flag indicating whether to normalize (scale down) the filter coefficients or not. Theoretically, the coefficients should have the denominator \f$=2^{ksize*2-dx-dy-2}\f$. If you are going to filter floating-point images, you are likely to use the normalized kernels. But if you @@ -1490,7 +1532,7 @@ The unnormalized square box filter can be useful in computing local image statis variance and standard deviation around the neighborhood of a pixel. @param src input image -@param dst output image of the same size and type as _src +@param dst output image of the same size and type as src @param ddepth the output image depth (-1 to use src.depth()) @param ksize kernel size @param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel @@ -1595,7 +1637,7 @@ calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first or the second x- or y- derivatives. -There is also the special value `ksize = #CV_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr +There is also the special value `ksize = #FILTER_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is \f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f] @@ -1667,7 +1709,7 @@ call is equivalent to -\f[\texttt{Sobel(src, dst, ddepth, dx, dy, CV_SCHARR, scale, delta, borderType)} .\f] +\f[\texttt{Sobel(src, dst, ddepth, dx, dy, FILTER_SCHARR, scale, delta, borderType)} .\f] @param src input image. @param dst output image of the same size and the same number of channels as src. @@ -1960,6 +2002,38 @@ CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners, InputArray mask, int blockSize, int gradientSize, bool useHarrisDetector = false, double k = 0.04 ); + +/** @brief Same as above, but returns also quality measure of the detected corners. + +@param image Input 8-bit or floating-point 32-bit, single-channel image. +@param corners Output vector of detected corners. +@param maxCorners Maximum number of corners to return. If there are more corners than are found, +the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set +and all detected corners are returned. +@param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The +parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue +(see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the +quality measure less than the product are rejected. For example, if the best corner has the +quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure +less than 15 are rejected. +@param minDistance Minimum possible Euclidean distance between the returned corners. +@param mask Region of interest. If the image is not empty (it needs to have the type +CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected. +@param cornersQuality Output vector of quality measure of the detected corners. +@param blockSize Size of an average block for computing a derivative covariation matrix over each +pixel neighborhood. See cornerEigenValsAndVecs . +@param gradientSize Aperture parameter for the Sobel operator used for derivatives computation. +See cornerEigenValsAndVecs . +@param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris) +or #cornerMinEigenVal. +@param k Free parameter of the Harris detector. + */ +CV_EXPORTS CV_WRAP_AS(goodFeaturesToTrackWithQuality) void goodFeaturesToTrack( + InputArray image, OutputArray corners, + int maxCorners, double qualityLevel, double minDistance, + InputArray mask, OutputArray cornersQuality, int blockSize = 3, + int gradientSize = 3, bool useHarrisDetector = false, double k = 0.04); + /** @example samples/cpp/tutorial_code/ImgTrans/houghlines.cpp An example using the Hough line detector ![Sample input image](Hough_Lines_Tutorial_Original_Image.jpg) ![Output image](Hough_Lines_Tutorial_Result.jpg) @@ -2032,8 +2106,8 @@ CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines, The function finds lines in a set of points using a modification of the Hough transform. @include snippets/imgproc_HoughLinesPointSet.cpp -@param _point Input vector of points. Each vector must be encoded as a Point vector \f$(x,y)\f$. Type must be CV_32FC2 or CV_32SC2. -@param _lines Output vector of found lines. Each vector is encoded as a vector \f$(votes, rho, theta)\f$. +@param point Input vector of points. Each vector must be encoded as a Point vector \f$(x,y)\f$. Type must be CV_32FC2 or CV_32SC2. +@param lines Output vector of found lines. Each vector is encoded as a vector \f$(votes, rho, theta)\f$. The larger the value of 'votes', the higher the reliability of the Hough line. @param lines_max Max count of hough lines. @param threshold Accumulator threshold parameter. Only those lines are returned that get enough @@ -2045,7 +2119,7 @@ votes ( \f$>\texttt{threshold}\f$ ) @param max_theta Maximum angle value of the accumulator in radians. @param theta_step Angle resolution of the accumulator in radians. */ -CV_EXPORTS_W void HoughLinesPointSet( InputArray _point, OutputArray _lines, int lines_max, int threshold, +CV_EXPORTS_W void HoughLinesPointSet( InputArray point, OutputArray lines, int lines_max, int threshold, double min_rho, double max_rho, double rho_step, double min_theta, double max_theta, double theta_step ); @@ -2062,28 +2136,37 @@ Example: : @note Usually the function detects the centers of circles well. However, it may fail to find correct radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if -you know it. Or, you may set maxRadius to a negative number to return centers only without radius -search, and find the correct radius using an additional procedure. +you know it. Or, in the case of #HOUGH_GRADIENT method you may set maxRadius to a negative number +to return centers only without radius search, and find the correct radius using an additional procedure. + +It also helps to smooth image a bit unless it's already soft. For example, +GaussianBlur() with 7x7 kernel and 1.5x1.5 sigma or similar blurring may help. @param image 8-bit, single-channel, grayscale input image. @param circles Output vector of found circles. Each vector is encoded as 3 or 4 element floating-point vector \f$(x, y, radius)\f$ or \f$(x, y, radius, votes)\f$ . -@param method Detection method, see #HoughModes. Currently, the only implemented method is #HOUGH_GRADIENT +@param method Detection method, see #HoughModes. The available methods are #HOUGH_GRADIENT and #HOUGH_GRADIENT_ALT. @param dp Inverse ratio of the accumulator resolution to the image resolution. For example, if dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has -half as big width and height. +half as big width and height. For #HOUGH_GRADIENT_ALT the recommended value is dp=1.5, +unless some small very circles need to be detected. @param minDist Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed. -@param param1 First method-specific parameter. In case of #HOUGH_GRADIENT , it is the higher -threshold of the two passed to the Canny edge detector (the lower one is twice smaller). -@param param2 Second method-specific parameter. In case of #HOUGH_GRADIENT , it is the +@param param1 First method-specific parameter. In case of #HOUGH_GRADIENT and #HOUGH_GRADIENT_ALT, +it is the higher threshold of the two passed to the Canny edge detector (the lower one is twice smaller). +Note that #HOUGH_GRADIENT_ALT uses #Scharr algorithm to compute image derivatives, so the threshold value +shough normally be higher, such as 300 or normally exposed and contrasty images. +@param param2 Second method-specific parameter. In case of #HOUGH_GRADIENT, it is the accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be -returned first. +returned first. In the case of #HOUGH_GRADIENT_ALT algorithm, this is the circle "perfectness" measure. +The closer it to 1, the better shaped circles algorithm selects. In most cases 0.9 should be fine. +If you want get better detection of small circles, you may decrease it to 0.85, 0.8 or even less. +But then also try to limit the search range [minRadius, maxRadius] to avoid many false circles. @param minRadius Minimum circle radius. -@param maxRadius Maximum circle radius. If <= 0, uses the maximum image dimension. If < 0, returns -centers without finding the radius. +@param maxRadius Maximum circle radius. If <= 0, uses the maximum image dimension. If < 0, #HOUGH_GRADIENT returns +centers without finding the radius. #HOUGH_GRADIENT_ALT always computes circle radiuses. @sa fitEllipse, minEnclosingCircle */ @@ -2387,10 +2470,16 @@ coordinate origin is assumed to be the top-left corner). @sa getAffineTransform, warpAffine, transform */ -CV_EXPORTS_W Mat getRotationMatrix2D( Point2f center, double angle, double scale ); +CV_EXPORTS_W Mat getRotationMatrix2D(Point2f center, double angle, double scale); -//! returns 3x3 perspective transformation for the corresponding 4 point pairs. -CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] ); +/** @sa getRotationMatrix2D */ +CV_EXPORTS Matx23d getRotationMatrix2D_(Point2f center, double angle, double scale); + +inline +Mat getRotationMatrix2D(Point2f center, double angle, double scale) +{ + return Mat(getRotationMatrix2D_(center, angle, scale), true); +} /** @brief Calculates an affine transform from three pairs of the corresponding points. @@ -2434,10 +2523,15 @@ where @param src Coordinates of quadrangle vertices in the source image. @param dst Coordinates of the corresponding quadrangle vertices in the destination image. +@param solveMethod method passed to cv::solve (#DecompTypes) @sa findHomography, warpPerspective, perspectiveTransform */ -CV_EXPORTS_W Mat getPerspectiveTransform( InputArray src, InputArray dst ); +CV_EXPORTS_W Mat getPerspectiveTransform(InputArray src, InputArray dst, int solveMethod = DECOMP_LU); + +/** @overload */ +CV_EXPORTS Mat getPerspectiveTransform(const Point2f src[], const Point2f dst[], int solveMethod = DECOMP_LU); + CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst ); @@ -2832,6 +2926,22 @@ An example is shown below: */ CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type); +/** @brief Performs the per-element division of the first Fourier spectrum by the second Fourier spectrum. + +The function cv::divSpectrums performs the per-element division of the first array by the second array. +The arrays are CCS-packed or complex matrices that are results of a real or complex Fourier transform. + +@param a first input array. +@param b second input array of the same size and type as src1 . +@param c output array of the same size and type as src1 . +@param flags operation flags; currently, the only supported flag is cv::DFT_ROWS, which indicates that +each row of src1 and src2 is an independent 1D Fourier spectrum. If you do not want to use this flag, then simply add a `0` as value. +@param conjB optional flag that conjugates the second input array before the multiplication (true) +or not (false). +*/ +CV_EXPORTS_W void divSpectrums(InputArray a, InputArray b, OutputArray c, + int flags, bool conjB = false); + //! @} imgproc_motion //! @addtogroup imgproc_misc @@ -2961,193 +3071,6 @@ CV_EXPORTS void buildPyramid( InputArray src, OutputArrayOfArrays dst, //! @} imgproc_filter -//! @addtogroup imgproc_transform -//! @{ - -/** @brief Transforms an image to compensate for lens distortion. - -The function transforms an image to compensate radial and tangential lens distortion. - -The function is simply a combination of #initUndistortRectifyMap (with unity R ) and #remap -(with bilinear interpolation). See the former function for details of the transformation being -performed. - -Those pixels in the destination image, for which there is no correspondent pixels in the source -image, are filled with zeros (black color). - -A particular subset of the source image that will be visible in the corrected image can be regulated -by newCameraMatrix. You can use #getOptimalNewCameraMatrix to compute the appropriate -newCameraMatrix depending on your requirements. - -The camera matrix and the distortion parameters can be determined using #calibrateCamera. If -the resolution of images is different from the resolution used at the calibration stage, \f$f_x, -f_y, c_x\f$ and \f$c_y\f$ need to be scaled accordingly, while the distortion coefficients remain -the same. - -@param src Input (distorted) image. -@param dst Output (corrected) image that has the same size and type as src . -@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . -@param distCoeffs Input vector of distortion coefficients -\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ -of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. -@param newCameraMatrix Camera matrix of the distorted image. By default, it is the same as -cameraMatrix but you may additionally scale and shift the result by using a different matrix. - */ -CV_EXPORTS_W void undistort( InputArray src, OutputArray dst, - InputArray cameraMatrix, - InputArray distCoeffs, - InputArray newCameraMatrix = noArray() ); - -/** @brief Computes the undistortion and rectification transformation map. - -The function computes the joint undistortion and rectification transformation and represents the -result in the form of maps for remap. The undistorted image looks like original, as if it is -captured with a camera using the camera matrix =newCameraMatrix and zero distortion. In case of a -monocular camera, newCameraMatrix is usually equal to cameraMatrix, or it can be computed by -#getOptimalNewCameraMatrix for a better control over scaling. In case of a stereo camera, -newCameraMatrix is normally set to P1 or P2 computed by #stereoRectify . - -Also, this new camera is oriented differently in the coordinate space, according to R. That, for -example, helps to align two heads of a stereo camera so that the epipolar lines on both images -become horizontal and have the same y- coordinate (in case of a horizontally aligned stereo camera). - -The function actually builds the maps for the inverse mapping algorithm that is used by remap. That -is, for each pixel \f$(u, v)\f$ in the destination (corrected and rectified) image, the function -computes the corresponding coordinates in the source image (that is, in the original image from -camera). The following process is applied: -\f[ -\begin{array}{l} -x \leftarrow (u - {c'}_x)/{f'}_x \\ -y \leftarrow (v - {c'}_y)/{f'}_y \\ -{[X\,Y\,W]} ^T \leftarrow R^{-1}*[x \, y \, 1]^T \\ -x' \leftarrow X/W \\ -y' \leftarrow Y/W \\ -r^2 \leftarrow x'^2 + y'^2 \\ -x'' \leftarrow x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} -+ 2p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4\\ -y'' \leftarrow y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} -+ p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\ -s\vecthree{x'''}{y'''}{1} = -\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)} -{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} -{0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\ -map_x(u,v) \leftarrow x''' f_x + c_x \\ -map_y(u,v) \leftarrow y''' f_y + c_y -\end{array} -\f] -where \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ -are the distortion coefficients. - -In case of a stereo camera, this function is called twice: once for each camera head, after -stereoRectify, which in its turn is called after #stereoCalibrate. But if the stereo camera -was not calibrated, it is still possible to compute the rectification transformations directly from -the fundamental matrix using #stereoRectifyUncalibrated. For each camera, the function computes -homography H as the rectification transformation in a pixel domain, not a rotation matrix R in 3D -space. R can be computed from H as -\f[\texttt{R} = \texttt{cameraMatrix} ^{-1} \cdot \texttt{H} \cdot \texttt{cameraMatrix}\f] -where cameraMatrix can be chosen arbitrarily. - -@param cameraMatrix Input camera matrix \f$A=\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . -@param distCoeffs Input vector of distortion coefficients -\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ -of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. -@param R Optional rectification transformation in the object space (3x3 matrix). R1 or R2 , -computed by #stereoRectify can be passed here. If the matrix is empty, the identity transformation -is assumed. In cvInitUndistortMap R assumed to be an identity matrix. -@param newCameraMatrix New camera matrix \f$A'=\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}\f$. -@param size Undistorted image size. -@param m1type Type of the first output map that can be CV_32FC1, CV_32FC2 or CV_16SC2, see #convertMaps -@param map1 The first output map. -@param map2 The second output map. - */ -CV_EXPORTS_W void initUndistortRectifyMap( InputArray cameraMatrix, InputArray distCoeffs, - InputArray R, InputArray newCameraMatrix, - Size size, int m1type, OutputArray map1, OutputArray map2 ); - -//! initializes maps for #remap for wide-angle -CV_EXPORTS_W float initWideAngleProjMap( InputArray cameraMatrix, InputArray distCoeffs, - Size imageSize, int destImageWidth, - int m1type, OutputArray map1, OutputArray map2, - int projType = PROJ_SPHERICAL_EQRECT, double alpha = 0); - -/** @brief Returns the default new camera matrix. - -The function returns the camera matrix that is either an exact copy of the input cameraMatrix (when -centerPrinicipalPoint=false ), or the modified one (when centerPrincipalPoint=true). - -In the latter case, the new camera matrix will be: - -\f[\begin{bmatrix} f_x && 0 && ( \texttt{imgSize.width} -1)*0.5 \\ 0 && f_y && ( \texttt{imgSize.height} -1)*0.5 \\ 0 && 0 && 1 \end{bmatrix} ,\f] - -where \f$f_x\f$ and \f$f_y\f$ are \f$(0,0)\f$ and \f$(1,1)\f$ elements of cameraMatrix, respectively. - -By default, the undistortion functions in OpenCV (see #initUndistortRectifyMap, #undistort) do not -move the principal point. However, when you work with stereo, it is important to move the principal -points in both views to the same y-coordinate (which is required by most of stereo correspondence -algorithms), and may be to the same x-coordinate too. So, you can form the new camera matrix for -each view where the principal points are located at the center. - -@param cameraMatrix Input camera matrix. -@param imgsize Camera view image size in pixels. -@param centerPrincipalPoint Location of the principal point in the new camera matrix. The -parameter indicates whether this location should be at the image center or not. - */ -CV_EXPORTS_W Mat getDefaultNewCameraMatrix( InputArray cameraMatrix, Size imgsize = Size(), - bool centerPrincipalPoint = false ); - -/** @brief Computes the ideal point coordinates from the observed point coordinates. - -The function is similar to #undistort and #initUndistortRectifyMap but it operates on a -sparse set of points instead of a raster image. Also the function performs a reverse transformation -to projectPoints. In case of a 3D object, it does not reconstruct its 3D coordinates, but for a -planar object, it does, up to a translation vector, if the proper R is specified. - -For each observed point coordinate \f$(u, v)\f$ the function computes: -\f[ -\begin{array}{l} -x^{"} \leftarrow (u - c_x)/f_x \\ -y^{"} \leftarrow (v - c_y)/f_y \\ -(x',y') = undistort(x^{"},y^{"}, \texttt{distCoeffs}) \\ -{[X\,Y\,W]} ^T \leftarrow R*[x' \, y' \, 1]^T \\ -x \leftarrow X/W \\ -y \leftarrow Y/W \\ -\text{only performed if P is specified:} \\ -u' \leftarrow x {f'}_x + {c'}_x \\ -v' \leftarrow y {f'}_y + {c'}_y -\end{array} -\f] - -where *undistort* is an approximate iterative algorithm that estimates the normalized original -point coordinates out of the normalized distorted point coordinates ("normalized" means that the -coordinates do not depend on the camera matrix). - -The function can be used for both a stereo camera head or a monocular camera (when R is empty). -@param src Observed point coordinates, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel (CV_32FC2 or CV_64FC2) (or -vector\ ). -@param dst Output ideal point coordinates (1xN/Nx1 2-channel or vector\ ) after undistortion and reverse perspective -transformation. If matrix P is identity or omitted, dst will contain normalized point coordinates. -@param cameraMatrix Camera matrix \f$\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . -@param distCoeffs Input vector of distortion coefficients -\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ -of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. -@param R Rectification transformation in the object space (3x3 matrix). R1 or R2 computed by -#stereoRectify can be passed here. If the matrix is empty, the identity transformation is used. -@param P New camera matrix (3x3) or new projection matrix (3x4) \f$\begin{bmatrix} {f'}_x & 0 & {c'}_x & t_x \\ 0 & {f'}_y & {c'}_y & t_y \\ 0 & 0 & 1 & t_z \end{bmatrix}\f$. P1 or P2 computed by -#stereoRectify can be passed here. If the matrix is empty, the identity new camera matrix is used. - */ -CV_EXPORTS_W void undistortPoints( InputArray src, OutputArray dst, - InputArray cameraMatrix, InputArray distCoeffs, - InputArray R = noArray(), InputArray P = noArray() ); -/** @overload - @note Default version of #undistortPoints does 5 iterations to compute undistorted points. - - */ -CV_EXPORTS_AS(undistortPointsIter) void undistortPoints( InputArray src, OutputArray dst, - InputArray cameraMatrix, InputArray distCoeffs, - InputArray R, InputArray P, TermCriteria criteria ); - -//! @} imgproc_transform - //! @addtogroup imgproc_hist //! @{ @@ -3356,6 +3279,9 @@ CV_EXPORTS_AS(EMD) float wrapperEMD( InputArray signature1, InputArray signature //! @} imgproc_hist +//! @addtogroup imgproc_segmentation +//! @{ + /** @example samples/cpp/watershed.cpp An example using the watershed algorithm */ @@ -3383,11 +3309,11 @@ function. size as image . @sa findContours - -@ingroup imgproc_misc */ CV_EXPORTS_W void watershed( InputArray image, InputOutputArray markers ); +//! @} imgproc_segmentation + //! @addtogroup imgproc_filter //! @{ @@ -3433,7 +3359,7 @@ CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst, //! @} -//! @addtogroup imgproc_misc +//! @addtogroup imgproc_segmentation //! @{ /** @example samples/cpp/grabcut.cpp @@ -3463,6 +3389,11 @@ CV_EXPORTS_W void grabCut( InputArray img, InputOutputArray mask, Rect rect, InputOutputArray bgdModel, InputOutputArray fgdModel, int iterCount, int mode = GC_EVAL ); +//! @} imgproc_segmentation + +//! @addtogroup imgproc_misc +//! @{ + /** @example samples/cpp/distrans.cpp An example on using the distance transform */ @@ -3634,7 +3565,7 @@ CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask, //! @param weights1 It has a type of CV_32FC1 and the same size with src1. //! @param weights2 It has a type of CV_32FC1 and the same size with src1. //! @param dst It is created if it does not have the same size and type with src1. -CV_EXPORTS void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst); +CV_EXPORTS_W void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst); //! @} imgproc_misc @@ -3790,14 +3721,43 @@ CV_EXPORTS_W void HuMoments( const Moments& m, OutputArray hu ); //! type of the template matching operation enum TemplateMatchModes { - TM_SQDIFF = 0, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f] - TM_SQDIFF_NORMED = 1, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f] - TM_CCORR = 2, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f] - TM_CCORR_NORMED = 3, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f] - TM_CCOEFF = 4, //!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f] - //!< where - //!< \f[\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h) \cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}\f] - TM_CCOEFF_NORMED = 5 //!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} }\f] + TM_SQDIFF = 0, /*!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f] + with mask: + \f[R(x,y)= \sum _{x',y'} \left( (T(x',y')-I(x+x',y+y')) \cdot + M(x',y') \right)^2\f] */ + TM_SQDIFF_NORMED = 1, /*!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{ + x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f] + with mask: + \f[R(x,y)= \frac{\sum _{x',y'} \left( (T(x',y')-I(x+x',y+y')) \cdot + M(x',y') \right)^2}{\sqrt{\sum_{x',y'} \left( T(x',y') \cdot + M(x',y') \right)^2 \cdot \sum_{x',y'} \left( I(x+x',y+y') \cdot + M(x',y') \right)^2}}\f] */ + TM_CCORR = 2, /*!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f] + with mask: + \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y') \cdot M(x',y') + ^2)\f] */ + TM_CCORR_NORMED = 3, /*!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{ + \sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f] + with mask: + \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y') \cdot + M(x',y')^2)}{\sqrt{\sum_{x',y'} \left( T(x',y') \cdot M(x',y') + \right)^2 \cdot \sum_{x',y'} \left( I(x+x',y+y') \cdot M(x',y') + \right)^2}}\f] */ + TM_CCOEFF = 4, /*!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f] + where + \f[\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{ + x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h) + \cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}\f] + with mask: + \f[\begin{array}{l} T'(x',y')=M(x',y') \cdot \left( T(x',y') - + \frac{1}{\sum _{x'',y''} M(x'',y'')} \cdot \sum _{x'',y''} + (T(x'',y'') \cdot M(x'',y'')) \right) \\ I'(x+x',y+y')=M(x',y') + \cdot \left( I(x+x',y+y') - \frac{1}{\sum _{x'',y''} M(x'',y'')} + \cdot \sum _{x'',y''} (I(x+x'',y+y'') \cdot M(x'',y'')) \right) + \end{array} \f] */ + TM_CCOEFF_NORMED = 5 /*!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ + \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} + }\f] */ }; /** @example samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp @@ -3807,9 +3767,10 @@ An example using Template Matching algorithm /** @brief Compares a template against overlapped image regions. The function slides through image , compares the overlapped patches of size \f$w \times h\f$ against -templ using the specified method and stores the comparison results in result . Here are the formulae -for the available comparison methods ( \f$I\f$ denotes image, \f$T\f$ template, \f$R\f$ result ). The summation -is done over template and/or the image patch: \f$x' = 0...w-1, y' = 0...h-1\f$ +templ using the specified method and stores the comparison results in result . #TemplateMatchModes +describes the formulae for the available comparison methods ( \f$I\f$ denotes image, \f$T\f$ +template, \f$R\f$ result, \f$M\f$ the optional mask ). The summation is done over template and/or +the image patch: \f$x' = 0...w-1, y' = 0...h-1\f$ After the function finishes the comparison, the best matches can be found as global minimums (when #TM_SQDIFF was used) or maximums (when #TM_CCORR or #TM_CCOEFF was used) using the @@ -3824,8 +3785,12 @@ data type. @param result Map of comparison results. It must be single-channel 32-bit floating-point. If image is \f$W \times H\f$ and templ is \f$w \times h\f$ , then result is \f$(W-w+1) \times (H-h+1)\f$ . @param method Parameter specifying the comparison method, see #TemplateMatchModes -@param mask Mask of searched template. It must have the same datatype and size with templ. It is -not set by default. Currently, only the #TM_SQDIFF and #TM_CCORR_NORMED methods are supported. +@param mask Optional mask. It must have the same size as templ. It must either have the same number + of channels as template or only one channel, which is then used for all template and + image channels. If the data type is #CV_8U, the mask is interpreted as a binary mask, + meaning only elements where mask is nonzero are used and are kept unchanged independent + of the actual mask value (weight equals 1). For data tpye #CV_32F, the mask values are + used as weights. The exact formulas are documented in #TemplateMatchModes. */ CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ, OutputArray result, int method, InputArray mask = noArray() ); @@ -3938,12 +3903,12 @@ parent, or nested contours, the corresponding elements of hierarchy[i] will be n contours are extracted from the image ROI and then they should be analyzed in the whole image context. */ -CV_EXPORTS_W void findContours( InputOutputArray image, OutputArrayOfArrays contours, +CV_EXPORTS_W void findContours( InputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset = Point()); /** @overload */ -CV_EXPORTS void findContours( InputOutputArray image, OutputArrayOfArrays contours, +CV_EXPORTS void findContours( InputArray image, OutputArrayOfArrays contours, int mode, int method, Point offset = Point()); /** @example samples/cpp/squares.cpp @@ -4159,9 +4124,9 @@ Examples of how intersectConvexConvex works /** @brief Finds intersection of two convex polygons -@param _p1 First polygon -@param _p2 Second polygon -@param _p12 Output polygon describing the intersecting area +@param p1 First polygon +@param p2 Second polygon +@param p12 Output polygon describing the intersecting area @param handleNested When true, an intersection is found if one of the polygons is fully enclosed in the other. When false, no intersection is found. If the polygons share a side or the vertex of one polygon lies on an edge of the other, they are not considered nested and an intersection will be found regardless of the value of handleNested. @@ -4170,8 +4135,8 @@ of the other, they are not considered nested and an intersection will be found r @note intersectConvexConvex doesn't confirm that both polygons are convex and will return invalid results if they aren't. */ -CV_EXPORTS_W float intersectConvexConvex( InputArray _p1, InputArray _p2, - OutputArray _p12, bool handleNested = true ); +CV_EXPORTS_W float intersectConvexConvex( InputArray p1, InputArray p2, + OutputArray p12, bool handleNested = true ); /** @example samples/cpp/fitellipse.cpp An example using the fitEllipse technique @@ -4469,7 +4434,7 @@ CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2, use `rec` parameter as alternative specification of the drawn rectangle: `r.tl() and r.br()-Point(1,1)` are opposite corners */ -CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec, +CV_EXPORTS_W void rectangle(InputOutputArray img, Rect rec, const Scalar& color, int thickness = 1, int lineType = LINE_8, int shift = 0); @@ -4539,18 +4504,6 @@ CV_EXPORTS_W void ellipse(InputOutputArray img, const RotatedRect& box, const Sc /* ADDING A SET OF PREDEFINED MARKERS WHICH COULD BE USED TO HIGHLIGHT POSITIONS IN AN IMAGE */ /* ----------------------------------------------------------------------------------------- */ -//! Possible set of marker types used for the cv::drawMarker function -enum MarkerTypes -{ - MARKER_CROSS = 0, //!< A crosshair marker shape - MARKER_TILTED_CROSS = 1, //!< A 45 degree tilted crosshair marker shape - MARKER_STAR = 2, //!< A star marker shape, combination of cross and tilted cross - MARKER_DIAMOND = 3, //!< A diamond marker shape - MARKER_SQUARE = 4, //!< A square marker shape - MARKER_TRIANGLE_UP = 5, //!< An upwards pointing triangle marker shape - MARKER_TRIANGLE_DOWN = 6 //!< A downwards pointing triangle marker shape -}; - /** @brief Draws a marker on a predefined position in an image. The function cv::drawMarker draws a marker on a given position in the image. For the moment several @@ -4564,7 +4517,7 @@ marker types are supported, see #MarkerTypes for more information. @param line_type Type of the line, See #LineTypes @param markerSize The length of the marker axis [default = 20 pixels] */ -CV_EXPORTS_W void drawMarker(CV_IN_OUT Mat& img, Point position, const Scalar& color, +CV_EXPORTS_W void drawMarker(InputOutputArray img, Point position, const Scalar& color, int markerType = MARKER_CROSS, int markerSize=20, int thickness=1, int line_type=8); @@ -4573,7 +4526,7 @@ CV_EXPORTS_W void drawMarker(CV_IN_OUT Mat& img, Point position, const Scalar& c /* ----------------------------------------------------------------------------------------- */ /** @overload */ -CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts, +CV_EXPORTS void fillConvexPoly(InputOutputArray img, const Point* pts, int npts, const Scalar& color, int lineType = LINE_8, int shift = 0); @@ -4595,7 +4548,7 @@ CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points, int shift = 0); /** @overload */ -CV_EXPORTS void fillPoly(Mat& img, const Point** pts, +CV_EXPORTS void fillPoly(InputOutputArray img, const Point** pts, const int* npts, int ncontours, const Scalar& color, int lineType = LINE_8, int shift = 0, Point offset = Point() ); @@ -4623,7 +4576,7 @@ CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts, Point offset = Point() ); /** @overload */ -CV_EXPORTS void polylines(Mat& img, const Point* const* pts, const int* npts, +CV_EXPORTS void polylines(InputOutputArray img, const Point* const* pts, const int* npts, int ncontours, bool isClosed, const Scalar& color, int thickness = 1, int lineType = LINE_8, int shift = 0 ); @@ -4870,10 +4823,39 @@ public: the line is 8-connected or 4-connected If leftToRight=true, then the iteration is always done from the left-most point to the right most, - not to depend on the ordering of pt1 and pt2 parameters + not to depend on the ordering of pt1 and pt2 parameters; */ LineIterator( const Mat& img, Point pt1, Point pt2, - int connectivity = 8, bool leftToRight = false ); + int connectivity = 8, bool leftToRight = false ) + { + init(&img, Rect(0, 0, img.cols, img.rows), pt1, pt2, connectivity, leftToRight); + ptmode = false; + } + LineIterator( Point pt1, Point pt2, + int connectivity = 8, bool leftToRight = false ) + { + init(0, Rect(std::min(pt1.x, pt2.x), + std::min(pt1.y, pt2.y), + std::max(pt1.x, pt2.x) - std::min(pt1.x, pt2.x) + 1, + std::max(pt1.y, pt2.y) - std::min(pt1.y, pt2.y) + 1), + pt1, pt2, connectivity, leftToRight); + ptmode = true; + } + LineIterator( Size boundingAreaSize, Point pt1, Point pt2, + int connectivity = 8, bool leftToRight = false ) + { + init(0, Rect(0, 0, boundingAreaSize.width, boundingAreaSize.height), + pt1, pt2, connectivity, leftToRight); + ptmode = true; + } + LineIterator( Rect boundingAreaRect, Point pt1, Point pt2, + int connectivity = 8, bool leftToRight = false ) + { + init(0, boundingAreaRect, pt1, pt2, connectivity, leftToRight); + ptmode = true; + } + void init(const Mat* img, Rect boundingAreaRect, Point pt1, Point pt2, int connectivity, bool leftToRight); + /** @brief returns pointer to the current pixel */ uchar* operator *(); @@ -4893,6 +4875,9 @@ public: int err, count; int minusDelta, plusDelta; int minusStep, plusStep; + int minusShift, plusShift; + Point p; + bool ptmode; }; //! @cond IGNORED @@ -4902,7 +4887,7 @@ public: inline uchar* LineIterator::operator *() { - return ptr; + return ptmode ? 0 : ptr; } inline @@ -4910,7 +4895,15 @@ LineIterator& LineIterator::operator ++() { int mask = err < 0 ? -1 : 0; err += minusDelta + (plusDelta & mask); - ptr += minusStep + (plusStep & mask); + if(!ptmode) + { + ptr += minusStep + (plusStep & mask); + } + else + { + p.x += minusShift + (plusShift & mask); + p.y += minusStep + (plusStep & mask); + } return *this; } @@ -4925,9 +4918,13 @@ LineIterator LineIterator::operator ++(int) inline Point LineIterator::pos() const { - Point p; - p.y = (int)((ptr - ptr0)/step); - p.x = (int)(((ptr - ptr0) - p.y*step)/elemSize); + if(!ptmode) + { + size_t offset = (size_t)(ptr - ptr0); + int y = (int)(offset/step); + int x = (int)((offset - (size_t)y*step)/elemSize); + return Point(x, y); + } return p; } @@ -4939,8 +4936,8 @@ Point LineIterator::pos() const } // cv -#ifndef DISABLE_OPENCV_24_COMPATIBILITY -#include "opencv2/imgproc/imgproc_c.h" -#endif + +#include "./imgproc/segmentation.hpp" + #endif diff --git a/3rdparty/include/opencv2/imgproc/bindings.hpp b/3rdparty/include/opencv2/imgproc/bindings.hpp new file mode 100644 index 0000000000..c69527a779 --- /dev/null +++ b/3rdparty/include/opencv2/imgproc/bindings.hpp @@ -0,0 +1,34 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_IMGPROC_BINDINGS_HPP +#define OPENCV_IMGPROC_BINDINGS_HPP + +// This file contains special overloads for OpenCV bindings +// No need to use these functions in C++ code. + +namespace cv { + +/** @brief Finds lines in a binary image using the standard Hough transform and get accumulator. + * + * @note This function is for bindings use only. Use original function in C++ code + * + * @sa HoughLines + */ +CV_WRAP static inline +void HoughLinesWithAccumulator( + InputArray image, OutputArray lines, + double rho, double theta, int threshold, + double srn = 0, double stn = 0, + double min_theta = 0, double max_theta = CV_PI +) +{ + std::vector lines_acc; + HoughLines(image, lines_acc, rho, theta, threshold, srn, stn, min_theta, max_theta); + Mat(lines_acc).copyTo(lines); +} + +} // namespace + +#endif // OPENCV_IMGPROC_BINDINGS_HPP diff --git a/3rdparty/include/opencv2/imgproc/detail/distortion_model.hpp b/3rdparty/include/opencv2/imgproc/detail/distortion_model.hpp deleted file mode 100644 index a9c3ddec8a..0000000000 --- a/3rdparty/include/opencv2/imgproc/detail/distortion_model.hpp +++ /dev/null @@ -1,123 +0,0 @@ -/*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_IMGPROC_DETAIL_DISTORTION_MODEL_HPP -#define OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP - -//! @cond IGNORED - -namespace cv { namespace detail { -/** -Computes the matrix for the projection onto a tilted image sensor -\param tauX angular parameter rotation around x-axis -\param tauY angular parameter rotation around y-axis -\param matTilt if not NULL returns the matrix -\f[ -\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)} -{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} -{0}{0}{1} R(\tau_x, \tau_y) -\f] -where -\f[ -R(\tau_x, \tau_y) = -\vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)} -\vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} = -\vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)} -{0}{\cos(\tau_x)}{\sin(\tau_x)} -{\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}. -\f] -\param dMatTiltdTauX if not NULL it returns the derivative of matTilt with -respect to \f$\tau_x\f$. -\param dMatTiltdTauY if not NULL it returns the derivative of matTilt with -respect to \f$\tau_y\f$. -\param invMatTilt if not NULL it returns the inverse of matTilt -**/ -template -void computeTiltProjectionMatrix(FLOAT tauX, - FLOAT tauY, - Matx* matTilt = 0, - Matx* dMatTiltdTauX = 0, - Matx* dMatTiltdTauY = 0, - Matx* invMatTilt = 0) -{ - FLOAT cTauX = cos(tauX); - FLOAT sTauX = sin(tauX); - FLOAT cTauY = cos(tauY); - FLOAT sTauY = sin(tauY); - Matx matRotX = Matx(1,0,0,0,cTauX,sTauX,0,-sTauX,cTauX); - Matx matRotY = Matx(cTauY,0,-sTauY,0,1,0,sTauY,0,cTauY); - Matx matRotXY = matRotY * matRotX; - Matx matProjZ = Matx(matRotXY(2,2),0,-matRotXY(0,2),0,matRotXY(2,2),-matRotXY(1,2),0,0,1); - if (matTilt) - { - // Matrix for trapezoidal distortion of tilted image sensor - *matTilt = matProjZ * matRotXY; - } - if (dMatTiltdTauX) - { - // Derivative with respect to tauX - Matx dMatRotXYdTauX = matRotY * Matx(0,0,0,0,-sTauX,cTauX,0,-cTauX,-sTauX); - Matx dMatProjZdTauX = Matx(dMatRotXYdTauX(2,2),0,-dMatRotXYdTauX(0,2), - 0,dMatRotXYdTauX(2,2),-dMatRotXYdTauX(1,2),0,0,0); - *dMatTiltdTauX = (matProjZ * dMatRotXYdTauX) + (dMatProjZdTauX * matRotXY); - } - if (dMatTiltdTauY) - { - // Derivative with respect to tauY - Matx dMatRotXYdTauY = Matx(-sTauY,0,-cTauY,0,0,0,cTauY,0,-sTauY) * matRotX; - Matx dMatProjZdTauY = Matx(dMatRotXYdTauY(2,2),0,-dMatRotXYdTauY(0,2), - 0,dMatRotXYdTauY(2,2),-dMatRotXYdTauY(1,2),0,0,0); - *dMatTiltdTauY = (matProjZ * dMatRotXYdTauY) + (dMatProjZdTauY * matRotXY); - } - if (invMatTilt) - { - FLOAT inv = 1./matRotXY(2,2); - Matx invMatProjZ = Matx(inv,0,inv*matRotXY(0,2),0,inv,inv*matRotXY(1,2),0,0,1); - *invMatTilt = matRotXY.t()*invMatProjZ; - } -} -}} // namespace detail, cv - - -//! @endcond - -#endif // OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP diff --git a/3rdparty/include/opencv2/imgproc/detail/gcgraph.hpp b/3rdparty/include/opencv2/imgproc/detail/gcgraph.hpp new file mode 100644 index 0000000000..f17c6e7afb --- /dev/null +++ b/3rdparty/include/opencv2/imgproc/detail/gcgraph.hpp @@ -0,0 +1,395 @@ +/*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. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_IMGPROC_DETAIL_GCGRAPH_HPP +#define OPENCV_IMGPROC_DETAIL_GCGRAPH_HPP + +//! @cond IGNORED + +namespace cv { namespace detail { +template class GCGraph +{ +public: + GCGraph(); + GCGraph( unsigned int vtxCount, unsigned int edgeCount ); + ~GCGraph(); + void create( unsigned int vtxCount, unsigned int edgeCount ); + int addVtx(); + void addEdges( int i, int j, TWeight w, TWeight revw ); + void addTermWeights( int i, TWeight sourceW, TWeight sinkW ); + TWeight maxFlow(); + bool inSourceSegment( int i ); +private: + class Vtx + { + public: + Vtx *next; // initialized and used in maxFlow() only + int parent; + int first; + int ts; + int dist; + TWeight weight; + uchar t; + }; + class Edge + { + public: + int dst; + int next; + TWeight weight; + }; + + std::vector vtcs; + std::vector edges; + TWeight flow; +}; + +template +GCGraph::GCGraph() +{ + flow = 0; +} +template +GCGraph::GCGraph( unsigned int vtxCount, unsigned int edgeCount ) +{ + create( vtxCount, edgeCount ); +} +template +GCGraph::~GCGraph() +{ +} +template +void GCGraph::create( unsigned int vtxCount, unsigned int edgeCount ) +{ + vtcs.reserve( vtxCount ); + edges.reserve( edgeCount + 2 ); + flow = 0; +} + +template +int GCGraph::addVtx() +{ + Vtx v; + memset( &v, 0, sizeof(Vtx)); + vtcs.push_back(v); + return (int)vtcs.size() - 1; +} + +template +void GCGraph::addEdges( int i, int j, TWeight w, TWeight revw ) +{ + CV_Assert( i>=0 && i<(int)vtcs.size() ); + CV_Assert( j>=0 && j<(int)vtcs.size() ); + CV_Assert( w>=0 && revw>=0 ); + CV_Assert( i != j ); + + if( !edges.size() ) + edges.resize( 2 ); + + Edge fromI, toI; + fromI.dst = j; + fromI.next = vtcs[i].first; + fromI.weight = w; + vtcs[i].first = (int)edges.size(); + edges.push_back( fromI ); + + toI.dst = i; + toI.next = vtcs[j].first; + toI.weight = revw; + vtcs[j].first = (int)edges.size(); + edges.push_back( toI ); +} + +template +void GCGraph::addTermWeights( int i, TWeight sourceW, TWeight sinkW ) +{ + CV_Assert( i>=0 && i<(int)vtcs.size() ); + + TWeight dw = vtcs[i].weight; + if( dw > 0 ) + sourceW += dw; + else + sinkW -= dw; + flow += (sourceW < sinkW) ? sourceW : sinkW; + vtcs[i].weight = sourceW - sinkW; +} + +template +TWeight GCGraph::maxFlow() +{ + CV_Assert(!vtcs.empty()); + CV_Assert(!edges.empty()); + const int TERMINAL = -1, ORPHAN = -2; + Vtx stub, *nilNode = &stub, *first = nilNode, *last = nilNode; + int curr_ts = 0; + stub.next = nilNode; + Vtx *vtxPtr = &vtcs[0]; + Edge *edgePtr = &edges[0]; + + std::vector orphans; + + // initialize the active queue and the graph vertices + for( int i = 0; i < (int)vtcs.size(); i++ ) + { + Vtx* v = vtxPtr + i; + v->ts = 0; + if( v->weight != 0 ) + { + last = last->next = v; + v->dist = 1; + v->parent = TERMINAL; + v->t = v->weight < 0; + } + else + v->parent = 0; + } + first = first->next; + last->next = nilNode; + nilNode->next = 0; + + // run the search-path -> augment-graph -> restore-trees loop + for(;;) + { + Vtx* v, *u; + int e0 = -1, ei = 0, ej = 0; + TWeight minWeight, weight; + uchar vt; + + // grow S & T search trees, find an edge connecting them + while( first != nilNode ) + { + v = first; + if( v->parent ) + { + vt = v->t; + for( ei = v->first; ei != 0; ei = edgePtr[ei].next ) + { + if( edgePtr[ei^vt].weight == 0 ) + continue; + u = vtxPtr+edgePtr[ei].dst; + if( !u->parent ) + { + u->t = vt; + u->parent = ei ^ 1; + u->ts = v->ts; + u->dist = v->dist + 1; + if( !u->next ) + { + u->next = nilNode; + last = last->next = u; + } + continue; + } + + if( u->t != vt ) + { + e0 = ei ^ vt; + break; + } + + if( u->dist > v->dist+1 && u->ts <= v->ts ) + { + // reassign the parent + u->parent = ei ^ 1; + u->ts = v->ts; + u->dist = v->dist + 1; + } + } + if( e0 > 0 ) + break; + } + // exclude the vertex from the active list + first = first->next; + v->next = 0; + } + + if( e0 <= 0 ) + break; + + // find the minimum edge weight along the path + minWeight = edgePtr[e0].weight; + CV_Assert( minWeight > 0 ); + // k = 1: source tree, k = 0: destination tree + for( int k = 1; k >= 0; k-- ) + { + for( v = vtxPtr+edgePtr[e0^k].dst;; v = vtxPtr+edgePtr[ei].dst ) + { + if( (ei = v->parent) < 0 ) + break; + weight = edgePtr[ei^k].weight; + minWeight = MIN(minWeight, weight); + CV_Assert( minWeight > 0 ); + } + weight = fabs(v->weight); + minWeight = MIN(minWeight, weight); + CV_Assert( minWeight > 0 ); + } + + // modify weights of the edges along the path and collect orphans + edgePtr[e0].weight -= minWeight; + edgePtr[e0^1].weight += minWeight; + flow += minWeight; + + // k = 1: source tree, k = 0: destination tree + for( int k = 1; k >= 0; k-- ) + { + for( v = vtxPtr+edgePtr[e0^k].dst;; v = vtxPtr+edgePtr[ei].dst ) + { + if( (ei = v->parent) < 0 ) + break; + edgePtr[ei^(k^1)].weight += minWeight; + if( (edgePtr[ei^k].weight -= minWeight) == 0 ) + { + orphans.push_back(v); + v->parent = ORPHAN; + } + } + + v->weight = v->weight + minWeight*(1-k*2); + if( v->weight == 0 ) + { + orphans.push_back(v); + v->parent = ORPHAN; + } + } + + // restore the search trees by finding new parents for the orphans + curr_ts++; + while( !orphans.empty() ) + { + Vtx* v2 = orphans.back(); + orphans.pop_back(); + + int d, minDist = INT_MAX; + e0 = 0; + vt = v2->t; + + for( ei = v2->first; ei != 0; ei = edgePtr[ei].next ) + { + if( edgePtr[ei^(vt^1)].weight == 0 ) + continue; + u = vtxPtr+edgePtr[ei].dst; + if( u->t != vt || u->parent == 0 ) + continue; + // compute the distance to the tree root + for( d = 0;; ) + { + if( u->ts == curr_ts ) + { + d += u->dist; + break; + } + ej = u->parent; + d++; + if( ej < 0 ) + { + if( ej == ORPHAN ) + d = INT_MAX-1; + else + { + u->ts = curr_ts; + u->dist = 1; + } + break; + } + u = vtxPtr+edgePtr[ej].dst; + } + + // update the distance + if( ++d < INT_MAX ) + { + if( d < minDist ) + { + minDist = d; + e0 = ei; + } + for( u = vtxPtr+edgePtr[ei].dst; u->ts != curr_ts; u = vtxPtr+edgePtr[u->parent].dst ) + { + u->ts = curr_ts; + u->dist = --d; + } + } + } + + if( (v2->parent = e0) > 0 ) + { + v2->ts = curr_ts; + v2->dist = minDist; + continue; + } + + /* no parent is found */ + v2->ts = 0; + for( ei = v2->first; ei != 0; ei = edgePtr[ei].next ) + { + u = vtxPtr+edgePtr[ei].dst; + ej = u->parent; + if( u->t != vt || !ej ) + continue; + if( edgePtr[ei^(vt^1)].weight && !u->next ) + { + u->next = nilNode; + last = last->next = u; + } + if( ej > 0 && vtxPtr+edgePtr[ej].dst == v2 ) + { + orphans.push_back(u); + u->parent = ORPHAN; + } + } + } + } + return flow; +} + +template +bool GCGraph::inSourceSegment( int i ) +{ + CV_Assert( i>=0 && i<(int)vtcs.size() ); + return vtcs[i].t == 0; +} + +}} // namespace detail, cv + + +//! @endcond + +#endif // OPENCV_IMGPROC_DETAIL_GCGRAPH_HPP diff --git a/3rdparty/include/opencv2/imgproc/hal/hal.hpp b/3rdparty/include/opencv2/imgproc/hal/hal.hpp index a435fd6b85..ac20725e63 100644 --- a/3rdparty/include/opencv2/imgproc/hal/hal.hpp +++ b/3rdparty/include/opencv2/imgproc/hal/hal.hpp @@ -108,7 +108,7 @@ CV_EXPORTS void warpAffine(int src_type, uchar * dst_data, size_t dst_step, int dst_width, int dst_height, const double M[6], int interpolation, int borderType, const double borderValue[4]); -CV_EXPORTS void warpPerspectve(int src_type, +CV_EXPORTS void warpPerspective(int src_type, const uchar * src_data, size_t src_step, int src_width, int src_height, uchar * dst_data, size_t dst_step, int dst_width, int dst_height, const double M[9], int interpolation, int borderType, const double borderValue[4]); diff --git a/3rdparty/include/opencv2/imgproc/imgproc_c.h b/3rdparty/include/opencv2/imgproc/imgproc_c.h index 2fe85b6c45..86dc119fdd 100644 --- a/3rdparty/include/opencv2/imgproc/imgproc_c.h +++ b/3rdparty/include/opencv2/imgproc/imgproc_c.h @@ -273,39 +273,6 @@ CVAPI(void) cvLinearPolar( const CvArr* src, CvArr* dst, CvPoint2D32f center, double maxRadius, int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS)); -/** @brief Transforms the input image to compensate lens distortion -@see cv::undistort -*/ -CVAPI(void) cvUndistort2( const CvArr* src, CvArr* dst, - const CvMat* camera_matrix, - const CvMat* distortion_coeffs, - const CvMat* new_camera_matrix CV_DEFAULT(0) ); - -/** @brief Computes transformation map from intrinsic camera parameters - that can used by cvRemap -*/ -CVAPI(void) cvInitUndistortMap( const CvMat* camera_matrix, - const CvMat* distortion_coeffs, - CvArr* mapx, CvArr* mapy ); - -/** @brief Computes undistortion+rectification map for a head of stereo camera -@see cv::initUndistortRectifyMap -*/ -CVAPI(void) cvInitUndistortRectifyMap( const CvMat* camera_matrix, - const CvMat* dist_coeffs, - const CvMat *R, const CvMat* new_camera_matrix, - CvArr* mapx, CvArr* mapy ); - -/** @brief Computes the original (undistorted) feature coordinates - from the observed (distorted) coordinates -@see cv::undistortPoints -*/ -CVAPI(void) cvUndistortPoints( const CvMat* src, CvMat* dst, - const CvMat* camera_matrix, - const CvMat* dist_coeffs, - const CvMat* R CV_DEFAULT(0), - const CvMat* P CV_DEFAULT(0)); - /** @brief Returns a structuring element of the specified size and shape for morphological operations. @note the created structuring element IplConvKernel\* element must be released in the end using diff --git a/3rdparty/include/opencv2/imgproc/segmentation.hpp b/3rdparty/include/opencv2/imgproc/segmentation.hpp new file mode 100644 index 0000000000..26882f444e --- /dev/null +++ b/3rdparty/include/opencv2/imgproc/segmentation.hpp @@ -0,0 +1,141 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_IMGPROC_SEGMENTATION_HPP +#define OPENCV_IMGPROC_SEGMENTATION_HPP + +#include "opencv2/imgproc.hpp" + +namespace cv { + +namespace segmentation { + +//! @addtogroup imgproc_segmentation +//! @{ + + +/** @brief Intelligent Scissors image segmentation + * + * This class is used to find the path (contour) between two points + * which can be used for image segmentation. + * + * Usage example: + * @snippet snippets/imgproc_segmentation.cpp usage_example_intelligent_scissors + * + * Reference: "Intelligent Scissors for Image Composition" + * algorithm designed by Eric N. Mortensen and William A. Barrett, Brigham Young University + * @cite Mortensen95intelligentscissors + */ +class CV_EXPORTS_W_SIMPLE IntelligentScissorsMB +{ +public: + CV_WRAP + IntelligentScissorsMB(); + + /** @brief Specify weights of feature functions + * + * Consider keeping weights normalized (sum of weights equals to 1.0) + * Discrete dynamic programming (DP) goal is minimization of costs between pixels. + * + * @param weight_non_edge Specify cost of non-edge pixels (default: 0.43f) + * @param weight_gradient_direction Specify cost of gradient direction function (default: 0.43f) + * @param weight_gradient_magnitude Specify cost of gradient magnitude function (default: 0.14f) + */ + CV_WRAP + IntelligentScissorsMB& setWeights(float weight_non_edge, float weight_gradient_direction, float weight_gradient_magnitude); + + /** @brief Specify gradient magnitude max value threshold + * + * Zero limit value is used to disable gradient magnitude thresholding (default behavior, as described in original article). + * Otherwize pixels with `gradient magnitude >= threshold` have zero cost. + * + * @note Thresholding should be used for images with irregular regions (to avoid stuck on parameters from high-contract areas, like embedded logos). + * + * @param gradient_magnitude_threshold_max Specify gradient magnitude max value threshold (default: 0, disabled) + */ + CV_WRAP + IntelligentScissorsMB& setGradientMagnitudeMaxLimit(float gradient_magnitude_threshold_max = 0.0f); + + /** @brief Switch to "Laplacian Zero-Crossing" edge feature extractor and specify its parameters + * + * This feature extractor is used by default according to article. + * + * Implementation has additional filtering for regions with low-amplitude noise. + * This filtering is enabled through parameter of minimal gradient amplitude (use some small value 4, 8, 16). + * + * @note Current implementation of this feature extractor is based on processing of grayscale images (color image is converted to grayscale image first). + * + * @note Canny edge detector is a bit slower, but provides better results (especially on color images): use setEdgeFeatureCannyParameters(). + * + * @param gradient_magnitude_min_value Minimal gradient magnitude value for edge pixels (default: 0, check is disabled) + */ + CV_WRAP + IntelligentScissorsMB& setEdgeFeatureZeroCrossingParameters(float gradient_magnitude_min_value = 0.0f); + + /** @brief Switch edge feature extractor to use Canny edge detector + * + * @note "Laplacian Zero-Crossing" feature extractor is used by default (following to original article) + * + * @sa Canny + */ + CV_WRAP + IntelligentScissorsMB& setEdgeFeatureCannyParameters( + double threshold1, double threshold2, + int apertureSize = 3, bool L2gradient = false + ); + + /** @brief Specify input image and extract image features + * + * @param image input image. Type is #CV_8UC1 / #CV_8UC3 + */ + CV_WRAP + IntelligentScissorsMB& applyImage(InputArray image); + + /** @brief Specify custom features of imput image + * + * Customized advanced variant of applyImage() call. + * + * @param non_edge Specify cost of non-edge pixels. Type is CV_8UC1. Expected values are `{0, 1}`. + * @param gradient_direction Specify gradient direction feature. Type is CV_32FC2. Values are expected to be normalized: `x^2 + y^2 == 1` + * @param gradient_magnitude Specify cost of gradient magnitude function: Type is CV_32FC1. Values should be in range `[0, 1]`. + * @param image **Optional parameter**. Must be specified if subset of features is specified (non-specified features are calculated internally) + */ + CV_WRAP + IntelligentScissorsMB& applyImageFeatures( + InputArray non_edge, InputArray gradient_direction, InputArray gradient_magnitude, + InputArray image = noArray() + ); + + /** @brief Prepares a map of optimal paths for the given source point on the image + * + * @note applyImage() / applyImageFeatures() must be called before this call + * + * @param sourcePt The source point used to find the paths + */ + CV_WRAP void buildMap(const Point& sourcePt); + + /** @brief Extracts optimal contour for the given target point on the image + * + * @note buildMap() must be called before this call + * + * @param targetPt The target point + * @param[out] contour The list of pixels which contains optimal path between the source and the target points of the image. Type is CV_32SC2 (compatible with `std::vector`) + * @param backward Flag to indicate reverse order of retrived pixels (use "true" value to fetch points from the target to the source point) + */ + CV_WRAP void getContour(const Point& targetPt, OutputArray contour, bool backward = false) const; + +#ifndef CV_DOXYGEN + struct Impl; + inline Impl* getImpl() const { return impl.get(); } +protected: + std::shared_ptr impl; +#endif +}; + +//! @} + +} // namespace segmentation +} // namespace cv + +#endif // OPENCV_IMGPROC_SEGMENTATION_HPP diff --git a/3rdparty/include/opencv2/line_descriptor.hpp b/3rdparty/include/opencv2/line_descriptor.hpp deleted file mode 100644 index cb2969fd8b..0000000000 --- a/3rdparty/include/opencv2/line_descriptor.hpp +++ /dev/null @@ -1,119 +0,0 @@ -/*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) 2013, OpenCV Foundation, 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_LINE_DESCRIPTOR_HPP__ -#define __OPENCV_LINE_DESCRIPTOR_HPP__ - -#include "opencv2/line_descriptor/descriptor.hpp" - -/** @defgroup line_descriptor Binary descriptors for lines extracted from an image - -Introduction ------------- - -One of the most challenging activities in computer vision is the extraction of useful information -from a given image. Such information, usually comes in the form of points that preserve some kind of -property (for instance, they are scale-invariant) and are actually representative of input image. - -The goal of this module is seeking a new kind of representative information inside an image and -providing the functionalities for its extraction and representation. In particular, differently from -previous methods for detection of relevant elements inside an image, lines are extracted in place of -points; a new class is defined ad hoc to summarize a line's properties, for reuse and plotting -purposes. - -Computation of binary descriptors ---------------------------------- - -To obtatin a binary descriptor representing a certain line detected from a certain octave of an -image, we first compute a non-binary descriptor as described in @cite LBD . Such algorithm works on -lines extracted using EDLine detector, as explained in @cite EDL . Given a line, we consider a -rectangular region centered at it and called *line support region (LSR)*. Such region is divided -into a set of bands \f$\{B_1, B_2, ..., B_m\}\f$, whose length equals the one of line. - -If we indicate with \f$\bf{d}_L\f$ the direction of line, the orthogonal and clockwise direction to line -\f$\bf{d}_{\perp}\f$ can be determined; these two directions, are used to construct a reference frame -centered in the middle point of line. The gradients of pixels \f$\bf{g'}\f$ inside LSR can be projected -to the newly determined frame, obtaining their local equivalent -\f$\bf{g'} = (\bf{g}^T \cdot \bf{d}_{\perp}, \bf{g}^T \cdot \bf{d}_L)^T \triangleq (\bf{g'}_{d_{\perp}}, \bf{g'}_{d_L})^T\f$. - -Later on, a Gaussian function is applied to all LSR's pixels along \f$\bf{d}_\perp\f$ direction; first, -we assign a global weighting coefficient \f$f_g(i) = (1/\sqrt{2\pi}\sigma_g)e^{-d^2_i/2\sigma^2_g}\f$ to -*i*-th row in LSR, where \f$d_i\f$ is the distance of *i*-th row from the center row in LSR, -\f$\sigma_g = 0.5(m \cdot w - 1)\f$ and \f$w\f$ is the width of bands (the same for every band). Secondly, -considering a band \f$B_j\f$ and its neighbor bands \f$B_{j-1}, B_{j+1}\f$, we assign a local weighting -\f$F_l(k) = (1/\sqrt{2\pi}\sigma_l)e^{-d'^2_k/2\sigma_l^2}\f$, where \f$d'_k\f$ is the distance of *k*-th -row from the center row in \f$B_j\f$ and \f$\sigma_l = w\f$. Using the global and local weights, we obtain, -at the same time, the reduction of role played by gradients far from line and of boundary effect, -respectively. - -Each band \f$B_j\f$ in LSR has an associated *band descriptor(BD)* which is computed considering -previous and next band (top and bottom bands are ignored when computing descriptor for first and -last band). Once each band has been assignen its BD, the LBD descriptor of line is simply given by - -\f[LBD = (BD_1^T, BD_2^T, ... , BD^T_m)^T.\f] - -To compute a band descriptor \f$B_j\f$, each *k*-th row in it is considered and the gradients in such -row are accumulated: - -\f[\begin{matrix} \bf{V1}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}>0}\bf{g}'_{d_\perp}, & \bf{V2}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}<0} -\bf{g}'_{d_\perp}, \\ \bf{V3}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}>0}\bf{g}'_{d_L}, & \bf{V4}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}<0} -\bf{g}'_{d_L}\end{matrix}.\f] - -with \f$\lambda = f_g(k)f_l(k)\f$. - -By stacking previous results, we obtain the *band description matrix (BDM)* - -\f[BDM_j = \left(\begin{matrix} \bf{V1}_j^1 & \bf{V1}_j^2 & \ldots & \bf{V1}_j^n \\ \bf{V2}_j^1 & \bf{V2}_j^2 & \ldots & \bf{V2}_j^n \\ \bf{V3}_j^1 & \bf{V3}_j^2 & \ldots & \bf{V3}_j^n \\ \bf{V4}_j^1 & \bf{V4}_j^2 & \ldots & \bf{V4}_j^n \end{matrix} \right) \in \mathbb{R}^{4\times n},\f] - -with \f$n\f$ the number of rows in band \f$B_j\f$: - -\f[n = \begin{cases} 2w, & j = 1||m; \\ 3w, & \mbox{else}. \end{cases}\f] - -Each \f$BD_j\f$ can be obtained using the standard deviation vector \f$S_j\f$ and mean vector \f$M_j\f$ of -\f$BDM_J\f$. Thus, finally: - -\f[LBD = (M_1^T, S_1^T, M_2^T, S_2^T, \ldots, M_m^T, S_m^T)^T \in \mathbb{R}^{8m}\f] - -Once the LBD has been obtained, it must be converted into a binary form. For such purpose, we -consider 32 possible pairs of BD inside it; each couple of BD is compared bit by bit and comparison -generates an 8 bit string. Concatenating 32 comparison strings, we get the 256-bit final binary -representation of a single LBD. -*/ - -#endif diff --git a/3rdparty/include/opencv2/line_descriptor/descriptor.hpp b/3rdparty/include/opencv2/line_descriptor/descriptor.hpp deleted file mode 100644 index 15e8fe7b4f..0000000000 --- a/3rdparty/include/opencv2/line_descriptor/descriptor.hpp +++ /dev/null @@ -1,1205 +0,0 @@ -/*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) 2014, Biagio Montesano, 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_DESCRIPTOR_HPP__ -#define __OPENCV_DESCRIPTOR_HPP__ - -#include -#include -#include - -#if defined _MSC_VER && _MSC_VER <= 1700 -#include -#else -#include -#endif - -#include -#include - -#include "opencv2/core/utility.hpp" -#include -#include "opencv2/core.hpp" - -/* define data types */ -typedef uint64_t UINT64; -typedef uint32_t UINT32; -typedef uint16_t UINT16; -typedef uint8_t UINT8; - -/* define constants */ -#define UINT64_1 ((UINT64)0x01) -#define UINT32_1 ((UINT32)0x01) - -namespace cv -{ -namespace line_descriptor -{ - -//! @addtogroup line_descriptor -//! @{ - -/** @brief A class to represent a line - -As aformentioned, it is been necessary to design a class that fully stores the information needed to -characterize completely a line and plot it on image it was extracted from, when required. - -*KeyLine* class has been created for such goal; it is mainly inspired to Feature2d's KeyPoint class, -since KeyLine shares some of *KeyPoint*'s fields, even if a part of them assumes a different -meaning, when speaking about lines. In particular: - -- the *class_id* field is used to gather lines extracted from different octaves which refer to - same line inside original image (such lines and the one they represent in original image share - the same *class_id* value) -- the *angle* field represents line's slope with respect to (positive) X axis -- the *pt* field represents line's midpoint -- the *response* field is computed as the ratio between the line's length and maximum between - image's width and height -- the *size* field is the area of the smallest rectangle containing line - -Apart from fields inspired to KeyPoint class, KeyLines stores information about extremes of line in -original image and in octave it was extracted from, about line's length and number of pixels it -covers. - */ -struct CV_EXPORTS_W_SIMPLE KeyLine -{ - public: - /** orientation of the line */ - CV_PROP_RW float angle; - - /** object ID, that can be used to cluster keylines by the line they represent */ - CV_PROP_RW int class_id; - - /** octave (pyramid layer), from which the keyline has been extracted */ - CV_PROP_RW int octave; - - /** coordinates of the middlepoint */ - CV_PROP_RW Point2f pt; - - /** the response, by which the strongest keylines have been selected. - It's represented by the ratio between line's length and maximum between - image's width and height */ - CV_PROP_RW float response; - - /** minimum area containing line */ - CV_PROP_RW float size; - - /** lines's extremes in original image */ - CV_PROP_RW float startPointX; - CV_PROP_RW float startPointY; - CV_PROP_RW float endPointX; - CV_PROP_RW float endPointY; - - /** line's extremes in image it was extracted from */ - CV_PROP_RW float sPointInOctaveX; - CV_PROP_RW float sPointInOctaveY; - CV_PROP_RW float ePointInOctaveX; - CV_PROP_RW float ePointInOctaveY; - - /** the length of line */ - CV_PROP_RW float lineLength; - - /** number of pixels covered by the line */ - CV_PROP_RW int numOfPixels; - - /** Returns the start point of the line in the original image */ - CV_WRAP Point2f getStartPoint() const - { - return Point2f(startPointX, startPointY); - } - - /** Returns the end point of the line in the original image */ - CV_WRAP Point2f getEndPoint() const - { - return Point2f(endPointX, endPointY); - } - - /** Returns the start point of the line in the octave it was extracted from */ - CV_WRAP Point2f getStartPointInOctave() const - { - return Point2f(sPointInOctaveX, sPointInOctaveY); - } - - /** Returns the end point of the line in the octave it was extracted from */ - CV_WRAP Point2f getEndPointInOctave() const - { - return Point2f(ePointInOctaveX, ePointInOctaveY); - } - - /** constructor */ - CV_WRAP KeyLine() - { - } -}; - -/** @brief Class implements both functionalities for detection of lines and computation of their -binary descriptor. - -Class' interface is mainly based on the ones of classical detectors and extractors, such as -Feature2d's @ref features2d_main and @ref features2d_match. Retrieved information about lines is -stored in line_descriptor::KeyLine objects. - */ -class CV_EXPORTS_W BinaryDescriptor : public Algorithm -{ - - public: - /** @brief List of BinaryDescriptor parameters: - */ - struct CV_EXPORTS Params - { - /*CV_WRAP*/ - Params(); - - /** the number of image octaves (default = 1) */ - - int numOfOctave_; - - /** the width of band; (default: 7) */ - - int widthOfBand_; - - /** image's reduction ratio in construction of Gaussian pyramids */ - int reductionRatio; - - int ksize_; - - /** read parameters from a FileNode object and store them (struct function) */ - void read( const FileNode& fn ); - - /** store parameters to a FileStorage object (struct function) */ - void write( FileStorage& fs ) const; - - }; - - /** @brief Constructor - - @param parameters configuration parameters BinaryDescriptor::Params - - If no argument is provided, constructor sets default values (see comments in the code snippet in - previous section). Default values are strongly recommended. - */ - BinaryDescriptor( const BinaryDescriptor::Params ¶meters = BinaryDescriptor::Params() ); - - /** @brief Create a BinaryDescriptor object with default parameters (or with the ones provided) - and return a smart pointer to it - */ - CV_WRAP static Ptr createBinaryDescriptor(); - static Ptr createBinaryDescriptor( Params parameters ); - - /** destructor */ - ~BinaryDescriptor(); - - /** @brief Get current number of octaves - */ - CV_WRAP int getNumOfOctaves(); - /** @brief Set number of octaves - @param octaves number of octaves - */ - CV_WRAP void setNumOfOctaves( int octaves ); - /** @brief Get current width of bands - */ - CV_WRAP int getWidthOfBand(); - /** @brief Set width of bands - @param width width of bands - */ - CV_WRAP void setWidthOfBand( int width ); - /** @brief Get current reduction ratio (used in Gaussian pyramids) - */ - CV_WRAP int getReductionRatio(); - /** @brief Set reduction ratio (used in Gaussian pyramids) - @param rRatio reduction ratio - */ - CV_WRAP void setReductionRatio( int rRatio ); - - /** @brief Read parameters from a FileNode object and store them - - @param fn source FileNode file - */ - virtual void read( const cv::FileNode& fn ) CV_OVERRIDE; - - /** @brief Store parameters to a FileStorage object - - @param fs output FileStorage file - */ - virtual void write( cv::FileStorage& fs ) const CV_OVERRIDE; - - /** @brief Requires line detection - - @param image input image - @param keypoints vector that will store extracted lines for one or more images - @param mask mask matrix to detect only KeyLines of interest - */ - CV_WRAP void detect( const Mat& image, CV_OUT std::vector& keypoints, const Mat& mask = Mat() ); - - /** @overload - - @param images input images - @param keylines set of vectors that will store extracted lines for one or more images - @param masks vector of mask matrices to detect only KeyLines of interest from each input image - */ - void detect( const std::vector& images, std::vector >& keylines, const std::vector& masks = - std::vector() ) const; - - /** @brief Requires descriptors computation - - @param image input image - @param keylines vector containing lines for which descriptors must be computed - @param descriptors - @param returnFloatDescr flag (when set to true, original non-binary descriptors are returned) - */ - CV_WRAP void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector& keylines, CV_OUT Mat& descriptors, bool returnFloatDescr = false ) const; - - /** @overload - - @param images input images - @param keylines set of vectors containing lines for which descriptors must be computed - @param descriptors - @param returnFloatDescr flag (when set to true, original non-binary descriptors are returned) - */ - void compute( const std::vector& images, std::vector >& keylines, std::vector& descriptors, bool returnFloatDescr = - false ) const; - - /** @brief Return descriptor size - */ - int descriptorSize() const; - - /** @brief Return data type - */ - int descriptorType() const; - - /** returns norm mode */ - /*CV_WRAP*/ - int defaultNorm() const; - - /** @brief Define operator '()' to perform detection of KeyLines and computation of descriptors in a row. - - @param image input image - @param mask mask matrix to select which lines in KeyLines must be accepted among the ones - extracted (used when *keylines* is not empty) - @param keylines vector that contains input lines (when filled, the detection part will be skipped - and input lines will be passed as input to the algorithm computing descriptors) - @param descriptors matrix that will store final descriptors - @param useProvidedKeyLines flag (when set to true, detection phase will be skipped and only - computation of descriptors will be executed, using lines provided in *keylines*) - @param returnFloatDescr flag (when set to true, original non-binary descriptors are returned) - */ - virtual void operator()( InputArray image, InputArray mask, CV_OUT std::vector& keylines, OutputArray descriptors, - bool useProvidedKeyLines = false, bool returnFloatDescr = false ) const; - - protected: - /** implementation of line detection */ - virtual void detectImpl( const Mat& imageSrc, std::vector& keylines, const Mat& mask = Mat() ) const; - - /** implementation of descriptors' computation */ - virtual void computeImpl( const Mat& imageSrc, std::vector& keylines, Mat& descriptors, bool returnFloatDescr, - bool useDetectionData ) const; - - private: - /** struct to represent lines extracted from an octave */ - struct OctaveLine - { - unsigned int octaveCount; //the octave which this line is detected - unsigned int lineIDInOctave; //the line ID in that octave image - unsigned int lineIDInScaleLineVec; //the line ID in Scale line vector - float lineLength; //the length of line in original image scale - }; - - // A 2D line (normal equation parameters). - struct SingleLine - { - //note: rho and theta are based on coordinate origin, i.e. the top-left corner of image - double rho; //unit: pixel length - double theta; //unit: rad - double linePointX; // = rho * cos(theta); - double linePointY; // = rho * sin(theta); - //for EndPoints, the coordinate origin is the top-left corner of image. - double startPointX; - double startPointY; - double endPointX; - double endPointY; - //direction of a line, the angle between positive line direction (dark side is in the left) and positive X axis. - double direction; - //mean gradient magnitude - double gradientMagnitude; - //mean gray value of pixels in dark side of line - double darkSideGrayValue; - //mean gray value of pixels in light side of line - double lightSideGrayValue; - //the length of line - double lineLength; - //the width of line; - double width; - //number of pixels - int numOfPixels; - //the decriptor of line - std::vector descriptor; - }; - - // Specifies a vector of lines. - typedef std::vector Lines_list; - - struct OctaveSingleLine - { - /*endPoints, the coordinate origin is the top-left corner of the original image. - *startPointX = sPointInOctaveX * (factor)^octaveCount; */ - float startPointX; - float startPointY; - float endPointX; - float endPointY; - //endPoints, the coordinate origin is the top-left corner of the octave image. - float sPointInOctaveX; - float sPointInOctaveY; - float ePointInOctaveX; - float ePointInOctaveY; - //direction of a line, the angle between positive line direction (dark side is in the left) and positive X axis. - float direction; - //the summation of gradient magnitudes of pixels on lines - float salience; - //the length of line - float lineLength; - //number of pixels - unsigned int numOfPixels; - //the octave which this line is detected - unsigned int octaveCount; - //the decriptor of line - std::vector descriptor; - - OctaveSingleLine() : startPointX(0), startPointY(0), endPointX(0), endPointY(0), - sPointInOctaveX(0), sPointInOctaveY(0), ePointInOctaveX(0), ePointInOctaveY(0), - direction(0), salience(0), lineLength(0), numOfPixels(0), octaveCount(0), - descriptor(std::vector()) - {} - }; - - struct Pixel - { - unsigned int x; //X coordinate - unsigned int y; //Y coordinate - }; - struct EdgeChains - { - std::vector xCors; //all the x coordinates of edge points - std::vector yCors; //all the y coordinates of edge points - std::vector sId; //the start index of each edge in the coordinate arrays - unsigned int numOfEdges; //the number of edges whose length are larger than minLineLen; numOfEdges < sId.size; - }; - - struct LineChains - { - std::vector xCors; //all the x coordinates of line points - std::vector yCors; //all the y coordinates of line points - std::vector sId; //the start index of each line in the coordinate arrays - unsigned int numOfLines; //the number of lines whose length are larger than minLineLen; numOfLines < sId.size; - }; - - typedef std::list PixelChain; //each edge is a pixel chain - - struct CV_EXPORTS_W_SIMPLE EDLineParam - { - CV_PROP_RW int ksize; - CV_PROP_RW float sigma; - CV_PROP_RW float gradientThreshold; - CV_PROP_RW float anchorThreshold; - CV_PROP_RW int scanIntervals; - CV_PROP_RW int minLineLen; - CV_PROP_RW double lineFitErrThreshold; - }; - - #define RELATIVE_ERROR_FACTOR 100.0 - #define MLN10 2.30258509299404568402 - #define log_gamma(x) ((x)>15.0?log_gamma_windschitl(x):log_gamma_lanczos(x)) - - /** This class is used to detect lines from input image. - * First, edges are extracted from input image following the method presented in Cihan Topal and - * Cuneyt Akinlar's paper:"Edge Drawing: A Heuristic Approach to Robust Real-Time Edge Detection", 2010. - * Then, lines are extracted from the edge image following the method presented in Cuneyt Akinlar and - * Cihan Topal's paper:"EDLines: A real-time line segment detector with a false detection control", 2011 - * PS: The linking step of edge detection has a little bit difference with the Edge drawing algorithm - * described in the paper. The edge chain doesn't stop when the pixel direction is changed. - */ - class CV_EXPORTS_W EDLineDetector - { - public: - CV_WRAP EDLineDetector(); - CV_WRAP_AS(EDLineDetectorWithParams) EDLineDetector( EDLineParam param ); - ~EDLineDetector(); - - /** @brief Creates an EDLineDetector object, using smart pointers. - */ - CV_WRAP static Ptr createEDLineDetector(); - - - CV_WRAP_AS(createEDLineDetectorWithParams) static Ptr createEDLineDetector(EDLineParam params); - /*extract edges from image - *image: In, gray image; - *edges: Out, store the edges, each edge is a pixel chain - *return -1: error happen - */ - int EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains ); - - /*extract lines from image - *image: In, gray image; - *lines: Out, store the extracted lines, - *return -1: error happen - */ - int EDline( cv::Mat &image, LineChains &lines ); - - /** extract line from image, and store them */ - CV_WRAP int EDline( cv::Mat &image ); - - cv::Mat dxImg_; //store the dxImg; - - cv::Mat dyImg_; //store the dyImg; - - cv::Mat gImgWO_; //store the gradient image without threshold; - - LineChains lines_; //store the detected line chains; - - //store the line Equation coefficients, vec3=[w1,w2,w3] for line w1*x + w2*y + w3=0; - std::vector > lineEquations_; - - //store the line endpoints, [x1,y1,x2,y3] - std::vector > lineEndpoints_; - - //store the line direction - std::vector lineDirection_; - - //store the line salience, which is the summation of gradients of pixels on line - std::vector lineSalience_; - - // image sizes - unsigned int imageWidth; - unsigned int imageHeight; - - /*The threshold of line fit error; - *If lineFitErr is large than this threshold, then - *the pixel chain is not accepted as a single line segment.*/ - double lineFitErrThreshold_; - - /*the threshold of pixel gradient magnitude. - *Only those pixel whose gradient magnitude are larger than this threshold will be - *taken as possible edge points. Default value is 36*/ - short gradienThreshold_; - - /*If the pixel's gradient value is bigger than both of its neighbors by a - *certain threshold (ANCHOR_THRESHOLD), the pixel is marked to be an anchor. - *Default value is 8*/ - unsigned char anchorThreshold_; - - /*anchor testing can be performed at different scan intervals, i.e., - *every row/column, every second row/column etc. - *Default value is 2*/ - unsigned int scanIntervals_; - - int minLineLen_; //minimal acceptable line length - - private: - void InitEDLine_(); - - /*For an input edge chain, find the best fit line, the default chain length is minLineLen_ - *xCors: In, pointer to the X coordinates of pixel chain; - *yCors: In, pointer to the Y coordinates of pixel chain; - *offsetS:In, start index of this chain in vector; - *lineEquation: Out, [a,b] which are the coefficient of lines y=ax+b(horizontal) or x=ay+b(vertical); - *return: line fit error; -1:error happens; - */ - double LeastSquaresLineFit_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, std::vector &lineEquation ); - - /*For an input pixel chain, find the best fit line. Only do the update based on new points. - *For A*x=v, Least square estimation of x = Inv(A^T * A) * (A^T * v); - *If some new observations are added, i.e, [A; A'] * x = [v; v'], - *then x' = Inv(A^T * A + (A')^T * A') * (A^T * v + (A')^T * v'); - *xCors: In, pointer to the X coordinates of pixel chain; - *yCors: In, pointer to the Y coordinates of pixel chain; - *offsetS:In, start index of this chain in vector; - *newOffsetS: In, start index of extended part; - *offsetE:In, end index of this chain in vector; - *lineEquation: Out, [a,b] which are the coefficient of lines y=ax+b(horizontal) or x=ay+b(vertical); - *return: line fit error; -1:error happens; - */ - double LeastSquaresLineFit_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, unsigned int newOffsetS, unsigned int offsetE, - std::vector &lineEquation ); - - /** Validate line based on the Helmholtz principle, which basically states that - * for a structure to be perceptually meaningful, the expectation of this structure - * by chance must be very low. - */ - bool LineValidation_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, unsigned int offsetE, std::vector &lineEquation, - float &direction ); - - bool bValidate_; //flag to decide whether line will be validated - - int ksize_; //the size of Gaussian kernel: ksize X ksize, default value is 5. - - float sigma_; //the sigma of Gaussian kernal, default value is 1.0. - - /*For example, there two edges in the image: - *edge1 = [(7,4), (8,5), (9,6),| (10,7)|, (11, 8), (12,9)] and - *edge2 = [(14,9), (15,10), (16,11), (17,12),| (18, 13)|, (19,14)] ; then we store them as following: - *pFirstPartEdgeX_ = [10, 11, 12, 18, 19];//store the first part of each edge[from middle to end] - *pFirstPartEdgeY_ = [7, 8, 9, 13, 14]; - *pFirstPartEdgeS_ = [0,3,5];// the index of start point of first part of each edge - *pSecondPartEdgeX_ = [10, 9, 8, 7, 18, 17, 16, 15, 14];//store the second part of each edge[from middle to front] - *pSecondPartEdgeY_ = [7, 6, 5, 4, 13, 12, 11, 10, 9];//anchor points(10, 7) and (18, 13) are stored again - *pSecondPartEdgeS_ = [0, 4, 9];// the index of start point of second part of each edge - *This type of storage order is because of the order of edge detection process. - *For each edge, start from one anchor point, first go right, then go left or first go down, then go up*/ - - //store the X coordinates of the first part of the pixels for chains - unsigned int *pFirstPartEdgeX_; - - //store the Y coordinates of the first part of the pixels for chains - unsigned int *pFirstPartEdgeY_; - - //store the start index of every edge chain in the first part arrays - unsigned int *pFirstPartEdgeS_; - - //store the X coordinates of the second part of the pixels for chains - unsigned int *pSecondPartEdgeX_; - - //store the Y coordinates of the second part of the pixels for chains - unsigned int *pSecondPartEdgeY_; - - //store the start index of every edge chain in the second part arrays - unsigned int *pSecondPartEdgeS_; - - //store the X coordinates of anchors - unsigned int *pAnchorX_; - - //store the Y coordinates of anchors - unsigned int *pAnchorY_; - - //edges - cv::Mat edgeImage_; - - cv::Mat gImg_; //store the gradient image; - - cv::Mat dirImg_; //store the direction image - - double logNT_; - - cv::Mat_ ATA; //the previous matrix of A^T * A; - - cv::Mat_ ATV; //the previous vector of A^T * V; - - cv::Mat_ fitMatT; //the matrix used in line fit function; - - cv::Mat_ fitVec; //the vector used in line fit function; - - cv::Mat_ tempMatLineFit; //the matrix used in line fit function; - - cv::Mat_ tempVecLineFit; //the vector used in line fit function; - -}; - - // Specifies a vector of lines. -typedef std::vector LinesVec; - -// each element in ScaleLines is a vector of lines -// which corresponds the same line detected in different octave images. -typedef std::vector ScaleLines; - -/* compute Gaussian pyramids */ -void computeGaussianPyramid( const Mat& image, const int numOctaves ); - -/* compute Sobel's derivatives */ -void computeSobel( const Mat& image, const int numOctaves ); - -/* conversion of an LBD descriptor to its binary representation */ -unsigned char binaryConversion( float* f1, float* f2 ); - -/* compute LBD descriptors using EDLine extractor */ -int computeLBD( ScaleLines &keyLines, bool useDetectionData = false ); - -/* gathers lines in groups using EDLine extractor. - Each group contains the same line, detected in different octaves */ -int OctaveKeyLines( cv::Mat& image, ScaleLines &keyLines ); - -/* the local gaussian coefficient applied to the orthogonal line direction within each band */ -std::vector gaussCoefL_; - -/* the global gaussian coefficient applied to each row within line support region */ -std::vector gaussCoefG_; - -/* descriptor parameters */ -Params params; - -/* vector of sizes of downsampled and blurred images */ -std::vector images_sizes; - -/*For each octave of image, we define an EDLineDetector, because we can get gradient images (dxImg, dyImg, gImg) - *from the EDLineDetector class without extra computation cost. Another reason is that, if we use - *a single EDLineDetector to detect lines in different octave of images, then we need to allocate and release - *memory for gradient images (dxImg, dyImg, gImg) repeatedly for their varying size*/ -std::vector > edLineVec_; - -/* Sobel's derivatives */ -std::vector dxImg_vector, dyImg_vector; - -/* Gaussian pyramid */ -std::vector octaveImages; - -}; - -/** -Lines extraction methodology ----------------------------- - -The lines extraction methodology described in the following is mainly based on @cite EDL . The -extraction starts with a Gaussian pyramid generated from an original image, downsampled N-1 times, -blurred N times, to obtain N layers (one for each octave), with layer 0 corresponding to input -image. Then, from each layer (octave) in the pyramid, lines are extracted using LSD algorithm. - -Differently from EDLine lines extractor used in original article, LSD furnishes information only -about lines extremes; thus, additional information regarding slope and equation of line are computed -via analytic methods. The number of pixels is obtained using *LineIterator*. Extracted lines are -returned in the form of KeyLine objects, but since extraction is based on a method different from -the one used in *BinaryDescriptor* class, data associated to a line's extremes in original image and -in octave it was extracted from, coincide. KeyLine's field *class_id* is used as an index to -indicate the order of extraction of a line inside a single octave. -*/ -struct CV_EXPORTS_W_SIMPLE LSDParam -{ - CV_PROP_RW double scale ; - CV_PROP_RW double sigma_scale; - CV_PROP_RW double quant; - CV_PROP_RW double ang_th; - CV_PROP_RW double log_eps; - CV_PROP_RW double density_th ; - CV_PROP_RW int n_bins ; - - -CV_WRAP LSDParam():scale(0.8), - sigma_scale(0.6), - quant(2.0), - ang_th(22.5), - log_eps(0), - density_th(0.7), - n_bins(1024){} - -}; - -class CV_EXPORTS_W LSDDetector : public Algorithm -{ -public: - -/* constructor */ -CV_WRAP LSDDetector() : params() -{ -} -; - -CV_WRAP_AS(LSDDetectorWithParams) LSDDetector(LSDParam _params) : params(_params) -{ -} -; - -/** @brief Creates ad LSDDetector object, using smart pointers. - */ -CV_WRAP static Ptr createLSDDetector(); - - -CV_WRAP_AS(createLSDDetectorWithParams) static Ptr createLSDDetector(LSDParam params); - - -/** @brief Detect lines inside an image. - -@param image input image -@param keypoints vector that will store extracted lines for one or more images -@param scale scale factor used in pyramids generation -@param numOctaves number of octaves inside pyramid -@param mask mask matrix to detect only KeyLines of interest - */ -CV_WRAP void detect( const Mat& image, CV_OUT std::vector& keypoints, int scale, int numOctaves, const Mat& mask = Mat() ); - -/** @overload -@param images input images -@param keylines set of vectors that will store extracted lines for one or more images -@param scale scale factor used in pyramids generation -@param numOctaves number of octaves inside pyramid -@param masks vector of mask matrices to detect only KeyLines of interest from each input image -*/ -CV_WRAP void detect( const std::vector& images, std::vector >& keylines, int scale, int numOctaves, -const std::vector& masks = std::vector() ) const; - -private: -/* compute Gaussian pyramid of input image */ -void computeGaussianPyramid( const Mat& image, int numOctaves, int scale ); - -/* implementation of line detection */ -void detectImpl( const Mat& imageSrc, std::vector& keylines, int numOctaves, int scale, const Mat& mask ) const; - -/* matrices for Gaussian pyramids */ -std::vector gaussianPyrs; - -/* parameters */ -LSDParam params; -}; - -/** @brief furnishes all functionalities for querying a dataset provided by user or internal to -class (that user must, anyway, populate) on the model of @ref features2d_match - - -Once descriptors have been extracted from an image (both they represent lines and points), it -becomes interesting to be able to match a descriptor with another one extracted from a different -image and representing the same line or point, seen from a differente perspective or on a different -scale. In reaching such goal, the main headache is designing an efficient search algorithm to -associate a query descriptor to one extracted from a dataset. In the following, a matching modality -based on *Multi-Index Hashing (MiHashing)* will be described. - -Multi-Index Hashing -------------------- - -The theory described in this section is based on @cite MIH . Given a dataset populated with binary -codes, each code is indexed *m* times into *m* different hash tables, according to *m* substrings it -has been divided into. Thus, given a query code, all the entries close to it at least in one -substring are returned by search as *neighbor candidates*. Returned entries are then checked for -validity by verifying that their full codes are not distant (in Hamming space) more than *r* bits -from query code. In details, each binary code **h** composed of *b* bits is divided into *m* -disjoint substrings \f$\mathbf{h}^{(1)}, ..., \mathbf{h}^{(m)}\f$, each with length -\f$\lfloor b/m \rfloor\f$ or \f$\lceil b/m \rceil\f$ bits. Formally, when two codes **h** and **g** differ -by at the most *r* bits, in at the least one of their *m* substrings they differ by at the most -\f$\lfloor r/m \rfloor\f$ bits. In particular, when \f$||\mathbf{h}-\mathbf{g}||_H \le r\f$ (where \f$||.||_H\f$ -is the Hamming norm), there must exist a substring *k* (with \f$1 \le k \le m\f$) such that - -\f[||\mathbf{h}^{(k)} - \mathbf{g}^{(k)}||_H \le \left\lfloor \frac{r}{m} \right\rfloor .\f] - -That means that if Hamming distance between each of the *m* substring is strictly greater than -\f$\lfloor r/m \rfloor\f$, then \f$||\mathbf{h}-\mathbf{g}||_H\f$ must be larger that *r* and that is a -contradiction. If the codes in dataset are divided into *m* substrings, then *m* tables will be -built. Given a query **q** with substrings \f$\{\mathbf{q}^{(i)}\}^m_{i=1}\f$, *i*-th hash table is -searched for entries distant at the most \f$\lfloor r/m \rfloor\f$ from \f$\mathbf{q}^{(i)}\f$ and a set of -candidates \f$\mathcal{N}_i(\mathbf{q})\f$ is obtained. The union of sets -\f$\mathcal{N}(\mathbf{q}) = \bigcup_i \mathcal{N}_i(\mathbf{q})\f$ is a superset of the *r*-neighbors -of **q**. Then, last step of algorithm is computing the Hamming distance between **q** and each -element in \f$\mathcal{N}(\mathbf{q})\f$, deleting the codes that are distant more that *r* from **q**. -*/ -class CV_EXPORTS_W BinaryDescriptorMatcher : public Algorithm -{ - -public: -/** @brief For every input query descriptor, retrieve the best matching one from a dataset provided from user -or from the one internal to class - -@param queryDescriptors query descriptors -@param trainDescriptors dataset of descriptors furnished by user -@param matches vector to host retrieved matches -@param mask mask to select which input descriptors must be matched to one in dataset - */ -CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors, CV_OUT std::vector& matches, const Mat& mask = Mat() ) const; - -/** @overload -@param queryDescriptors query descriptors -@param matches vector to host retrieved matches -@param masks vector of masks to select which input descriptors must be matched to one in dataset -(the *i*-th mask in vector indicates whether each input query can be matched with descriptors in -dataset relative to *i*-th image) -*/ -CV_WRAP_AS(matchQuery) void match( const Mat& queryDescriptors, CV_OUT std::vector& matches, const std::vector& masks = std::vector() ); - -/** @brief For every input query descriptor, retrieve the best *k* matching ones from a dataset provided from -user or from the one internal to class - -@param queryDescriptors query descriptors -@param trainDescriptors dataset of descriptors furnished by user -@param matches vector to host retrieved matches -@param k number of the closest descriptors to be returned for every input query -@param mask mask to select which input descriptors must be matched to ones in dataset -@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any -matches for a given query is not inserted in final result) - */ -CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, CV_OUT std::vector >& matches, int k, const Mat& mask = Mat(), -bool compactResult = false ) const; - -/** @overload -@param queryDescriptors query descriptors -@param matches vector to host retrieved matches -@param k number of the closest descriptors to be returned for every input query -@param masks vector of masks to select which input descriptors must be matched to ones in dataset -(the *i*-th mask in vector indicates whether each input query can be matched with descriptors in -dataset relative to *i*-th image) -@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any -matches for a given query is not inserted in final result) -*/ -CV_WRAP_AS(knnMatchQuery) void knnMatch( const Mat& queryDescriptors, std::vector >& matches, int k, const std::vector& masks = std::vector(), -bool compactResult = false ); - -/** @brief For every input query descriptor, retrieve, from a dataset provided from user or from the one -internal to class, all the descriptors that are not further than *maxDist* from input query - -@param queryDescriptors query descriptors -@param trainDescriptors dataset of descriptors furnished by user -@param matches vector to host retrieved matches -@param maxDistance search radius -@param mask mask to select which input descriptors must be matched to ones in dataset -@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any -matches for a given query is not inserted in final result) - */ -void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector >& matches, float maxDistance, -const Mat& mask = Mat(), bool compactResult = false ) const; - -/** @overload -@param queryDescriptors query descriptors -@param matches vector to host retrieved matches -@param maxDistance search radius -@param masks vector of masks to select which input descriptors must be matched to ones in dataset -(the *i*-th mask in vector indicates whether each input query can be matched with descriptors in -dataset relative to *i*-th image) -@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any -matches for a given query is not inserted in final result) -*/ -void radiusMatch( const Mat& queryDescriptors, std::vector >& matches, float maxDistance, const std::vector& masks = -std::vector(), -bool compactResult = false ); - -/** @brief Store locally new descriptors to be inserted in dataset, without updating dataset. - -@param descriptors matrices containing descriptors to be inserted into dataset - -@note Each matrix *i* in **descriptors** should contain descriptors relative to lines extracted from -*i*-th image. - */ -void add( const std::vector& descriptors ); - -/** @brief Update dataset by inserting into it all descriptors that were stored locally by *add* function. - -@note Every time this function is invoked, current dataset is deleted and locally stored descriptors -are inserted into dataset. The locally stored copy of just inserted descriptors is then removed. - */ -void train(); - -/** @brief Create a BinaryDescriptorMatcher object and return a smart pointer to it. - */ -static Ptr createBinaryDescriptorMatcher(); - -/** @brief Clear dataset and internal data - */ -void clear() CV_OVERRIDE; - -/** @brief Constructor. - -The BinaryDescriptorMatcher constructed is able to store and manage 256-bits long entries. - */ -CV_WRAP BinaryDescriptorMatcher(); - -/** destructor */ -~BinaryDescriptorMatcher() -{ -} - -private: -class BucketGroup -{ - -public: -/** constructor */ -BucketGroup(bool needAllocateGroup = true); - -/** destructor */ -~BucketGroup(); - -/** insert data into the bucket */ -void insert( int subindex, UINT32 data ); - -/** perform a query to the bucket */ -UINT32* query( int subindex, int *size ); - -/** utility functions */ -void insert_value( std::vector& vec, int index, UINT32 data ); -void push_value( std::vector& vec, UINT32 Data ); - -/** data fields */ -UINT32 empty; -std::vector group; - - -}; - -class SparseHashtable -{ - -private: - -/** Maximum bits per key before folding the table */ -static const int MAX_B; - -/** Bins (each bin is an Array object for duplicates of the same key) */ -std::vector table; - -public: - -/** constructor */ -SparseHashtable(); - -/** destructor */ -~SparseHashtable(); - -/** initializer */ -int init( int _b ); - -/** insert data */ -void insert( UINT64 index, UINT32 data ); - -/** query data */ -UINT32* query( UINT64 index, int* size ); - -/** Bits per index */ -int b; - -/** Number of bins */ -UINT64 size; - -}; - -/** class defining a sequence of bits */ -class bitarray -{ - -public: -/** pointer to bits sequence and sequence's length */ -UINT32 *arr; -UINT32 length; - -/** constructor setting default values */ -bitarray() -{ -arr = NULL; -length = 0; -} - -/** constructor setting sequence's length */ -bitarray( UINT64 _bits ) -{ -arr = NULL; -init( _bits ); -} - -/** initializer of private fields */ -void init( UINT64 _bits ) -{ -if( arr ) -delete[] arr; -length = (UINT32) ceil( _bits / 32.00 ); -arr = new UINT32[length]; -erase(); -} - -/** destructor */ -~bitarray() -{ -if( arr ) -delete[] arr; -} - -inline void flip( UINT64 index ) -{ -arr[index >> 5] ^= ( (UINT32) 0x01 ) << ( index % 32 ); -} - -inline void set( UINT64 index ) -{ -arr[index >> 5] |= ( (UINT32) 0x01 ) << ( index % 32 ); -} - -inline UINT8 get( UINT64 index ) -{ -return ( arr[index >> 5] & ( ( (UINT32) 0x01 ) << ( index % 32 ) ) ) != 0; -} - -/** reserve menory for an UINT32 */ -inline void erase() -{ -memset( arr, 0, sizeof(UINT32) * length ); -} - -}; - -class Mihasher -{ - -public: -/** Bits per code */ -int B; - -/** B/8 */ -int B_over_8; - -/** Bits per chunk (must be less than 64) */ -int b; - -/** Number of chunks */ -int m; - -/** Number of chunks with b bits (have 1 bit more than others) */ -int mplus; - -/** Maximum hamming search radius (we use B/2 by default) */ -int D; - -/** Maximum hamming search radius per substring */ -int d; - -/** Maximum results to return */ -int K; - -/** Number of codes */ -UINT64 N; - -/** Table of original full-length codes */ -cv::Mat codes; - -/** Counter for eliminating duplicate results (it is not thread safe) */ -Ptr counter; - -/** Array of m hashtables */ -std::vector H; - -/** Volume of a b-bit Hamming ball with radius s (for s = 0 to d) */ -std::vector xornum; - -/** Used within generation of binary codes at a certain Hamming distance */ -int power[100]; - -/** constructor */ -Mihasher(); - -/** desctructor */ -~Mihasher(); - -/** constructor 2 */ -Mihasher( int B, int m ); - -/** K setter */ -void setK( int K ); - -/** populate tables */ -void populate( cv::Mat & codes, UINT32 N, int dim1codes ); - -/** execute a batch query */ -void batchquery( UINT32 * results, UINT32 *numres/*, qstat *stats*/, const cv::Mat & q, UINT32 numq, int dim1queries ); - -private: - -/** execute a single query */ -void query( UINT32 * results, UINT32* numres/*, qstat *stats*/, UINT8 *q, UINT64 * chunks, UINT32 * res ); -}; - -/** retrieve Hamming distances */ -void checkKDistances( UINT32 * numres, int k, std::vector& k_distances, int row, int string_length ) const; - -/** matrix to store new descriptors */ -Mat descriptorsMat; - -/** map storing where each bunch of descriptors benins in DS */ -std::map indexesMap; - -/** internal MiHaser representing dataset */ -Ptr dataset; - -/** index from which next added descriptors' bunch must begin */ -int nextAddedIndex; - -/** number of images whose descriptors are stored in DS */ -int numImages; - -/** number of descriptors in dataset */ -int descrInDS; - -}; - -/* -------------------------------------------------------------------------------------------- - UTILITY FUNCTIONS - -------------------------------------------------------------------------------------------- */ - -/** struct for drawing options */ -struct CV_EXPORTS_W_SIMPLE DrawLinesMatchesFlags -{ -CV_PROP_RW enum -{ -DEFAULT = 0, //!< Output image matrix will be created (Mat::create), - //!< i.e. existing memory of output image may be reused. - //!< Two source images, matches, and single keylines - //!< will be drawn. -DRAW_OVER_OUTIMG = 1,//!< Output image matrix will not be -//!< created (using Mat::create). Matches will be drawn -//!< on existing content of output image. -NOT_DRAW_SINGLE_LINES = 2//!< Single keylines will not be drawn. -}; -}; - -/** @brief Draws the found matches of keylines from two images. - -@param img1 first image -@param keylines1 keylines extracted from first image -@param img2 second image -@param keylines2 keylines extracted from second image -@param matches1to2 vector of matches -@param outImg output matrix to draw on -@param matchColor drawing color for matches (chosen randomly in case of default value) -@param singleLineColor drawing color for keylines (chosen randomly in case of default value) -@param matchesMask mask to indicate which matches must be drawn -@param flags drawing flags, see DrawLinesMatchesFlags - -@note If both *matchColor* and *singleLineColor* are set to their default values, function draws -matched lines and line connecting them with same color - */ -CV_EXPORTS_W void drawLineMatches( const Mat& img1, const std::vector& keylines1, const Mat& img2, const std::vector& keylines2, - const std::vector& matches1to2, CV_OUT Mat& outImg, const Scalar& matchColor = Scalar::all( -1 ), - const Scalar& singleLineColor = Scalar::all( -1 ), const std::vector& matchesMask = std::vector(), - int flags = DrawLinesMatchesFlags::DEFAULT ); - -/** @brief Draws keylines. - -@param image input image -@param keylines keylines to be drawn -@param outImage output image to draw on -@param color color of lines to be drawn (if set to defaul value, color is chosen randomly) -@param flags drawing flags - */ -CV_EXPORTS_W void drawKeylines( const Mat& image, const std::vector& keylines, CV_OUT Mat& outImage, const Scalar& color = Scalar::all( -1 ), - int flags = DrawLinesMatchesFlags::DEFAULT ); - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/ml.hpp b/3rdparty/include/opencv2/ml.hpp index 396a792119..d537ab7759 100644 --- a/3rdparty/include/opencv2/ml.hpp +++ b/3rdparty/include/opencv2/ml.hpp @@ -198,7 +198,7 @@ public: CV_WRAP virtual Mat getTestSampleWeights() const = 0; CV_WRAP virtual Mat getVarIdx() const = 0; CV_WRAP virtual Mat getVarType() const = 0; - CV_WRAP Mat getVarSymbolFlags() const; + CV_WRAP virtual Mat getVarSymbolFlags() const = 0; CV_WRAP virtual int getResponseType() const = 0; CV_WRAP virtual Mat getTrainSampleIdx() const = 0; CV_WRAP virtual Mat getTestSampleIdx() const = 0; @@ -234,10 +234,10 @@ public: CV_WRAP virtual void shuffleTrainTest() = 0; /** @brief Returns matrix of test samples */ - CV_WRAP Mat getTestSamples() const; + CV_WRAP virtual Mat getTestSamples() const = 0; /** @brief Returns vector of symbolic names captured in loadFromCSV() */ - CV_WRAP void getNames(std::vector& names) const; + CV_WRAP virtual void getNames(std::vector& names) const = 0; /** @brief Extract from 1D vector elements specified by passed indexes. @param vec input vector (supported types: CV_32S, CV_32F, CV_64F) @@ -746,7 +746,7 @@ public: regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed. */ - CV_WRAP bool trainAuto(InputArray samples, + CV_WRAP virtual bool trainAuto(InputArray samples, int layout, InputArray responses, int kFold = 10, @@ -756,7 +756,7 @@ public: Ptr nuGrid = SVM::getDefaultGridPtr(SVM::NU), Ptr coeffGrid = SVM::getDefaultGridPtr(SVM::COEF), Ptr degreeGrid = SVM::getDefaultGridPtr(SVM::DEGREE), - bool balanced=false); + bool balanced=false) = 0; /** @brief Retrieves all the support vectors @@ -771,7 +771,7 @@ public: support vector, used for prediction, was derived from. They are returned in a floating-point matrix, where the support vectors are stored as matrix rows. */ - CV_WRAP Mat getUncompressedSupportVectors() const; + CV_WRAP virtual Mat getUncompressedSupportVectors() const = 0; /** @brief Retrieves the decision function @@ -1292,13 +1292,13 @@ public: @param results Array where the result of the calculation will be written. @param flags Flags for defining the type of RTrees. */ - CV_WRAP void getVotes(InputArray samples, OutputArray results, int flags) const; + CV_WRAP virtual void getVotes(InputArray samples, OutputArray results, int flags) const = 0; /** Returns the OOB error value, computed at the training stage when calcOOBError is set to true. * If this flag was set to false, 0 is returned. The OOB error is also scaled by sample weighting. */ -#if CV_VERSION_MAJOR == 3 - CV_WRAP double getOOBError() const; +#if CV_VERSION_MAJOR == 4 + CV_WRAP virtual double getOOBError() const { return 0; } #else /*CV_WRAP*/ virtual double getOOBError() const = 0; #endif @@ -1531,33 +1531,33 @@ public: /** ANNEAL: Update initial temperature. It must be \>=0. Default value is 10.*/ /** @see setAnnealInitialT */ - CV_WRAP double getAnnealInitialT() const; + CV_WRAP virtual double getAnnealInitialT() const = 0; /** @copybrief getAnnealInitialT @see getAnnealInitialT */ - CV_WRAP void setAnnealInitialT(double val); + CV_WRAP virtual void setAnnealInitialT(double val) = 0; /** ANNEAL: Update final temperature. It must be \>=0 and less than initialT. Default value is 0.1.*/ /** @see setAnnealFinalT */ - CV_WRAP double getAnnealFinalT() const; + CV_WRAP virtual double getAnnealFinalT() const = 0; /** @copybrief getAnnealFinalT @see getAnnealFinalT */ - CV_WRAP void setAnnealFinalT(double val); + CV_WRAP virtual void setAnnealFinalT(double val) = 0; /** ANNEAL: Update cooling ratio. It must be \>0 and less than 1. Default value is 0.95.*/ /** @see setAnnealCoolingRatio */ - CV_WRAP double getAnnealCoolingRatio() const; + CV_WRAP virtual double getAnnealCoolingRatio() const = 0; /** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */ - CV_WRAP void setAnnealCoolingRatio(double val); + CV_WRAP virtual void setAnnealCoolingRatio(double val) = 0; /** ANNEAL: Update iteration per step. It must be \>0 . Default value is 10.*/ /** @see setAnnealItePerStep */ - CV_WRAP int getAnnealItePerStep() const; + CV_WRAP virtual int getAnnealItePerStep() const = 0; /** @copybrief getAnnealItePerStep @see getAnnealItePerStep */ - CV_WRAP void setAnnealItePerStep(int val); + CV_WRAP virtual void setAnnealItePerStep(int val) = 0; /** @brief Set/initialize anneal RNG */ - void setAnnealEnergyRNG(const RNG& rng); + virtual void setAnnealEnergyRNG(const RNG& rng) = 0; /** possible activation functions */ enum ActivationFunctions { @@ -1614,6 +1614,10 @@ public: }; +#ifndef DISABLE_OPENCV_3_COMPATIBILITY +typedef ANN_MLP ANN_MLP_ANNEAL; +#endif + /****************************************************************************************\ * Logistic Regression * \****************************************************************************************/ @@ -1898,43 +1902,6 @@ CV_EXPORTS void randMVNormal( InputArray mean, InputArray cov, int nsamples, Out CV_EXPORTS void createConcentricSpheresTestSet( int nsamples, int nfeatures, int nclasses, OutputArray samples, OutputArray responses); -/** @brief Artificial Neural Networks - Multi-Layer Perceptrons. - -@sa @ref ml_intro_ann -*/ -class CV_EXPORTS_W ANN_MLP_ANNEAL : public ANN_MLP -{ -public: - /** @see setAnnealInitialT */ - CV_WRAP virtual double getAnnealInitialT() const = 0; - /** @copybrief getAnnealInitialT @see getAnnealInitialT */ - CV_WRAP virtual void setAnnealInitialT(double val) = 0; - - /** ANNEAL: Update final temperature. - It must be \>=0 and less than initialT. Default value is 0.1.*/ - /** @see setAnnealFinalT */ - CV_WRAP virtual double getAnnealFinalT() const = 0; - /** @copybrief getAnnealFinalT @see getAnnealFinalT */ - CV_WRAP virtual void setAnnealFinalT(double val) = 0; - - /** ANNEAL: Update cooling ratio. - It must be \>0 and less than 1. Default value is 0.95.*/ - /** @see setAnnealCoolingRatio */ - CV_WRAP virtual double getAnnealCoolingRatio() const = 0; - /** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */ - CV_WRAP virtual void setAnnealCoolingRatio(double val) = 0; - - /** ANNEAL: Update iteration per step. - It must be \>0 . Default value is 10.*/ - /** @see setAnnealItePerStep */ - CV_WRAP virtual int getAnnealItePerStep() const = 0; - /** @copybrief getAnnealItePerStep @see getAnnealItePerStep */ - CV_WRAP virtual void setAnnealItePerStep(int val) = 0; - - /** @brief Set/initialize anneal RNG */ - virtual void setAnnealEnergyRNG(const RNG& rng) = 0; -}; - /****************************************************************************************\ * Simulated annealing solver * diff --git a/3rdparty/include/opencv2/objdetect.hpp b/3rdparty/include/opencv2/objdetect.hpp index 0387b10239..eaee1290ce 100644 --- a/3rdparty/include/opencv2/objdetect.hpp +++ b/3rdparty/include/opencv2/objdetect.hpp @@ -91,7 +91,7 @@ compensate for the differences in the size of areas. The sums of pixel values ov regions are calculated rapidly using integral images (see below and the integral description). To see the object detector at work, have a look at the facedetect demo: - + The following reference is for the detection part only. There is a separate application called opencv_traincascade that can train a cascade of boosted classifiers from a set of samples. @@ -163,7 +163,7 @@ CV_EXPORTS void groupRectangles_meanshift(std::vector& rectList, std::ve std::vector& foundScales, double detectThreshold = 0.0, Size winDetSize = Size(64, 128)); -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvHaarClassifierCascade* obj) const; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvHaarClassifierCascade* obj) const; }; enum { CASCADE_DO_CANNY_PRUNING = 1, CASCADE_SCALE_IMAGE = 2, @@ -372,13 +372,15 @@ http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python- struct CV_EXPORTS_W HOGDescriptor { public: - enum { L2Hys = 0 //!< Default histogramNormType + enum HistogramNormType { L2Hys = 0 //!< Default histogramNormType }; enum { DEFAULT_NLEVELS = 64 //!< Default nlevels value. }; + enum DescriptorStorageFormat { DESCR_FORMAT_COL_BY_COL, DESCR_FORMAT_ROW_BY_ROW }; + /**@brief Creates the HOG descriptor and detector with default params. - aqual to HOGDescriptor(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9, 1 ) + aqual to HOGDescriptor(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9 ) */ CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8), cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1), @@ -402,7 +404,7 @@ public: */ CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride, Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1, - int _histogramNormType=HOGDescriptor::L2Hys, + HOGDescriptor::HistogramNormType _histogramNormType=HOGDescriptor::L2Hys, double _L2HysThreshold=0.2, bool _gammaCorrection=false, int _nlevels=HOGDescriptor::DEFAULT_NLEVELS, bool _signedGradient=false) : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize), @@ -412,7 +414,7 @@ public: {} /** @overload - @param filename the file name containing HOGDescriptor properties and coefficients of the trained classifier + @param filename The file name containing HOGDescriptor properties and coefficients for the linear SVM classifier. */ CV_WRAP HOGDescriptor(const String& filename) { @@ -446,28 +448,28 @@ public: /**@example samples/cpp/peopledetect.cpp */ /**@brief Sets coefficients for the linear SVM classifier. - @param _svmdetector coefficients for the linear SVM classifier. + @param svmdetector coefficients for the linear SVM classifier. */ - CV_WRAP virtual void setSVMDetector(InputArray _svmdetector); + CV_WRAP virtual void setSVMDetector(InputArray svmdetector); - /** @brief Reads HOGDescriptor parameters from a file node. + /** @brief Reads HOGDescriptor parameters from a cv::FileNode. @param fn File node */ virtual bool read(FileNode& fn); - /** @brief Stores HOGDescriptor parameters in a file storage. + /** @brief Stores HOGDescriptor parameters in a cv::FileStorage. @param fs File storage @param objname Object name */ virtual void write(FileStorage& fs, const String& objname) const; - /** @brief loads coefficients for the linear SVM classifier from a file - @param filename Name of the file to read. + /** @brief loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file. + @param filename Path of the file to read. @param objname The optional name of the node to read (if empty, the first top-level node will be used). */ CV_WRAP virtual bool load(const String& filename, const String& objname = String()); - /** @brief saves coefficients for the linear SVM classifier to a file + /** @brief saves HOGDescriptor parameters and coefficients for the linear SVM classifier to a file @param filename File name @param objname Object name */ @@ -503,7 +505,7 @@ public: @param padding Padding @param searchLocations Vector of Point includes set of requested locations to be evaluated. */ - CV_WRAP virtual void detect(const Mat& img, CV_OUT std::vector& foundLocations, + CV_WRAP virtual void detect(InputArray img, CV_OUT std::vector& foundLocations, CV_OUT std::vector& weights, double hitThreshold = 0, Size winStride = Size(), Size padding = Size(), @@ -519,7 +521,7 @@ public: @param padding Padding @param searchLocations Vector of Point includes locations to search. */ - virtual void detect(const Mat& img, CV_OUT std::vector& foundLocations, + virtual void detect(InputArray img, CV_OUT std::vector& foundLocations, double hitThreshold = 0, Size winStride = Size(), Size padding = Size(), const std::vector& searchLocations=std::vector()) const; @@ -568,7 +570,7 @@ public: @param paddingTL Padding from top-left @param paddingBR Padding from bottom-right */ - CV_WRAP virtual void computeGradient(const Mat& img, CV_OUT Mat& grad, CV_OUT Mat& angleOfs, + CV_WRAP virtual void computeGradient(InputArray img, InputOutputArray grad, InputOutputArray angleOfs, Size paddingTL = Size(), Size paddingBR = Size()) const; /** @brief Returns coefficients of the classifier trained for people detection (for 64x128 windows). @@ -603,7 +605,7 @@ public: CV_PROP double winSigma; //! histogramNormType - CV_PROP int histogramNormType; + CV_PROP HOGDescriptor::HistogramNormType histogramNormType; //! L2-Hys normalization method shrinkage. CV_PROP double L2HysThreshold; @@ -637,7 +639,7 @@ public: @param winStride winStride @param padding padding */ - virtual void detectROI(const cv::Mat& img, const std::vector &locations, + virtual void detectROI(InputArray img, const std::vector &locations, CV_OUT std::vector& foundLocations, CV_OUT std::vector& confidences, double hitThreshold = 0, cv::Size winStride = Size(), cv::Size padding = Size()) const; @@ -650,17 +652,12 @@ public: in the detector coefficients (as the last free coefficient). But if the free coefficient is omitted (which is allowed), you can specify it manually here. @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. */ - virtual void detectMultiScaleROI(const cv::Mat& img, + virtual void detectMultiScaleROI(InputArray img, CV_OUT std::vector& foundLocations, std::vector& locations, double hitThreshold = 0, int groupThreshold = 0) const; - /** @brief read/parse Dalal's alt model file - @param modelfile Path of Dalal's alt model file. - */ - void readALTModel(String modelfile); - /** @brief Groups the object candidate rectangles. @param rectList Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.) @param weights Input/output vector of weights of rectangles. Output vector includes weights of retained and grouped rectangles. (The Python list is not modified in place.) @@ -700,7 +697,7 @@ public: @param points Quadrangle vertices found by detect() method (or some other algorithm). @param straight_qrcode The optional output image containing rectified and binarized QR code */ - CV_WRAP cv::String decode(InputArray img, InputArray points, OutputArray straight_qrcode = noArray()); + CV_WRAP std::string decode(InputArray img, InputArray points, OutputArray straight_qrcode = noArray()); /** @brief Decodes QR code on a curved surface in image once it's found by the detect() method. @@ -717,8 +714,8 @@ public: @param points optional output array of vertices of the found QR code quadrangle. Will be empty if not found. @param straight_qrcode The optional output image containing rectified and binarized QR code */ - CV_WRAP cv::String detectAndDecode(InputArray img, OutputArray points=noArray(), - OutputArray straight_qrcode = noArray()); + CV_WRAP std::string detectAndDecode(InputArray img, OutputArray points=noArray(), + OutputArray straight_qrcode = noArray()); /** @brief Both detects and decodes QR code on a curved surface @@ -726,8 +723,8 @@ public: @param points optional output array of vertices of the found QR code quadrangle. Will be empty if not found. @param straight_qrcode The optional output image containing rectified and binarized QR code */ - CV_WRAP cv::String detectAndDecodeCurved(InputArray img, OutputArray points=noArray(), - OutputArray straight_qrcode = noArray()); + CV_WRAP std::string detectAndDecodeCurved(InputArray img, OutputArray points=noArray(), + OutputArray straight_qrcode = noArray()); /** @brief Detects QR codes in image and returns the vector of the quadrangles containing the codes. @param img grayscale or color (BGR) image containing (or not) QR codes. @@ -745,7 +742,7 @@ public: CV_WRAP bool decodeMulti( InputArray img, InputArray points, - CV_OUT std::vector& decoded_info, + CV_OUT std::vector& decoded_info, OutputArrayOfArrays straight_qrcode = noArray() ) const; @@ -757,84 +754,19 @@ public: */ CV_WRAP bool detectAndDecodeMulti( - InputArray img, CV_OUT std::vector& decoded_info, - OutputArray points = noArray(), - OutputArrayOfArrays straight_qrcode = noArray() - ) const; - - -#ifndef CV_DOXYGEN // COMPATIBILITY - inline bool decodeMulti( - InputArray img, InputArray points, - CV_OUT std::vector& decoded_info, - OutputArrayOfArrays straight_qrcode = noArray() - ) const - { - std::vector decoded_info_; - bool res = decodeMulti(img, points, decoded_info_, straight_qrcode); - decoded_info.resize(decoded_info_.size()); - for (size_t i = 0; i < decoded_info.size(); ++i) - { - cv::String s; std::swap(s, decoded_info_[i]); - decoded_info[i] = s; - } - return res; - } - - inline bool detectAndDecodeMulti( InputArray img, CV_OUT std::vector& decoded_info, OutputArray points = noArray(), OutputArrayOfArrays straight_qrcode = noArray() - ) const - { - std::vector decoded_info_; - bool res = detectAndDecodeMulti(img, decoded_info_, points, straight_qrcode); - decoded_info.resize(decoded_info_.size()); - for (size_t i = 0; i < decoded_info.size(); ++i) - { - cv::String s; std::swap(s, decoded_info_[i]); - decoded_info[i] = s; - } - return res; - } -#endif + ) const; protected: struct Impl; Ptr p; }; -/** @brief Detect QR code in image and return minimum area of quadrangle that describes QR code. - @param in Matrix of the type CV_8UC1 containing an image where QR code are detected. - @param points Output vector of vertices of a quadrangle of minimal area that describes QR code. - @param eps_x Epsilon neighborhood, which allows you to determine the horizontal pattern of the scheme 1:1:3:1:1 according to QR code standard. - @param eps_y Epsilon neighborhood, which allows you to determine the vertical pattern of the scheme 1:1:3:1:1 according to QR code standard. - */ -CV_EXPORTS bool detectQRCode(InputArray in, std::vector &points, double eps_x = 0.2, double eps_y = 0.1); - -/** @brief Decode QR code in image and return text that is encrypted in QR code. - @param in Matrix of the type CV_8UC1 containing an image where QR code are detected. - @param points Input vector of vertices of a quadrangle of minimal area that describes QR code. - @param decoded_info String information that is encrypted in QR code. - @param straight_qrcode Matrix of the type CV_8UC1 containing an binary straight QR code. - */ -CV_EXPORTS bool decodeQRCode(InputArray in, InputArray points, std::string &decoded_info, OutputArray straight_qrcode = noArray()); - -/** @brief Decode QR code on a curved surface in image and return text that is encrypted in QR code. - @param in Matrix of the type CV_8UC1 containing an image where QR code are detected. - @param points Input vector of vertices of a quadrangle of minimal area that describes QR code. - @param decoded_info String information that is encrypted in QR code. - @param straight_qrcode Matrix of the type CV_8UC1 containing an binary straight QR code. - */ -CV_EXPORTS bool decodeCurvedQRCode(InputArray in, InputArray points, std::string &decoded_info, OutputArray straight_qrcode = noArray()); - //! @} objdetect } #include "opencv2/objdetect/detection_based_tracker.hpp" -#ifndef DISABLE_OPENCV_24_COMPATIBILITY -#include "opencv2/objdetect/objdetect_c.h" -#endif - #endif diff --git a/3rdparty/include/opencv2/objdetect/detection_based_tracker.hpp b/3rdparty/include/opencv2/objdetect/detection_based_tracker.hpp index 07dd587491..18cde13eab 100644 --- a/3rdparty/include/opencv2/objdetect/detection_based_tracker.hpp +++ b/3rdparty/include/opencv2/objdetect/detection_based_tracker.hpp @@ -46,10 +46,6 @@ #include -// After this condition removal update blacklist for bindings: modules/python/common.cmake -#if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(__ANDROID__) || \ - defined(CV_CXX11) - #include namespace cv @@ -222,6 +218,5 @@ class CV_EXPORTS DetectionBasedTracker //! @} objdetect } //end of cv namespace -#endif #endif diff --git a/3rdparty/include/opencv2/objdetect/objdetect_c.h b/3rdparty/include/opencv2/objdetect/objdetect_c.h deleted file mode 100644 index 67dc2f4e66..0000000000 --- a/3rdparty/include/opencv2/objdetect/objdetect_c.h +++ /dev/null @@ -1,166 +0,0 @@ -/*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. -// Copyright (C) 2013, OpenCV Foundation, 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_OBJDETECT_C_H -#define OPENCV_OBJDETECT_C_H - -#include "opencv2/core/core_c.h" - -#ifdef __cplusplus -#include -#include - -extern "C" { -#endif - -/** @addtogroup objdetect_c - @{ - */ - -/****************************************************************************************\ -* Haar-like Object Detection functions * -\****************************************************************************************/ - -#define CV_HAAR_MAGIC_VAL 0x42500000 -#define CV_TYPE_NAME_HAAR "opencv-haar-classifier" - -#define CV_IS_HAAR_CLASSIFIER( haar ) \ - ((haar) != NULL && \ - (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL) - -#define CV_HAAR_FEATURE_MAX 3 -#define CV_HAAR_STAGE_MAX 1000 - -typedef struct CvHaarFeature -{ - int tilted; - struct - { - CvRect r; - float weight; - } rect[CV_HAAR_FEATURE_MAX]; -} CvHaarFeature; - -typedef struct CvHaarClassifier -{ - int count; - CvHaarFeature* haar_feature; - float* threshold; - int* left; - int* right; - float* alpha; -} CvHaarClassifier; - -typedef struct CvHaarStageClassifier -{ - int count; - float threshold; - CvHaarClassifier* classifier; - - int next; - int child; - int parent; -} CvHaarStageClassifier; - -typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade; - -typedef struct CvHaarClassifierCascade -{ - int flags; - int count; - CvSize orig_window_size; - CvSize real_window_size; - double scale; - CvHaarStageClassifier* stage_classifier; - CvHidHaarClassifierCascade* hid_cascade; -} CvHaarClassifierCascade; - -typedef struct CvAvgComp -{ - CvRect rect; - int neighbors; -} CvAvgComp; - -/* Loads haar classifier cascade from a directory. - It is obsolete: convert your cascade to xml and use cvLoad instead */ -CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade( - const char* directory, CvSize orig_window_size); - -CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade ); - -#define CV_HAAR_DO_CANNY_PRUNING 1 -#define CV_HAAR_SCALE_IMAGE 2 -#define CV_HAAR_FIND_BIGGEST_OBJECT 4 -#define CV_HAAR_DO_ROUGH_SEARCH 8 - -CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image, - CvHaarClassifierCascade* cascade, CvMemStorage* storage, - double scale_factor CV_DEFAULT(1.1), - int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0), - CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0))); - -/* sets images for haar classifier cascade */ -CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade, - const CvArr* sum, const CvArr* sqsum, - const CvArr* tilted_sum, double scale ); - -/* runs the cascade on the specified window */ -CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade, - CvPoint pt, int start_stage CV_DEFAULT(0)); - -/** @} objdetect_c */ - -#ifdef __cplusplus -} - -CV_EXPORTS CvSeq* cvHaarDetectObjectsForROC( const CvArr* image, - CvHaarClassifierCascade* cascade, CvMemStorage* storage, - std::vector& rejectLevels, std::vector& levelWeightds, - double scale_factor = 1.1, - int min_neighbors = 3, int flags = 0, - CvSize min_size = cvSize(0, 0), CvSize max_size = cvSize(0, 0), - bool outputRejectLevels = false ); - -#endif - -#endif /* OPENCV_OBJDETECT_C_H */ diff --git a/3rdparty/include/opencv2/opencv.hpp b/3rdparty/include/opencv2/opencv.hpp index 40481587f0..d17b94a4ea 100644 --- a/3rdparty/include/opencv2/opencv.hpp +++ b/3rdparty/include/opencv2/opencv.hpp @@ -82,58 +82,14 @@ #ifdef HAVE_OPENCV_PHOTO #include "opencv2/photo.hpp" #endif -#ifdef HAVE_OPENCV_SHAPE -#include "opencv2/shape.hpp" -#endif #ifdef HAVE_OPENCV_STITCHING #include "opencv2/stitching.hpp" #endif -#ifdef HAVE_OPENCV_SUPERRES -#include "opencv2/superres.hpp" -#endif #ifdef HAVE_OPENCV_VIDEO #include "opencv2/video.hpp" #endif #ifdef HAVE_OPENCV_VIDEOIO #include "opencv2/videoio.hpp" #endif -#ifdef HAVE_OPENCV_VIDEOSTAB -#include "opencv2/videostab.hpp" -#endif -#ifdef HAVE_OPENCV_VIZ -#include "opencv2/viz.hpp" -#endif - -// Finally CUDA specific entries are checked and added -#ifdef HAVE_OPENCV_CUDAARITHM -#include "opencv2/cudaarithm.hpp" -#endif -#ifdef HAVE_OPENCV_CUDABGSEGM -#include "opencv2/cudabgsegm.hpp" -#endif -#ifdef HAVE_OPENCV_CUDACODEC -#include "opencv2/cudacodec.hpp" -#endif -#ifdef HAVE_OPENCV_CUDAFEATURES2D -#include "opencv2/cudafeatures2d.hpp" -#endif -#ifdef HAVE_OPENCV_CUDAFILTERS -#include "opencv2/cudafilters.hpp" -#endif -#ifdef HAVE_OPENCV_CUDAIMGPROC -#include "opencv2/cudaimgproc.hpp" -#endif -#ifdef HAVE_OPENCV_CUDAOBJDETECT -#include "opencv2/cudaobjdetect.hpp" -#endif -#ifdef HAVE_OPENCV_CUDAOPTFLOW -#include "opencv2/cudaoptflow.hpp" -#endif -#ifdef HAVE_OPENCV_CUDASTEREO -#include "opencv2/cudastereo.hpp" -#endif -#ifdef HAVE_OPENCV_CUDAWARPING -#include "opencv2/cudawarping.hpp" -#endif #endif diff --git a/3rdparty/include/opencv2/opencv_modules.hpp b/3rdparty/include/opencv2/opencv_modules.hpp index b097aa1ef5..c9e24d845f 100644 --- a/3rdparty/include/opencv2/opencv_modules.hpp +++ b/3rdparty/include/opencv2/opencv_modules.hpp @@ -8,43 +8,23 @@ // This definition means that OpenCV is built with enabled non-free code. // For example, patented algorithms for non-profit/non-commercial use only. -#define OPENCV_ENABLE_NONFREE +/* #undef OPENCV_ENABLE_NONFREE */ -#define HAVE_OPENCV_ARUCO -#define HAVE_OPENCV_BIOINSPIRED #define HAVE_OPENCV_CALIB3D -#define HAVE_OPENCV_CCALIB #define HAVE_OPENCV_CORE -#define HAVE_OPENCV_DATASETS #define HAVE_OPENCV_DNN -#define HAVE_OPENCV_DNN_OBJDETECT -#define HAVE_OPENCV_DPM #define HAVE_OPENCV_FEATURES2D #define HAVE_OPENCV_FLANN -#define HAVE_OPENCV_FUZZY -#define HAVE_OPENCV_HFS +#define HAVE_OPENCV_GAPI #define HAVE_OPENCV_HIGHGUI -#define HAVE_OPENCV_IMG_HASH #define HAVE_OPENCV_IMGCODECS #define HAVE_OPENCV_IMGPROC -#define HAVE_OPENCV_LINE_DESCRIPTOR #define HAVE_OPENCV_ML #define HAVE_OPENCV_OBJDETECT -#define HAVE_OPENCV_PHASE_UNWRAPPING #define HAVE_OPENCV_PHOTO -#define HAVE_OPENCV_PLOT -#define HAVE_OPENCV_REG -#define HAVE_OPENCV_RGBD -#define HAVE_OPENCV_SALIENCY -#define HAVE_OPENCV_STEREO #define HAVE_OPENCV_STITCHING -#define HAVE_OPENCV_STRUCTURED_LIGHT -#define HAVE_OPENCV_SURFACE_MATCHING -#define HAVE_OPENCV_TEXT +#define HAVE_OPENCV_VIDEO +#define HAVE_OPENCV_VIDEOIO #define HAVE_OPENCV_WORLD -#define HAVE_OPENCV_XFEATURES2D -#define HAVE_OPENCV_XIMGPROC -#define HAVE_OPENCV_XOBJDETECT -#define HAVE_OPENCV_XPHOTO diff --git a/3rdparty/include/opencv2/optflow.hpp b/3rdparty/include/opencv2/optflow.hpp deleted file mode 100644 index e68d5b78d0..0000000000 --- a/3rdparty/include/opencv2/optflow.hpp +++ /dev/null @@ -1,364 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2013, OpenCV Foundation, 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -#ifndef __OPENCV_OPTFLOW_HPP__ -#define __OPENCV_OPTFLOW_HPP__ - -#include "opencv2/core.hpp" -#include "opencv2/video.hpp" - -/** -@defgroup optflow Optical Flow Algorithms - -Dense optical flow algorithms compute motion for each point: - -- cv::optflow::calcOpticalFlowSF -- cv::optflow::createOptFlow_DeepFlow - -Motion templates is alternative technique for detecting motion and computing its direction. -See samples/motempl.py. - -- cv::motempl::updateMotionHistory -- cv::motempl::calcMotionGradient -- cv::motempl::calcGlobalOrientation -- cv::motempl::segmentMotion - -Functions reading and writing .flo files in "Middlebury" format, see: - -- cv::optflow::readOpticalFlow -- cv::optflow::writeOpticalFlow - - */ - -#include "opencv2/optflow/pcaflow.hpp" -#include "opencv2/optflow/sparse_matching_gpc.hpp" - -namespace cv -{ -namespace optflow -{ - -//! @addtogroup optflow -//! @{ - -/** @overload */ -CV_EXPORTS_W void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, - int layers, int averaging_block_size, int max_flow); - -/** @brief Calculate an optical flow using "SimpleFlow" algorithm. - -@param from First 8-bit 3-channel image. -@param to Second 8-bit 3-channel image of the same size as prev -@param flow computed flow image that has the same size as prev and type CV_32FC2 -@param layers Number of layers -@param averaging_block_size Size of block through which we sum up when calculate cost function -for pixel -@param max_flow maximal flow that we search at each level -@param sigma_dist vector smooth spatial sigma parameter -@param sigma_color vector smooth color sigma parameter -@param postprocess_window window size for postprocess cross bilateral filter -@param sigma_dist_fix spatial sigma for postprocess cross bilateralf filter -@param sigma_color_fix color sigma for postprocess cross bilateral filter -@param occ_thr threshold for detecting occlusions -@param upscale_averaging_radius window size for bilateral upscale operation -@param upscale_sigma_dist spatial sigma for bilateral upscale operation -@param upscale_sigma_color color sigma for bilateral upscale operation -@param speed_up_thr threshold to detect point with irregular flow - where flow should be -recalculated after upscale - -See @cite Tao2012 . And site of project - . - -@note - - An example using the simpleFlow algorithm can be found at samples/simpleflow_demo.cpp - */ -CV_EXPORTS_W void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, int layers, - int averaging_block_size, int max_flow, - double sigma_dist, double sigma_color, int postprocess_window, - double sigma_dist_fix, double sigma_color_fix, double occ_thr, - int upscale_averaging_radius, double upscale_sigma_dist, - double upscale_sigma_color, double speed_up_thr ); - -/** @brief Fast dense optical flow based on PyrLK sparse matches interpolation. - -@param from first 8-bit 3-channel or 1-channel image. -@param to second 8-bit 3-channel or 1-channel image of the same size as from -@param flow computed flow image that has the same size as from and CV_32FC2 type -@param grid_step stride used in sparse match computation. Lower values usually - result in higher quality but slow down the algorithm. -@param k number of nearest-neighbor matches considered, when fitting a locally affine - model. Lower values can make the algorithm noticeably faster at the cost of - some quality degradation. -@param sigma parameter defining how fast the weights decrease in the locally-weighted affine - fitting. Higher values can help preserve fine details, lower values can help to get rid - of the noise in the output flow. -@param use_post_proc defines whether the ximgproc::fastGlobalSmootherFilter() is used - for post-processing after interpolation -@param fgs_lambda see the respective parameter of the ximgproc::fastGlobalSmootherFilter() -@param fgs_sigma see the respective parameter of the ximgproc::fastGlobalSmootherFilter() - */ -CV_EXPORTS_W void calcOpticalFlowSparseToDense ( InputArray from, InputArray to, OutputArray flow, - int grid_step = 8, int k = 128, float sigma = 0.05f, - bool use_post_proc = true, float fgs_lambda = 500.0f, - float fgs_sigma = 1.5f ); - -/** @brief Read a .flo file - -@param path Path to the file to be loaded - -The function readOpticalFlow loads a flow field from a file and returns it as a single matrix. -Resulting Mat has a type CV_32FC2 - floating-point, 2-channel. First channel corresponds to the -flow in the horizontal direction (u), second - vertical (v). - */ -CV_EXPORTS_W Mat readOpticalFlow( const String& path ); -/** @brief Write a .flo to disk - -@param path Path to the file to be written -@param flow Flow field to be stored - -The function stores a flow field in a file, returns true on success, false otherwise. -The flow field must be a 2-channel, floating-point matrix (CV_32FC2). First channel corresponds -to the flow in the horizontal direction (u), second - vertical (v). - */ -CV_EXPORTS_W bool writeOpticalFlow( const String& path, InputArray flow ); - -/** @brief Variational optical flow refinement - -This class implements variational refinement of the input flow field, i.e. -it uses input flow to initialize the minimization of the following functional: -\f$E(U) = \int_{\Omega} \delta \Psi(E_I) + \gamma \Psi(E_G) + \alpha \Psi(E_S) \f$, -where \f$E_I,E_G,E_S\f$ are color constancy, gradient constancy and smoothness terms -respectively. \f$\Psi(s^2)=\sqrt{s^2+\epsilon^2}\f$ is a robust penalizer to limit the -influence of outliers. A complete formulation and a description of the minimization -procedure can be found in @cite Brox2004 -*/ -class CV_EXPORTS_W VariationalRefinement : public DenseOpticalFlow -{ -public: - /** @brief @ref calc function overload to handle separate horizontal (u) and vertical (v) flow components - (to avoid extra splits/merges) */ - CV_WRAP virtual void calcUV(InputArray I0, InputArray I1, InputOutputArray flow_u, InputOutputArray flow_v) = 0; - - /** @brief Number of outer (fixed-point) iterations in the minimization procedure. - @see setFixedPointIterations */ - CV_WRAP virtual int getFixedPointIterations() const = 0; - /** @copybrief getFixedPointIterations @see getFixedPointIterations */ - CV_WRAP virtual void setFixedPointIterations(int val) = 0; - - /** @brief Number of inner successive over-relaxation (SOR) iterations - in the minimization procedure to solve the respective linear system. - @see setSorIterations */ - CV_WRAP virtual int getSorIterations() const = 0; - /** @copybrief getSorIterations @see getSorIterations */ - CV_WRAP virtual void setSorIterations(int val) = 0; - - /** @brief Relaxation factor in SOR - @see setOmega */ - CV_WRAP virtual float getOmega() const = 0; - /** @copybrief getOmega @see getOmega */ - CV_WRAP virtual void setOmega(float val) = 0; - - /** @brief Weight of the smoothness term - @see setAlpha */ - CV_WRAP virtual float getAlpha() const = 0; - /** @copybrief getAlpha @see getAlpha */ - CV_WRAP virtual void setAlpha(float val) = 0; - - /** @brief Weight of the color constancy term - @see setDelta */ - CV_WRAP virtual float getDelta() const = 0; - /** @copybrief getDelta @see getDelta */ - CV_WRAP virtual void setDelta(float val) = 0; - - /** @brief Weight of the gradient constancy term - @see setGamma */ - CV_WRAP virtual float getGamma() const = 0; - /** @copybrief getGamma @see getGamma */ - CV_WRAP virtual void setGamma(float val) = 0; -}; - -/** @brief Creates an instance of VariationalRefinement -*/ -CV_EXPORTS_W Ptr createVariationalFlowRefinement(); - -/** @brief DeepFlow optical flow algorithm implementation. - -The class implements the DeepFlow optical flow algorithm described in @cite Weinzaepfel2013 . See -also . -Parameters - class fields - that may be modified after creating a class instance: -- member float alpha -Smoothness assumption weight -- member float delta -Color constancy assumption weight -- member float gamma -Gradient constancy weight -- member float sigma -Gaussian smoothing parameter -- member int minSize -Minimal dimension of an image in the pyramid (next, smaller images in the pyramid are generated -until one of the dimensions reaches this size) -- member float downscaleFactor -Scaling factor in the image pyramid (must be \< 1) -- member int fixedPointIterations -How many iterations on each level of the pyramid -- member int sorIterations -Iterations of Succesive Over-Relaxation (solver) -- member float omega -Relaxation factor in SOR - */ -CV_EXPORTS_W Ptr createOptFlow_DeepFlow(); - -//! Additional interface to the SimpleFlow algorithm - calcOpticalFlowSF() -CV_EXPORTS_W Ptr createOptFlow_SimpleFlow(); - -//! Additional interface to the Farneback's algorithm - calcOpticalFlowFarneback() -CV_EXPORTS_W Ptr createOptFlow_Farneback(); - -//! Additional interface to the SparseToDenseFlow algorithm - calcOpticalFlowSparseToDense() -CV_EXPORTS_W Ptr createOptFlow_SparseToDense(); - -/** @brief DIS optical flow algorithm. - -This class implements the Dense Inverse Search (DIS) optical flow algorithm. More -details about the algorithm can be found at @cite Kroeger2016 . Includes three presets with preselected -parameters to provide reasonable trade-off between speed and quality. However, even the slowest preset is -still relatively fast, use DeepFlow if you need better quality and don't care about speed. - -This implementation includes several additional features compared to the algorithm described in the paper, -including spatial propagation of flow vectors (@ref getUseSpatialPropagation), as well as an option to -utilize an initial flow approximation passed to @ref calc (which is, essentially, temporal propagation, -if the previous frame's flow field is passed). -*/ -class CV_EXPORTS_W DISOpticalFlow : public DenseOpticalFlow -{ -public: - enum - { - PRESET_ULTRAFAST = 0, - PRESET_FAST = 1, - PRESET_MEDIUM = 2 - }; - - /** @brief Finest level of the Gaussian pyramid on which the flow is computed (zero level - corresponds to the original image resolution). The final flow is obtained by bilinear upscaling. - @see setFinestScale */ - CV_WRAP virtual int getFinestScale() const = 0; - /** @copybrief getFinestScale @see getFinestScale */ - CV_WRAP virtual void setFinestScale(int val) = 0; - - /** @brief Size of an image patch for matching (in pixels). Normally, default 8x8 patches work well - enough in most cases. - @see setPatchSize */ - CV_WRAP virtual int getPatchSize() const = 0; - /** @copybrief getPatchSize @see getPatchSize */ - CV_WRAP virtual void setPatchSize(int val) = 0; - - /** @brief Stride between neighbor patches. Must be less than patch size. Lower values correspond - to higher flow quality. - @see setPatchStride */ - CV_WRAP virtual int getPatchStride() const = 0; - /** @copybrief getPatchStride @see getPatchStride */ - CV_WRAP virtual void setPatchStride(int val) = 0; - - /** @brief Maximum number of gradient descent iterations in the patch inverse search stage. Higher values - may improve quality in some cases. - @see setGradientDescentIterations */ - CV_WRAP virtual int getGradientDescentIterations() const = 0; - /** @copybrief getGradientDescentIterations @see getGradientDescentIterations */ - CV_WRAP virtual void setGradientDescentIterations(int val) = 0; - - /** @brief Number of fixed point iterations of variational refinement per scale. Set to zero to - disable variational refinement completely. Higher values will typically result in more smooth and - high-quality flow. - @see setGradientDescentIterations */ - CV_WRAP virtual int getVariationalRefinementIterations() const = 0; - /** @copybrief getGradientDescentIterations @see getGradientDescentIterations */ - CV_WRAP virtual void setVariationalRefinementIterations(int val) = 0; - - /** @brief Weight of the smoothness term - @see setVariationalRefinementAlpha */ - CV_WRAP virtual float getVariationalRefinementAlpha() const = 0; - /** @copybrief getVariationalRefinementAlpha @see getVariationalRefinementAlpha */ - CV_WRAP virtual void setVariationalRefinementAlpha(float val) = 0; - - /** @brief Weight of the color constancy term - @see setVariationalRefinementDelta */ - CV_WRAP virtual float getVariationalRefinementDelta() const = 0; - /** @copybrief getVariationalRefinementDelta @see getVariationalRefinementDelta */ - CV_WRAP virtual void setVariationalRefinementDelta(float val) = 0; - - /** @brief Weight of the gradient constancy term - @see setVariationalRefinementGamma */ - CV_WRAP virtual float getVariationalRefinementGamma() const = 0; - /** @copybrief getVariationalRefinementGamma @see getVariationalRefinementGamma */ - CV_WRAP virtual void setVariationalRefinementGamma(float val) = 0; - - - /** @brief Whether to use mean-normalization of patches when computing patch distance. It is turned on - by default as it typically provides a noticeable quality boost because of increased robustness to - illumination variations. Turn it off if you are certain that your sequence doesn't contain any changes - in illumination. - @see setUseMeanNormalization */ - CV_WRAP virtual bool getUseMeanNormalization() const = 0; - /** @copybrief getUseMeanNormalization @see getUseMeanNormalization */ - CV_WRAP virtual void setUseMeanNormalization(bool val) = 0; - - /** @brief Whether to use spatial propagation of good optical flow vectors. This option is turned on by - default, as it tends to work better on average and can sometimes help recover from major errors - introduced by the coarse-to-fine scheme employed by the DIS optical flow algorithm. Turning this - option off can make the output flow field a bit smoother, however. - @see setUseSpatialPropagation */ - CV_WRAP virtual bool getUseSpatialPropagation() const = 0; - /** @copybrief getUseSpatialPropagation @see getUseSpatialPropagation */ - CV_WRAP virtual void setUseSpatialPropagation(bool val) = 0; -}; - -/** @brief Creates an instance of DISOpticalFlow - -@param preset one of PRESET_ULTRAFAST, PRESET_FAST and PRESET_MEDIUM -*/ -CV_EXPORTS_W Ptr createOptFlow_DIS(int preset = DISOpticalFlow::PRESET_FAST); - -//! @} - -} //optflow -} - -#include "opencv2/optflow/motempl.hpp" - -#endif diff --git a/3rdparty/include/opencv2/optflow/motempl.hpp b/3rdparty/include/opencv2/optflow/motempl.hpp deleted file mode 100644 index aeea9e8cd7..0000000000 --- a/3rdparty/include/opencv2/optflow/motempl.hpp +++ /dev/null @@ -1,147 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2013, OpenCV Foundation, 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -#ifndef __OPENCV_OPTFLOW_MOTEMPL_HPP__ -#define __OPENCV_OPTFLOW_MOTEMPL_HPP__ - -#include "opencv2/core.hpp" - -namespace cv -{ -namespace motempl -{ - -//! @addtogroup optflow -//! @{ - -/** @brief Updates the motion history image by a moving silhouette. - -@param silhouette Silhouette mask that has non-zero pixels where the motion occurs. -@param mhi Motion history image that is updated by the function (single-channel, 32-bit -floating-point). -@param timestamp Current time in milliseconds or other units. -@param duration Maximal duration of the motion track in the same units as timestamp . - -The function updates the motion history image as follows: - -\f[\texttt{mhi} (x,y)= \forkthree{\texttt{timestamp}}{if \(\texttt{silhouette}(x,y) \ne 0\)}{0}{if \(\texttt{silhouette}(x,y) = 0\) and \(\texttt{mhi} < (\texttt{timestamp} - \texttt{duration})\)}{\texttt{mhi}(x,y)}{otherwise}\f] - -That is, MHI pixels where the motion occurs are set to the current timestamp , while the pixels -where the motion happened last time a long time ago are cleared. - -The function, together with calcMotionGradient and calcGlobalOrientation , implements a motion -templates technique described in @cite Davis97 and @cite Bradski00 . - */ -CV_EXPORTS_W void updateMotionHistory( InputArray silhouette, InputOutputArray mhi, - double timestamp, double duration ); - -/** @brief Calculates a gradient orientation of a motion history image. - -@param mhi Motion history single-channel floating-point image. -@param mask Output mask image that has the type CV_8UC1 and the same size as mhi . Its non-zero -elements mark pixels where the motion gradient data is correct. -@param orientation Output motion gradient orientation image that has the same type and the same -size as mhi . Each pixel of the image is a motion orientation, from 0 to 360 degrees. -@param delta1 Minimal (or maximal) allowed difference between mhi values within a pixel -neighborhood. -@param delta2 Maximal (or minimal) allowed difference between mhi values within a pixel -neighborhood. That is, the function finds the minimum ( \f$m(x,y)\f$ ) and maximum ( \f$M(x,y)\f$ ) mhi -values over \f$3 \times 3\f$ neighborhood of each pixel and marks the motion orientation at \f$(x, y)\f$ -as valid only if -\f[\min ( \texttt{delta1} , \texttt{delta2} ) \le M(x,y)-m(x,y) \le \max ( \texttt{delta1} , \texttt{delta2} ).\f] -@param apertureSize Aperture size of the Sobel operator. - -The function calculates a gradient orientation at each pixel \f$(x, y)\f$ as: - -\f[\texttt{orientation} (x,y)= \arctan{\frac{d\texttt{mhi}/dy}{d\texttt{mhi}/dx}}\f] - -In fact, fastAtan2 and phase are used so that the computed angle is measured in degrees and covers -the full range 0..360. Also, the mask is filled to indicate pixels where the computed angle is -valid. - -@note - - (Python) An example on how to perform a motion template technique can be found at - opencv_source_code/samples/python2/motempl.py - */ -CV_EXPORTS_W void calcMotionGradient( InputArray mhi, OutputArray mask, OutputArray orientation, - double delta1, double delta2, int apertureSize = 3 ); - -/** @brief Calculates a global motion orientation in a selected region. - -@param orientation Motion gradient orientation image calculated by the function calcMotionGradient -@param mask Mask image. It may be a conjunction of a valid gradient mask, also calculated by -calcMotionGradient , and the mask of a region whose direction needs to be calculated. -@param mhi Motion history image calculated by updateMotionHistory . -@param timestamp Timestamp passed to updateMotionHistory . -@param duration Maximum duration of a motion track in milliseconds, passed to updateMotionHistory - -The function calculates an average motion direction in the selected region and returns the angle -between 0 degrees and 360 degrees. The average direction is computed from the weighted orientation -histogram, where a recent motion has a larger weight and the motion occurred in the past has a -smaller weight, as recorded in mhi . - */ -CV_EXPORTS_W double calcGlobalOrientation( InputArray orientation, InputArray mask, InputArray mhi, - double timestamp, double duration ); - -/** @brief Splits a motion history image into a few parts corresponding to separate independent motions (for -example, left hand, right hand). - -@param mhi Motion history image. -@param segmask Image where the found mask should be stored, single-channel, 32-bit floating-point. -@param boundingRects Vector containing ROIs of motion connected components. -@param timestamp Current time in milliseconds or other units. -@param segThresh Segmentation threshold that is recommended to be equal to the interval between -motion history "steps" or greater. - -The function finds all of the motion segments and marks them in segmask with individual values -(1,2,...). It also computes a vector with ROIs of motion connected components. After that the motion -direction for every component can be calculated with calcGlobalOrientation using the extracted mask -of the particular component. - */ -CV_EXPORTS_W void segmentMotion( InputArray mhi, OutputArray segmask, - CV_OUT std::vector& boundingRects, - double timestamp, double segThresh ); - - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/optflow/pcaflow.hpp b/3rdparty/include/opencv2/optflow/pcaflow.hpp deleted file mode 100644 index 78946f69db..0000000000 --- a/3rdparty/include/opencv2/optflow/pcaflow.hpp +++ /dev/null @@ -1,149 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2016, OpenCV Foundation, 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -/** - * @file pcaflow.hpp - * @author Vladislav Samsonov - * @brief Implementation of the PCAFlow algorithm from the following paper: - * http://files.is.tue.mpg.de/black/papers/cvpr2015_pcaflow.pdf - * - * @cite Wulff:CVPR:2015 - * - * There are some key differences which distinguish this algorithm from the original PCAFlow (see paper): - * - Discrete Cosine Transform basis is used instead of basis extracted with PCA. - * Reasoning: DCT basis has comparable performance and it doesn't require additional storage space. - * Also, this decision helps to avoid overloading the algorithm with a lot of external input. - * - Usage of built-in OpenCV feature tracking instead of libviso. -*/ - -#ifndef __OPENCV_OPTFLOW_PCAFLOW_HPP__ -#define __OPENCV_OPTFLOW_PCAFLOW_HPP__ - -#include "opencv2/core.hpp" -#include "opencv2/video.hpp" - -namespace cv -{ -namespace optflow -{ - -//! @addtogroup optflow -//! @{ - -/** @brief - * This class can be used for imposing a learned prior on the resulting optical flow. - * Solution will be regularized according to this prior. - * You need to generate appropriate prior file with "learn_prior.py" script beforehand. - */ -class CV_EXPORTS_W PCAPrior -{ -private: - Mat L1; - Mat L2; - Mat c1; - Mat c2; - -public: - PCAPrior( const char *pathToPrior ); - - int getPadding() const { return L1.size().height; } - - int getBasisSize() const { return L1.size().width; } - - void fillConstraints( float *A1, float *A2, float *b1, float *b2 ) const; -}; - -/** @brief PCAFlow algorithm. - */ -class CV_EXPORTS_W OpticalFlowPCAFlow : public DenseOpticalFlow -{ -protected: - const Ptr prior; - const Size basisSize; - const float sparseRate; // (0 .. 0.1) - const float retainedCornersFraction; // [0 .. 1] - const float occlusionsThreshold; - const float dampingFactor; - const float claheClip; - bool useOpenCL; - -public: - /** @brief Creates an instance of PCAFlow algorithm. - * @param _prior Learned prior or no prior (default). @see cv::optflow::PCAPrior - * @param _basisSize Number of basis vectors. - * @param _sparseRate Controls density of sparse matches. - * @param _retainedCornersFraction Retained corners fraction. - * @param _occlusionsThreshold Occlusion threshold. - * @param _dampingFactor Regularization term for solving least-squares. It is not related to the prior regularization. - * @param _claheClip Clip parameter for CLAHE. - */ - OpticalFlowPCAFlow( Ptr _prior = Ptr(), const Size _basisSize = Size( 18, 14 ), - float _sparseRate = 0.024, float _retainedCornersFraction = 0.2, - float _occlusionsThreshold = 0.0003, float _dampingFactor = 0.00002, float _claheClip = 14 ); - - void calc( InputArray I0, InputArray I1, InputOutputArray flow ) CV_OVERRIDE; - void collectGarbage() CV_OVERRIDE; - -private: - void findSparseFeatures( UMat &from, UMat &to, std::vector &features, - std::vector &predictedFeatures ) const; - - void removeOcclusions( UMat &from, UMat &to, std::vector &features, - std::vector &predictedFeatures ) const; - - void getSystem( OutputArray AOut, OutputArray b1Out, OutputArray b2Out, const std::vector &features, - const std::vector &predictedFeatures, const Size size ); - - void getSystem( OutputArray A1Out, OutputArray A2Out, OutputArray b1Out, OutputArray b2Out, - const std::vector &features, const std::vector &predictedFeatures, - const Size size ); - - OpticalFlowPCAFlow& operator=( const OpticalFlowPCAFlow& ); // make it non-assignable -}; - -/** @brief Creates an instance of PCAFlow -*/ -CV_EXPORTS_W Ptr createOptFlow_PCAFlow(); - -//! @} - -} -} - -#endif diff --git a/3rdparty/include/opencv2/optflow/sparse_matching_gpc.hpp b/3rdparty/include/opencv2/optflow/sparse_matching_gpc.hpp deleted file mode 100644 index 5256534bb9..0000000000 --- a/3rdparty/include/opencv2/optflow/sparse_matching_gpc.hpp +++ /dev/null @@ -1,372 +0,0 @@ -/* -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 - (3-clause BSD License) - -Copyright (C) 2016, OpenCV Foundation, 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: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions 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. - - * Neither the names of the copyright holders nor the names of the contributors - may 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 copyright holders 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. -*/ - -/** - * @file sparse_matching_gpc.hpp - * @author Vladislav Samsonov - * @brief Implementation of the Global Patch Collider. - * - * Implementation of the Global Patch Collider algorithm from the following paper: - * http://research.microsoft.com/en-us/um/people/pkohli/papers/wfrik_cvpr2016.pdf - * - * @cite Wang_2016_CVPR - */ - -#ifndef __OPENCV_OPTFLOW_SPARSE_MATCHING_GPC_HPP__ -#define __OPENCV_OPTFLOW_SPARSE_MATCHING_GPC_HPP__ - -#include "opencv2/core.hpp" -#include "opencv2/imgproc.hpp" - -namespace cv -{ -namespace optflow -{ - -//! @addtogroup optflow -//! @{ - -struct CV_EXPORTS_W GPCPatchDescriptor -{ - static const unsigned nFeatures = 18; //!< number of features in a patch descriptor - Vec< double, nFeatures > feature; - - double dot( const Vec< double, nFeatures > &coef ) const; - - void markAsSeparated() { feature[0] = std::numeric_limits< double >::quiet_NaN(); } - - bool isSeparated() const { return cvIsNaN( feature[0] ) != 0; } -}; - -struct CV_EXPORTS_W GPCPatchSample -{ - GPCPatchDescriptor ref; - GPCPatchDescriptor pos; - GPCPatchDescriptor neg; - - void getDirections( bool &refdir, bool &posdir, bool &negdir, const Vec< double, GPCPatchDescriptor::nFeatures > &coef, double rhs ) const; -}; - -typedef std::vector< GPCPatchSample > GPCSamplesVector; - -/** @brief Descriptor types for the Global Patch Collider. - */ -enum GPCDescType -{ - GPC_DESCRIPTOR_DCT = 0, //!< Better quality but slow - GPC_DESCRIPTOR_WHT //!< Worse quality but much faster -}; - -/** @brief Class encapsulating training samples. - */ -class CV_EXPORTS_W GPCTrainingSamples -{ -private: - GPCSamplesVector samples; - int descriptorType; - -public: - /** @brief This function can be used to extract samples from a pair of images and a ground truth flow. - * Sizes of all the provided vectors must be equal. - */ - static Ptr< GPCTrainingSamples > create( const std::vector< String > &imagesFrom, const std::vector< String > &imagesTo, - const std::vector< String > >, int descriptorType ); - - static Ptr< GPCTrainingSamples > create( InputArrayOfArrays imagesFrom, InputArrayOfArrays imagesTo, InputArrayOfArrays gt, - int descriptorType ); - - size_t size() const { return samples.size(); } - - int type() const { return descriptorType; } - - operator GPCSamplesVector &() { return samples; } -}; - -/** @brief Class encapsulating training parameters. - */ -struct GPCTrainingParams -{ - unsigned maxTreeDepth; //!< Maximum tree depth to stop partitioning. - int minNumberOfSamples; //!< Minimum number of samples in the node to stop partitioning. - int descriptorType; //!< Type of descriptors to use. - bool printProgress; //!< Print progress to stdout. - - GPCTrainingParams( unsigned _maxTreeDepth = 20, int _minNumberOfSamples = 3, GPCDescType _descriptorType = GPC_DESCRIPTOR_DCT, - bool _printProgress = true ) - : maxTreeDepth( _maxTreeDepth ), minNumberOfSamples( _minNumberOfSamples ), descriptorType( _descriptorType ), - printProgress( _printProgress ) - { - CV_Assert( check() ); - } - - bool check() const { return maxTreeDepth > 1 && minNumberOfSamples > 1; } -}; - -/** @brief Class encapsulating matching parameters. - */ -struct GPCMatchingParams -{ - bool useOpenCL; //!< Whether to use OpenCL to speed up the matching. - - GPCMatchingParams( bool _useOpenCL = false ) : useOpenCL( _useOpenCL ) {} - - GPCMatchingParams( const GPCMatchingParams ¶ms ) : useOpenCL( params.useOpenCL ) {} -}; - -/** @brief Class for individual tree. - */ -class CV_EXPORTS_W GPCTree : public Algorithm -{ -public: - struct Node - { - Vec< double, GPCPatchDescriptor::nFeatures > coef; //!< Hyperplane coefficients - double rhs; //!< Bias term of the hyperplane - unsigned left; - unsigned right; - - bool operator==( const Node &n ) const { return coef == n.coef && rhs == n.rhs && left == n.left && right == n.right; } - }; - -private: - typedef GPCSamplesVector::iterator SIter; - - std::vector< Node > nodes; - GPCTrainingParams params; - - bool trainNode( size_t nodeId, SIter begin, SIter end, unsigned depth ); - -public: - void train( GPCTrainingSamples &samples, const GPCTrainingParams params = GPCTrainingParams() ); - - void write( FileStorage &fs ) const CV_OVERRIDE; - - void read( const FileNode &fn ) CV_OVERRIDE; - - unsigned findLeafForPatch( const GPCPatchDescriptor &descr ) const; - - static Ptr< GPCTree > create() { return makePtr< GPCTree >(); } - - bool operator==( const GPCTree &t ) const { return nodes == t.nodes; } - - int getDescriptorType() const { return params.descriptorType; } -}; - -template < int T > class GPCForest : public Algorithm -{ -private: - struct Trail - { - unsigned leaf[T]; //!< Inside which leaf of the tree 0..T the patch fell? - Point2i coord; //!< Patch coordinates. - - bool operator==( const Trail &trail ) const { return memcmp( leaf, trail.leaf, sizeof( leaf ) ) == 0; } - - bool operator<( const Trail &trail ) const - { - for ( int i = 0; i < T - 1; ++i ) - if ( leaf[i] != trail.leaf[i] ) - return leaf[i] < trail.leaf[i]; - return leaf[T - 1] < trail.leaf[T - 1]; - } - }; - - class ParallelTrailsFilling : public ParallelLoopBody - { - private: - const GPCForest *forest; - const std::vector< GPCPatchDescriptor > *descr; - std::vector< Trail > *trails; - - ParallelTrailsFilling &operator=( const ParallelTrailsFilling & ); - - public: - ParallelTrailsFilling( const GPCForest *_forest, const std::vector< GPCPatchDescriptor > *_descr, std::vector< Trail > *_trails ) - : forest( _forest ), descr( _descr ), trails( _trails ){}; - - void operator()( const Range &range ) const CV_OVERRIDE - { - for ( int t = range.start; t < range.end; ++t ) - for ( size_t i = 0; i < descr->size(); ++i ) - trails->at( i ).leaf[t] = forest->tree[t].findLeafForPatch( descr->at( i ) ); - } - }; - - GPCTree tree[T]; - -public: - /** @brief Train the forest using one sample set for every tree. - * Please, consider using the next method instead of this one for better quality. - */ - void train( GPCTrainingSamples &samples, const GPCTrainingParams params = GPCTrainingParams() ) - { - for ( int i = 0; i < T; ++i ) - tree[i].train( samples, params ); - } - - /** @brief Train the forest using individual samples for each tree. - * It is generally better to use this instead of the first method. - */ - void train( const std::vector< String > &imagesFrom, const std::vector< String > &imagesTo, const std::vector< String > >, - const GPCTrainingParams params = GPCTrainingParams() ) - { - for ( int i = 0; i < T; ++i ) - { - Ptr< GPCTrainingSamples > samples = - GPCTrainingSamples::create( imagesFrom, imagesTo, gt, params.descriptorType ); // Create training set for the tree - tree[i].train( *samples, params ); - } - } - - void train( InputArrayOfArrays imagesFrom, InputArrayOfArrays imagesTo, InputArrayOfArrays gt, - const GPCTrainingParams params = GPCTrainingParams() ) - { - for ( int i = 0; i < T; ++i ) - { - Ptr< GPCTrainingSamples > samples = - GPCTrainingSamples::create( imagesFrom, imagesTo, gt, params.descriptorType ); // Create training set for the tree - tree[i].train( *samples, params ); - } - } - - void write( FileStorage &fs ) const CV_OVERRIDE - { - fs << "ntrees" << T << "trees" - << "["; - for ( int i = 0; i < T; ++i ) - { - fs << "{"; - tree[i].write( fs ); - fs << "}"; - } - fs << "]"; - } - - void read( const FileNode &fn ) CV_OVERRIDE - { - CV_Assert( T <= (int)fn["ntrees"] ); - FileNodeIterator it = fn["trees"].begin(); - for ( int i = 0; i < T; ++i, ++it ) - tree[i].read( *it ); - } - - /** @brief Find correspondences between two images. - * @param[in] imgFrom First image in a sequence. - * @param[in] imgTo Second image in a sequence. - * @param[out] corr Output vector with pairs of corresponding points. - * @param[in] params Additional matching parameters for fine-tuning. - */ - void findCorrespondences( InputArray imgFrom, InputArray imgTo, std::vector< std::pair< Point2i, Point2i > > &corr, - const GPCMatchingParams params = GPCMatchingParams() ) const; - - static Ptr< GPCForest > create() { return makePtr< GPCForest >(); } -}; - -class CV_EXPORTS_W GPCDetails -{ -public: - static void dropOutliers( std::vector< std::pair< Point2i, Point2i > > &corr ); - - static void getAllDescriptorsForImage( const Mat *imgCh, std::vector< GPCPatchDescriptor > &descr, const GPCMatchingParams &mp, - int type ); - - static void getCoordinatesFromIndex( size_t index, Size sz, int &x, int &y ); -}; - -template < int T > -void GPCForest< T >::findCorrespondences( InputArray imgFrom, InputArray imgTo, std::vector< std::pair< Point2i, Point2i > > &corr, - const GPCMatchingParams params ) const -{ - CV_Assert( imgFrom.channels() == 3 ); - CV_Assert( imgTo.channels() == 3 ); - - Mat from, to; - imgFrom.getMat().convertTo( from, CV_32FC3 ); - imgTo.getMat().convertTo( to, CV_32FC3 ); - cvtColor( from, from, COLOR_BGR2YCrCb ); - cvtColor( to, to, COLOR_BGR2YCrCb ); - - Mat fromCh[3], toCh[3]; - split( from, fromCh ); - split( to, toCh ); - - std::vector< GPCPatchDescriptor > descr; - GPCDetails::getAllDescriptorsForImage( fromCh, descr, params, tree[0].getDescriptorType() ); - std::vector< Trail > trailsFrom( descr.size() ), trailsTo( descr.size() ); - - for ( size_t i = 0; i < descr.size(); ++i ) - GPCDetails::getCoordinatesFromIndex( i, from.size(), trailsFrom[i].coord.x, trailsFrom[i].coord.y ); - parallel_for_( Range( 0, T ), ParallelTrailsFilling( this, &descr, &trailsFrom ) ); - - descr.clear(); - GPCDetails::getAllDescriptorsForImage( toCh, descr, params, tree[0].getDescriptorType() ); - - for ( size_t i = 0; i < descr.size(); ++i ) - GPCDetails::getCoordinatesFromIndex( i, to.size(), trailsTo[i].coord.x, trailsTo[i].coord.y ); - parallel_for_( Range( 0, T ), ParallelTrailsFilling( this, &descr, &trailsTo ) ); - - std::sort( trailsFrom.begin(), trailsFrom.end() ); - std::sort( trailsTo.begin(), trailsTo.end() ); - - for ( size_t i = 0; i < trailsFrom.size(); ++i ) - { - bool uniq = true; - while ( i + 1 < trailsFrom.size() && trailsFrom[i] == trailsFrom[i + 1] ) - ++i, uniq = false; - if ( uniq ) - { - typename std::vector< Trail >::const_iterator lb = std::lower_bound( trailsTo.begin(), trailsTo.end(), trailsFrom[i] ); - if ( lb != trailsTo.end() && *lb == trailsFrom[i] && ( ( lb + 1 ) == trailsTo.end() || !( *lb == *( lb + 1 ) ) ) ) - corr.push_back( std::make_pair( trailsFrom[i].coord, lb->coord ) ); - } - } - - GPCDetails::dropOutliers( corr ); -} - -//! @} - -} // namespace optflow - -CV_EXPORTS void write( FileStorage &fs, const String &name, const optflow::GPCTree::Node &node ); - -CV_EXPORTS void read( const FileNode &fn, optflow::GPCTree::Node &node, optflow::GPCTree::Node ); -} // namespace cv - -#endif diff --git a/3rdparty/include/opencv2/phase_unwrapping.hpp b/3rdparty/include/opencv2/phase_unwrapping.hpp deleted file mode 100644 index 0e15e71ed6..0000000000 --- a/3rdparty/include/opencv2/phase_unwrapping.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/*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) 2015, OpenCV Foundation, 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 "opencv2/phase_unwrapping/phase_unwrapping.hpp" -#include "opencv2/phase_unwrapping/histogramphaseunwrapping.hpp" - -/** @defgroup phase_unwrapping Phase Unwrapping API - -Two-dimensional phase unwrapping is found in different applications like terrain elevation estimation -in synthetic aperture radar (SAR), field mapping in magnetic resonance imaging or as a way of finding -corresponding pixels in structured light reconstruction with sinusoidal patterns. - -Given a phase map, wrapped between [-pi; pi], phase unwrapping aims at finding the "true" phase map -by adding the right number of 2*pi to each pixel. - -The problem is straightforward for perfect wrapped phase map, but real data are usually not noise-free. -Among the different algorithms that were developed, quality-guided phase unwrapping methods are fast -and efficient. They follow a path that unwraps high quality pixels first, -avoiding error propagation from the start. - -In this module, a quality-guided phase unwrapping is implemented following the approach described in @cite histogramUnwrapping . - -*/ \ No newline at end of file diff --git a/3rdparty/include/opencv2/phase_unwrapping/histogramphaseunwrapping.hpp b/3rdparty/include/opencv2/phase_unwrapping/histogramphaseunwrapping.hpp deleted file mode 100644 index 177cb430da..0000000000 --- a/3rdparty/include/opencv2/phase_unwrapping/histogramphaseunwrapping.hpp +++ /dev/null @@ -1,108 +0,0 @@ -/*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) 2015, OpenCV Foundation, 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_HISTOGRAM_PHASE_UNWRAPPING_HPP__ -#define __OPENCV_HISTOGRAM_PHASE_UNWRAPPING_HPP__ - -#include "opencv2/core.hpp" -#include -#include "opencv2/phase_unwrapping/phase_unwrapping.hpp" - -namespace cv { -namespace phase_unwrapping { -//! @addtogroup phase_unwrapping -//! @{ - - /** @brief Class implementing two-dimensional phase unwrapping based on @cite histogramUnwrapping - * This algorithm belongs to the quality-guided phase unwrapping methods. - * First, it computes a reliability map from second differences between a pixel and its eight neighbours. - * Reliability values lie between 0 and 16*pi*pi. Then, this reliability map is used to compute - * the reliabilities of "edges". An edge is an entity defined by two pixels that are connected - * horizontally or vertically. Its reliability is found by adding the the reliabilities of the - * two pixels connected through it. Edges are sorted in a histogram based on their reliability values. - * This histogram is then used to unwrap pixels, starting from the highest quality pixel. - - * The wrapped phase map and the unwrapped result are stored in CV_32FC1 Mat. - */ -class CV_EXPORTS_W HistogramPhaseUnwrapping : public PhaseUnwrapping -{ - -public: - /** - * @brief Parameters of phaseUnwrapping constructor. - - * @param width Phase map width. - * @param height Phase map height. - * @param histThresh Bins in the histogram are not of equal size. Default value is 3*pi*pi. The one before "histThresh" value are smaller. - * @param nbrOfSmallBins Number of bins between 0 and "histThresh". Default value is 10. - * @param nbrOfLargeBins Number of bins between "histThresh" and 32*pi*pi (highest edge reliability value). Default value is 5. - */ - struct CV_EXPORTS_W_SIMPLE Params - { - CV_WRAP Params(); - CV_PROP_RW int width; - CV_PROP_RW int height; - CV_PROP_RW float histThresh; - CV_PROP_RW int nbrOfSmallBins; - CV_PROP_RW int nbrOfLargeBins; - }; - /** - * @brief Constructor - - * @param parameters HistogramPhaseUnwrapping parameters HistogramPhaseUnwrapping::Params: width,height of the phase map and histogram characteristics. - */ - CV_WRAP - static Ptr create( const HistogramPhaseUnwrapping::Params ¶meters = - HistogramPhaseUnwrapping::Params() ); - - /** - * @brief Get the reliability map computed from the wrapped phase map. - - * @param reliabilityMap Image where the reliability map is stored. - */ - CV_WRAP - virtual void getInverseReliabilityMap( OutputArray reliabilityMap ) = 0; -}; - -//! @} -} -} -#endif \ No newline at end of file diff --git a/3rdparty/include/opencv2/phase_unwrapping/phase_unwrapping.hpp b/3rdparty/include/opencv2/phase_unwrapping/phase_unwrapping.hpp deleted file mode 100644 index 1091ff3802..0000000000 --- a/3rdparty/include/opencv2/phase_unwrapping/phase_unwrapping.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/*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) 2015, OpenCV Foundation, 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_PHASE_UNWRAPPING_HPP__ -#define __OPENCV_PHASE_UNWRAPPING_HPP__ - -#include "opencv2/core.hpp" - -namespace cv { -namespace phase_unwrapping { -//! @addtogroup phase_unwrapping -//! @{ - - /** - @brief Abstract base class for phase unwrapping. - */ -class CV_EXPORTS_W PhaseUnwrapping : public virtual Algorithm -{ -public: - /** - * @brief Unwraps a 2D phase map. - - * @param wrappedPhaseMap The wrapped phase map of type CV_32FC1 that needs to be unwrapped. - * @param unwrappedPhaseMap The unwrapped phase map. - * @param shadowMask Optional CV_8UC1 mask image used when some pixels do not hold any phase information in the wrapped phase map. - */ - CV_WRAP - virtual void unwrapPhaseMap( InputArray wrappedPhaseMap, OutputArray unwrappedPhaseMap, - InputArray shadowMask = noArray() ) = 0; - -}; - -//! @} -} -} -#endif \ No newline at end of file diff --git a/3rdparty/include/opencv2/photo.hpp b/3rdparty/include/opencv2/photo.hpp index a457295a48..c2e89a3858 100644 --- a/3rdparty/include/opencv2/photo.hpp +++ b/3rdparty/include/opencv2/photo.hpp @@ -855,8 +855,4 @@ CV_EXPORTS_W void stylization(InputArray src, OutputArray dst, float sigma_s = 6 } // cv -#ifndef DISABLE_OPENCV_24_COMPATIBILITY -#include "opencv2/photo/photo_c.h" -#endif - #endif diff --git a/3rdparty/include/opencv2/photo/legacy/constants_c.h b/3rdparty/include/opencv2/photo/legacy/constants_c.h new file mode 100644 index 0000000000..ec1d4403fd --- /dev/null +++ b/3rdparty/include/opencv2/photo/legacy/constants_c.h @@ -0,0 +1,14 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_PHOTO_LEGACY_CONSTANTS_H +#define OPENCV_PHOTO_LEGACY_CONSTANTS_H + +enum InpaintingModes +{ + CV_INPAINT_NS =0, + CV_INPAINT_TELEA =1 +}; + +#endif // OPENCV_PHOTO_LEGACY_CONSTANTS_H diff --git a/3rdparty/include/opencv2/photo/photo_c.h b/3rdparty/include/opencv2/photo/photo_c.h deleted file mode 100644 index cd623c1913..0000000000 --- a/3rdparty/include/opencv2/photo/photo_c.h +++ /dev/null @@ -1,74 +0,0 @@ -/*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) 2008-2012, 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_PHOTO_C_H -#define OPENCV_PHOTO_C_H - -#include "opencv2/core/core_c.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @addtogroup photo_c - @{ - */ - -/* Inpainting algorithms */ -enum InpaintingModes -{ - CV_INPAINT_NS =0, - CV_INPAINT_TELEA =1 -}; - - -/* Inpaints the selected region in the image */ -CVAPI(void) cvInpaint( const CvArr* src, const CvArr* inpaint_mask, - CvArr* dst, double inpaintRange, int flags ); - -/** @} */ - -#ifdef __cplusplus -} //extern "C" -#endif - -#endif //OPENCV_PHOTO_C_H diff --git a/3rdparty/include/opencv2/plot.hpp b/3rdparty/include/opencv2/plot.hpp deleted file mode 100644 index 06a12a1479..0000000000 --- a/3rdparty/include/opencv2/plot.hpp +++ /dev/null @@ -1,120 +0,0 @@ -/*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-2012, 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*/ -//################################################################################ -// -// Created by Nuno Moutinho -// -//################################################################################ - -#ifndef _OPENCV_PLOT_H_ -#define _OPENCV_PLOT_H_ -#ifdef __cplusplus - -#include - -/** -@defgroup plot Plot function for Mat data -*/ - -namespace cv -{ - namespace plot - { - //! @addtogroup plot - //! @{ - - class CV_EXPORTS_W Plot2d : public Algorithm - { - public: - - CV_WRAP virtual void setMinX(double _plotMinX) = 0; - CV_WRAP virtual void setMinY(double _plotMinY) = 0; - CV_WRAP virtual void setMaxX(double _plotMaxX) = 0; - CV_WRAP virtual void setMaxY(double _plotMaxY) = 0; - CV_WRAP virtual void setPlotLineWidth(int _plotLineWidth) = 0; - /** - * @brief Switches data visualization mode - * - * @param _needPlotLine if true then neighbour plot points will be connected by lines. - * In other case data will be plotted as a set of standalone points. - */ - CV_WRAP virtual void setNeedPlotLine(bool _needPlotLine) = 0; - CV_WRAP virtual void setPlotLineColor(Scalar _plotLineColor) = 0; - CV_WRAP virtual void setPlotBackgroundColor(Scalar _plotBackgroundColor) = 0; - CV_WRAP virtual void setPlotAxisColor(Scalar _plotAxisColor) = 0; - CV_WRAP virtual void setPlotGridColor(Scalar _plotGridColor) = 0; - CV_WRAP virtual void setPlotTextColor(Scalar _plotTextColor) = 0; - CV_WRAP virtual void setPlotSize(int _plotSizeWidth, int _plotSizeHeight) = 0; - CV_WRAP virtual void setShowGrid(bool needShowGrid) = 0; - CV_WRAP virtual void setShowText(bool needShowText) = 0; - CV_WRAP virtual void setGridLinesNumber(int gridLinesNumber) = 0; - CV_WRAP virtual void setInvertOrientation(bool _invertOrientation) = 0; - /** - * @brief Sets the index of a point which coordinates will be printed on the top left corner of the plot (if ShowText flag is true). - * - * @param pointIdx index of the required point in data array. - */ - CV_WRAP virtual void setPointIdxToPrint(int pointIdx) = 0; - CV_WRAP virtual void render(OutputArray _plotResult) = 0; - - /** - * @brief Creates Plot2d object - * - * @param data \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot. \f$X\f$ values - * will be equal to indexes of correspondind elements in data matrix. - */ - CV_WRAP static Ptr create(InputArray data); - - /** - * @brief Creates Plot2d object - * - * @param dataX \f$1xN\f$ or \f$Nx1\f$ matrix \f$X\f$ values of points to plot. - * @param dataY \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot. - */ - CV_WRAP static Ptr create(InputArray dataX, InputArray dataY); - }; - //! @} - } -} - -#endif -#endif diff --git a/3rdparty/include/opencv2/reg/map.hpp b/3rdparty/include/opencv2/reg/map.hpp deleted file mode 100644 index a885a2844b..0000000000 --- a/3rdparty/include/opencv2/reg/map.hpp +++ /dev/null @@ -1,175 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAP_H_ -#define MAP_H_ - -#include // Basic OpenCV structures (cv::Mat, Scalar) - -/** @defgroup reg Image Registration - -The Registration module implements parametric image registration. The implemented method is direct -alignment, that is, it uses directly the pixel values for calculating the registration between a -pair of images, as opposed to feature-based registration. The implementation follows essentially the -corresponding part of @cite Szeliski06 . - -Feature based methods have some advantages over pixel based methods when we are trying to register -pictures that have been shoot under different lighting conditions or exposition times, or when the -images overlap only partially. On the other hand, the main advantage of pixel-based methods when -compared to feature based methods is their better precision for some pictures (those shoot under -similar lighting conditions and that have a significative overlap), due to the fact that we are -using all the information available in the image, which allows us to achieve subpixel accuracy. This -is particularly important for certain applications like multi-frame denoising or super-resolution. - -In fact, pixel and feature registration methods can complement each other: an application could -first obtain a coarse registration using features and then refine the registration using a pixel -based method on the overlapping area of the images. The code developed allows this use case. - -The module implements classes derived from the abstract classes cv::reg::Map or cv::reg::Mapper. The -former models a coordinate transformation between two reference frames, while the later encapsulates -a way of invoking a method that calculates a Map between two images. Although the objective has been -to implement pixel based methods, the module can be extended to support other methods that can -calculate transformations between images (feature methods, optical flow, etc.). - -Each class derived from Map implements a motion model, as follows: - -- MapShift: Models a simple translation -- MapAffine: Models an affine transformation -- MapProjec: Models a projective transformation - -MapProject can also be used to model affine motion or translations, but some operations on it are -more costly, and that is the reason for defining the other two classes. - -The classes derived from Mapper are - -- MapperGradShift: Gradient based alignment for calculating translations. It produces a MapShift - (two parameters that correspond to the shift vector). -- MapperGradEuclid: Gradient based alignment for euclidean motions, that is, rotations and - translations. It calculates three parameters (angle and shift vector), although the result is - stored in a MapAffine object for convenience. -- MapperGradSimilar: Gradient based alignment for calculating similarities, which adds scaling to - the euclidean motion. It calculates four parameters (two for the anti-symmetric matrix and two - for the shift vector), although the result is stored in a MapAffine object for better - convenience. -- MapperGradAffine: Gradient based alignment for an affine motion model. The number of parameters - is six and the result is stored in a MapAffine object. -- MapperGradProj: Gradient based alignment for calculating projective transformations. The number - of parameters is eight and the result is stored in a MapProject object. -- MapperPyramid: It implements hyerarchical motion estimation using a Gaussian pyramid. Its - constructor accepts as argument any other object that implements the Mapper interface, and it is - that mapper the one called by MapperPyramid for each scale of the pyramid. - -If the motion between the images is not very small, the normal way of using these classes is to -create a MapperGrad\* object and use it as input to create a MapperPyramid, which in turn is called -to perform the calculation. However, if the motion between the images is small enough, we can use -directly the MapperGrad\* classes. Another possibility is to use first a feature based method to -perform a coarse registration and then do a refinement through MapperPyramid or directly a -MapperGrad\* object. The "calculate" method of the mappers accepts an initial estimation of the -motion as input. - -When deciding which MapperGrad to use we must take into account that mappers with more parameters -can handle more complex motions, but involve more calculations and are therefore slower. Also, if we -are confident on the motion model that is followed by the sequence, increasing the number of -parameters beyond what we need will decrease the accuracy: it is better to use the least number of -degrees of freedom that we can. - -In the module tests there are examples that show how to register a pair of images using any of the -implemented mappers. -*/ - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/** @brief Base class for modelling a Map between two images. - -The class is only used to define the common interface for any possible map. - */ -class CV_EXPORTS_W Map -{ -public: - /*! - * Virtual destructor - */ - virtual ~Map(); - - /*! - * Warps image to a new coordinate frame. The calculation is img2(x)=img1(T^{-1}(x)), as we - * have to apply the inverse transformation to the points to move them to were the values - * of img2 are. - * \param[in] img1 Original image - * \param[out] img2 Warped image - */ - CV_WRAP virtual void warp(InputArray img1, OutputArray img2) const; - - /*! - * Warps image to a new coordinate frame. The calculation is img2(x)=img1(T(x)), so in fact - * this is the inverse warping as we are taking the value of img1 with the forward - * transformation of the points. - * \param[in] img1 Original image - * \param[out] img2 Warped image - */ - CV_WRAP virtual void inverseWarp(InputArray img1, OutputArray img2) const = 0; - - /*! - * Calculates the inverse map - * \return Inverse map - */ - CV_WRAP virtual cv::Ptr inverseMap() const = 0; - - /*! - * Changes the map composing the current transformation with the one provided in the call. - * The order is first the current transformation, then the input argument. - * \param[in] map Transformation to compose with. - */ - CV_WRAP virtual void compose(cv::Ptr map) = 0; - - /*! - * Scales the map by a given factor as if the coordinates system is expanded/compressed - * by that factor. - * \param[in] factor Expansion if bigger than one, compression if smaller than one - */ - CV_WRAP virtual void scale(double factor) = 0; -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAP_H_ diff --git a/3rdparty/include/opencv2/reg/mapaffine.hpp b/3rdparty/include/opencv2/reg/mapaffine.hpp deleted file mode 100644 index 52ab8d6b70..0000000000 --- a/3rdparty/include/opencv2/reg/mapaffine.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPAFFINE_H_ -#define MAPAFFINE_H_ - -#include "map.hpp" - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/*! - * Defines an affine transformation - */ -class CV_EXPORTS_W MapAffine : public Map -{ -public: - /*! - * Default constructor builds an identity map - */ - CV_WRAP MapAffine(); - - /*! - * Constructor providing explicit values - * \param[in] linTr Linear part of the affine transformation - * \param[in] shift Displacement part of the affine transformation - */ - CV_WRAP MapAffine(InputArray linTr, InputArray shift); - - /*! - * Destructor - */ - ~MapAffine(); - - CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const CV_OVERRIDE; - - CV_WRAP cv::Ptr inverseMap() const CV_OVERRIDE; - - CV_WRAP void compose(cv::Ptr map) CV_OVERRIDE; - - CV_WRAP void scale(double factor) CV_OVERRIDE; - - /*! - * Return linear part of the affine transformation - * \return Linear part of the affine transformation - */ - const cv::Matx& getLinTr() const { - return linTr_; - } - - CV_WRAP void getLinTr(OutputArray linTr) const { - Mat(linTr_).copyTo(linTr); - } - - /*! - * Return displacement part of the affine transformation - * \return Displacement part of the affine transformation - */ - const cv::Vec& getShift() const { - return shift_; - } - - CV_WRAP void getShift(OutputArray shift) const { - Mat(shift_).copyTo(shift); - } - -private: - cv::Matx linTr_; - cv::Vec shift_; -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPAFFINE_H_ diff --git a/3rdparty/include/opencv2/reg/mapper.hpp b/3rdparty/include/opencv2/reg/mapper.hpp deleted file mode 100644 index 2c2862d49d..0000000000 --- a/3rdparty/include/opencv2/reg/mapper.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPPER_H_ -#define MAPPER_H_ - -#include // Basic OpenCV structures (cv::Mat, Scalar) -#include "map.hpp" - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/** @brief Base class for modelling an algorithm for calculating a map - -The class is only used to define the common interface for any possible mapping algorithm. - */ -class CV_EXPORTS_W Mapper -{ -public: - virtual ~Mapper(void) {} - - /* - * Calculate mapping between two images - * \param[in] img1 Reference image - * \param[in] img2 Warped image - * \param[in] If present, it is an initial rough estimation that the mapper will try to refine. - * \return Map from img1 to img2, stored in a smart pointer. - */ - CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const = 0; - - /* - * Returns a map compatible with the Mapper class - * \return Pointer to identity Map - */ - CV_WRAP virtual cv::Ptr getMap() const = 0; - -protected: - /* - * Calculates gradient and difference between images - * \param[in] img1 Image one - * \param[in] img2 Image two - * \param[out] Ix Gradient x-coordinate - * \param[out] Iy Gradient y-coordinate - * \param[out] It Difference of images - */ - void gradient(const cv::Mat& img1, const cv::Mat& img2, - cv::Mat& Ix, cv::Mat& Iy, cv::Mat& It) const; - - /* - * Fills matrices with pixel coordinates of an image - * \param[in] img Image - * \param[out] grid_r Row (y-coordinate) - * \param[out] grid_c Column (x-coordinate) - */ - void grid(const Mat& img, Mat& grid_r, Mat& grid_c) const; - - /* - * Per-element square of a matrix - * \param[in] mat1 Input matrix - * \return mat1[i,j]^2 - */ - cv::Mat sqr(const cv::Mat& mat1) const - { - cv::Mat res; - res.create(mat1.size(), mat1.type()); - res = mat1.mul(mat1); - return res; - } -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPPER_H_ - diff --git a/3rdparty/include/opencv2/reg/mappergradaffine.hpp b/3rdparty/include/opencv2/reg/mappergradaffine.hpp deleted file mode 100644 index 49b0bc7bcd..0000000000 --- a/3rdparty/include/opencv2/reg/mappergradaffine.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPPERGRADAFFINE_H_ -#define MAPPERGRADAFFINE_H_ - -#include "mapper.hpp" - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/*! - * Mapper for affine motion - */ -class CV_EXPORTS_W MapperGradAffine: public Mapper -{ -public: - CV_WRAP MapperGradAffine(); - ~MapperGradAffine(void); - - CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; - - CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPPERGRADAFFINE_H_ diff --git a/3rdparty/include/opencv2/reg/mappergradeuclid.hpp b/3rdparty/include/opencv2/reg/mappergradeuclid.hpp deleted file mode 100644 index 4f6c5c8f18..0000000000 --- a/3rdparty/include/opencv2/reg/mappergradeuclid.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPPERGRADEUCLID_H_ -#define MAPPERGRADEUCLID_H_ - -#include "mapper.hpp" - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/*! - * Mapper for euclidean motion: rotation plus shift - */ -class CV_EXPORTS_W MapperGradEuclid: public Mapper -{ -public: - CV_WRAP MapperGradEuclid(); - ~MapperGradEuclid(); - - CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; - - CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPPERGRADEUCLID_H_ diff --git a/3rdparty/include/opencv2/reg/mappergradproj.hpp b/3rdparty/include/opencv2/reg/mappergradproj.hpp deleted file mode 100644 index 1e01c71bf6..0000000000 --- a/3rdparty/include/opencv2/reg/mappergradproj.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPPERGRADPROJ_H_ -#define MAPPERGRADPROJ_H_ - -#include "mapper.hpp" - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/*! - * Gradient mapper for a projective transformation - */ -class CV_EXPORTS_W MapperGradProj: public Mapper -{ -public: - CV_WRAP MapperGradProj(); - ~MapperGradProj(); - - CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; - - CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPPERGRADPROJ_H_ diff --git a/3rdparty/include/opencv2/reg/mappergradshift.hpp b/3rdparty/include/opencv2/reg/mappergradshift.hpp deleted file mode 100644 index cd812d9868..0000000000 --- a/3rdparty/include/opencv2/reg/mappergradshift.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPPERGRADSHIFT_H_ -#define MAPPERGRADSHIFT_H_ - -#include "mapper.hpp" - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/*! - * Gradient mapper for a translation - */ -class CV_EXPORTS_W MapperGradShift: public Mapper -{ -public: - CV_WRAP MapperGradShift(); - virtual ~MapperGradShift(); - - CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; - - CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPPERGRADSHIFT_H_ diff --git a/3rdparty/include/opencv2/reg/mappergradsimilar.hpp b/3rdparty/include/opencv2/reg/mappergradsimilar.hpp deleted file mode 100644 index 07d64d9674..0000000000 --- a/3rdparty/include/opencv2/reg/mappergradsimilar.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPPERGRADSIMILAR_H_ -#define MAPPERGRADSIMILAR_H_ - -#include "mapper.hpp" - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/*! - * Calculates a similarity transformation between to images (scale, rotation, and shift) - */ -class CV_EXPORTS_W MapperGradSimilar: public Mapper -{ -public: - CV_WRAP MapperGradSimilar(); - ~MapperGradSimilar(); - - CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; - - CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPPERGRADSIMILAR_H_ diff --git a/3rdparty/include/opencv2/reg/mapperpyramid.hpp b/3rdparty/include/opencv2/reg/mapperpyramid.hpp deleted file mode 100644 index 6106f49b98..0000000000 --- a/3rdparty/include/opencv2/reg/mapperpyramid.hpp +++ /dev/null @@ -1,105 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPPERPYRAMID_H_ -#define MAPPERPYRAMID_H_ - -#include "mapper.hpp" -#include "mapaffine.hpp" -#include "mapprojec.hpp" -#include "mapshift.hpp" - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/*! - * Calculates a map using a gaussian pyramid - */ -class CV_EXPORTS_W MapperPyramid: public Mapper -{ -public: - /* - * Constructor - * \param[in] baseMapper Base mapper used for the refinements - */ - CV_WRAP MapperPyramid(Ptr baseMapper); - - CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; - - CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; - - CV_PROP_RW int numLev_; /*!< Number of levels of the pyramid */ - CV_PROP_RW int numIterPerScale_; /*!< Number of iterations at a given scale of the pyramid */ - -private: - MapperPyramid& operator=(const MapperPyramid&); - const Mapper& baseMapper_; /*!< Mapper used in inner level */ -}; - -/*! - * Converts a pointer to a Map returned by MapperPyramid::calculate into the specified Map pointer type - */ -class CV_EXPORTS_W MapTypeCaster -{ -public: - CV_WRAP static Ptr toAffine(Ptr sourceMap) - { - MapAffine& affineMap = dynamic_cast(*sourceMap); - return Ptr(new MapAffine(affineMap)); - } - - CV_WRAP static Ptr toShift(Ptr sourceMap) - { - MapShift& shiftMap = dynamic_cast(*sourceMap); - return Ptr(new MapShift(shiftMap)); - } - - CV_WRAP static Ptr toProjec(Ptr sourceMap) - { - MapProjec& projecMap = dynamic_cast(*sourceMap); - return Ptr(new MapProjec(projecMap)); - } -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPPERPYRAMID_H_ diff --git a/3rdparty/include/opencv2/reg/mapprojec.hpp b/3rdparty/include/opencv2/reg/mapprojec.hpp deleted file mode 100644 index 6d1e565e0b..0000000000 --- a/3rdparty/include/opencv2/reg/mapprojec.hpp +++ /dev/null @@ -1,109 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPPROJEC_H_ -#define MAPPROJEC_H_ - -#include "map.hpp" - - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/*! - * Defines an transformation that consists on a projective transformation - */ -class CV_EXPORTS_W MapProjec : public Map -{ -public: - /*! - * Default constructor builds an identity map - */ - CV_WRAP MapProjec(); - - /*! - * Constructor providing explicit values - * \param[in] projTr Projective transformation - */ - CV_WRAP MapProjec(InputArray projTr); - - /*! - * Destructor - */ - ~MapProjec(); - - CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const CV_OVERRIDE; - - CV_WRAP cv::Ptr inverseMap() const CV_OVERRIDE; - - CV_WRAP void compose(cv::Ptr map) CV_OVERRIDE; - - CV_WRAP void scale(double factor) CV_OVERRIDE; - - /*! - * Returns projection matrix - * \return Projection matrix - */ - const cv::Matx& getProjTr() const { - return projTr_; - } - - CV_WRAP void getProjTr(OutputArray projTr) const { - Mat(projTr_).copyTo(projTr); - } - - /*! - * Normalizes object's homography - */ - CV_WRAP void normalize() { - double z = 1./projTr_(2, 2); - for(size_t v_i = 0; v_i < sizeof(projTr_.val)/sizeof(projTr_.val[0]); ++v_i) - projTr_.val[v_i] *= z; - } - -private: - cv::Matx projTr_; /*< Projection matrix */ -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPPROJEC_H_ diff --git a/3rdparty/include/opencv2/reg/mapshift.hpp b/3rdparty/include/opencv2/reg/mapshift.hpp deleted file mode 100644 index ada9545017..0000000000 --- a/3rdparty/include/opencv2/reg/mapshift.hpp +++ /dev/null @@ -1,101 +0,0 @@ -/*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. -// -// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 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 MAPSHIFT_H_ -#define MAPSHIFT_H_ - -#include "map.hpp" - - -namespace cv { -namespace reg { - -//! @addtogroup reg -//! @{ - -/*! - * Defines an transformation that consists on a simple displacement - */ -class CV_EXPORTS_W MapShift : public Map -{ -public: - /*! - * Default constructor builds an identity map - */ - CV_WRAP MapShift(); - - /*! - * Constructor providing explicit values - * \param[in] shift Displacement - */ - - CV_WRAP MapShift(InputArray shift); - - /*! - * Destructor - */ - ~MapShift(); - - CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const CV_OVERRIDE; - - CV_WRAP cv::Ptr inverseMap() const CV_OVERRIDE; - - CV_WRAP void compose(cv::Ptr map) CV_OVERRIDE; - - CV_WRAP void scale(double factor) CV_OVERRIDE; - - /*! - * Return displacement - * \return Displacement - */ - const cv::Vec& getShift() const { - return shift_; - } - - CV_WRAP void getShift(OutputArray shift) const { - Mat(shift_).copyTo(shift); - } - -private: - cv::Vec shift_; /*< Displacement */ -}; - -//! @} - -}} // namespace cv::reg - -#endif // MAPSHIFT_H_ diff --git a/3rdparty/include/opencv2/rgbd.hpp b/3rdparty/include/opencv2/rgbd.hpp deleted file mode 100644 index 8f74344255..0000000000 --- a/3rdparty/include/opencv2/rgbd.hpp +++ /dev/null @@ -1,1094 +0,0 @@ -/* - * Software License Agreement (BSD License) - * - * Copyright (c) 2009, Willow Garage, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions 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. - * * Neither the name of Willow Garage, Inc. nor the names of its - * contributors may 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 - * COPYRIGHT OWNER 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. - * - */ - -#ifndef __OPENCV_RGBD_HPP__ -#define __OPENCV_RGBD_HPP__ - -#ifdef __cplusplus - -#include -#include - -/** @defgroup rgbd RGB-Depth Processing -*/ - -namespace cv -{ -namespace rgbd -{ - -//! @addtogroup rgbd -//! @{ - - /** Checks if the value is a valid depth. For CV_16U or CV_16S, the convention is to be invalid if it is - * a limit. For a float/double, we just check if it is a NaN - * @param depth the depth to check for validity - */ - CV_EXPORTS - inline bool - isValidDepth(const float & depth) - { - return !cvIsNaN(depth); - } - CV_EXPORTS - inline bool - isValidDepth(const double & depth) - { - return !cvIsNaN(depth); - } - CV_EXPORTS - inline bool - isValidDepth(const short int & depth) - { - return (depth != std::numeric_limits::min()) && (depth != std::numeric_limits::max()); - } - CV_EXPORTS - inline bool - isValidDepth(const unsigned short int & depth) - { - return (depth != std::numeric_limits::min()) - && (depth != std::numeric_limits::max()); - } - CV_EXPORTS - inline bool - isValidDepth(const int & depth) - { - return (depth != std::numeric_limits::min()) && (depth != std::numeric_limits::max()); - } - CV_EXPORTS - inline bool - isValidDepth(const unsigned int & depth) - { - return (depth != std::numeric_limits::min()) && (depth != std::numeric_limits::max()); - } - - /** Object that can compute the normals in an image. - * It is an object as it can cache data for speed efficiency - * The implemented methods are either: - * - FALS (the fastest) and SRI from - * ``Fast and Accurate Computation of Surface Normals from Range Images`` - * by H. Badino, D. Huber, Y. Park and T. Kanade - * - the normals with bilateral filtering on a depth image from - * ``Gradient Response Maps for Real-Time Detection of Texture-Less Objects`` - * by S. Hinterstoisser, C. Cagniart, S. Ilic, P. Sturm, N. Navab, P. Fua, and V. Lepetit - */ - class CV_EXPORTS_W RgbdNormals: public Algorithm - { - public: - enum RGBD_NORMALS_METHOD - { - RGBD_NORMALS_METHOD_FALS = 0, - RGBD_NORMALS_METHOD_LINEMOD = 1, - RGBD_NORMALS_METHOD_SRI = 2 - }; - - RgbdNormals() - : - rows_(0), - cols_(0), - depth_(0), - K_(Mat()), - window_size_(0), - method_(RGBD_NORMALS_METHOD_FALS), - rgbd_normals_impl_(0) - { - } - - /** Constructor - * @param rows the number of rows of the depth image normals will be computed on - * @param cols the number of cols of the depth image normals will be computed on - * @param depth the depth of the normals (only CV_32F or CV_64F) - * @param K the calibration matrix to use - * @param window_size the window size to compute the normals: can only be 1,3,5 or 7 - * @param method one of the methods to use: RGBD_NORMALS_METHOD_SRI, RGBD_NORMALS_METHOD_FALS - */ - RgbdNormals(int rows, int cols, int depth, InputArray K, int window_size = 5, int method = - RgbdNormals::RGBD_NORMALS_METHOD_FALS); - - ~RgbdNormals(); - - CV_WRAP static Ptr create(int rows, int cols, int depth, InputArray K, int window_size = 5, int method = - RgbdNormals::RGBD_NORMALS_METHOD_FALS); - - /** Given a set of 3d points in a depth image, compute the normals at each point. - * @param points a rows x cols x 3 matrix of CV_32F/CV64F or a rows x cols x 1 CV_U16S - * @param normals a rows x cols x 3 matrix - */ - CV_WRAP_AS(apply) void - operator()(InputArray points, OutputArray normals) const; - - /** Initializes some data that is cached for later computation - * If that function is not called, it will be called the first time normals are computed - */ - CV_WRAP void - initialize() const; - - CV_WRAP int getRows() const - { - return rows_; - } - CV_WRAP void setRows(int val) - { - rows_ = val; - } - CV_WRAP int getCols() const - { - return cols_; - } - CV_WRAP void setCols(int val) - { - cols_ = val; - } - CV_WRAP int getWindowSize() const - { - return window_size_; - } - CV_WRAP void setWindowSize(int val) - { - window_size_ = val; - } - CV_WRAP int getDepth() const - { - return depth_; - } - CV_WRAP void setDepth(int val) - { - depth_ = val; - } - CV_WRAP cv::Mat getK() const - { - return K_; - } - CV_WRAP void setK(const cv::Mat &val) - { - K_ = val; - } - CV_WRAP int getMethod() const - { - return method_; - } - CV_WRAP void setMethod(int val) - { - method_ = val; - } - - protected: - void - initialize_normals_impl(int rows, int cols, int depth, const Mat & K, int window_size, int method) const; - - int rows_, cols_, depth_; - Mat K_; - int window_size_; - int method_; - mutable void* rgbd_normals_impl_; - }; - - /** Object that can clean a noisy depth image - */ - class CV_EXPORTS_W DepthCleaner: public Algorithm - { - public: - /** NIL method is from - * ``Modeling Kinect Sensor Noise for Improved 3d Reconstruction and Tracking`` - * by C. Nguyen, S. Izadi, D. Lovel - */ - enum DEPTH_CLEANER_METHOD - { - DEPTH_CLEANER_NIL - }; - - DepthCleaner() - : - depth_(0), - window_size_(0), - method_(DEPTH_CLEANER_NIL), - depth_cleaner_impl_(0) - { - } - - /** Constructor - * @param depth the depth of the normals (only CV_32F or CV_64F) - * @param window_size the window size to compute the normals: can only be 1,3,5 or 7 - * @param method one of the methods to use: RGBD_NORMALS_METHOD_SRI, RGBD_NORMALS_METHOD_FALS - */ - DepthCleaner(int depth, int window_size = 5, int method = DepthCleaner::DEPTH_CLEANER_NIL); - - ~DepthCleaner(); - - CV_WRAP static Ptr create(int depth, int window_size = 5, int method = DepthCleaner::DEPTH_CLEANER_NIL); - - /** Given a set of 3d points in a depth image, compute the normals at each point. - * @param points a rows x cols x 3 matrix of CV_32F/CV64F or a rows x cols x 1 CV_U16S - * @param depth a rows x cols matrix of the cleaned up depth - */ - CV_WRAP_AS(apply) void - operator()(InputArray points, OutputArray depth) const; - - /** Initializes some data that is cached for later computation - * If that function is not called, it will be called the first time normals are computed - */ - CV_WRAP void - initialize() const; - - CV_WRAP int getWindowSize() const - { - return window_size_; - } - CV_WRAP void setWindowSize(int val) - { - window_size_ = val; - } - CV_WRAP int getDepth() const - { - return depth_; - } - CV_WRAP void setDepth(int val) - { - depth_ = val; - } - CV_WRAP int getMethod() const - { - return method_; - } - CV_WRAP void setMethod(int val) - { - method_ = val; - } - - protected: - void - initialize_cleaner_impl() const; - - int depth_; - int window_size_; - int method_; - mutable void* depth_cleaner_impl_; - }; - - - /** Registers depth data to an external camera - * Registration is performed by creating a depth cloud, transforming the cloud by - * the rigid body transformation between the cameras, and then projecting the - * transformed points into the RGB camera. - * - * uv_rgb = K_rgb * [R | t] * z * inv(K_ir) * uv_ir - * - * Currently does not check for negative depth values. - * - * @param unregisteredCameraMatrix the camera matrix of the depth camera - * @param registeredCameraMatrix the camera matrix of the external camera - * @param registeredDistCoeffs the distortion coefficients of the external camera - * @param Rt the rigid body transform between the cameras. Transforms points from depth camera frame to external camera frame. - * @param unregisteredDepth the input depth data - * @param outputImagePlaneSize the image plane dimensions of the external camera (width, height) - * @param registeredDepth the result of transforming the depth into the external camera - * @param depthDilation whether or not the depth is dilated to avoid holes and occlusion errors (optional) - */ - CV_EXPORTS_W - void - registerDepth(InputArray unregisteredCameraMatrix, InputArray registeredCameraMatrix, InputArray registeredDistCoeffs, - InputArray Rt, InputArray unregisteredDepth, const Size& outputImagePlaneSize, - OutputArray registeredDepth, bool depthDilation=false); - - /** - * @param depth the depth image - * @param in_K - * @param in_points the list of xy coordinates - * @param points3d the resulting 3d points - */ - CV_EXPORTS_W - void - depthTo3dSparse(InputArray depth, InputArray in_K, InputArray in_points, OutputArray points3d); - - /** Converts a depth image to an organized set of 3d points. - * The coordinate system is x pointing left, y down and z away from the camera - * @param depth the depth image (if given as short int CV_U, it is assumed to be the depth in millimeters - * (as done with the Microsoft Kinect), otherwise, if given as CV_32F or CV_64F, it is assumed in meters) - * @param K The calibration matrix - * @param points3d the resulting 3d points. They are of depth the same as `depth` if it is CV_32F or CV_64F, and the - * depth of `K` if `depth` is of depth CV_U - * @param mask the mask of the points to consider (can be empty) - */ - CV_EXPORTS_W - void - depthTo3d(InputArray depth, InputArray K, OutputArray points3d, InputArray mask = noArray()); - - /** If the input image is of type CV_16UC1 (like the Kinect one), the image is converted to floats, divided - * by 1000 to get a depth in meters, and the values 0 are converted to std::numeric_limits::quiet_NaN() - * Otherwise, the image is simply converted to floats - * @param in the depth image (if given as short int CV_U, it is assumed to be the depth in millimeters - * (as done with the Microsoft Kinect), it is assumed in meters) - * @param depth the desired output depth (floats or double) - * @param out The rescaled float depth image - */ - CV_EXPORTS_W - void - rescaleDepth(InputArray in, int depth, OutputArray out); - - /** Object that can compute planes in an image - */ - class CV_EXPORTS_W RgbdPlane: public Algorithm - { - public: - enum RGBD_PLANE_METHOD - { - RGBD_PLANE_METHOD_DEFAULT - }; - - RgbdPlane(int method = RgbdPlane::RGBD_PLANE_METHOD_DEFAULT) - : - method_(method), - block_size_(40), - min_size_(block_size_*block_size_), - threshold_(0.01), - sensor_error_a_(0), - sensor_error_b_(0), - sensor_error_c_(0) - { - } - - /** Constructor - * @param block_size The size of the blocks to look at for a stable MSE - * @param min_size The minimum size of a cluster to be considered a plane - * @param threshold The maximum distance of a point from a plane to belong to it (in meters) - * @param sensor_error_a coefficient of the sensor error. 0 by default, 0.0075 for a Kinect - * @param sensor_error_b coefficient of the sensor error. 0 by default - * @param sensor_error_c coefficient of the sensor error. 0 by default - * @param method The method to use to compute the planes. - */ - RgbdPlane(int method, int block_size, - int min_size, double threshold, double sensor_error_a = 0, - double sensor_error_b = 0, double sensor_error_c = 0); - - ~RgbdPlane(); - - CV_WRAP static Ptr create(int method, int block_size, int min_size, double threshold, - double sensor_error_a = 0, double sensor_error_b = 0, - double sensor_error_c = 0); - - /** Find The planes in a depth image - * @param points3d the 3d points organized like the depth image: rows x cols with 3 channels - * @param normals the normals for every point in the depth image - * @param mask An image where each pixel is labeled with the plane it belongs to - * and 255 if it does not belong to any plane - * @param plane_coefficients the coefficients of the corresponding planes (a,b,c,d) such that ax+by+cz+d=0, norm(a,b,c)=1 - * and c < 0 (so that the normal points towards the camera) - */ - CV_WRAP_AS(apply) void - operator()(InputArray points3d, InputArray normals, OutputArray mask, - OutputArray plane_coefficients); - - /** Find The planes in a depth image but without doing a normal check, which is faster but less accurate - * @param points3d the 3d points organized like the depth image: rows x cols with 3 channels - * @param mask An image where each pixel is labeled with the plane it belongs to - * and 255 if it does not belong to any plane - * @param plane_coefficients the coefficients of the corresponding planes (a,b,c,d) such that ax+by+cz+d=0 - */ - CV_WRAP_AS(apply) void - operator()(InputArray points3d, OutputArray mask, OutputArray plane_coefficients); - - CV_WRAP int getBlockSize() const - { - return block_size_; - } - CV_WRAP void setBlockSize(int val) - { - block_size_ = val; - } - CV_WRAP int getMinSize() const - { - return min_size_; - } - CV_WRAP void setMinSize(int val) - { - min_size_ = val; - } - CV_WRAP int getMethod() const - { - return method_; - } - CV_WRAP void setMethod(int val) - { - method_ = val; - } - CV_WRAP double getThreshold() const - { - return threshold_; - } - CV_WRAP void setThreshold(double val) - { - threshold_ = val; - } - CV_WRAP double getSensorErrorA() const - { - return sensor_error_a_; - } - CV_WRAP void setSensorErrorA(double val) - { - sensor_error_a_ = val; - } - CV_WRAP double getSensorErrorB() const - { - return sensor_error_b_; - } - CV_WRAP void setSensorErrorB(double val) - { - sensor_error_b_ = val; - } - CV_WRAP double getSensorErrorC() const - { - return sensor_error_c_; - } - CV_WRAP void setSensorErrorC(double val) - { - sensor_error_c_ = val; - } - - private: - /** The method to use to compute the planes */ - int method_; - /** The size of the blocks to look at for a stable MSE */ - int block_size_; - /** The minimum size of a cluster to be considered a plane */ - int min_size_; - /** How far a point can be from a plane to belong to it (in meters) */ - double threshold_; - /** coefficient of the sensor error with respect to the. All 0 by default but you want a=0.0075 for a Kinect */ - double sensor_error_a_, sensor_error_b_, sensor_error_c_; - }; - - /** Object that contains a frame data. - */ - struct CV_EXPORTS_W RgbdFrame - { - RgbdFrame(); - RgbdFrame(const Mat& image, const Mat& depth, const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); - virtual ~RgbdFrame(); - - CV_WRAP static Ptr create(const Mat& image=Mat(), const Mat& depth=Mat(), const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); - - CV_WRAP virtual void - release(); - - CV_PROP int ID; - CV_PROP Mat image; - CV_PROP Mat depth; - CV_PROP Mat mask; - CV_PROP Mat normals; - }; - - /** Object that contains a frame data that is possibly needed for the Odometry. - * It's used for the efficiency (to pass precomputed/cached data of the frame that participates - * in the Odometry processing several times). - */ - struct CV_EXPORTS_W OdometryFrame : public RgbdFrame - { - /** These constants are used to set a type of cache which has to be prepared depending on the frame role: - * srcFrame or dstFrame (see compute method of the Odometry class). For the srcFrame and dstFrame different cache data may be required, - * some part of a cache may be common for both frame roles. - * @param CACHE_SRC The cache data for the srcFrame will be prepared. - * @param CACHE_DST The cache data for the dstFrame will be prepared. - * @param CACHE_ALL The cache data for both srcFrame and dstFrame roles will be computed. - */ - enum - { - CACHE_SRC = 1, CACHE_DST = 2, CACHE_ALL = CACHE_SRC + CACHE_DST - }; - - OdometryFrame(); - OdometryFrame(const Mat& image, const Mat& depth, const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); - - CV_WRAP static Ptr create(const Mat& image=Mat(), const Mat& depth=Mat(), const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); - - CV_WRAP virtual void - release() CV_OVERRIDE; - - CV_WRAP void - releasePyramids(); - - CV_PROP std::vector pyramidImage; - CV_PROP std::vector pyramidDepth; - CV_PROP std::vector pyramidMask; - - CV_PROP std::vector pyramidCloud; - - CV_PROP std::vector pyramid_dI_dx; - CV_PROP std::vector pyramid_dI_dy; - CV_PROP std::vector pyramidTexturedMask; - - CV_PROP std::vector pyramidNormals; - CV_PROP std::vector pyramidNormalsMask; - }; - - /** Base class for computation of odometry. - */ - class CV_EXPORTS_W Odometry: public Algorithm - { - public: - - /** A class of transformation*/ - enum - { - ROTATION = 1, TRANSLATION = 2, RIGID_BODY_MOTION = 4 - }; - - CV_WRAP static inline float - DEFAULT_MIN_DEPTH() - { - return 0.f; // in meters - } - CV_WRAP static inline float - DEFAULT_MAX_DEPTH() - { - return 4.f; // in meters - } - CV_WRAP static inline float - DEFAULT_MAX_DEPTH_DIFF() - { - return 0.07f; // in meters - } - CV_WRAP static inline float - DEFAULT_MAX_POINTS_PART() - { - return 0.07f; // in [0, 1] - } - CV_WRAP static inline float - DEFAULT_MAX_TRANSLATION() - { - return 0.15f; // in meters - } - CV_WRAP static inline float - DEFAULT_MAX_ROTATION() - { - return 15; // in degrees - } - - /** Method to compute a transformation from the source frame to the destination one. - * Some odometry algorithms do not used some data of frames (eg. ICP does not use images). - * In such case corresponding arguments can be set as empty Mat. - * The method returns true if all internal computions were possible (e.g. there were enough correspondences, - * system of equations has a solution, etc) and resulting transformation satisfies some test if it's provided - * by the Odometry inheritor implementation (e.g. thresholds for maximum translation and rotation). - * @param srcImage Image data of the source frame (CV_8UC1) - * @param srcDepth Depth data of the source frame (CV_32FC1, in meters) - * @param srcMask Mask that sets which pixels have to be used from the source frame (CV_8UC1) - * @param dstImage Image data of the destination frame (CV_8UC1) - * @param dstDepth Depth data of the destination frame (CV_32FC1, in meters) - * @param dstMask Mask that sets which pixels have to be used from the destination frame (CV_8UC1) - * @param Rt Resulting transformation from the source frame to the destination one (rigid body motion): - dst_p = Rt * src_p, where dst_p is a homogeneous point in the destination frame and src_p is - homogeneous point in the source frame, - Rt is 4x4 matrix of CV_64FC1 type. - * @param initRt Initial transformation from the source frame to the destination one (optional) - */ - CV_WRAP bool - compute(const Mat& srcImage, const Mat& srcDepth, const Mat& srcMask, const Mat& dstImage, const Mat& dstDepth, - const Mat& dstMask, OutputArray Rt, const Mat& initRt = Mat()) const; - - /** One more method to compute a transformation from the source frame to the destination one. - * It is designed to save on computing the frame data (image pyramids, normals, etc.). - */ - CV_WRAP_AS(compute2) bool - compute(Ptr& srcFrame, Ptr& dstFrame, OutputArray Rt, const Mat& initRt = Mat()) const; - - /** Prepare a cache for the frame. The function checks the precomputed/passed data (throws the error if this data - * does not satisfy) and computes all remaining cache data needed for the frame. Returned size is a resolution - * of the prepared frame. - * @param frame The odometry which will process the frame. - * @param cacheType The cache type: CACHE_SRC, CACHE_DST or CACHE_ALL. - */ - CV_WRAP virtual Size prepareFrameCache(Ptr& frame, int cacheType) const; - - CV_WRAP static Ptr create(const String & odometryType); - - /** @see setCameraMatrix */ - CV_WRAP virtual cv::Mat getCameraMatrix() const = 0; - /** @copybrief getCameraMatrix @see getCameraMatrix */ - CV_WRAP virtual void setCameraMatrix(const cv::Mat &val) = 0; - /** @see setTransformType */ - CV_WRAP virtual int getTransformType() const = 0; - /** @copybrief getTransformType @see getTransformType */ - CV_WRAP virtual void setTransformType(int val) = 0; - - protected: - virtual void - checkParams() const = 0; - - virtual bool - computeImpl(const Ptr& srcFrame, const Ptr& dstFrame, OutputArray Rt, - const Mat& initRt) const = 0; - }; - - /** Odometry based on the paper "Real-Time Visual Odometry from Dense RGB-D Images", - * F. Steinbucker, J. Strum, D. Cremers, ICCV, 2011. - */ - class CV_EXPORTS_W RgbdOdometry: public Odometry - { - public: - RgbdOdometry(); - /** Constructor. - * @param cameraMatrix Camera matrix - * @param minDepth Pixels with depth less than minDepth will not be used (in meters) - * @param maxDepth Pixels with depth larger than maxDepth will not be used (in meters) - * @param maxDepthDiff Correspondences between pixels of two given frames will be filtered out - * if their depth difference is larger than maxDepthDiff (in meters) - * @param iterCounts Count of iterations on each pyramid level. - * @param minGradientMagnitudes For each pyramid level the pixels will be filtered out - * if they have gradient magnitude less than minGradientMagnitudes[level]. - * @param maxPointsPart The method uses a random pixels subset of size frameWidth x frameHeight x pointsPart - * @param transformType Class of transformation - */ - RgbdOdometry(const Mat& cameraMatrix, float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), - float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), const std::vector& iterCounts = std::vector(), - const std::vector& minGradientMagnitudes = std::vector(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), - int transformType = Odometry::RIGID_BODY_MOTION); - - CV_WRAP static Ptr create(const Mat& cameraMatrix = Mat(), float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), - float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), const std::vector& iterCounts = std::vector(), - const std::vector& minGradientMagnitudes = std::vector(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), - int transformType = Odometry::RIGID_BODY_MOTION); - - CV_WRAP virtual Size prepareFrameCache(Ptr& frame, int cacheType) const CV_OVERRIDE; - - CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE - { - return cameraMatrix; - } - CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE - { - cameraMatrix = val; - } - CV_WRAP double getMinDepth() const - { - return minDepth; - } - CV_WRAP void setMinDepth(double val) - { - minDepth = val; - } - CV_WRAP double getMaxDepth() const - { - return maxDepth; - } - CV_WRAP void setMaxDepth(double val) - { - maxDepth = val; - } - CV_WRAP double getMaxDepthDiff() const - { - return maxDepthDiff; - } - CV_WRAP void setMaxDepthDiff(double val) - { - maxDepthDiff = val; - } - CV_WRAP cv::Mat getIterationCounts() const - { - return iterCounts; - } - CV_WRAP void setIterationCounts(const cv::Mat &val) - { - iterCounts = val; - } - CV_WRAP cv::Mat getMinGradientMagnitudes() const - { - return minGradientMagnitudes; - } - CV_WRAP void setMinGradientMagnitudes(const cv::Mat &val) - { - minGradientMagnitudes = val; - } - CV_WRAP double getMaxPointsPart() const - { - return maxPointsPart; - } - CV_WRAP void setMaxPointsPart(double val) - { - maxPointsPart = val; - } - CV_WRAP int getTransformType() const CV_OVERRIDE - { - return transformType; - } - CV_WRAP void setTransformType(int val) CV_OVERRIDE - { - transformType = val; - } - CV_WRAP double getMaxTranslation() const - { - return maxTranslation; - } - CV_WRAP void setMaxTranslation(double val) - { - maxTranslation = val; - } - CV_WRAP double getMaxRotation() const - { - return maxRotation; - } - CV_WRAP void setMaxRotation(double val) - { - maxRotation = val; - } - - protected: - virtual void - checkParams() const CV_OVERRIDE; - - virtual bool - computeImpl(const Ptr& srcFrame, const Ptr& dstFrame, OutputArray Rt, - const Mat& initRt) const CV_OVERRIDE; - - // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. - /*float*/ - double minDepth, maxDepth, maxDepthDiff; - /*vector*/ - Mat iterCounts; - /*vector*/ - Mat minGradientMagnitudes; - double maxPointsPart; - - Mat cameraMatrix; - int transformType; - - double maxTranslation, maxRotation; - }; - - /** Odometry based on the paper "KinectFusion: Real-Time Dense Surface Mapping and Tracking", - * Richard A. Newcombe, Andrew Fitzgibbon, at al, SIGGRAPH, 2011. - */ - class CV_EXPORTS_W ICPOdometry: public Odometry - { - public: - ICPOdometry(); - /** Constructor. - * @param cameraMatrix Camera matrix - * @param minDepth Pixels with depth less than minDepth will not be used - * @param maxDepth Pixels with depth larger than maxDepth will not be used - * @param maxDepthDiff Correspondences between pixels of two given frames will be filtered out - * if their depth difference is larger than maxDepthDiff - * @param maxPointsPart The method uses a random pixels subset of size frameWidth x frameHeight x pointsPart - * @param iterCounts Count of iterations on each pyramid level. - * @param transformType Class of trasformation - */ - ICPOdometry(const Mat& cameraMatrix, float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), - float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), - const std::vector& iterCounts = std::vector(), int transformType = Odometry::RIGID_BODY_MOTION); - - CV_WRAP static Ptr create(const Mat& cameraMatrix = Mat(), float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), - float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), - const std::vector& iterCounts = std::vector(), int transformType = Odometry::RIGID_BODY_MOTION); - - CV_WRAP virtual Size prepareFrameCache(Ptr& frame, int cacheType) const CV_OVERRIDE; - - CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE - { - return cameraMatrix; - } - CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE - { - cameraMatrix = val; - } - CV_WRAP double getMinDepth() const - { - return minDepth; - } - CV_WRAP void setMinDepth(double val) - { - minDepth = val; - } - CV_WRAP double getMaxDepth() const - { - return maxDepth; - } - CV_WRAP void setMaxDepth(double val) - { - maxDepth = val; - } - CV_WRAP double getMaxDepthDiff() const - { - return maxDepthDiff; - } - CV_WRAP void setMaxDepthDiff(double val) - { - maxDepthDiff = val; - } - CV_WRAP cv::Mat getIterationCounts() const - { - return iterCounts; - } - CV_WRAP void setIterationCounts(const cv::Mat &val) - { - iterCounts = val; - } - CV_WRAP double getMaxPointsPart() const - { - return maxPointsPart; - } - CV_WRAP void setMaxPointsPart(double val) - { - maxPointsPart = val; - } - CV_WRAP int getTransformType() const CV_OVERRIDE - { - return transformType; - } - CV_WRAP void setTransformType(int val) CV_OVERRIDE - { - transformType = val; - } - CV_WRAP double getMaxTranslation() const - { - return maxTranslation; - } - CV_WRAP void setMaxTranslation(double val) - { - maxTranslation = val; - } - CV_WRAP double getMaxRotation() const - { - return maxRotation; - } - CV_WRAP void setMaxRotation(double val) - { - maxRotation = val; - } - CV_WRAP Ptr getNormalsComputer() const - { - return normalsComputer; - } - - protected: - virtual void - checkParams() const CV_OVERRIDE; - - virtual bool - computeImpl(const Ptr& srcFrame, const Ptr& dstFrame, OutputArray Rt, - const Mat& initRt) const CV_OVERRIDE; - - // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. - /*float*/ - double minDepth, maxDepth, maxDepthDiff; - /*float*/ - double maxPointsPart; - /*vector*/ - Mat iterCounts; - - Mat cameraMatrix; - int transformType; - - double maxTranslation, maxRotation; - - mutable Ptr normalsComputer; - }; - - /** Odometry that merges RgbdOdometry and ICPOdometry by minimize sum of their energy functions. - */ - - class CV_EXPORTS_W RgbdICPOdometry: public Odometry - { - public: - RgbdICPOdometry(); - /** Constructor. - * @param cameraMatrix Camera matrix - * @param minDepth Pixels with depth less than minDepth will not be used - * @param maxDepth Pixels with depth larger than maxDepth will not be used - * @param maxDepthDiff Correspondences between pixels of two given frames will be filtered out - * if their depth difference is larger than maxDepthDiff - * @param maxPointsPart The method uses a random pixels subset of size frameWidth x frameHeight x pointsPart - * @param iterCounts Count of iterations on each pyramid level. - * @param minGradientMagnitudes For each pyramid level the pixels will be filtered out - * if they have gradient magnitude less than minGradientMagnitudes[level]. - * @param transformType Class of trasformation - */ - RgbdICPOdometry(const Mat& cameraMatrix, float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), - float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), - const std::vector& iterCounts = std::vector(), - const std::vector& minGradientMagnitudes = std::vector(), - int transformType = Odometry::RIGID_BODY_MOTION); - - CV_WRAP static Ptr create(const Mat& cameraMatrix = Mat(), float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), - float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), - const std::vector& iterCounts = std::vector(), - const std::vector& minGradientMagnitudes = std::vector(), - int transformType = Odometry::RIGID_BODY_MOTION); - - CV_WRAP virtual Size prepareFrameCache(Ptr& frame, int cacheType) const CV_OVERRIDE; - - CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE - { - return cameraMatrix; - } - CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE - { - cameraMatrix = val; - } - CV_WRAP double getMinDepth() const - { - return minDepth; - } - CV_WRAP void setMinDepth(double val) - { - minDepth = val; - } - CV_WRAP double getMaxDepth() const - { - return maxDepth; - } - CV_WRAP void setMaxDepth(double val) - { - maxDepth = val; - } - CV_WRAP double getMaxDepthDiff() const - { - return maxDepthDiff; - } - CV_WRAP void setMaxDepthDiff(double val) - { - maxDepthDiff = val; - } - CV_WRAP double getMaxPointsPart() const - { - return maxPointsPart; - } - CV_WRAP void setMaxPointsPart(double val) - { - maxPointsPart = val; - } - CV_WRAP cv::Mat getIterationCounts() const - { - return iterCounts; - } - CV_WRAP void setIterationCounts(const cv::Mat &val) - { - iterCounts = val; - } - CV_WRAP cv::Mat getMinGradientMagnitudes() const - { - return minGradientMagnitudes; - } - CV_WRAP void setMinGradientMagnitudes(const cv::Mat &val) - { - minGradientMagnitudes = val; - } - CV_WRAP int getTransformType() const CV_OVERRIDE - { - return transformType; - } - CV_WRAP void setTransformType(int val) CV_OVERRIDE - { - transformType = val; - } - CV_WRAP double getMaxTranslation() const - { - return maxTranslation; - } - CV_WRAP void setMaxTranslation(double val) - { - maxTranslation = val; - } - CV_WRAP double getMaxRotation() const - { - return maxRotation; - } - CV_WRAP void setMaxRotation(double val) - { - maxRotation = val; - } - CV_WRAP Ptr getNormalsComputer() const - { - return normalsComputer; - } - - protected: - virtual void - checkParams() const CV_OVERRIDE; - - virtual bool - computeImpl(const Ptr& srcFrame, const Ptr& dstFrame, OutputArray Rt, - const Mat& initRt) const CV_OVERRIDE; - - // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. - /*float*/ - double minDepth, maxDepth, maxDepthDiff; - /*float*/ - double maxPointsPart; - /*vector*/ - Mat iterCounts; - /*vector*/ - Mat minGradientMagnitudes; - - Mat cameraMatrix; - int transformType; - - double maxTranslation, maxRotation; - - mutable Ptr normalsComputer; - }; - - /** Warp the image: compute 3d points from the depth, transform them using given transformation, - * then project color point cloud to an image plane. - * This function can be used to visualize results of the Odometry algorithm. - * @param image The image (of CV_8UC1 or CV_8UC3 type) - * @param depth The depth (of type used in depthTo3d fuction) - * @param mask The mask of used pixels (of CV_8UC1), it can be empty - * @param Rt The transformation that will be applied to the 3d points computed from the depth - * @param cameraMatrix Camera matrix - * @param distCoeff Distortion coefficients - * @param warpedImage The warped image. - * @param warpedDepth The warped depth. - * @param warpedMask The warped mask. - */ - CV_EXPORTS_W - void - warpFrame(const Mat& image, const Mat& depth, const Mat& mask, const Mat& Rt, const Mat& cameraMatrix, - const Mat& distCoeff, OutputArray warpedImage, OutputArray warpedDepth = noArray(), OutputArray warpedMask = noArray()); - -// TODO Depth interpolation -// Curvature -// Get rescaleDepth return dubles if asked for - -//! @} - -} /* namespace rgbd */ -} /* namespace cv */ - -#include "opencv2/rgbd/linemod.hpp" - -#endif /* __cplusplus */ -#endif - -/* End of file. */ - diff --git a/3rdparty/include/opencv2/rgbd/linemod.hpp b/3rdparty/include/opencv2/rgbd/linemod.hpp deleted file mode 100644 index 95eed96c4a..0000000000 --- a/3rdparty/include/opencv2/rgbd/linemod.hpp +++ /dev/null @@ -1,463 +0,0 @@ -/*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. -// Copyright (C) 2013, OpenCV Foundation, 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_OBJDETECT_LINEMOD_HPP__ -#define __OPENCV_OBJDETECT_LINEMOD_HPP__ - -#include "opencv2/core.hpp" -#include - -/****************************************************************************************\ -* LINE-MOD * -\****************************************************************************************/ - -namespace cv { -namespace linemod { - -//! @addtogroup rgbd -//! @{ - -/** - * \brief Discriminant feature described by its location and label. - */ -struct CV_EXPORTS_W_SIMPLE Feature -{ - CV_PROP_RW int x; ///< x offset - CV_PROP_RW int y; ///< y offset - CV_PROP_RW int label; ///< Quantization - - CV_WRAP Feature() : x(0), y(0), label(0) {} - CV_WRAP Feature(int x, int y, int label); - - void read(const FileNode& fn); - void write(FileStorage& fs) const; -}; - -inline Feature::Feature(int _x, int _y, int _label) : x(_x), y(_y), label(_label) {} - -struct CV_EXPORTS_W_SIMPLE Template -{ - CV_PROP int width; - CV_PROP int height; - CV_PROP int pyramid_level; - CV_PROP std::vector features; - - void read(const FileNode& fn); - void write(FileStorage& fs) const; -}; - -/** - * \brief Represents a modality operating over an image pyramid. - */ -class CV_EXPORTS_W QuantizedPyramid -{ -public: - // Virtual destructor - virtual ~QuantizedPyramid() {} - - /** - * \brief Compute quantized image at current pyramid level for online detection. - * - * \param[out] dst The destination 8-bit image. For each pixel at most one bit is set, - * representing its classification. - */ - CV_WRAP virtual void quantize(CV_OUT Mat& dst) const =0; - - /** - * \brief Extract most discriminant features at current pyramid level to form a new template. - * - * \param[out] templ The new template. - */ - CV_WRAP virtual bool extractTemplate(CV_OUT Template& templ) const =0; - - /** - * \brief Go to the next pyramid level. - * - * \todo Allow pyramid scale factor other than 2 - */ - CV_WRAP virtual void pyrDown() =0; - -protected: - /// Candidate feature with a score - struct Candidate - { - Candidate(int x, int y, int label, float score); - - /// Sort candidates with high score to the front - bool operator<(const Candidate& rhs) const - { - return score > rhs.score; - } - - Feature f; - float score; - }; - - /** - * \brief Choose candidate features so that they are not bunched together. - * - * \param[in] candidates Candidate features sorted by score. - * \param[out] features Destination vector of selected features. - * \param[in] num_features Number of candidates to select. - * \param[in] distance Hint for desired distance between features. - */ - static void selectScatteredFeatures(const std::vector& candidates, - std::vector& features, - size_t num_features, float distance); -}; - -inline QuantizedPyramid::Candidate::Candidate(int x, int y, int label, float _score) : f(x, y, label), score(_score) {} - -/** - * \brief Interface for modalities that plug into the LINE template matching representation. - * - * \todo Max response, to allow optimization of summing (255/MAX) features as uint8 - */ -class CV_EXPORTS_W Modality -{ -public: - // Virtual destructor - virtual ~Modality() {} - - /** - * \brief Form a quantized image pyramid from a source image. - * - * \param[in] src The source image. Type depends on the modality. - * \param[in] mask Optional mask. If not empty, unmasked pixels are set to zero - * in quantized image and cannot be extracted as features. - */ - CV_WRAP Ptr process(const Mat& src, - const Mat& mask = Mat()) const - { - return processImpl(src, mask); - } - - CV_WRAP virtual String name() const =0; - - CV_WRAP virtual void read(const FileNode& fn) =0; - virtual void write(FileStorage& fs) const =0; - - /** - * \brief Create modality by name. - * - * The following modality types are supported: - * - "ColorGradient" - * - "DepthNormal" - */ - CV_WRAP static Ptr create(const String& modality_type); - - /** - * \brief Load a modality from file. - */ - CV_WRAP static Ptr create(const FileNode& fn); - -protected: - // Indirection is because process() has a default parameter. - virtual Ptr processImpl(const Mat& src, - const Mat& mask) const =0; -}; - -/** - * \brief Modality that computes quantized gradient orientations from a color image. - */ -class CV_EXPORTS_W ColorGradient : public Modality -{ -public: - /** - * \brief Default constructor. Uses reasonable default parameter values. - */ - ColorGradient(); - - /** - * \brief Constructor. - * - * \param weak_threshold When quantizing, discard gradients with magnitude less than this. - * \param num_features How many features a template must contain. - * \param strong_threshold Consider as candidate features only gradients whose norms are - * larger than this. - */ - ColorGradient(float weak_threshold, size_t num_features, float strong_threshold); - - CV_WRAP static Ptr create(float weak_threshold, size_t num_features, float strong_threshold); - - virtual String name() const CV_OVERRIDE; - - virtual void read(const FileNode& fn) CV_OVERRIDE; - virtual void write(FileStorage& fs) const CV_OVERRIDE; - - CV_PROP float weak_threshold; - CV_PROP size_t num_features; - CV_PROP float strong_threshold; - -protected: - virtual Ptr processImpl(const Mat& src, - const Mat& mask) const CV_OVERRIDE; -}; - -/** - * \brief Modality that computes quantized surface normals from a dense depth map. - */ -class CV_EXPORTS_W DepthNormal : public Modality -{ -public: - /** - * \brief Default constructor. Uses reasonable default parameter values. - */ - DepthNormal(); - - /** - * \brief Constructor. - * - * \param distance_threshold Ignore pixels beyond this distance. - * \param difference_threshold When computing normals, ignore contributions of pixels whose - * depth difference with the central pixel is above this threshold. - * \param num_features How many features a template must contain. - * \param extract_threshold Consider as candidate feature only if there are no differing - * orientations within a distance of extract_threshold. - */ - DepthNormal(int distance_threshold, int difference_threshold, size_t num_features, - int extract_threshold); - - CV_WRAP static Ptr create(int distance_threshold, int difference_threshold, - size_t num_features, int extract_threshold); - - virtual String name() const CV_OVERRIDE; - - virtual void read(const FileNode& fn) CV_OVERRIDE; - virtual void write(FileStorage& fs) const CV_OVERRIDE; - - CV_PROP int distance_threshold; - CV_PROP int difference_threshold; - CV_PROP size_t num_features; - CV_PROP int extract_threshold; - -protected: - virtual Ptr processImpl(const Mat& src, - const Mat& mask) const CV_OVERRIDE; -}; - -/** - * \brief Debug function to colormap a quantized image for viewing. - */ -CV_EXPORTS_W void colormap(const Mat& quantized, CV_OUT Mat& dst); - -/** - * \brief Represents a successful template match. - */ -struct CV_EXPORTS_W_SIMPLE Match -{ - CV_WRAP Match() - { - } - - CV_WRAP Match(int x, int y, float similarity, const String& class_id, int template_id); - - /// Sort matches with high similarity to the front - bool operator<(const Match& rhs) const - { - // Secondarily sort on template_id for the sake of duplicate removal - if (similarity != rhs.similarity) - return similarity > rhs.similarity; - else - return template_id < rhs.template_id; - } - - bool operator==(const Match& rhs) const - { - return x == rhs.x && y == rhs.y && similarity == rhs.similarity && class_id == rhs.class_id; - } - - CV_PROP_RW int x; - CV_PROP_RW int y; - CV_PROP_RW float similarity; - CV_PROP_RW String class_id; - CV_PROP_RW int template_id; -}; - -inline -Match::Match(int _x, int _y, float _similarity, const String& _class_id, int _template_id) - : x(_x), y(_y), similarity(_similarity), class_id(_class_id), template_id(_template_id) -{} - -/** - * \brief Object detector using the LINE template matching algorithm with any set of - * modalities. - */ -class CV_EXPORTS_W Detector -{ -public: - /** - * \brief Empty constructor, initialize with read(). - */ - CV_WRAP Detector(); - - /** - * \brief Constructor. - * - * \param modalities Modalities to use (color gradients, depth normals, ...). - * \param T_pyramid Value of the sampling step T at each pyramid level. The - * number of pyramid levels is T_pyramid.size(). - */ - CV_WRAP Detector(const std::vector< Ptr >& modalities, const std::vector& T_pyramid); - - /** - * \brief Detect objects by template matching. - * - * Matches globally at the lowest pyramid level, then refines locally stepping up the pyramid. - * - * \param sources Source images, one for each modality. - * \param threshold Similarity threshold, a percentage between 0 and 100. - * \param[out] matches Template matches, sorted by similarity score. - * \param class_ids If non-empty, only search for the desired object classes. - * \param[out] quantized_images Optionally return vector of quantized images. - * \param masks The masks for consideration during matching. The masks should be CV_8UC1 - * where 255 represents a valid pixel. If non-empty, the vector must be - * the same size as sources. Each element must be - * empty or the same size as its corresponding source. - */ - CV_WRAP void match(const std::vector& sources, float threshold, CV_OUT std::vector& matches, - const std::vector& class_ids = std::vector(), - OutputArrayOfArrays quantized_images = noArray(), - const std::vector& masks = std::vector()) const; - - /** - * \brief Add new object template. - * - * \param sources Source images, one for each modality. - * \param class_id Object class ID. - * \param object_mask Mask separating object from background. - * \param[out] bounding_box Optionally return bounding box of the extracted features. - * - * \return Template ID, or -1 if failed to extract a valid template. - */ - CV_WRAP int addTemplate(const std::vector& sources, const String& class_id, - const Mat& object_mask, CV_OUT Rect* bounding_box = NULL); - - /** - * \brief Add a new object template computed by external means. - */ - CV_WRAP int addSyntheticTemplate(const std::vector