3 Star 2 Fork 3

crist_xu / opencv_mcu

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
32bit_build_patch.txt 13.92 KB
一键复制 编辑 原始数据 按行查看 历史
crist.xu 提交于 2021-09-13 06:24 . A commit of a sub-opencv enable on MCU
diff --git a/modules/core/include/opencv2/core/saturate.hpp b/modules/core/include/opencv2/core/saturate.hpp
index 8127e3d..6893c0e 100644
--- a/modules/core/include/opencv2/core/saturate.hpp
+++ b/modules/core/include/opencv2/core/saturate.hpp
@@ -89,6 +89,10 @@ template<typename _Tp> static inline _Tp saturate_cast(unsigned v) { return _Tp(
/** @overload */
template<typename _Tp> static inline _Tp saturate_cast(int v) { return _Tp(v); }
/** @overload */
+template<typename _Tp> static inline _Tp saturate_cast(uint32_t v) { return _Tp(v); }
+/** @overload */
+template<typename _Tp> static inline _Tp saturate_cast(int32_t v) { return _Tp(v); }
+/** @overload */
template<typename _Tp> static inline _Tp saturate_cast(float v) { return _Tp(v); }
/** @overload */
template<typename _Tp> static inline _Tp saturate_cast(double v) { return _Tp(v); }
@@ -100,8 +104,10 @@ template<typename _Tp> static inline _Tp saturate_cast(uint64 v) { return _Tp(
template<> inline uchar saturate_cast<uchar>(schar v) { return (uchar)std::max((int)v, 0); }
template<> inline uchar saturate_cast<uchar>(ushort v) { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); }
template<> inline uchar saturate_cast<uchar>(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); }
+template<> inline uchar saturate_cast<uchar>(int32_t v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); }
template<> inline uchar saturate_cast<uchar>(short v) { return saturate_cast<uchar>((int)v); }
template<> inline uchar saturate_cast<uchar>(unsigned v) { return (uchar)std::min(v, (unsigned)UCHAR_MAX); }
+template<> inline uchar saturate_cast<uchar>(uint32_t v) { return (uchar)std::min(v, (uint32_t)UCHAR_MAX); }
template<> inline uchar saturate_cast<uchar>(float v) { int iv = cvRound(v); return saturate_cast<uchar>(iv); }
template<> inline uchar saturate_cast<uchar>(double v) { int iv = cvRound(v); return saturate_cast<uchar>(iv); }
template<> inline uchar saturate_cast<uchar>(int64 v) { return (uchar)((uint64)v <= (uint64)UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); }
@@ -110,8 +116,10 @@ template<> inline uchar saturate_cast<uchar>(uint64 v) { return (uchar)std
template<> inline schar saturate_cast<schar>(uchar v) { return (schar)std::min((int)v, SCHAR_MAX); }
template<> inline schar saturate_cast<schar>(ushort v) { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); }
template<> inline schar saturate_cast<schar>(int v) { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); }
+template<> inline schar saturate_cast<schar>(int32_t v) { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); }
template<> inline schar saturate_cast<schar>(short v) { return saturate_cast<schar>((int)v); }
template<> inline schar saturate_cast<schar>(unsigned v) { return (schar)std::min(v, (unsigned)SCHAR_MAX); }
+template<> inline schar saturate_cast<schar>(uint32_t v) { return (schar)std::min(v, (uint32_t)SCHAR_MAX); }
template<> inline schar saturate_cast<schar>(float v) { int iv = cvRound(v); return saturate_cast<schar>(iv); }
template<> inline schar saturate_cast<schar>(double v) { int iv = cvRound(v); return saturate_cast<schar>(iv); }
template<> inline schar saturate_cast<schar>(int64 v) { return (schar)((uint64)((int64)v-SCHAR_MIN) <= (uint64)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); }
@@ -120,7 +128,9 @@ template<> inline schar saturate_cast<schar>(uint64 v) { return (schar)std
template<> inline ushort saturate_cast<ushort>(schar v) { return (ushort)std::max((int)v, 0); }
template<> inline ushort saturate_cast<ushort>(short v) { return (ushort)std::max((int)v, 0); }
template<> inline ushort saturate_cast<ushort>(int v) { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); }
+template<> inline ushort saturate_cast<ushort>(int32_t v) { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); }
template<> inline ushort saturate_cast<ushort>(unsigned v) { return (ushort)std::min(v, (unsigned)USHRT_MAX); }
+template<> inline ushort saturate_cast<ushort>(uint32_t v) { return (ushort)std::min(v, (uint32_t)USHRT_MAX); }
template<> inline ushort saturate_cast<ushort>(float v) { int iv = cvRound(v); return saturate_cast<ushort>(iv); }
template<> inline ushort saturate_cast<ushort>(double v) { int iv = cvRound(v); return saturate_cast<ushort>(iv); }
template<> inline ushort saturate_cast<ushort>(int64 v) { return (ushort)((uint64)v <= (uint64)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); }
@@ -129,29 +139,51 @@ template<> inline ushort saturate_cast<ushort>(uint64 v) { return (ushort)st
template<> inline short saturate_cast<short>(ushort v) { return (short)std::min((int)v, SHRT_MAX); }
template<> inline short saturate_cast<short>(int v) { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); }
template<> inline short saturate_cast<short>(unsigned v) { return (short)std::min(v, (unsigned)SHRT_MAX); }
+template<> inline short saturate_cast<short>(int32_t v) { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); }
+template<> inline short saturate_cast<short>(uint32_t v) { return (short)std::min(v, (uint32_t)SHRT_MAX); }
template<> inline short saturate_cast<short>(float v) { int iv = cvRound(v); return saturate_cast<short>(iv); }
template<> inline short saturate_cast<short>(double v) { int iv = cvRound(v); return saturate_cast<short>(iv); }
template<> inline short saturate_cast<short>(int64 v) { return (short)((uint64)((int64)v - SHRT_MIN) <= (uint64)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); }
template<> inline short saturate_cast<short>(uint64 v) { return (short)std::min(v, (uint64)SHRT_MAX); }
template<> inline int saturate_cast<int>(unsigned v) { return (int)std::min(v, (unsigned)INT_MAX); }
+template<> inline int saturate_cast<int>(uint_least32_t v) { return (int)std::min(v, (uint_least32_t)INT_MAX); }
template<> inline int saturate_cast<int>(int64 v) { return (int)((uint64)(v - INT_MIN) <= (uint64)UINT_MAX ? v : v > 0 ? INT_MAX : INT_MIN); }
template<> inline int saturate_cast<int>(uint64 v) { return (int)std::min(v, (uint64)INT_MAX); }
template<> inline int saturate_cast<int>(float v) { return cvRound(v); }
template<> inline int saturate_cast<int>(double v) { return cvRound(v); }
+template<> inline int32_t saturate_cast<int32_t>(unsigned v) { return (int)std::min(v, (unsigned)INT_MAX); }
+template<> inline int32_t saturate_cast<int32_t>(uint_least32_t v) { return (int)std::min(v, (uint_least32_t)INT_MAX); }
+template<> inline int32_t saturate_cast<int32_t>(int64 v) { return (int)((uint64)(v - INT_MIN) <= (uint64)UINT_MAX ? v : v > 0 ? INT_MAX : INT_MIN); }
+template<> inline int32_t saturate_cast<int32_t>(uint64 v) { return (int)std::min(v, (uint64)INT_MAX); }
+template<> inline int32_t saturate_cast<int32_t>(float v) { return cvRound(v); }
+template<> inline int32_t saturate_cast<int32_t>(double v) { return cvRound(v); }
+
template<> inline unsigned saturate_cast<unsigned>(schar v) { return (unsigned)std::max(v, (schar)0); }
template<> inline unsigned saturate_cast<unsigned>(short v) { return (unsigned)std::max(v, (short)0); }
template<> inline unsigned saturate_cast<unsigned>(int v) { return (unsigned)std::max(v, (int)0); }
+template<> inline unsigned saturate_cast<unsigned>(int32_t v) { return (unsigned)std::max(v, (int32_t)0); }
template<> inline unsigned saturate_cast<unsigned>(int64 v) { return (unsigned)((uint64)v <= (uint64)UINT_MAX ? v : v > 0 ? UINT_MAX : 0); }
template<> inline unsigned saturate_cast<unsigned>(uint64 v) { return (unsigned)std::min(v, (uint64)UINT_MAX); }
// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.
template<> inline unsigned saturate_cast<unsigned>(float v) { return static_cast<unsigned>(cvRound(v)); }
template<> inline unsigned saturate_cast<unsigned>(double v) { return static_cast<unsigned>(cvRound(v)); }
+template<> inline uint32_t saturate_cast<uint32_t>(schar v) { return (unsigned)std::max(v, (schar)0); }
+template<> inline uint32_t saturate_cast<uint32_t>(short v) { return (unsigned)std::max(v, (short)0); }
+template<> inline uint32_t saturate_cast<uint32_t>(int v) { return (unsigned)std::max(v, (int)0); }
+template<> inline uint32_t saturate_cast<uint32_t>(int32_t v) { return (unsigned)std::max(v, (int32_t)0); }
+template<> inline uint32_t saturate_cast<uint32_t>(int64 v) { return (unsigned)((uint64)v <= (uint64)UINT_MAX ? v : v > 0 ? UINT_MAX : 0); }
+template<> inline uint32_t saturate_cast<uint32_t>(uint64 v) { return (unsigned)std::min(v, (uint64)UINT_MAX); }
+// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.
+template<> inline uint32_t saturate_cast<uint32_t>(float v) { return static_cast<unsigned>(cvRound(v)); }
+template<> inline uint32_t saturate_cast<uint32_t>(double v) { return static_cast<unsigned>(cvRound(v)); }
+
template<> inline uint64 saturate_cast<uint64>(schar v) { return (uint64)std::max(v, (schar)0); }
template<> inline uint64 saturate_cast<uint64>(short v) { return (uint64)std::max(v, (short)0); }
template<> inline uint64 saturate_cast<uint64>(int v) { return (uint64)std::max(v, (int)0); }
+template<> inline uint64 saturate_cast<uint64>(int32_t v) { return (uint64)std::max(v, (int32_t)0); }
template<> inline uint64 saturate_cast<uint64>(int64 v) { return (uint64)std::max(v, (int64)0); }
template<> inline int64 saturate_cast<int64>(uint64 v) { return (int64)std::min(v, (uint64)LLONG_MAX); }
@@ -167,11 +199,15 @@ template<> inline float16_t saturate_cast<float16_t>(ushort v) { return float16
template<> inline float16_t saturate_cast<float16_t>(short v) { return float16_t((float)v); }
template<> inline float16_t saturate_cast<float16_t>(unsigned v){ return float16_t((float)v); }
template<> inline float16_t saturate_cast<float16_t>(int v) { return float16_t((float)v); }
+template<> inline float16_t saturate_cast<float16_t>(uint32_t v){ return float16_t((float)v); }
+template<> inline float16_t saturate_cast<float16_t>(int32_t v) { return float16_t((float)v); }
template<> inline float16_t saturate_cast<float16_t>(uint64 v) { return float16_t((float)v); }
template<> inline float16_t saturate_cast<float16_t>(int64 v) { return float16_t((float)v); }
template<> inline float16_t saturate_cast<float16_t>(float v) { return float16_t(v); }
template<> inline float16_t saturate_cast<float16_t>(double v) { return float16_t((float)v); }
+#undef int32_t
+#undef uint32_t
//! @}
} // cv
diff --git a/modules/core/include/opencv2/core/softfloat.hpp b/modules/core/include/opencv2/core/softfloat.hpp
index 485e15c..c34b355 100644
--- a/modules/core/include/opencv2/core/softfloat.hpp
+++ b/modules/core/include/opencv2/core/softfloat.hpp
@@ -82,7 +82,6 @@ namespace cv
*/
//! @{
-
struct softfloat;
struct softdouble;
diff --git a/modules/core/src/softfloat.cpp b/modules/core/src/softfloat.cpp
index a876ee1..a098122 100644
--- a/modules/core/src/softfloat.cpp
+++ b/modules/core/src/softfloat.cpp
@@ -64,7 +64,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "precomp.hpp"
-
#include "opencv2/core/softfloat.hpp"
namespace cv
@@ -221,7 +220,6 @@ static float64_t f64_cos( float64_t x );
/*----------------------------------------------------------------------------
| softfloat and softdouble methods and members
*----------------------------------------------------------------------------*/
-
softfloat::softfloat( const uint32_t a ) { *this = ui32_to_f32(a); }
softfloat::softfloat( const uint64_t a ) { *this = ui64_to_f32(a); }
softfloat::softfloat( const int32_t a ) { *this = i32_to_f32(a); }
diff --git a/modules/imgproc/src/color_lab.cpp b/modules/imgproc/src/color_lab.cpp
index a181880..dd316f2 100644
--- a/modules/imgproc/src/color_lab.cpp
+++ b/modules/imgproc/src/color_lab.cpp
@@ -17,6 +17,13 @@
using cv::softfloat;
+#warning "a compatible solved way"
+#define int32_t int
+#define uint32_t unsigned int
+
+#undef int64_t
+#undef uint64_t
+
static const float * splineBuild(const softfloat* f, size_t n)
{
float* tab = cv::allocSingleton<float>(n * 4);
@@ -3520,7 +3527,6 @@ struct RGB2Luv_b
bool useInterpolation;
};
-
struct Luv2RGBinteger
{
typedef uchar channel_type;
diff --git a/modules/imgproc/src/fixedpoint.inl.hpp b/modules/imgproc/src/fixedpoint.inl.hpp
index f5f433f..71bc024 100644
--- a/modules/imgproc/src/fixedpoint.inl.hpp
+++ b/modules/imgproc/src/fixedpoint.inl.hpp
@@ -9,6 +9,8 @@
#ifndef _CV_FIXEDPOINT_HPP_
#define _CV_FIXEDPOINT_HPP_
+
+
namespace {
class fixedpoint64
diff --git a/modules/imgproc/src/resize.cpp b/modules/imgproc/src/resize.cpp
index 4f82bdd..96e188a 100644
--- a/modules/imgproc/src/resize.cpp
+++ b/modules/imgproc/src/resize.cpp
@@ -57,8 +57,14 @@
#include "resize.hpp"
#include "opencv2/core/softfloat.hpp"
+
+#warning "the compiler will define long as int32_t, and long long as int64_t, in a 32-bit CPU, but inside code will use the int/int32_t mixted"
+#define int32_t int
+#define uint32_t unsigned int
+
#include "fixedpoint.inl.hpp"
+
using namespace cv;
namespace
diff --git a/modules/imgproc/src/smooth.dispatch.cpp b/modules/imgproc/src/smooth.dispatch.cpp
index 69d0758..3bbdc95 100644
--- a/modules/imgproc/src/smooth.dispatch.cpp
+++ b/modules/imgproc/src/smooth.dispatch.cpp
@@ -60,6 +60,10 @@
#include "opencv2/core/softfloat.hpp"
namespace cv {
+#warning "a compatible define, int32_t => int, not long, in 32-bit CPU, the long is also 32bit"
+#define int32_t int
+#define uint32_t unsigned int
+
#include "fixedpoint.inl.hpp"
}
1
https://gitee.com/crist_xu/opencv_mcu.git
git@gitee.com:crist_xu/opencv_mcu.git
crist_xu
opencv_mcu
opencv_mcu
master

搜索帮助