Merge remote-tracking branch 'upstream/3.4' into merge-3.4

pull/13282/head
Alexander Alekhin 6 years ago
commit 8f4e5c2fb8
  1. 4
      CMakeLists.txt
  2. 6
      cmake/OpenCVModule.cmake
  3. 699
      doc/opencv.bib
  4. 2
      modules/core/include/opencv2/core/types_c.h
  5. 7
      modules/core/src/ocl.cpp
  6. 25
      modules/core/src/utils/datafile.cpp
  7. 10
      modules/core/src/utils/filesystem.cpp
  8. 22
      modules/dnn/src/layers/elementwise_layers.cpp
  9. 23
      modules/dnn/src/onnx/onnx_importer.cpp
  10. 35
      modules/dnn/test/test_backends.cpp
  11. 4
      modules/dnn/test/test_darknet_importer.cpp
  12. 4
      modules/dnn/test/test_halide_layers.cpp
  13. 15
      modules/dnn/test/test_layers.cpp
  14. 3
      modules/flann/include/opencv2/flann/dist.h
  15. 2
      modules/highgui/src/precomp.hpp
  16. 2
      modules/highgui/src/window.cpp
  17. 18
      modules/highgui/src/window_w32.cpp
  18. 87
      modules/imgproc/perf/perf_contours.cpp
  19. 175
      modules/imgproc/src/contours.cpp
  20. 14
      modules/python/common.cmake

@ -1478,7 +1478,7 @@ if(BUILD_opencv_python2)
status(" Libraries:" HAVE_opencv_python2 THEN "${PYTHON2_LIBRARIES}" ELSE NO)
endif()
status(" numpy:" PYTHON2_NUMPY_INCLUDE_DIRS THEN "${PYTHON2_NUMPY_INCLUDE_DIRS} (ver ${PYTHON2_NUMPY_VERSION})" ELSE "NO (Python wrappers can not be generated)")
status(" packages path:" PYTHON2_EXECUTABLE THEN "${PYTHON2_PACKAGES_PATH}" ELSE "-")
status(" install path:" HAVE_opencv_python2 THEN "${__INSTALL_PATH_PYTHON2}" ELSE "-")
endif()
if(BUILD_opencv_python3)
@ -1491,7 +1491,7 @@ if(BUILD_opencv_python3)
status(" Libraries:" HAVE_opencv_python3 THEN "${PYTHON3_LIBRARIES}" ELSE NO)
endif()
status(" numpy:" PYTHON3_NUMPY_INCLUDE_DIRS THEN "${PYTHON3_NUMPY_INCLUDE_DIRS} (ver ${PYTHON3_NUMPY_VERSION})" ELSE "NO (Python3 wrappers can not be generated)")
status(" packages path:" PYTHON3_EXECUTABLE THEN "${PYTHON3_PACKAGES_PATH}" ELSE "-")
status(" install path:" HAVE_opencv_python3 THEN "${__INSTALL_PATH_PYTHON3}" ELSE "-")
endif()
status("")

