Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Oct 2, 2018
2 parents ae4c72a + ee0c985 commit 690fb05
Show file tree
Hide file tree
Showing 22 changed files with 180 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
return __atomic_load_n(ptr, __ATOMIC_RELAXED);
}

inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
__atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_RELEASE, __ATOMIC_ACQUIRE);
return old_value;
}

#endif // defined(__LP64__)

} // namespace internal
Expand Down
1 change: 1 addition & 0 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if(DOXYGEN_FOUND)
add_custom_target(doxygen)

# not documented modules list
set(blacklist "${DOXYGEN_BLACKLIST}")
list(APPEND blacklist "ts" "java_bindings_generator" "java" "python_bindings_generator" "python2" "python3" "js" "world")
unset(CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT)
unset(CMAKE_DOXYGEN_TUTORIAL_JS_ROOT)
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/imgproc/pyramids/pyramids.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Theory
entire pyramid.
- The procedure above was useful to downsample an image. What if we want to make it bigger?:
columns filled with zeros (\f$0 \f$)
- First, upsize the image to twice the original in each dimension, wit the new even rows and
- First, upsize the image to twice the original in each dimension, with the new even rows and
- Perform a convolution with the same kernel shown above (multiplied by 4) to approximate the
values of the "missing pixels"
- These two procedures (downsampling and upsampling as explained above) are implemented by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
#ifndef OPENCV_CONFIGURATION_PRIVATE_HPP
#define OPENCV_CONFIGURATION_PRIVATE_HPP

#include "opencv2/core/cvstd.hpp"
#include <vector>
#include <string>

namespace cv { namespace utils {

typedef std::vector<std::string> Paths;
CV_EXPORTS bool getConfigurationParameterBool(const char* name, bool defaultValue);
CV_EXPORTS size_t getConfigurationParameterSizeT(const char* name, size_t defaultValue);
CV_EXPORTS cv::String getConfigurationParameterString(const char* name, const char* defaultValue);
CV_EXPORTS Paths getConfigurationParameterPaths(const char* name, const Paths &defaultValue = Paths());

}} // namespace

Expand Down
17 changes: 17 additions & 0 deletions modules/core/src/ocl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ static const bool CV_OPENCL_DISABLE_BUFFER_RECT_OPERATIONS = utils::getConfigura
#endif
);

static const String getBuildExtraOptions()
{
static String param_buildExtraOptions;
static bool initialized = false;
if (!initialized)
{
param_buildExtraOptions = utils::getConfigurationParameterString("OPENCV_OPENCL_BUILD_EXTRA_OPTIONS", "");
initialized = true;
if (!param_buildExtraOptions.empty())
CV_LOG_WARNING(NULL, "OpenCL: using extra build options: '" << param_buildExtraOptions << "'");
}
return param_buildExtraOptions;
}

#endif // HAVE_OPENCL

struct UMat2D
Expand Down Expand Up @@ -3517,6 +3531,9 @@ struct Program::Impl
buildflags = joinBuildOptions(buildflags, " -D AMD_DEVICE");
else if (device.isIntel())
buildflags = joinBuildOptions(buildflags, " -D INTEL_DEVICE");
const String param_buildExtraOptions = getBuildExtraOptions();
if (!param_buildExtraOptions.empty())
buildflags = joinBuildOptions(buildflags, param_buildExtraOptions);
}
compile(ctx, src_, errmsg);
}
Expand Down
116 changes: 89 additions & 27 deletions modules/core/src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

#include "precomp.hpp"
#include <iostream>
#include <ostream>

#include <opencv2/core/utils/configuration.private.hpp>
#include <opencv2/core/utils/trace.private.hpp>
Expand Down Expand Up @@ -1594,18 +1595,26 @@ static TLSData<ThreadID>& getThreadIDTLS()
} // namespace
int utils::getThreadID() { return getThreadIDTLS().get()->id; }

bool utils::getConfigurationParameterBool(const char* name, bool defaultValue)

