From 4cfbee70bd9b25dba9f8d80a4b8242b95f2436ba Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Wed, 20 Nov 2013 13:47:35 +0400 Subject: [PATCH 1/5] Simplified the Windows implementation of CV_XADD. _InterlockedExchangeAdd is a Visual Studio intrinsic that's available for all architectures and in all VS versions that we care about. It's also faster than the underscore-less function, since it's an intrinsic. We also don't need to declare it ourselves. It is, however, a Visual Studio-specific intrinsic, so I changed the preprocessing condition accordingly. Fixes . --- modules/core/include/opencv2/core/cvdef.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index 53d399546e..c831e8091b 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -458,15 +458,8 @@ CV_INLINE int cvIsInf( double value ) # define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta)) # endif # endif -#elif (defined WIN32 || defined _WIN32 || defined WINCE) && (!defined RC_INVOKED) -# if !defined(_M_AMD64) && !defined(_M_IA64) && !defined(_M_ARM) - CV_EXTERN_C __declspec(dllimport) long __stdcall InterlockedExchangeAdd(long volatile *Addend, long Value); -# define CV_XADD(addr, delta) (int)InterlockedExchangeAdd((long volatile*)addr, delta) -# else - CV_EXTERN_C long _InterlockedExchangeAdd (long volatile *Addend, long Value); -# pragma intrinsic(_InterlockedExchangeAdd) -# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta) -# endif +#elif defined _MSC_VER && !defined RC_INVOKED +# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta) #else CV_INLINE CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; } #endif From fc49d33c8d17dd6c5e3de6f23024d1d4fa98e920 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Thu, 21 Nov 2013 18:26:38 +0400 Subject: [PATCH 2/5] Gave cv::String appropriate += operators. Note that since String is a reference to an immutable string, this doesn't actually change the string; it just replaces *this with a reference to the concatenated string. --- modules/core/include/opencv2/core/cvstd.hpp | 26 +++++++++++++++++++ .../core/include/opencv2/core/cvstd.inl.hpp | 7 +++++ 2 files changed, 33 insertions(+) diff --git a/modules/core/include/opencv2/core/cvstd.hpp b/modules/core/include/opencv2/core/cvstd.hpp index afdeb2549a..f15e6a9351 100644 --- a/modules/core/include/opencv2/core/cvstd.hpp +++ b/modules/core/include/opencv2/core/cvstd.hpp @@ -364,6 +364,10 @@ public: 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; @@ -416,6 +420,7 @@ public: 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); @@ -544,6 +549,27 @@ String& String::operator=(char 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 { diff --git a/modules/core/include/opencv2/core/cvstd.inl.hpp b/modules/core/include/opencv2/core/cvstd.inl.hpp index 8642b7442e..ce18da30a3 100644 --- a/modules/core/include/opencv2/core/cvstd.inl.hpp +++ b/modules/core/include/opencv2/core/cvstd.inl.hpp @@ -103,6 +103,13 @@ String& String::operator = (const std::string& str) return *this; } +inline +String& String::operator += (const std::string& str) +{ + *this = *this + str; + return *this; +} + inline String::operator std::string() const { From dd817857b41eda7644c199fbd8589ff95c741c71 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Fri, 22 Nov 2013 16:55:30 +0400 Subject: [PATCH 3/5] Replaced most of the instances of "s = s +" with "s +=". This resynchronizes master code with 2.4. I say "most", because I might have missed some due to different spacing; I'll deal with those instances later if I find them. --- modules/ocl/src/arithm.cpp | 4 ++-- modules/ocl/src/cl_operations.cpp | 4 ++-- modules/ocl/src/cl_programcache.cpp | 6 +++--- modules/ocl/src/haar.cpp | 18 +++++++++--------- modules/ocl/src/imgproc.cpp | 16 ++++++++-------- modules/ocl/src/mcwutil.cpp | 2 +- modules/ocl/src/split_merge.cpp | 10 +++++----- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/modules/ocl/src/arithm.cpp b/modules/ocl/src/arithm.cpp index 0acb4c2055..77845604ae 100644 --- a/modules/ocl/src/arithm.cpp +++ b/modules/ocl/src/arithm.cpp @@ -505,7 +505,7 @@ static void arithmetic_minMax_run(const oclMat &src, const oclMat & mask, cl_mem args.push_back( std::make_pair( sizeof(cl_int) , (void *)&minvalid_cols )); args.push_back( std::make_pair( sizeof(cl_int) , (void *)&moffset )); - kernelName = kernelName + "_mask"; + kernelName += "_mask"; } size_t globalThreads[3] = {groupnum * 256, 1, 1}; @@ -634,7 +634,7 @@ static void arithm_absdiff_nonsaturate_run(const oclMat & src1, const oclMat & s args.push_back( std::make_pair( sizeof(cl_int), (void *)&src2step1 )); args.push_back( std::make_pair( sizeof(cl_int), (void *)&src2offset1 )); - kernelName = kernelName + "_binary"; + kernelName += "_binary"; } args.push_back( std::make_pair( sizeof(cl_mem), (void *)&diff.data )); diff --git a/modules/ocl/src/cl_operations.cpp b/modules/ocl/src/cl_operations.cpp index a3b7c71e57..f618e02012 100644 --- a/modules/ocl/src/cl_operations.cpp +++ b/modules/ocl/src/cl_operations.cpp @@ -379,7 +379,7 @@ cl_kernel openCLGetKernelFromSource(Context *ctx, const cv::ocl::ProgramEntry* s idxStr << "_C" << channels; if(depth != -1) idxStr << "_D" << depth; - kernelName = kernelName + idxStr.str(); + kernelName += idxStr.str(); std::string fixedOptions = removeDuplicatedWhiteSpaces(build_options); cl_kernel kernel = openCLGetKernelFromSource(ctx, source, kernelName, fixedOptions.c_str()); @@ -497,7 +497,7 @@ void openCLExecuteKernelInterop(Context *ctx, const cv::ocl::ProgramSource& sour idxStr << "_C" << channels; if(depth != -1) idxStr << "_D" << depth; - kernelName = kernelName + idxStr.str(); + kernelName += idxStr.str(); std::string name = std::string("custom_") + source.name; ProgramEntry program = { name.c_str(), source.programStr, source.programHash }; diff --git a/modules/ocl/src/cl_programcache.cpp b/modules/ocl/src/cl_programcache.cpp index 245bf3330a..56f0213c5e 100644 --- a/modules/ocl/src/cl_programcache.cpp +++ b/modules/ocl/src/cl_programcache.cpp @@ -489,11 +489,11 @@ cl_program ProgramCache::getProgram(const Context *ctx, const cv::ocl::ProgramEn String all_build_options; if (!ctx->getDeviceInfo().compilationExtraOptions.empty()) - all_build_options = all_build_options + ctx->getDeviceInfo().compilationExtraOptions; + all_build_options += ctx->getDeviceInfo().compilationExtraOptions; if (build_options != NULL) { - all_build_options = all_build_options + " "; - all_build_options = all_build_options + build_options; + all_build_options += " "; + all_build_options += build_options; } const DeviceInfo& devInfo = ctx->getDeviceInfo(); String filename = binpath + (source->name ? source->name : "NULL") + "_" + devInfo.platform->platformName + "_" + devInfo.deviceName + ".clb"; diff --git a/modules/ocl/src/haar.cpp b/modules/ocl/src/haar.cpp index c10d089a19..00dfb52e4f 100644 --- a/modules/ocl/src/haar.cpp +++ b/modules/ocl/src/haar.cpp @@ -959,15 +959,15 @@ void OclCascadeClassifier::detectMultiScale(oclMat &gimg, CV_OUT std::vectororig_window_size.width); - options = options + format(" -D WND_SIZE_Y=%d",cascade->orig_window_size.height); - options = options + format(" -D STUMP_BASED=%d",gcascade->is_stump_based); - options = options + format(" -D LSx=%d",localThreads[0]); - options = options + format(" -D LSy=%d",localThreads[1]); - options = options + format(" -D SPLITNODE=%d",splitnode); - options = options + format(" -D SPLITSTAGE=%d",splitstage); - options = options + format(" -D OUTPUTSZ=%d",outputsz); + options += format(" -D NODE_SIZE=%d",NODE_SIZE); + options += format(" -D WND_SIZE_X=%d",cascade->orig_window_size.width); + options += format(" -D WND_SIZE_Y=%d",cascade->orig_window_size.height); + options += format(" -D STUMP_BASED=%d",gcascade->is_stump_based); + options += format(" -D LSx=%d",localThreads[0]); + options += format(" -D LSy=%d",localThreads[1]); + options += format(" -D SPLITNODE=%d",splitnode); + options += format(" -D SPLITSTAGE=%d",splitstage); + options += format(" -D OUTPUTSZ=%d",outputsz); // init candiate global count by 0 int pattern = 0; diff --git a/modules/ocl/src/imgproc.cpp b/modules/ocl/src/imgproc.cpp index 549e9c7b98..593486cc37 100644 --- a/modules/ocl/src/imgproc.cpp +++ b/modules/ocl/src/imgproc.cpp @@ -217,15 +217,15 @@ namespace cv String kernelName = "remap"; if (map1.type() == CV_32FC2 && map2.empty()) - kernelName = kernelName + "_32FC2"; + kernelName += "_32FC2"; else if (map1.type() == CV_16SC2) { - kernelName = kernelName + "_16SC2"; + kernelName += "_16SC2"; if (!map2.empty()) - kernelName = kernelName + "_16UC1"; + kernelName += "_16UC1"; } else if (map1.type() == CV_32FC1 && map2.type() == CV_32FC1) - kernelName = kernelName + "_2_32FC1"; + kernelName += "_2_32FC1"; else CV_Error(Error::StsBadArg, "Unsupported map types"); @@ -916,16 +916,16 @@ namespace cv switch(borderType) { case cv::BORDER_REPLICATE: - option = option + " -D BORDER_REPLICATE"; + option += " -D BORDER_REPLICATE"; break; case cv::BORDER_REFLECT: - option = option + " -D BORDER_REFLECT"; + option += " -D BORDER_REFLECT"; break; case cv::BORDER_REFLECT101: - option = option + " -D BORDER_REFLECT101"; + option += " -D BORDER_REFLECT101"; break; case cv::BORDER_WRAP: - option = option + " -D BORDER_WRAP"; + option += " -D BORDER_WRAP"; break; } openCLExecuteKernel(src.clCxt, &imgproc_sobel3, "sobel3", gt2, lt2, args, -1, -1, option.c_str() ); diff --git a/modules/ocl/src/mcwutil.cpp b/modules/ocl/src/mcwutil.cpp index f6efbf7adc..e5dfdd44a5 100644 --- a/modules/ocl/src/mcwutil.cpp +++ b/modules/ocl/src/mcwutil.cpp @@ -64,7 +64,7 @@ namespace cv idxStr << "_C" << channels; if(depth != -1) idxStr << "_D" << depth; - kernelName = kernelName + idxStr.str().c_str(); + kernelName += idxStr.str().c_str(); cl_kernel kernel; kernel = openCLGetKernelFromSource(clCxt, source, kernelName, build_options); diff --git a/modules/ocl/src/split_merge.cpp b/modules/ocl/src/split_merge.cpp index 0bd5eb7ebb..5838697474 100644 --- a/modules/ocl/src/split_merge.cpp +++ b/modules/ocl/src/split_merge.cpp @@ -234,13 +234,13 @@ namespace cv (int)VEC_SIZE, depth, channels); if (dst0Aligned) - build_options = build_options + " -D DST0_ALIGNED"; + build_options += " -D DST0_ALIGNED"; if (dst1Aligned) - build_options = build_options + " -D DST1_ALIGNED"; + build_options += " -D DST1_ALIGNED"; if (dst2Aligned) - build_options = build_options + " -D DST2_ALIGNED"; + build_options += " -D DST2_ALIGNED"; if (dst3Aligned) - build_options = build_options + " -D DST3_ALIGNED"; + build_options += " -D DST3_ALIGNED"; const DeviceInfo& devInfo = clCtx->getDeviceInfo(); @@ -251,7 +251,7 @@ namespace cv && (devInfo.deviceVersion.find("Build 56860") != std::string::npos || devInfo.deviceVersion.find("Build 76921") != std::string::npos || devInfo.deviceVersion.find("Build 78712") != std::string::npos)) - build_options = build_options + " -D BYPASS_VSTORE=true"; + build_options += " -D BYPASS_VSTORE=true"; size_t globalThreads[3] = { divUp(src.cols, VEC_SIZE), src.rows, 1 }; openCLExecuteKernel(clCtx, &split_mat, kernelName, globalThreads, NULL, args, -1, -1, build_options.c_str()); From 88b2fe9dbb786ebd3dec3889e8194c0b52bb8e72 Mon Sep 17 00:00:00 2001 From: Jason Newton Date: Sun, 24 Nov 2013 01:20:07 -0800 Subject: [PATCH 4/5] correct upper bound for maximum number of labels for 8-way connectivity --- modules/imgproc/src/connectedcomponents.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/imgproc/src/connectedcomponents.cpp b/modules/imgproc/src/connectedcomponents.cpp index 41cb480945..9212992730 100644 --- a/modules/imgproc/src/connectedcomponents.cpp +++ b/modules/imgproc/src/connectedcomponents.cpp @@ -195,11 +195,9 @@ namespace cv{ CV_Assert(connectivity == 8 || connectivity == 4); const int rows = L.rows; const int cols = L.cols; - size_t Plength = (size_t(rows + 3 - 1)/3) * (size_t(cols + 3 - 1)/3); - if(connectivity == 4){ - Plength = 4 * Plength;//a quick and dirty upper bound, an exact answer exists if you want to find it - //the 4 comes from the fact that a 3x3 block can never have more than 4 unique labels - } + //A quick and dirty upper bound for the maximimum number of labels. The 4 comes from + //the fact that a 3x3 block can never have more than 4 unique labels for both 4 & 8-way + const size_t Plength = 4 * (size_t(rows + 3 - 1)/3) * (size_t(cols + 3 - 1)/3); LabelT *P = (LabelT *) fastMalloc(sizeof(LabelT) * Plength); P[0] = 0; LabelT lunique = 1; From e4793e3d5e86d46c8c3247f1ef99553d2b8c1569 Mon Sep 17 00:00:00 2001 From: GregoryMorse Date: Mon, 18 Nov 2013 20:25:50 +0800 Subject: [PATCH 5/5] Update system.cpp Fixed to use native C++ instead of C++/CX although it does require significantly more code, it goes along with the spirit of keeping the project in native C++ Update system.cpp Cleaned up whitespace, removed redundant code and added edge cases for string cleanup Update system.cpp Fixed compiler warning over comma operator clause Update system.cpp NULL initialization Update system.cpp Fixed use of WindowsGetStringRawBuffer which returns internal pointer to buffer Update system.cpp Support C++/CX and native C++ through conditional compilation. Fixed style - long lines, comma operators, long conditional. Optimized string usage to use reference. Update system.cpp Fixed conditional compilation around include and library Update system.cpp Fixed trailing space Update system.cpp Cleaned up whitespace, removed redundant code and added edge cases for string cleanup Update system.cpp Fixed compiler warning over comma operator clause Update system.cpp NULL initialization Update system.cpp Fixed use of WindowsGetStringRawBuffer which returns internal pointer to buffer Update system.cpp Support C++/CX and native C++ through conditional compilation. Fixed style - long lines, comma operators, long conditional. Optimized string usage to use reference. Update system.cpp Fixed conditional compilation around include and library Update system.cpp Fixed trailing space --- modules/core/src/system.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index c45ffa0811..729903b467 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -87,10 +87,41 @@ #ifdef HAVE_WINRT #include +#ifndef __cplusplus_winrt +#include +#pragma comment(lib, "runtimeobject.lib") +#endif std::wstring GetTempPathWinRT() { +#ifdef __cplusplus_winrt return std::wstring(Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data()); +#else + Microsoft::WRL::ComPtr appdataFactory; + Microsoft::WRL::ComPtr appdataRef; + Microsoft::WRL::ComPtr storagefolderRef; + Microsoft::WRL::ComPtr storageitemRef; + HSTRING str; + HSTRING_HEADER hstrHead; + std::wstring wstr; + if (FAILED(WindowsCreateStringReference(RuntimeClass_Windows_Storage_ApplicationData, + (UINT32)wcslen(RuntimeClass_Windows_Storage_ApplicationData), &hstrHead, &str))) + return wstr; + if (FAILED(RoGetActivationFactory(str, IID_PPV_ARGS(appdataFactory.ReleaseAndGetAddressOf())))) + return wstr; + if (FAILED(appdataFactory->get_Current(appdataRef.ReleaseAndGetAddressOf()))) + return wstr; + if (FAILED(appdataRef->get_TemporaryFolder(storagefolderRef.ReleaseAndGetAddressOf()))) + return wstr; + if (FAILED(storagefolderRef.As(&storageitemRef))) + return wstr; + str = NULL; + if (FAILED(storageitemRef->get_Path(&str))) + return wstr; + wstr = WindowsGetStringRawBuffer(str, NULL); + WindowsDeleteString(str); + return wstr; +#endif } std::wstring GetTempFileNameWinRT(std::wstring prefix)