@ -910,7 +910,11 @@ macro(_ocv_create_module)
source_group("Src" FILES "${_VS_VERSION_FILE}")
endif()
endif()
if(WIN32 AND NOT ("${the_module}" STREQUAL "opencv_core" OR "${the_module}" STREQUAL "opencv_world")
if(WIN32 AND NOT (
"${the_module}" STREQUAL "opencv_core" OR
"${the_module}" STREQUAL "opencv_world" OR
"${the_module}" STREQUAL "opencv_cudev"
)
AND (BUILD_SHARED_LIBS AND NOT "x${OPENCV_MODULE_TYPE}" STREQUAL "xSTATIC")
AND NOT OPENCV_SKIP_DLLMAIN_GENERATION
)

File diff suppressed because it is too large Load Diff

@ -364,7 +364,7 @@ IplImage;
CV_INLINE IplImage cvIplImage()
{
#if !defined(CV__ENABLE_C_API_CTORS)
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
IplImage self = CV_STRUCT_INITIALIZER; self.nSize = sizeof(IplImage); return self;
#else
return _IplImage();

@ -2772,6 +2772,7 @@ struct Kernel::Impl
for( int i = 0; i < MAX_ARRS; i++ )
u[i] = 0;
haveTempDstUMats = false;
haveTempSrcUMats = false;
}
void cleanupUMats()
@ -2788,6 +2789,7 @@ struct Kernel::Impl
}
nu = 0;
haveTempDstUMats = false;
haveTempSrcUMats = false;
}
void addUMat(const UMat& m, bool dst)
@ -2798,6 +2800,8 @@ struct Kernel::Impl
nu++;
if(dst && m.u->tempUMat())
haveTempDstUMats = true;
if(m.u->originalUMatData == NULL && m.u->tempUMat())
haveTempSrcUMats = true; // UMat is created on RAW memory (without proper lifetime management, even from Mat)
}
void addImage(const Image2D& image)
@ -2835,6 +2839,7 @@ struct Kernel::Impl
int nu;
std::list<Image2D> images;
bool haveTempDstUMats;
bool haveTempSrcUMats;
};
}} // namespace cv::ocl
@ -3108,6 +3113,8 @@ bool Kernel::Impl::run(int dims, size_t globalsize[], size_t localsize[],
cl_command_queue qq = getQueue(q);
if (haveTempDstUMats)
sync = true;
if (haveTempSrcUMats)
sync = true;
if (timeNS)
sync = true;
cl_event asyncEvent = 0;

@ -24,6 +24,8 @@
#undef min
#undef max
#undef abs
#elif defined(__linux__)
#include <dlfcn.h> // requires -ldl
#elif defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_MAC
@ -123,27 +125,10 @@ static cv::String getModuleLocation(const void* addr)
}
}
#elif defined(__linux__)
std::ifstream fs("/proc/self/maps");
std::string line;
while (std::getline(fs, line, '\n'))
Dl_info info;
if (0 != dladdr(addr, &info))
{
long long int addr_begin = 0, addr_end = 0;
if (2 == sscanf(line.c_str(), "%llx-%llx", &addr_begin, &addr_end))
{
if ((intptr_t)addr >= (intptr_t)addr_begin && (intptr_t)addr < (intptr_t)addr_end)
{
size_t pos = line.rfind(" "); // 2 spaces
if (pos == cv::String::npos)
pos = line.rfind(' '); // 1 spaces
else
pos++;
if (pos == cv::String::npos)
{
CV_LOG_DEBUG(NULL, "Can't parse module path: '" << line << '\'');
}
return line.substr(pos + 1);
}
}
return cv::String(info.dli_fname);
}
#elif defined(__APPLE__)
# if TARGET_OS_MAC