class ParseError
{
#ifdef NO_GETENV
const char* envValue = NULL;
#else
const char* envValue = getenv(name);
#endif
if (envValue == NULL)
std::string bad_value;
public:
ParseError(const std::string bad_value_) :bad_value(bad_value_) {}
std::string toString(const std::string &param) const
{
return defaultValue;
std::ostringstream out;
out << "Invalid value for parameter " << param << ": " << bad_value;
return out.str();
}
cv::String value = envValue;
};

template <typename T>
T parseOption(const std::string &);

template<>
inline bool parseOption(const std::string & value)
{
if (value == "1" || value == "True" || value == "true" || value == "TRUE")
{
return true;
Expand All @@ -1614,22 +1623,12 @@ bool utils::getConfigurationParameterBool(const char* name, bool defaultValue)
{
return false;
}
CV_Error(cv::Error::StsBadArg, cv::format("Invalid value for %s parameter: %s", name, value.c_str()));
throw ParseError(value);
}


size_t utils::getConfigurationParameterSizeT(const char* name, size_t defaultValue)
template<>
inline size_t parseOption(const std::string &value)
{
#ifdef NO_GETENV
const char* envValue = NULL;
#else
const char* envValue = getenv(name);
#endif
if (envValue == NULL)
{
return defaultValue;
}
cv::String value = envValue;
size_t pos = 0;
for (; pos < value.size(); pos++)
{
Expand All @@ -1645,17 +1644,80 @@ size_t utils::getConfigurationParameterSizeT(const char* name, size_t defaultVal
return v * 1024 * 1024;
else if (suffixStr == "KB" || suffixStr == "Kb" || suffixStr == "kb")
return v * 1024;
CV_Error(cv::Error::StsBadArg, cv::format("Invalid value for %s parameter: %s", name, value.c_str()));
throw ParseError(value);
}

cv::String utils::getConfigurationParameterString(const char* name, const char* defaultValue)
template<>
inline cv::String parseOption(const std::string &value)
{
return value;
}

template<>
inline utils::Paths parseOption(const std::string &value)
{
utils::Paths result;
#ifdef _WIN32
const char sep = ';';
#else
const char sep = ':';
#endif
size_t start_pos = 0;
while (start_pos != std::string::npos)
{
const size_t pos = value.find(sep, start_pos);
const std::string one_piece(value, start_pos, pos == std::string::npos ? pos : pos - start_pos);
if (!one_piece.empty())
result.push_back(one_piece);
start_pos = pos == std::string::npos ? pos : pos + 1;
}
return result;
}

static inline const char * envRead(const char * name)
{
#ifdef NO_GETENV
const char* envValue = NULL;
CV_UNUSED(name);
return NULL;
#else
const char* envValue = getenv(name);
return getenv(name);
#endif
return envValue ? cv::String(envValue) : (defaultValue ? cv::String(defaultValue) : cv::String());
}

template<typename T>
inline T read(const std::string & k, const T & defaultValue)
{
try
{
const char * res = envRead(k.c_str());
if (res)
return parseOption<T>(std::string(res));
}
catch (const ParseError &err)
{
CV_Error(cv::Error::StsBadArg, err.toString(k));
}
return defaultValue;
}

bool utils::getConfigurationParameterBool(const char* name, bool defaultValue)
{
return read<bool>(name, defaultValue);
}

size_t utils::getConfigurationParameterSizeT(const char* name, size_t defaultValue)
{
return read<size_t>(name, defaultValue);
}

cv::String utils::getConfigurationParameterString(const char* name, const char* defaultValue)
{
return read<cv::String>(name, defaultValue ? cv::String(defaultValue) : cv::String());
}

utils::Paths utils::getConfigurationParameterPaths(const char* name, const utils::Paths &defaultValue)
{
return read<utils::Paths>(name, defaultValue);
}


Expand Down
17 changes: 3 additions & 14 deletions modules/dnn/src/opencl/conv_layer_spatial.cl
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,6 @@ convolve_simd(

in_addr += INPUT_PITCH;

Dtype weight_buf[WEIGHT_PREF];
int w_idx=0;

for (int i = 0; i < WEIGHT_PREF; i++)
{
weight_buf[i] = weights[weight_addr];
weight_addr += SIMD_SIZE;
}

#define BLOCK_IN(n, c) intel_sub_group_shuffle(in_buf[n], (c))

int kr = 0; // kr = Kernel Row
Expand All @@ -297,20 +288,18 @@ convolve_simd(
int kc = 0; // kc = Kernel Column
LOOP(KERNEL_WIDTH, kc,
{
Dtype weight_value = weights[weight_addr];
weight_addr += SIMD_SIZE;
for (int br=0; br < OUT_BLOCK_HEIGHT; br++)
{
for(int bc=0; bc < OUT_BLOCK_WIDTH; bc++)
{
Dtype input = BLOCK_IN((br * STRIDE_Y + kr * DILATION_Y), bc * STRIDE_X + kc * DILATION_X);
out[br * OUT_BLOCK_WIDTH + bc] = mad(weight_buf[w_idx % WEIGHT_PREF], input, out[br * OUT_BLOCK_WIDTH + bc]);
out[br * OUT_BLOCK_WIDTH + bc] = mad(weight_value, input, out[br * OUT_BLOCK_WIDTH + bc]);
}
}
weight_buf[w_idx % WEIGHT_PREF] = weights[weight_addr];
weight_addr += SIMD_SIZE;
++w_idx;
});
});
weight_addr -= WEIGHT_PREF * SIMD_SIZE;
}

fm = fm % ALIGNED_NUM_FILTERS;
Expand Down
2 changes: 1 addition & 1 deletion modules/features2d/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
set(the_description "2D Features Framework")
ocv_define_module(features2d opencv_imgproc OPTIONAL opencv_flann opencv_highgui WRAP java python)
ocv_define_module(features2d opencv_imgproc OPTIONAL opencv_flann opencv_highgui WRAP java python js)
4 changes: 4 additions & 0 deletions modules/features2d/include/opencv2/features2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ class CV_EXPORTS KeyPointsFilter

/** @brief Abstract base class for 2D image feature detectors and descriptor extractors
*/
#ifdef __EMSCRIPTEN__
class CV_EXPORTS_W Feature2D : public Algorithm
#else
class CV_EXPORTS_W Feature2D : public virtual Algorithm
#endif
{
public:
virtual ~Feature2D();
Expand Down
2 changes: 2 additions & 0 deletions modules/features2d/src/matchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
//M*/

#include "precomp.hpp"
#ifdef HAVE_OPENCV_FLANN
#include "opencv2/flann/miniflann.hpp"
#endif
#include <limits>
#include "opencl_kernels_features2d.hpp"

Expand Down
4 changes: 3 additions & 1 deletion modules/imgcodecs/include/opencv2/imgcodecs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace cv
//! Imread flags
enum ImreadModes {
IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).
IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image.
IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image (codec internal conversion).
IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.
Expand Down Expand Up @@ -155,6 +155,8 @@ Currently, the following file formats are supported:
- The function determines the type of an image by the content, not by the file extension.
- In the case of color images, the decoded images will have the channels stored in **B G R** order.
- When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available.
Results may differ to the output of cvtColor()
- On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg,
libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs,
and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FpsMeter {
private static final int STEP = 20;
private static final DecimalFormat FPS_FORMAT = new DecimalFormat("0.00");

private int mFramesCouner;
private int mFramesCounter;
private double mFrequency;
private long mprevFrameTime;
private String mStrfps;
Expand All @@ -24,7 +24,7 @@ public class FpsMeter {
int mHeight = 0;

public void init() {
mFramesCouner = 0;
mFramesCounter = 0;
mFrequency = Core.getTickFrequency();
mprevFrameTime = Core.getTickCount();
mStrfps = "";
Expand All @@ -39,8 +39,8 @@ public void measure() {
init();
mIsInitialized = true;
} else {
mFramesCouner++;
if (mFramesCouner % STEP == 0) {
mFramesCounter++;
if (mFramesCounter % STEP == 0) {
long time = Core.getTickCount();
double fps = STEP * mFrequency / (time - mprevFrameTime);
mprevFrameTime = time;
Expand Down
Loading

0 comments on commit 690fb05

Please sign in to comment.