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

This commit is contained in:
Alexander Alekhin 2018-10-09 21:18:37 +00:00
commit dada5a422d
32 changed files with 616 additions and 151 deletions

View File

@ -4,7 +4,7 @@ $output = "$PSScriptRoot\@OPENCV_BIN_INSTALL_PATH@\opencv_ffmpeg@OPENCV_DLLVERSI
Write-Output ("=" * 120)
try {
Get-content -Path "$PSScriptRoot\etc\licenses\ffmpeg-readme.txt" -ErrorAction 'Stop'
Get-content -Path "$PSScriptRoot\@OPENCV_LICENSES_INSTALL_PATH@\ffmpeg-readme.txt" -ErrorAction 'Stop'
} catch {
Write-Output "Refer to OpenCV FFmpeg wrapper readme notes about library usage / licensing details."
}

View File

@ -40,3 +40,5 @@ if(OPENCV_INSTALL_FFMPEG_DOWNLOAD_SCRIPT)
configure_file("${CMAKE_CURRENT_LIST_DIR}/ffmpeg-download.ps1.in" "${CMAKE_BINARY_DIR}/win-install/ffmpeg-download.ps1" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/win-install/ffmpeg-download.ps1" DESTINATION "." COMPONENT libs)
endif()
ocv_install_3rdparty_licenses(ffmpeg license.txt readme.txt)

View File

@ -86,7 +86,11 @@ endif()
if(CV_GCC OR CV_CLANG)
# High level of warnings.
add_extra_compiler_option(-W)
add_extra_compiler_option(-Wall)
if (NOT MSVC)
# clang-cl interprets -Wall as MSVC would: -Weverything, which is more than
# we want.
add_extra_compiler_option(-Wall)
endif()
add_extra_compiler_option(-Werror=return-type)
add_extra_compiler_option(-Werror=non-virtual-dtor)
add_extra_compiler_option(-Werror=address)
@ -173,7 +177,7 @@ if(CV_GCC OR CV_CLANG)
string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}")
string(REPLACE "-fdata-sections" "" ${flags} "${${flags}}")
endforeach()
elseif(NOT ((IOS OR ANDROID) AND NOT BUILD_SHARED_LIBS))
elseif(NOT ((IOS OR ANDROID) AND NOT BUILD_SHARED_LIBS) AND NOT MSVC)
# Remove unreferenced functions: function level linking
add_extra_compiler_option(-ffunction-sections)
add_extra_compiler_option(-fdata-sections)
@ -266,6 +270,7 @@ endif()
# set default visibility to hidden
if((CV_GCC OR CV_CLANG)
AND NOT MSVC
AND NOT OPENCV_SKIP_VISIBILITY_HIDDEN
AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fvisibility")
add_extra_compiler_option(-fvisibility=hidden)

View File

@ -38,7 +38,7 @@ if(NOT ${found})
set(PYTHON_EXECUTABLE "${${executable}}")
endif()
if(WIN32 AND NOT ${executable})
if(WIN32 AND NOT ${executable} AND OPENCV_PYTHON_PREFER_WIN32_REGISTRY) # deprecated
# search for executable with the same bitness as resulting binaries
# standard FindPythonInterp always prefers executable from system path
# this is really important because we are using the interpreter for numpy search and for choosing the install location
@ -53,16 +53,47 @@ if(NOT ${found})
endforeach()
endif()
string(REGEX MATCH "^[0-9]+" _preferred_version_major "${preferred_version}")
find_host_package(PythonInterp "${preferred_version}")
if(NOT PYTHONINTERP_FOUND)
if(preferred_version)
set(__python_package_version "${preferred_version} EXACT")
find_host_package(PythonInterp "${preferred_version}" EXACT)
if(NOT PYTHONINTERP_FOUND)
message(STATUS "Python is not found: ${preferred_version} EXACT")
endif()
else()
set(__python_package_version "${min_version}")
find_host_package(PythonInterp "${min_version}")
endif()
string(REGEX MATCH "^[0-9]+" _python_version_major "${min_version}")
if(PYTHONINTERP_FOUND)
# Check if python major version is correct
if("${_preferred_version_major}" STREQUAL "" OR "${_preferred_version_major}" STREQUAL "${PYTHON_VERSION_MAJOR}")
if(NOT "${_python_version_major}" STREQUAL "${PYTHON_VERSION_MAJOR}"
AND NOT DEFINED ${executable}
)
if(NOT OPENCV_SKIP_PYTHON_WARNING)
message(WARNING "CMake's 'find_host_package(PythonInterp ${__python_package_version})' founds wrong Python version:\n"
"PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}\n"
"PYTHON_VERSION_STRING=${PYTHON_VERSION_STRING}\n"
"Consider specify '${executable}' variable via CMake command line or environment variables\n")
endif()
ocv_clear_vars(PYTHONINTERP_FOUND PYTHON_EXECUTABLE PYTHON_VERSION_STRING PYTHON_VERSION_MAJOR PYTHON_VERSION_MINOR PYTHON_VERSION_PATCH)
if(NOT CMAKE_VERSION VERSION_LESS "3.12")
if(_python_version_major STREQUAL "2")
set(__PYTHON_PREFIX Python2)
else()
set(__PYTHON_PREFIX Python3)
endif()
find_host_package(${__PYTHON_PREFIX} "${preferred_version}" COMPONENTS Interpreter)
if(${__PYTHON_PREFIX}_EXECUTABLE)
set(PYTHON_EXECUTABLE "${${__PYTHON_PREFIX}_EXECUTABLE}")
find_host_package(PythonInterp "${preferred_version}") # Populate other variables
endif()
else()
message(STATUS "Consider using CMake 3.12+ for better Python support")
endif()
endif()
if(PYTHONINTERP_FOUND AND "${_python_version_major}" STREQUAL "${PYTHON_VERSION_MAJOR}")
# Copy outputs
set(_found ${PYTHONINTERP_FOUND})
set(_executable ${PYTHON_EXECUTABLE})
@ -235,7 +266,7 @@ if(OPENCV_PYTHON_SKIP_DETECTION)
return()
endif()
find_python(2.7 "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
find_python("" "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING
PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND
PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY
@ -243,7 +274,8 @@ find_python(2.7 "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH
PYTHON2_NUMPY_INCLUDE_DIRS PYTHON2_NUMPY_VERSION)
find_python(3.4 "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
option(OPENCV_PYTHON3_VERSION "Python3 version" "")
find_python("${OPENCV_PYTHON3_VERSION}" "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
PYTHON3INTERP_FOUND PYTHON3_EXECUTABLE PYTHON3_VERSION_STRING
PYTHON3_VERSION_MAJOR PYTHON3_VERSION_MINOR PYTHON3LIBS_FOUND
PYTHON3LIBS_VERSION_STRING PYTHON3_LIBRARIES PYTHON3_LIBRARY

View File

@ -44,8 +44,10 @@ else()
if(Protobuf_FOUND)
if(TARGET protobuf::libprotobuf)
add_library(libprotobuf INTERFACE)
target_link_libraries(libprotobuf INTERFACE protobuf::libprotobuf)
add_library(libprotobuf INTERFACE IMPORTED)
set_target_properties(libprotobuf PROPERTIES
INTERFACE_LINK_LIBRARIES protobuf::libprotobuf
)
else()
add_library(libprotobuf UNKNOWN IMPORTED)
set_target_properties(libprotobuf PROPERTIES

View File

@ -1,6 +1,6 @@
set(MIN_VER_CMAKE 3.5.1)
set(MIN_VER_CUDA 6.5)
set(MIN_VER_PYTHON2 2.6)
set(MIN_VER_PYTHON2 2.7)
set(MIN_VER_PYTHON3 3.2)
set(MIN_VER_ZLIB 1.2.3)
set(MIN_VER_GTK 2.18.0)

View File

@ -3541,6 +3541,9 @@ double cv::stereoCalibrate( InputArrayOfArrays _objectPoints,
OutputArray _Emat, OutputArray _Fmat, int flags,
TermCriteria criteria)
{
if (flags & CALIB_USE_EXTRINSIC_GUESS)
CV_Error(Error::StsBadFlag, "stereoCalibrate does not support CALIB_USE_EXTRINSIC_GUESS.");
Mat Rmat, Tmat;
double ret = stereoCalibrate(_objectPoints, _imagePoints1, _imagePoints2, _cameraMatrix1, _distCoeffs1,
_cameraMatrix2, _distCoeffs2, imageSize, Rmat, Tmat, _Emat, _Fmat,

View File

@ -390,6 +390,8 @@ CV_EXPORTS CV_NORETURN void error(int _code, const String& _err, const char* _fu
#define CV_Error(...) do { abort(); } while (0)
#define CV_Error_( code, args ) do { 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

View File

@ -368,6 +368,9 @@ inline unsigned int trailingZeros32(unsigned int value) {
unsigned long index = 0;
_BitScanForward(&index, value);
return (unsigned int)index;
#elif defined(__clang__)
// clang-cl doesn't export _tzcnt_u32 for non BMI systems
return value ? __builtin_ctz(value) : 32;
#else
return _tzcnt_u32(value);
#endif

View File

@ -352,7 +352,8 @@ public:
KernelArg(int _flags, UMat* _m, int wscale=1, int iwscale=1, const void* _obj=0, size_t _sz=0);
KernelArg();
static KernelArg Local() { return KernelArg(LOCAL, 0); }
static KernelArg Local(size_t localMemSize)
{ return KernelArg(LOCAL, 0, 1, 1, 0, localMemSize); }
static KernelArg PtrWriteOnly(const UMat& m)
{ return KernelArg(PTR_ONLY+WRITE_ONLY, (UMat*)&m); }
static KernelArg PtrReadOnly(const UMat& m)

View File

@ -142,9 +142,13 @@ namespace cv
CV_EXPORTS void scalarToRawData(const cv::Scalar& s, void* buf, int type, int unroll_to = 0);
//! Allocate all memory buffers which will not be freed, ease filtering memcheck issues
template <typename T>
T* allocSingleton(size_t count) { return static_cast<T*>(fastMalloc(sizeof(T) * count)); }
}
CV_EXPORTS void* allocSingletonBuffer(size_t size);
//! Allocate all memory buffers which will not be freed, ease filtering memcheck issues
template <typename T> static inline
T* allocSingleton(size_t count = 1) { return static_cast<T*>(allocSingletonBuffer(sizeof(T) * count)); }
} // namespace
#if 1 // TODO: Remove in OpenCV 4.x

View File

@ -910,37 +910,23 @@ double cv::invert( InputArray _src, OutputArray _dst, int method )
{
result = true;
d = 1./d;
#if CV_SSE2
if(USE_SSE2)
{
__m128 zero = _mm_setzero_ps();
__m128 t0 = _mm_loadl_pi(zero, (const __m64*)srcdata); //t0 = sf(0,0) sf(0,1)
__m128 t1 = _mm_loadh_pi(zero, (const __m64*)(srcdata+srcstep)); //t1 = sf(1,0) sf(1,1)
__m128 s0 = _mm_or_ps(t0, t1);
__m128 det =_mm_set1_ps((float)d);
s0 = _mm_mul_ps(s0, det);
static const uchar CV_DECL_ALIGNED(16) inv[16] = {0,0,0,0,0,0,0,0x80,0,0,0,0x80,0,0,0,0};
__m128 pattern = _mm_load_ps((const float*)inv);
s0 = _mm_xor_ps(s0, pattern);//==-1*s0
s0 = _mm_shuffle_ps(s0, s0, _MM_SHUFFLE(0,2,1,3));
_mm_storel_pi((__m64*)dstdata, s0);
_mm_storeh_pi((__m64*)((float*)(dstdata+dststep)), s0);
}
else
#endif
{
double t0, t1;
t0 = Sf(0,0)*d;
t1 = Sf(1,1)*d;
Df(1,1) = (float)t0;
Df(0,0) = (float)t1;
t0 = -Sf(0,1)*d;
t1 = -Sf(1,0)*d;
Df(0,1) = (float)t0;
Df(1,0) = (float)t1;
}
#if CV_SIMD128
static const float CV_DECL_ALIGNED(16) inv[4] = { 0.f,-0.f,-0.f,0.f };
v_float32x4 s0 = (v_load_halves((const float*)srcdata, (const float*)(srcdata + srcstep)) * v_setall_f32((float)d)) ^ v_load((const float *)inv);//0123//3120
s0 = v_extract<3>(s0, v_combine_low(v_rotate_right<1>(s0), s0));
v_store_low((float*)dstdata, s0);
v_store_high((float*)(dstdata + dststep), s0);
#else
double t0, t1;
t0 = Sf(0,0)*d;
t1 = Sf(1,1)*d;
Df(1,1) = (float)t0;
Df(0,0) = (float)t1;
t0 = -Sf(0,1)*d;
t1 = -Sf(1,0)*d;
Df(0,1) = (float)t0;
Df(1,0) = (float)t1;
#endif
}
}
else
@ -950,39 +936,25 @@ double cv::invert( InputArray _src, OutputArray _dst, int method )
{
result = true;
d = 1./d;
#if CV_SSE2
if(USE_SSE2)
{
__m128d s0 = _mm_loadu_pd((const double*)srcdata); //s0 = sf(0,0) sf(0,1)
__m128d s1 = _mm_loadu_pd ((const double*)(srcdata+srcstep));//s1 = sf(1,0) sf(1,1)
__m128d sm = _mm_unpacklo_pd(s0, _mm_load_sd((const double*)(srcdata+srcstep)+1)); //sm = sf(0,0) sf(1,1) - main diagonal
__m128d ss = _mm_shuffle_pd(s0, s1, _MM_SHUFFLE2(0,1)); //ss = sf(0,1) sf(1,0) - secondary diagonal
__m128d det = _mm_load1_pd((const double*)&d);
sm = _mm_mul_pd(sm, det);
static const uchar CV_DECL_ALIGNED(16) inv[8] = {0,0,0,0,0,0,0,0x80};
__m128d pattern = _mm_load1_pd((double*)inv);
ss = _mm_mul_pd(ss, det);
ss = _mm_xor_pd(ss, pattern);//==-1*ss
s0 = _mm_shuffle_pd(sm, ss, _MM_SHUFFLE2(0,1));
s1 = _mm_shuffle_pd(ss, sm, _MM_SHUFFLE2(0,1));
_mm_storeu_pd((double*)dstdata, s0);
_mm_storeu_pd((double*)(dstdata+dststep), s1);
}
else
#endif
{
double t0, t1;
t0 = Sd(0,0)*d;
t1 = Sd(1,1)*d;
Dd(1,1) = t0;
Dd(0,0) = t1;
t0 = -Sd(0,1)*d;
t1 = -Sd(1,0)*d;
Dd(0,1) = t0;
Dd(1,0) = t1;
}
#if CV_SIMD128_64F
v_float64x2 det = v_setall_f64(d);
v_float64x2 s0 = v_load((const double*)srcdata) * det;
v_float64x2 s1 = v_load((const double*)(srcdata+srcstep)) * det;
v_float64x2 sm = v_extract<1>(s1, s0);//30
v_float64x2 ss = v_extract<1>(s0, s1) ^ v_setall_f64(-0.);//12
v_store((double*)dstdata, v_combine_low(sm, ss));//31
v_store((double*)(dstdata + dststep), v_combine_high(ss, sm));//20
#else
double t0, t1;
t0 = Sd(0,0)*d;
t1 = Sd(1,1)*d;
Dd(1,1) = t0;
Dd(0,0) = t1;
t0 = -Sd(0,1)*d;
t1 = -Sd(1,0)*d;
Dd(0,1) = t0;
Dd(1,0) = t1;
#endif
}
}
}

View File

@ -70,6 +70,8 @@ static bool param_dumpErrors = utils::getConfigurationParameterBool("OPENCV_DUMP
#endif
);
void* allocSingletonBuffer(size_t size) { return fastMalloc(size); }
} // namespace cv
#ifndef CV_ERROR_SET_TERMINATE_HANDLER // build config option

View File

@ -483,6 +483,7 @@ struct DataLayer : public Layer
}
#ifdef HAVE_OPENCL
std::vector<Mat> tmp_expressions;
bool forward_ocl(InputArrayOfArrays, OutputArrayOfArrays outputs_, OutputArrayOfArrays internals_)
{
// Supported modes:
@ -493,8 +494,11 @@ struct DataLayer : public Layer
std::vector<UMat> outputs;
outputs_.getUMatVector(outputs);
tmp_expressions.clear();
for (int i = 0; i < inputsData.size(); ++i)
{
Mat inputData = inputsData[i];
double scale = scaleFactors[i];
Scalar& mean = means[i];
@ -508,7 +512,10 @@ struct DataLayer : public Layer
if (outputs_.depth() == CV_16S)
{
if (singleMean)
convertFp16(scale * (inputsData[i] - mean[0]), outputs[i]);
{
tmp_expressions.push_back(Mat(scale * (inputsData[i] - mean[0])));
convertFp16(tmp_expressions.back(), outputs[i]);
}
else
{
for (int n = 0; n < inputsData[i].size[0]; ++n)
@ -521,7 +528,8 @@ struct DataLayer : public Layer
plane[1] = Range(c, c + 1);
UMat out = outputs[i](plane).reshape(1, inp.dims, inp.size);
convertFp16(scale * (inp - mean[c]), out);
tmp_expressions.push_back(scale * (inp - mean[c]));
convertFp16(tmp_expressions.back(), out);
}
}
}
@ -529,7 +537,9 @@ struct DataLayer : public Layer
{
CV_Assert(outputs_.depth() == CV_32F);
if (singleMean)
{
inputsData[i].convertTo(outputs[i], CV_32F, scale, -mean[0] * scale);
}
else
{
for (int n = 0; n < inputsData[i].size[0]; ++n)
@ -2518,7 +2528,7 @@ void Net::forward(OutputArrayOfArrays outputBlobs, const String& outputName)
if (outputBlobs.isUMat())
{
outputBlobs.assign(impl->getBlob(layerName).getUMat(ACCESS_RW));
impl->getBlob(layerName).copyTo(outputBlobs);
}
else if (outputBlobs.isMat())
{
@ -2566,7 +2576,7 @@ void Net::forward(OutputArrayOfArrays outputBlobs, const String& outputName)
{
outputvec.resize(ld.outputBlobs.size());
for (int i = 0; i < outputvec.size(); ++i)
outputvec[i] = ld.outputBlobs[i].getUMat(ACCESS_RW);
ld.outputBlobs[i].copyTo(outputvec[i]);
}
}
}

View File

@ -172,8 +172,8 @@ public:
if (umat_weight.empty())
{
umat_weight = weights_.getUMat(ACCESS_READ);
umat_bias = bias_.getUMat(ACCESS_READ);
weights_.copyTo(umat_weight);
bias_.copyTo(umat_bias);
}
UMat &inpBlob = inputs[0];

View File

@ -1452,8 +1452,10 @@ public:
if (umat_weights.empty())
{
transpose(blobs[0].reshape(1, inpCn), umat_weights);
umat_biases = hasBias() ? blobs[1].reshape(1, outCn).getUMat(ACCESS_READ) :
UMat::zeros(outCn, 1, CV_32F);
if (hasBias())
blobs[1].reshape(1, outCn).copyTo(umat_biases);
else
umat_biases = UMat::zeros(outCn, 1, CV_32F);
}
String buildopt = format("-DT=%s ", ocl::typeToStr(inputs[0].type()));

View File

@ -969,11 +969,12 @@ struct ChannelsPReLUFunctor
{
typedef ChannelsPReLULayer Layer;
Mat scale;
#ifdef HAVE_OPENCL
UMat scale_umat;
#endif
explicit ChannelsPReLUFunctor(const Mat& scale_=Mat()) : scale(scale_)
{
scale_umat = scale.getUMat(ACCESS_READ);
}
bool supportBackend(int backendId, int)
@ -1021,6 +1022,9 @@ struct ChannelsPReLUFunctor
#ifdef HAVE_OPENCL
bool applyOCL(InputArrayOfArrays inps, OutputArrayOfArrays outs, OutputArrayOfArrays internals)
{
if (scale_umat.empty())
scale.copyTo(scale_umat);
std::vector<UMat> inputs;
std::vector<UMat> outputs;

View File

@ -96,12 +96,6 @@ public:
biasMat = blobs[1] = blobs[1].reshape(1, 1);
else
biasMat = Mat::zeros(1, numOutput, weightsMat.type());
#ifdef HAVE_OPENCL
size_t n = blobs.size();
umat_blobs.resize(n);
for (int i = 0; i < n; i++) umat_blobs[i] = blobs[i].getUMat(ACCESS_READ);
#endif
}
bool getMemoryShapes(const std::vector<MatShape> &inputs,
@ -276,6 +270,8 @@ public:
virtual void finalize(InputArrayOfArrays, OutputArrayOfArrays) CV_OVERRIDE
{
innerProductOp.release();
umat_blobs.clear();
half_blobs.clear();
}
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, InputArrayOfArrays internals)
@ -288,13 +284,17 @@ public:
outs.getUMatVector(outputs);
int axisCan = clamp(axis, inputs[0].dims);
int numOutput = umat_blobs[0].size[0];
int innerSize = umat_blobs[0].size[1];
int numOutput = blobs[0].size[0];
int innerSize = blobs[0].size[1];
int outerSize = total(shape(inputs[0]), 0, axisCan);
bool ret = true;
if (innerProductOp.empty())
{
size_t n = blobs.size();
umat_blobs.resize(n);
for (int i = 0; i < n; i++) blobs[i].copyTo(umat_blobs[i]);
OCL4DNNInnerProductConfig config;
config.num_output = numOutput;
config.bias_term = bias;

View File

@ -71,6 +71,9 @@ public:
}
Mat scale, shift;
#ifdef HAVE_OPENCL
UMat umat_scale, umat_shift;
#endif
bool fuse_batch_norm;
Ptr<ReLULayer> activ_relu;
@ -105,6 +108,10 @@ public:
for( i = 0; i < splitDim; i++ )
newRows *= inputs[0].size[i];
zeroDev = inputs[0].total() == newRows;
#ifdef HAVE_OPENCL
umat_scale.release();
umat_shift.release();
#endif
}
virtual bool supportBackend(int backendId) CV_OVERRIDE
@ -118,8 +125,13 @@ public:
#ifdef HAVE_OPENCL
bool fast_forward_ocl(std::vector<UMat> &inputs, std::vector<UMat> &outputs)
{
UMat bnorm_weight = scale.empty() ? UMat() : scale.getUMat(ACCESS_READ);
UMat bnorm_bias = shift.empty() ? UMat() : shift.getUMat(ACCESS_READ);
if (umat_scale.empty() && !scale.empty())
scale.copyTo(umat_scale);
if (umat_shift.empty() && !shift.empty())
shift.copyTo(umat_shift);
UMat& bnorm_weight = umat_scale;
UMat& bnorm_bias = umat_shift;
bool use_half = (inputs[0].depth() == CV_16S);
String opts = format(" -DT=%s -DT4=%s -Dconvert_T=%s", use_half ? "half" : "float",
use_half ? "half4" : "float4", use_half ? "convert_half4" : "convert_float4");
@ -177,6 +189,13 @@ public:
bool forward_ocl(InputArrayOfArrays inputs_, OutputArrayOfArrays outputs_, OutputArrayOfArrays internals_)
{
if (umat_scale.empty() && !scale.empty())
scale.copyTo(umat_scale);
if (umat_shift.empty() && !shift.empty())
shift.copyTo(umat_shift);
UMat& bnorm_weight = umat_scale;
UMat& bnorm_bias = umat_shift;
std::vector<UMat> inputs;
std::vector<UMat> outputs;
@ -192,8 +211,6 @@ public:
if (inputs[0].depth() == CV_16S)
return false;
UMat bnorm_weight = scale.empty() ? UMat() : scale.getUMat(ACCESS_READ);
UMat bnorm_bias = shift.empty() ? UMat() : shift.getUMat(ACCESS_READ);
String opts = format(" -DT=float -DT4=float4 -Dconvert_T=convert_float4");
for (size_t inpIdx = 0; inpIdx < inputs.size(); inpIdx++)

View File

@ -132,8 +132,6 @@ public:
for (size_t i = 0; i < inputs.size(); i++)
{
CV_Assert(inputs[i].size() == 4);
CV_Assert(inputs[i][2] == shapeBefore[2] && inputs[i][3] == shapeBefore[3]);
CV_Assert(total(inputs[i]) == total(shapeAfter));
outputs.push_back(shapeAfter);
}

View File

@ -60,6 +60,9 @@ public:
int coords, classes, anchors, classfix;
float thresh, nmsThreshold;
bool useSoftmax, useLogistic;
#ifdef HAVE_OPENCL
UMat blob_umat;
#endif
RegionLayerImpl(const LayerParams& params)
{
@ -123,6 +126,9 @@ public:
#ifdef HAVE_OPENCL
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, OutputArrayOfArrays internals)
{
if (blob_umat.empty())
blobs[0].copyTo(blob_umat);
std::vector<UMat> inputs;
std::vector<UMat> outputs;
@ -135,7 +141,6 @@ public:
CV_Assert(inputs.size() >= 1);
int const cell_size = classes + coords + 1;
UMat blob_umat = blobs[0].getUMat(ACCESS_READ);
for (size_t ii = 0; ii < outputs.size(); ii++)
{

View File

@ -486,6 +486,11 @@ void ONNXImporter::populateNet(Net dstNet)
layerParams.set("num_output", layerParams.blobs[0].size[0]);
layerParams.set("bias_term", node_proto.input_size() == 3);
}
else if (layer_type == "Transpose")
{
layerParams.type = "Permute";
replaceLayerParam(layerParams, "perm", "order");
}
else if (layer_type == "Unsqueeze")
{
CV_Assert(node_proto.input_size() == 1);

View File

@ -69,10 +69,16 @@
#endif
#ifdef FUSED_CONV_ELTWISE
#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { (_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(eltwise_data[(_offset_)] + (_data_), _channel_);} while(0)
#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { \
const Dtype _x_ = eltwise_data[(_offset_)] + (_data_); \
(_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_x_, _channel_); \
} while(0)
#define ELTWISE_DATA_ARG __global Dtype* eltwise_data,
#else
#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { (_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_data_, _channel_);} while(0)
#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { \
const Dtype _x_ = (_data_); \
(_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_x_, _channel_); \
} while(0)
#define ELTWISE_DATA_ARG
#endif

View File

@ -108,6 +108,14 @@ TEST_P(Test_ONNX_layers, BatchNormalization)
testONNXModels("batch_norm");
}
TEST_P(Test_ONNX_layers, Transpose)
{
if (backend == DNN_BACKEND_INFERENCE_ENGINE &&
(target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_OPENCL || target == DNN_TARGET_MYRIAD))
throw SkipTestException("");
testONNXModels("transpose");
}
TEST_P(Test_ONNX_layers, Multiplication)
{
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16 ||
@ -351,6 +359,14 @@ TEST_P(Test_ONNX_nets, Inception_v1)
testONNXModels("inception_v1", pb);
}
TEST_P(Test_ONNX_nets, Shufflenet)
{
if (backend == DNN_BACKEND_INFERENCE_ENGINE &&
(target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_OPENCL || target == DNN_TARGET_MYRIAD))
throw SkipTestException("");
testONNXModels("shufflenet", pb);
}
INSTANTIATE_TEST_CASE_P(/**/, Test_ONNX_nets, dnnBackendsAndTargets());
}} // namespace

View File

@ -3485,6 +3485,24 @@ channels is derived automatically from src and code.
*/
CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 );
/** @brief Converts an image from one color space to another where the source image is
stored in two planes.
This function only supports YUV420 to RGB conversion as of now.
@param src1: 8-bit image (#CV_8U) of the Y plane.
@param src2: image containing interleaved U/V plane.
@param dst: output image.
@param code: Specifies the type of conversion. It can take any of the following values:
- #COLOR_YUV2BGR_NV12
- #COLOR_YUV2RGB_NV12
- #COLOR_YUV2BGRA_NV12
- #COLOR_YUV2RGBA_NV12
- #COLOR_YUV2BGR_NV21
- #COLOR_YUV2RGB_NV21
- #COLOR_YUV2BGRA_NV21
- #COLOR_YUV2RGBA_NV21
*/
CV_EXPORTS_W void cvtColorTwoPlane( InputArray src1, InputArray src2, OutputArray dst, int code );
//! @} imgproc_misc

View File

@ -43,6 +43,8 @@
#include "precomp.hpp"
#include "opencl_kernels_imgproc.hpp"
#include "opencv2/core/hal/intrin.hpp"
namespace cv
{
@ -60,15 +62,12 @@ struct Integral_SIMD
}
};
#if CV_SSE2
#if CV_SIMD && CV_SIMD_WIDTH <= 64
template <>
struct Integral_SIMD<uchar, int, double>
{
Integral_SIMD()
{
haveSSE2 = checkHardwareSupport(CV_CPU_SSE2);
}
Integral_SIMD() {}
bool operator()(const uchar * src, size_t _srcstep,
int * sum, size_t _sumstep,
@ -76,15 +75,12 @@ struct Integral_SIMD<uchar, int, double>
int * tilted, size_t,
int width, int height, int cn) const
{
if (sqsum || tilted || cn != 1 || !haveSSE2)
if (sqsum || tilted || cn != 1)
return false;
// the first iteration
memset(sum, 0, (width + 1) * sizeof(int));
__m128i v_zero = _mm_setzero_si128(), prev = v_zero;
int j = 0;
// the others
for (int i = 0; i < height; ++i)
{
@ -94,48 +90,113 @@ struct Integral_SIMD<uchar, int, double>
sum_row[-1] = 0;
prev = v_zero;
j = 0;
for ( ; j + 7 < width; j += 8)
v_int32 prev = vx_setzero_s32();
int j = 0;
for ( ; j + v_uint16::nlanes <= width; j += v_uint16::nlanes)
{
__m128i vsuml = _mm_loadu_si128((const __m128i *)(prev_sum_row + j));
__m128i vsumh = _mm_loadu_si128((const __m128i *)(prev_sum_row + j + 4));
__m128i el8shr0 = _mm_loadl_epi64((const __m128i *)(src_row + j));
__m128i el8shr1 = _mm_slli_si128(el8shr0, 1);
__m128i el8shr2 = _mm_slli_si128(el8shr0, 2);
__m128i el8shr3 = _mm_slli_si128(el8shr0, 3);
vsuml = _mm_add_epi32(vsuml, prev);
vsumh = _mm_add_epi32(vsumh, prev);
__m128i el8shr12 = _mm_add_epi16(_mm_unpacklo_epi8(el8shr1, v_zero),
_mm_unpacklo_epi8(el8shr2, v_zero));
__m128i el8shr03 = _mm_add_epi16(_mm_unpacklo_epi8(el8shr0, v_zero),
_mm_unpacklo_epi8(el8shr3, v_zero));
__m128i el8 = _mm_add_epi16(el8shr12, el8shr03);
__m128i el4h = _mm_add_epi16(_mm_unpackhi_epi16(el8, v_zero),
_mm_unpacklo_epi16(el8, v_zero));
vsuml = _mm_add_epi32(vsuml, _mm_unpacklo_epi16(el8, v_zero));
vsumh = _mm_add_epi32(vsumh, el4h);
_mm_storeu_si128((__m128i *)(sum_row + j), vsuml);
_mm_storeu_si128((__m128i *)(sum_row + j + 4), vsumh);
prev = _mm_add_epi32(prev, _mm_shuffle_epi32(el4h, _MM_SHUFFLE(3, 3, 3, 3)));
v_int16 el8 = v_reinterpret_as_s16(vx_load_expand(src_row + j));
v_int32 el4l, el4h;
#if CV_AVX2
__m256i vsum = _mm256_add_epi16(el8.val, _mm256_slli_si256(el8.val, 2));
vsum = _mm256_add_epi16(vsum, _mm256_slli_si256(vsum, 4));
vsum = _mm256_add_epi16(vsum, _mm256_slli_si256(vsum, 8));
__m256i shmask = _mm256_set1_epi32(7);
el4l.val = _mm256_add_epi32(_mm256_cvtepi16_epi32(_v256_extract_low(vsum)), prev.val);
el4h.val = _mm256_add_epi32(_mm256_cvtepi16_epi32(_v256_extract_high(vsum)), _mm256_permutevar8x32_epi32(el4l.val, shmask));
prev.val = _mm256_permutevar8x32_epi32(el4h.val, shmask);
#else
el8 += v_rotate_left<1>(el8);
el8 += v_rotate_left<2>(el8);
#if CV_SIMD_WIDTH == 32
el8 += v_rotate_left<4>(el8);
#if CV_SIMD_WIDTH == 64
el8 += v_rotate_left<8>(el8);
#endif
#endif
v_expand(el8, el4l, el4h);
el4l += prev;
el4h += el4l;
prev = vx_setall_s32(v_rotate_right<v_int32::nlanes - 1>(el4h).get0());
#endif
v_store(sum_row + j , el4l + vx_load(prev_sum_row + j ));
v_store(sum_row + j + v_int32::nlanes, el4h + vx_load(prev_sum_row + j + v_int32::nlanes));
}
for (int v = sum_row[j - 1] - prev_sum_row[j - 1]; j < width; ++j)
sum_row[j] = (v += src_row[j]) + prev_sum_row[j];
}
vx_cleanup();
return true;
}
};
bool haveSSE2;
template <>
struct Integral_SIMD<uchar, float, double>
{
Integral_SIMD() {}
bool operator()(const uchar * src, size_t _srcstep,
float * sum, size_t _sumstep,
double * sqsum, size_t,
float * tilted, size_t,
int width, int height, int cn) const
{
if (sqsum || tilted || cn != 1)
return false;
// the first iteration
memset(sum, 0, (width + 1) * sizeof(int));
// the others
for (int i = 0; i < height; ++i)
{
const uchar * src_row = src + _srcstep * i;
float * prev_sum_row = (float *)((uchar *)sum + _sumstep * i) + 1;
float * sum_row = (float *)((uchar *)sum + _sumstep * (i + 1)) + 1;
sum_row[-1] = 0;
v_float32 prev = vx_setzero_f32();
int j = 0;
for (; j + v_uint16::nlanes <= width; j += v_uint16::nlanes)
{
v_int16 el8 = v_reinterpret_as_s16(vx_load_expand(src_row + j));
v_float32 el4l, el4h;
#if CV_AVX2
__m256i vsum = _mm256_add_epi16(el8.val, _mm256_slli_si256(el8.val, 2));
vsum = _mm256_add_epi16(vsum, _mm256_slli_si256(vsum, 4));
vsum = _mm256_add_epi16(vsum, _mm256_slli_si256(vsum, 8));
__m256i shmask = _mm256_set1_epi32(7);
el4l.val = _mm256_add_ps(_mm256_cvtepi32_ps(_mm256_cvtepi16_epi32(_v256_extract_low(vsum))), prev.val);
el4h.val = _mm256_add_ps(_mm256_cvtepi32_ps(_mm256_cvtepi16_epi32(_v256_extract_high(vsum))), _mm256_permutevar8x32_ps(el4l.val, shmask));
prev.val = _mm256_permutevar8x32_ps(el4h.val, shmask);
#else
el8 += v_rotate_left<1>(el8);
el8 += v_rotate_left<2>(el8);
#if CV_SIMD_WIDTH == 32
el8 += v_rotate_left<4>(el8);
#if CV_SIMD_WIDTH == 64
el8 += v_rotate_left<8>(el8);
#endif
#endif
v_int32 el4li, el4hi;
v_expand(el8, el4li, el4hi);
el4l = v_cvt_f32(el4li) + prev;
el4h = v_cvt_f32(el4hi) + el4l;
prev = vx_setall_f32(v_rotate_right<v_float32::nlanes - 1>(el4h).get0());
#endif
v_store(sum_row + j , el4l + vx_load(prev_sum_row + j ));
v_store(sum_row + j + v_float32::nlanes, el4h + vx_load(prev_sum_row + j + v_float32::nlanes));
}
for (float v = sum_row[j - 1] - prev_sum_row[j - 1]; j < width; ++j)
sum_row[j] = (v += src_row[j]) + prev_sum_row[j];
}
vx_cleanup();
return true;
}
};
#endif

View File

@ -333,6 +333,7 @@ EMSCRIPTEN_BINDINGS(binding_utils)
register_vector<cv::Point>("PointVector");
register_vector<cv::Mat>("MatVector");
register_vector<cv::Rect>("RectVector");
register_vector<cv::KeyPoint>("KeyPointVector");
emscripten::class_<cv::Mat>("Mat")
.constructor<>()
@ -478,6 +479,14 @@ EMSCRIPTEN_BINDINGS(binding_utils)
function("rotatedRectBoundingRect", select_overload<Rect(const cv::RotatedRect&)>(&binding_utils::rotatedRectBoundingRect));
function("rotatedRectBoundingRect2f", select_overload<Rect2f(const cv::RotatedRect&)>(&binding_utils::rotatedRectBoundingRect2f));
emscripten::value_object<cv::KeyPoint>("KeyPoint")
.field("angle", &cv::KeyPoint::angle)
.field("class_id", &cv::KeyPoint::class_id)
.field("octave", &cv::KeyPoint::octave)
.field("pt", &cv::KeyPoint::pt)
.field("response", &cv::KeyPoint::response)
.field("size", &cv::KeyPoint::size);
emscripten::value_array<cv::Scalar_<double>> ("Scalar")
.element(index<0>())
.element(index<1>())

View File

@ -555,4 +555,6 @@ namespace cvtest
void cv::cuda::PrintTo(const DeviceInfo& info, std::ostream* os)
{
(*os) << info.name();
if (info.deviceID())
(*os) << " [ID: " << info.deviceID() << "]";
}

View File

@ -48,6 +48,7 @@
#include <algorithm>
#include <limits>
#define OPENCV_FOURCC(c1, c2, c3, c4) (((c1) & 255) + (((c2) & 255) << 8) + (((c3) & 255) << 16) + (((c4) & 255) << 24))
#define CALC_FFMPEG_VERSION(a,b,c) ( a<<16 | b<<8 | c )
#if defined _MSC_VER && _MSC_VER >= 1200
@ -350,6 +351,41 @@ struct AVInterruptCallbackMetadata
int timeout;
};
// https://github.com/opencv/opencv/pull/12693#issuecomment-426236731
static
inline const char* _opencv_avcodec_get_name(AVCodecID id)
{
#if LIBAVCODEC_VERSION_MICRO >= 100 \
&& LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(53, 47, 100)
return avcodec_get_name(id);
#else
const AVCodecDescriptor *cd;
AVCodec *codec;
if (id == AV_CODEC_ID_NONE)
{
return "none";
}
cd = avcodec_descriptor_get(id);
if (cd)
{
return cd->name;
}
codec = avcodec_find_decoder(id);
if (codec)
{
return codec->name;
}
codec = avcodec_find_encoder(id);
if (codec)
{
return codec->name;
}
return "unknown_codec";
#endif
}
static
inline void _opencv_ffmpeg_free(void** ptr)
{
@ -1121,6 +1157,10 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
{
if( !video_st ) return 0;
double codec_tag = 0;
AVCodecID codec_id = AV_CODEC_ID_NONE;
const char* codec_fourcc = NULL;
switch( property_id )
{
case CV_FFMPEG_CAP_PROP_POS_MSEC:
@ -1139,10 +1179,25 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
return get_fps();
case CV_FFMPEG_CAP_PROP_FOURCC:
#if LIBAVFORMAT_BUILD > 4628
return (double)video_st->codec->codec_tag;
codec_id = video_st->codec->codec_id;
codec_tag = (double) video_st->codec->codec_tag;
#else
return (double)video_st->codec.codec_tag;
codec_id = video_st->codec.codec_id;
codec_tag = (double)video_st->codec.codec_tag;
#endif
if(codec_tag || codec_id == AV_CODEC_ID_NONE)
{
return codec_tag;
}
codec_fourcc = _opencv_avcodec_get_name(codec_id);
if(!codec_fourcc || strlen(codec_fourcc) < 4 || strcmp(codec_fourcc, "unknown_codec") == 0)
{
return codec_tag;
}
return (double) OPENCV_FOURCC(codec_fourcc[0], codec_fourcc[1], codec_fourcc[2], codec_fourcc[3]);
case CV_FFMPEG_CAP_PROP_SAR_NUM:
return _opencv_ffmpeg_get_sample_aspect_ratio(ic->streams[video_stream]).num;
case CV_FFMPEG_CAP_PROP_SAR_DEN:

View File

@ -12,6 +12,13 @@
fun:_ZN2cv22getInitializationMutexEv
}
{
OpenCV-SingletonBuffer
Memcheck:Leak
...
fun:_ZN2cv20allocSingletonBufferEm
}
{
OpenCV-getStdAllocator
Memcheck:Leak

View File

@ -0,0 +1,42 @@
# cmake needs this line
cmake_minimum_required(VERSION 3.1)
if(NOT DEFINED EXAMPLE_NAME)
message(FATAL_ERROR "Invalid build script: missing EXAMPLE_NAME")
endif()
if(NOT DEFINED EXAMPLE_FILE)
message(FATAL_ERROR "Invalid build script: missing EXAMPLE_FILE")
endif()
file(TO_CMAKE_PATH "${EXAMPLE_FILE}" EXAMPLE_FILE)
message(STATUS "Project: ${EXAMPLE_NAME}")
message(STATUS "File : ${EXAMPLE_FILE}")
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Define project name
project(${EXAMPLE_NAME})
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Declare the executable target built from your sources
add_executable(${EXAMPLE_NAME} "${EXAMPLE_FILE}")
# Link your application with OpenCV libraries
target_link_libraries(${EXAMPLE_NAME} ${OpenCV_LIBS})

View File

@ -0,0 +1,180 @@
:: Usage:
:: - Drag & drop .cpp file on this file from Windows explorer
:: - Run from cmd/powershell:
:: - > _winpack_build_sample.cmd cpp\opencv_version.cpp
:: Requires:
:: - CMake
:: - MSVS 2015/2017
:: (tools are searched on default paths or environment should be pre-configured)
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set SCRIPTDIR=%~dp0
if NOT exist "%SCRIPTDIR%\..\..\build" (
set "MSG=OpenCV Winpack installation is required"
goto die
)
if [%1]==[] (
set "MSG=Sample path is required"
goto die
)
if exist %1\* (
set "MSG=Only .cpp samples are allowed (not a directory): %1"
goto die
)
if NOT "%~x1" == ".cpp" (
set "MSG=Only .cpp samples are allowed: %~x1"
goto die
)
set SRC_FILENAME=%~dpnx1
echo SRC_FILENAME=!SRC_FILENAME!
call :dirname "!SRC_FILENAME!" SRC_DIR
echo SRC_DIR=!SRC_DIR!
set "SRC_NAME=%~n1"
echo SRC_NAME=!SRC_NAME!
echo ================================================================================
:: Path to FFMPEG binary files
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\bin\"
:: Detect CMake
cmake --version >NUL 2>NUL
if !ERRORLEVEL! EQU 0 (
set CMAKE_FOUND=1
) else (
if exist "C:\Program Files\CMake\bin" (
set "PATH=!PATH!;C:\Program Files\CMake\bin"
cmake --version >NUL 2>NUL
if !ERRORLEVEL! EQU 0 (
set CMAKE_FOUND=1
)
)
)
if NOT DEFINED CMAKE_FOUND (
set "MSG=CMake is required to build OpenCV samples. Download it from here: https://cmake.org/download/ and install into 'C:\Program Files\CMake'"
goto die
) else (
echo CMake is detected
)
:: Detect compiler
cl /? >NUL 2>NUL <NUL
if !ERRORLEVEL! NEQ 0 (
PUSHD !CD!
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat" (
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat"
) else (
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars64.bat" (
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
) else (
if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" (
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
)
)
)
POPD
cl /? >NUL 2>NUL <NUL
if !ERRORLEVEL! NEQ 0 (
set "MSG=ERROR: Can't detect Microsoft Visial Studio C++ compiler (cl.exe). MSVS 2015/2017 are supported only from standard locations"
goto die
)
)
:: Detect available MSVS version
if NOT DEFINED VisualStudioVersion (
set "MSG=Can't determine MSVS version. 'VisualStudioVersion' is not defined"
goto die
)
if "!VisualStudioVersion!" == "14.0" (
set CMAKE_GENERATOR="Visual Studio 14 Win64"
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\x64\vc14\bin\"
) else (
if "!VisualStudioVersion!" == "15.0" (
set CMAKE_GENERATOR="Visual Studio 15 Win64"
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\x64\vc15\bin\"
) else (
set "MSG=Unsupported MSVS version. VisualStudioVersion=!VisualStudioVersion!"
goto die
)
)
set "BUILD_DIR=!SRC_DIR!\build_!SRC_NAME!"
call :set_title Create build directory
if NOT exist "!BUILD_DIR!" ( call :execute md "!BUILD_DIR!" )
PUSHD "!BUILD_DIR!"
if NOT exist "!BUILD_DIR!/sample" ( call :execute md "!BUILD_DIR!/sample" )
call :execute copy /Y "!SCRIPTDIR!/CMakeLists.example.in" "!BUILD_DIR!/sample/CMakeLists.txt"
call :set_title Configuring via CMake
call :execute cmake -G!CMAKE_GENERATOR! "!BUILD_DIR!\sample" -DEXAMPLE_NAME=!SRC_NAME! "-DEXAMPLE_FILE=!SRC_FILENAME!" "-DOpenCV_DIR=!SCRIPTDIR!\..\..\build"
if !ERRORLEVEL! NEQ 0 (
set "MSG=CMake configuration step failed: !BUILD_DIR!"
goto die
)
call :set_title Build sample project via CMake
call :execute cmake --build . --config Release
if !ERRORLEVEL! NEQ 0 (
set "MSG=Build step failed: !BUILD_DIR!"
goto die
)
call :set_title Launch !SRC_NAME!
if NOT exist "!BUILD_DIR!\Release\!SRC_NAME!.exe" (
echo. "ERROR: Can't find executable file (build seems broken): !SRC_NAME!.exe"
) else (
cd "!BUILD_DIR!\Release"
call :execute "!SRC_NAME!.exe" --help
echo ================================================================================
echo ** Type '!SRC_NAME!.exe' to run sample application
echo ** Type '!SRC_NAME!.exe --help' to get list of available options (if available)
echo ** Type 'start ..\!SRC_NAME!.sln' to launch MSVS IDE
echo ** Type 'cmake --build .. --config Release' to rebuild sample
echo ** Type 'exit' to exit from interactive shell and open the build directory
echo ================================================================================
)
call :set_title Hands-on: !SRC_NAME!
cmd /k echo Current directory: !CD!
call :set_title Done: !SRC_NAME!
echo Opening build directory with project files...
explorer "!BUILD_DIR!"
POPD
echo Done!
pause
exit /B 0
::
:: Helper routines
::
:set_title
title OpenCV sample: %*
EXIT /B 0
:execute
echo =================================================================================
setlocal enableextensions disabledelayedexpansion
echo %*
call %*
endlocal
EXIT /B %ERRORLEVEL%
:dirname file resultVar
setlocal
set _dir=%~dp1
set _dir=%_dir:~0,-1%
endlocal & set %2=%_dir%
EXIT /B 0
:: 'goto die' instead of 'call'
:die
TITLE OpenCV sample: ERROR: %MSG%
echo ERROR: %MSG%
pause
EXIT /B 1