@ -34,7 +34,7 @@
#include <errno.h>
#include <io.h>
#include <stdio.h>
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -178,7 +178,7 @@ cv::String getcwd()
sz = GetCurrentDirectoryA((DWORD)buf.size(), buf.data());
return cv::String(buf.data(), (size_t)sz);
#endif
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__
for(;;)
{
char* p = ::getcwd(buf.data(), buf.size());
@ -212,7 +212,7 @@ bool createDirectory(const cv::String& path)
#else
int result = _mkdir(path.c_str());
#endif
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__
int result = mkdir(path.c_str(), 0777);
#else
int result = -1;
@ -327,7 +327,7 @@ private:
Impl& operator=(const Impl&); // disabled
};
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__
struct FileLock::Impl
{
@ -441,7 +441,7 @@ cv::String getCacheDirectory(const char* sub_directory_name, const char* configu
default_cache_path = "/tmp/";
CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path);
}
#elif defined __linux__ || defined __HAIKU__
#elif defined __linux__ || defined __HAIKU__ || defined __FreeBSD__
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
if (default_cache_path.empty())
{

@ -752,7 +752,8 @@ struct AbsValFunctor
bool supportBackend(int backendId, int)
{
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE;
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE ||
backendId == DNN_BACKEND_INFERENCE_ENGINE;
}
void apply(const float* srcptr, float* dstptr, int len, size_t planeSize, int cn0, int cn1) const
@ -806,8 +807,11 @@ struct AbsValFunctor
#ifdef HAVE_INF_ENGINE
InferenceEngine::CNNLayerPtr initInfEngine(InferenceEngine::LayerParams& lp)
{
CV_Error(Error::StsNotImplemented, "Abs");
return InferenceEngine::CNNLayerPtr();
lp.type = "ReLU";
std::shared_ptr<InferenceEngine::ReLULayer> ieLayer(new InferenceEngine::ReLULayer(lp));
ieLayer->negative_slope = -1;
ieLayer->params["negative_slope"] = "-1.0";
return ieLayer;
}
#endif // HAVE_INF_ENGINE
@ -900,7 +904,7 @@ struct PowerFunctor
bool supportBackend(int backendId, int targetId)
{
if (backendId == DNN_BACKEND_INFERENCE_ENGINE)
return (targetId != DNN_TARGET_OPENCL && targetId != DNN_TARGET_OPENCL_FP16) || power == 1.0;
return (targetId != DNN_TARGET_OPENCL && targetId != DNN_TARGET_OPENCL_FP16) || power == 1.0 || power == 0.5;
else
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE;
}
@ -1054,7 +1058,8 @@ struct ChannelsPReLUFunctor
bool supportBackend(int backendId, int)
{
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE;
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE ||
backendId == DNN_BACKEND_INFERENCE_ENGINE;
}
void apply(const float* srcptr, float* dstptr, int len, size_t planeSize, int cn0, int cn1) const
@ -1140,8 +1145,11 @@ struct ChannelsPReLUFunctor
#ifdef HAVE_INF_ENGINE
InferenceEngine::CNNLayerPtr initInfEngine(InferenceEngine::LayerParams& lp)
{
CV_Error(Error::StsNotImplemented, "PReLU");
return InferenceEngine::CNNLayerPtr();
lp.type = "PReLU";
std::shared_ptr<InferenceEngine::PReLULayer> ieLayer(new InferenceEngine::PReLULayer(lp));
const size_t numChannels = scale.total();
ieLayer->_weights = wrapToInfEngineBlob(scale, {numChannels}, InferenceEngine::Layout::C);
return ieLayer;
}
#endif // HAVE_INF_ENGINE

@ -358,7 +358,8 @@ void ONNXImporter::populateNet(Net dstNet)
layerParams.set("shift", blob.at<float>(0));
}
else {
layerParams.type = "Shift";
layerParams.type = "Scale";
layerParams.set("bias_term", true);
layerParams.blobs.push_back(blob);
}
}
@ -375,8 +376,26 @@ void ONNXImporter::populateNet(Net dstNet)
layerParams.set("shift", blob.at<float>(0));
}
else {
layerParams.type = "Shift";
layerParams.type = "Scale";
layerParams.set("has_bias", true);
layerParams.blobs.push_back(blob);
}
}
else if (layer_type == "Div")
{
Mat blob = getBlob(node_proto, constBlobs, 1);
CV_Assert_N(blob.type() == CV_32F, blob.total());
divide(1.0, blob, blob);
if (blob.total() == 1)
{
layerParams.set("scale", blob.at<float>(0));
layerParams.type = "Power";
}
else
{
layerParams.type = "Scale";
layerParams.blobs.push_back(blob);
layerParams.set("bias_term", false);
}
}
else if (layer_type == "Constant")

@ -128,10 +128,16 @@ TEST_P(DNNTestNetwork, GoogLeNet)
TEST_P(DNNTestNetwork, Inception_5h)
{
if (backend == DNN_BACKEND_INFERENCE_ENGINE) throw SkipTestException("");
double l1 = default_l1, lInf = default_lInf;
if (backend == DNN_BACKEND_INFERENCE_ENGINE && (target == DNN_TARGET_CPU || target == DNN_TARGET_OPENCL))
{
l1 = 1.72e-5;
lInf = 8e-4;
}
processNet("dnn/tensorflow_inception_graph.pb", "", Size(224, 224), "softmax2",
target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_inception_5h.yml" :
"dnn/halide_scheduler_inception_5h.yml");
"dnn/halide_scheduler_inception_5h.yml",
l1, lInf);
}
TEST_P(DNNTestNetwork, ENet)
@ -193,41 +199,42 @@ TEST_P(DNNTestNetwork, SSD_VGG16)
TEST_P(DNNTestNetwork, OpenPose_pose_coco)
{
if (backend == DNN_BACKEND_HALIDE ||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
if (backend == DNN_BACKEND_HALIDE)
throw SkipTestException("");
processNet("dnn/openpose_pose_coco.caffemodel", "dnn/openpose_pose_coco.prototxt",
Size(368, 368));
Size(46, 46));
}
TEST_P(DNNTestNetwork, OpenPose_pose_mpi)
{
if (backend == DNN_BACKEND_HALIDE ||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
if (backend == DNN_BACKEND_HALIDE)
throw SkipTestException("");
processNet("dnn/openpose_pose_mpi.caffemodel", "dnn/openpose_pose_mpi.prototxt",
Size(368, 368));
Size(46, 46));
}
TEST_P(DNNTestNetwork, OpenPose_pose_mpi_faster_4_stages)
{
if (backend == DNN_BACKEND_HALIDE ||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
if (backend == DNN_BACKEND_HALIDE)
throw SkipTestException("");
// The same .caffemodel but modified .prototxt
// See https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/src/openpose/pose/poseParameters.cpp
processNet("dnn/openpose_pose_mpi.caffemodel", "dnn/openpose_pose_mpi_faster_4_stages.prototxt",
Size(368, 368));
Size(46, 46));
}
TEST_P(DNNTestNetwork, OpenFace)
{
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE < 2018030000
#if defined(INF_ENGINE_RELEASE)
#if INF_ENGINE_RELEASE < 2018030000
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
throw SkipTestException("Test is enabled starts from OpenVINO 2018R3");
#elif INF_ENGINE_RELEASE < 2018040000
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16)
throw SkipTestException("Test is enabled starts from OpenVINO 2018R4");
#endif
if (backend == DNN_BACKEND_HALIDE ||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16))
#endif
if (backend == DNN_BACKEND_HALIDE)
throw SkipTestException("");
processNet("dnn/openface_nn4.small2.v1.t7", "", Size(96, 96), "");
}

@ -347,8 +347,10 @@ INSTANTIATE_TEST_CASE_P(/**/, Test_Darknet_nets, dnnBackendsAndTargets());
TEST_P(Test_Darknet_layers, shortcut)
{
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE < 2018040000
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_CPU)
throw SkipTestException("");
throw SkipTestException("Test is enabled starts from OpenVINO 2018R4");
#endif
testDarknetLayer("shortcut");
}

@ -273,9 +273,11 @@ TEST_P(AvePooling, Accuracy)
Size stride = get<3>(GetParam());
Backend backendId = get<0>(get<4>(GetParam()));
Target targetId = get<1>(get<4>(GetParam()));
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE < 2018040000
if (backendId == DNN_BACKEND_INFERENCE_ENGINE && targetId == DNN_TARGET_MYRIAD &&
stride == Size(3, 2) && kernel == Size(3, 3) && outSize != Size(1, 1))
throw SkipTestException("");
throw SkipTestException("Test is enabled starts from OpenVINO 2018R4");
#endif
const int inWidth = (outSize.width - 1) * stride.width + kernel.width;
const int inHeight = (outSize.height - 1) * stride.height + kernel.height;

@ -243,9 +243,14 @@ TEST_P(Test_Caffe_layers, Concat)
TEST_P(Test_Caffe_layers, Fused_Concat)
{
if ((backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_CPU) ||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL))
#if defined(INF_ENGINE_RELEASE)
if (backend == DNN_BACKEND_INFERENCE_ENGINE)
{
if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16 ||
(INF_ENGINE_RELEASE < 2018040000 && target == DNN_TARGET_CPU))
throw SkipTestException("");
}
#endif
checkBackend();
// Test case
@ -349,12 +354,6 @@ TEST_P(Test_Caffe_layers, Reshape_Split_Slice)
TEST_P(Test_Caffe_layers, Conv_Elu)
{
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
{
if (!checkIETarget(DNN_TARGET_MYRIAD))
throw SkipTestException("Myriad is not available/disabled in OpenCV");
}
Net net = readNetFromTensorflow(_tf("layer_elu_model.pb"));
ASSERT_FALSE(net.empty());

@ -462,10 +462,9 @@ struct Hamming
}
}
#else // NO NEON and NOT GNUC
typedef unsigned long long pop_t;
HammingLUT lut;
result = lut(reinterpret_cast<const unsigned char*> (a),
reinterpret_cast<const unsigned char*> (b), size * sizeof(pop_t));
reinterpret_cast<const unsigned char*> (b), size);
#endif
return result;
}

@ -107,6 +107,8 @@ double cvGetRatioWindow_GTK(const char* name);
double cvGetOpenGlProp_W32(const char* name);
double cvGetOpenGlProp_GTK(const char* name);
double cvGetPropVisible_W32(const char* name);
//for QT
#if defined (HAVE_QT)
CvRect cvGetWindowRect_QT(const char* name);

@ -152,6 +152,8 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
case CV_WND_PROP_VISIBLE:
#if defined (HAVE_QT)
return cvGetPropVisible_QT(name);
#elif defined(HAVE_WIN32UI)
return cvGetPropVisible_W32(name);
#else
return -1;
#endif

@ -642,6 +642,24 @@ double cvGetOpenGlProp_W32(const char* name)
return result;
}
double cvGetPropVisible_W32(const char* name)
{
double result = -1;
CV_FUNCNAME( "cvGetPropVisible_W32" );
__BEGIN__;
if (!name)
CV_ERROR( CV_StsNullPtr, "NULL name string" );
result = (icvFindWindowByName( name ) != NULL);
__END__;
return result;
}
// OpenGL support

@ -0,0 +1,87 @@
// 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 "perf_precomp.hpp"
namespace opencv_test {
CV_ENUM(RetrMode, RETR_EXTERNAL, RETR_LIST, RETR_CCOMP, RETR_TREE)
CV_ENUM(ApproxMode, CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS)
typedef TestBaseWithParam< tuple<Size, RetrMode, ApproxMode, int> > TestFindContours;
PERF_TEST_P(TestFindContours, findContours,
Combine(
Values( szVGA, sz1080p ), // image size
RetrMode::all(), // retrieval mode
ApproxMode::all(), // approximation method
Values( 32, 128 ) // blob count
)
)
{
Size img_size = get<0>(GetParam());
int retr_mode = get<1>(GetParam());
int approx_method = get<2>(GetParam());
int blob_count = get<3>(GetParam());
RNG rng;
Mat img = Mat::zeros(img_size, CV_8UC1);
for(int i = 0; i < blob_count; i++ )
{
Point center;
center.x = (unsigned)rng % (img.cols-2);
center.y = (unsigned)rng % (img.rows-2);
Size axes;
axes.width = ((unsigned)rng % 49 + 2)/2;
axes.height = ((unsigned)rng % 49 + 2)/2;
double angle = (unsigned)rng % 180;
int brightness = (unsigned)rng % 2;
// keep the border clear
ellipse( img(Rect(1,1,img.cols-2,img.rows-2)), Point(center), Size(axes), angle, 0., 360., Scalar(brightness), -1);
}
vector< vector<Point> > contours;
TEST_CYCLE() findContours( img, contours, retr_mode, approx_method );
SANITY_CHECK_NOTHING();
}
typedef TestBaseWithParam< tuple<Size, ApproxMode, int> > TestFindContoursFF;
PERF_TEST_P(TestFindContoursFF, findContours,
Combine(
Values(szVGA, sz1080p), // image size
ApproxMode::all(), // approximation method
Values(32, 128) // blob count
)
)
{
Size img_size = get<0>(GetParam());
int approx_method = get<1>(GetParam());
int blob_count = get<2>(GetParam());
RNG rng;
Mat img = Mat::zeros(img_size, CV_32SC1);
for (int i = 0; i < blob_count; i++)
{
Point center;
center.x = (unsigned)rng % (img.cols - 2);
center.y = (unsigned)rng % (img.rows - 2);
Size axes;
axes.width = ((unsigned)rng % 49 + 2) / 2;
axes.height = ((unsigned)rng % 49 + 2) / 2;
double angle = (unsigned)rng % 180;
int brightness = (unsigned)rng % 2;
// keep the border clear
ellipse(img(Rect(1, 1, img.cols - 2, img.rows - 2)), Point(center), Size(axes), angle, 0., 360., Scalar(brightness), -1);
}
vector< vector<Point> > contours;
TEST_CYCLE() findContours(img, contours, RETR_FLOODFILL, approx_method);
SANITY_CHECK_NOTHING();
}
} // namespace

@ -41,6 +41,8 @@
#include "precomp.hpp"
#include "opencv2/core/hal/intrin.hpp"
using namespace cv;
/* initializes 8-element array for fast access to 3x3 neighborhood of a pixel */
#define CV_INIT_3X3_DELTAS( deltas, step, nch ) \
((deltas)[0] = (nch), (deltas)[1] = -(step) + (nch), \
@ -1006,10 +1008,6 @@ cvFindNextContour( CvContourScanner scanner )
if( !scanner )
CV_Error( CV_StsNullPtr, "" );
#if CV_SSE2
bool haveSIMD = cv::checkHardwareSupport(CPU_SSE2);
#endif
CV_Assert(scanner->img_step >= 0);
icvEndProcessContour( scanner );
@ -1056,48 +1054,22 @@ cvFindNextContour( CvContourScanner scanner )
}
else
{
#if CV_SSE2
if ((p = img[x]) != prev) {
#if CV_SIMD
if ((p = img[x]) != prev)
{
goto _next_contour;
} else if (haveSIMD) {
__m128i v_prev = _mm_set1_epi8((char)prev);
int v_size = width - 32;
for (; x <= v_size; x += 32) {
__m128i v_p1 = _mm_loadu_si128((const __m128i*)(img + x));
__m128i v_p2 = _mm_loadu_si128((const __m128i*)(img + x + 16));
__m128i v_cmp1 = _mm_cmpeq_epi8(v_p1, v_prev);
__m128i v_cmp2 = _mm_cmpeq_epi8(v_p2, v_prev);
unsigned int mask1 = _mm_movemask_epi8(v_cmp1);
unsigned int mask2 = _mm_movemask_epi8(v_cmp2);
mask1 ^= 0x0000ffff;
mask2 ^= 0x0000ffff;
if (mask1) {
p = img[(x += cv::trailingZeros32(mask1))];
goto _next_contour;
}
if (mask2) {
p = img[(x += cv::trailingZeros32(mask2 << 16))];
goto _next_contour;
}
}
if(x <= width - 16) {
__m128i v_p = _mm_loadu_si128((__m128i*)(img + x));
unsigned int mask = _mm_movemask_epi8(_mm_cmpeq_epi8(v_p, v_prev)) ^ 0x0000ffff;
if (mask) {
}
else
{
v_uint8 v_prev = vx_setall_u8((uchar)prev);
for (; x <= width - v_uint8::nlanes; x += v_uint8::nlanes)
{
unsigned int mask = (unsigned int)v_signmask(vx_load((uchar*)(img + x)) != v_prev);
if (mask)
{
p = img[(x += cv::trailingZeros32(mask))];
goto _next_contour;
}
x += 16;
}
}
#endif
@ -1107,7 +1079,7 @@ cvFindNextContour( CvContourScanner scanner )
if( x >= width )
break;
#if CV_SSE2
#if CV_SIMD
_next_contour:
#endif
{
@ -1353,99 +1325,45 @@ typedef struct CvLinkedRunPoint
}
CvLinkedRunPoint;
inline int findStartContourPoint(uchar *src_data, CvSize img_size, int j, bool haveSIMD) {
#if CV_SSE2
if (haveSIMD) {
__m128i v_zero = _mm_setzero_si128();
int v_size = img_size.width - 32;
for (; j <= v_size; j += 32) {
__m128i v_p1 = _mm_loadu_si128((const __m128i*)(src_data + j));
__m128i v_p2 = _mm_loadu_si128((const __m128i*)(src_data + j + 16));
__m128i v_cmp1 = _mm_cmpeq_epi8(v_p1, v_zero);
__m128i v_cmp2 = _mm_cmpeq_epi8(v_p2, v_zero);
unsigned int mask1 = _mm_movemask_epi8(v_cmp1);
unsigned int mask2 = _mm_movemask_epi8(v_cmp2);
mask1 ^= 0x0000ffff;
mask2 ^= 0x0000ffff;
if (mask1) {
j += cv::trailingZeros32(mask1);
return j;
}
if (mask2) {
j += cv::trailingZeros32(mask2 << 16);
return j;
}
}
if (j <= img_size.width - 16) {
__m128i v_p = _mm_loadu_si128((const __m128i*)(src_data + j));
unsigned int mask = _mm_movemask_epi8(_mm_cmpeq_epi8(v_p, v_zero)) ^ 0x0000ffff;
if (mask) {
j += cv::trailingZeros32(mask);
return j;
}
j += 16;
inline int findStartContourPoint(uchar *src_data, CvSize img_size, int j)
{
#if CV_SIMD
v_uint8 v_zero = vx_setzero_u8();
for (; j <= img_size.width - v_uint8::nlanes; j += v_uint8::nlanes)
{
unsigned int mask = (unsigned int)v_signmask(vx_load((uchar*)(src_data + j)) != v_zero);
if (mask)
{
j += cv::trailingZeros32(mask);
return j;
}
}
#else
CV_UNUSED(haveSIMD);
#endif
for (; j < img_size.width && !src_data[j]; ++j)
;
return j;
}
inline int findEndContourPoint(uchar *src_data, CvSize img_size, int j, bool haveSIMD) {
#if CV_SSE2
if (j < img_size.width && !src_data[j]) {
inline int findEndContourPoint(uchar *src_data, CvSize img_size, int j)
{
#if CV_SIMD
if (j < img_size.width && !src_data[j])
{
return j;
} else if (haveSIMD) {
__m128i v_zero = _mm_setzero_si128();
int v_size = img_size.width - 32;
for (; j <= v_size; j += 32) {
__m128i v_p1 = _mm_loadu_si128((const __m128i*)(src_data + j));
__m128i v_p2 = _mm_loadu_si128((const __m128i*)(src_data + j + 16));
__m128i v_cmp1 = _mm_cmpeq_epi8(v_p1, v_zero);
__m128i v_cmp2 = _mm_cmpeq_epi8(v_p2, v_zero);
unsigned int mask1 = _mm_movemask_epi8(v_cmp1);
unsigned int mask2 = _mm_movemask_epi8(v_cmp2);
if (mask1) {
j += cv::trailingZeros32(mask1);
return j;
}
if (mask2) {
j += cv::trailingZeros32(mask2 << 16);
return j;
}
}
if (j <= img_size.width - 16) {
__m128i v_p = _mm_loadu_si128((const __m128i*)(src_data + j));
unsigned int mask = _mm_movemask_epi8(_mm_cmpeq_epi8(v_p, v_zero));
if (mask) {
}
else
{
v_uint8 v_zero = vx_setzero_u8();
for (; j <= img_size.width - v_uint8::nlanes; j += v_uint8::nlanes)
{
unsigned int mask = (unsigned int)v_signmask(vx_load((uchar*)(src_data + j)) == v_zero);
if (mask)
{
j += cv::trailingZeros32(mask);
return j;
}
j += 16;
}
}
#else
CV_UNUSED(haveSIMD);
#endif
for (; j < img_size.width && src_data[j]; ++j)
;
@ -1475,7 +1393,6 @@ icvFindContoursInInterval( const CvArr* src,
int lower_total;
int upper_total;
int all_total;
bool haveSIMD = false;
CvSeq* runs;
CvLinkedRunPoint tmp;
@ -1505,9 +1422,7 @@ icvFindContoursInInterval( const CvArr* src,
if( contourHeaderSize < (int)sizeof(CvContour))
CV_Error( CV_StsBadSize, "Contour header size must be >= sizeof(CvContour)" );
#if CV_SSE2
haveSIMD = cv::checkHardwareSupport(CPU_SSE2);
#endif
storage00.reset(cvCreateChildMemStorage(storage));
storage01.reset(cvCreateChildMemStorage(storage));
@ -1540,7 +1455,7 @@ icvFindContoursInInterval( const CvArr* src,
tmp_prev = upper_line;
for( j = 0; j < img_size.width; )
{
j = findStartContourPoint(src_data, cvSize(img_size), j, haveSIMD);
j = findStartContourPoint(src_data, cvSize(img_size), j);
if( j == img_size.width )
break;
@ -1550,7 +1465,7 @@ icvFindContoursInInterval( const CvArr* src,
tmp_prev->next = (CvLinkedRunPoint*)CV_GET_WRITTEN_ELEM( writer );
tmp_prev = tmp_prev->next;
j = findEndContourPoint(src_data, cvSize(img_size), j + 1, haveSIMD);
j = findEndContourPoint(src_data, cvSize(img_size), j + 1);
tmp.pt.x = j - 1;
CV_WRITE_SEQ_ELEM( tmp, writer );
@ -1574,7 +1489,7 @@ icvFindContoursInInterval( const CvArr* src,
all_total = runs->total;
for( j = 0; j < img_size.width; )
{
j = findStartContourPoint(src_data, cvSize(img_size), j, haveSIMD);
j = findStartContourPoint(src_data, cvSize(img_size), j);
if( j == img_size.width ) break;
@ -1583,7 +1498,7 @@ icvFindContoursInInterval( const CvArr* src,
tmp_prev->next = (CvLinkedRunPoint*)CV_GET_WRITTEN_ELEM( writer );
tmp_prev = tmp_prev->next;
j = findEndContourPoint(src_data, cvSize(img_size), j + 1, haveSIMD);
j = findEndContourPoint(src_data, cvSize(img_size), j + 1);
tmp.pt.x = j - 1;
CV_WRITE_SEQ_ELEM( tmp, writer );

@ -122,6 +122,8 @@ endif()
if(NOT " ${PYTHON}" STREQUAL " PYTHON" AND DEFINED OPENCV_${PYTHON}_INSTALL_PATH)
set(__python_binary_install_path "${OPENCV_${PYTHON}_INSTALL_PATH}")
elseif(OPENCV_SKIP_PYTHON_LOADER AND DEFINED ${PYTHON}_PACKAGES_PATH)
set(__python_binary_install_path "${${PYTHON}_PACKAGES_PATH}")
else()
ocv_assert(DEFINED OPENCV_PYTHON_INSTALL_PATH)
set(__python_binary_install_path "${OPENCV_PYTHON_INSTALL_PATH}/${__python_loader_subdir}python-${${PYTHON}_VERSION_MAJOR}.${${PYTHON}_VERSION_MINOR}")
@ -134,6 +136,8 @@ install(TARGETS ${the_module}
${PYTHON_INSTALL_ARCHIVE}
)
set(__INSTALL_PATH_${PYTHON} "${__python_binary_install_path}" CACHE INTERNAL "") # CMake status
if(NOT OPENCV_SKIP_PYTHON_LOADER)
ocv_assert(DEFINED OPENCV_PYTHON_INSTALL_PATH)
if(OpenCV_FOUND)
@ -143,12 +147,11 @@ if(NOT OPENCV_SKIP_PYTHON_LOADER)
endif()
set(__python_loader_install_tmp_path "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/install/python_loader/")
set(OpenCV_PYTHON_LOADER_FULL_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_PYTHON_INSTALL_PATH}/cv2")
if(IS_ABSOLUTE "${OPENCV_PYTHON_INSTALL_PATH}")
set(OpenCV_PYTHON_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PREFIX}/")
set(CMAKE_PYTHON_EXTENSION_INSTALL_PATH_BASE "'${CMAKE_INSTALL_PREFIX}'")
set(CMAKE_PYTHON_EXTENSION_INSTALL_PATH_BASE "'${OPENCV_PYTHON_INSTALL_PATH}/cv2'")
else()
file(RELATIVE_PATH OpenCV_PYTHON_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PREFIX}/${OPENCV_PYTHON_INSTALL_PATH}/cv2" ${CMAKE_INSTALL_PREFIX})
set(CMAKE_PYTHON_EXTENSION_INSTALL_PATH_BASE "os.path.join(LOADER_DIR, '${OpenCV_PYTHON_INSTALL_PATH_RELATIVE_CONFIGCMAKE}')")
set(CMAKE_PYTHON_EXTENSION_INSTALL_PATH_BASE "LOADER_DIR")
endif()
if(DEFINED ${PYTHON}_VERSION_MINOR)
@ -167,7 +170,8 @@ if(NOT OPENCV_SKIP_PYTHON_LOADER)
if(IS_ABSOLUTE __python_binary_install_path)
set(CMAKE_PYTHON_EXTENSION_PATH "'${__python_binary_install_path}'")
else()
set(CMAKE_PYTHON_EXTENSION_PATH "os.path.join(${CMAKE_PYTHON_EXTENSION_INSTALL_PATH_BASE}, '${__python_binary_install_path}')")
file(RELATIVE_PATH OpenCV_PYTHON_BINARY_RELATIVE_INSTALL_PATH "${OpenCV_PYTHON_LOADER_FULL_INSTALL_PATH}" "${CMAKE_INSTALL_PREFIX}/${__python_binary_install_path}")
set(CMAKE_PYTHON_EXTENSION_PATH "os.path.join(${CMAKE_PYTHON_EXTENSION_INSTALL_PATH_BASE}, '${OpenCV_PYTHON_BINARY_RELATIVE_INSTALL_PATH}')")
endif()
configure_file("${PYTHON_SOURCE_DIR}/package/template/config-x.y.py.in" "${__python_loader_install_tmp_path}/cv2/${__target_config}" @ONLY)
install(FILES "${__python_loader_install_tmp_path}/cv2/${__target_config}" DESTINATION "${OPENCV_PYTHON_INSTALL_PATH}/cv2/" COMPONENT python)

Loading…
Cancel
Save