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

This commit is contained in:
Alexander Alekhin 2020-06-19 07:33:50 +00:00
commit e3d502310f
11 changed files with 186 additions and 86 deletions

View File

@ -22,7 +22,7 @@
# sqfu@openailab.com # sqfu@openailab.com
# #
SET(TENGINE_COMMIT_VERSION "2f3cd86217f3530c8e4a82f3ed5af14c7a4e3943") SET(TENGINE_COMMIT_VERSION "8a4c58e0e05cd850f4bb0936a330edc86dc0e28c")
SET(OCV_TENGINE_DIR "${OpenCV_BINARY_DIR}/3rdparty/libtengine") SET(OCV_TENGINE_DIR "${OpenCV_BINARY_DIR}/3rdparty/libtengine")
SET(OCV_TENGINE_SOURCE_PATH "${OCV_TENGINE_DIR}/Tengine-${TENGINE_COMMIT_VERSION}") SET(OCV_TENGINE_SOURCE_PATH "${OCV_TENGINE_DIR}/Tengine-${TENGINE_COMMIT_VERSION}")
@ -34,7 +34,7 @@ IF(EXISTS "${OCV_TENGINE_SOURCE_PATH}")
ELSE() ELSE()
SET(OCV_TENGINE_FILENAME "${TENGINE_COMMIT_VERSION}.zip")#name2 SET(OCV_TENGINE_FILENAME "${TENGINE_COMMIT_VERSION}.zip")#name2
SET(OCV_TENGINE_URL "https://github.com/OAID/Tengine/archive/") #url2 SET(OCV_TENGINE_URL "https://github.com/OAID/Tengine/archive/") #url2
SET(tengine_md5sum 9124324b6e2b350012e46ae1db4bad7d) #md5sum2 SET(tengine_md5sum f51ca8f3963faeeff3f019a6f6edc206) #md5sum2
#MESSAGE(STATUS "**** TENGINE DOWNLOAD BEGIN ****") #MESSAGE(STATUS "**** TENGINE DOWNLOAD BEGIN ****")
ocv_download(FILENAME ${OCV_TENGINE_FILENAME} ocv_download(FILENAME ${OCV_TENGINE_FILENAME}
@ -69,7 +69,6 @@ if(BUILD_TENGINE)
elseif(${ANDROID_ABI} STREQUAL "arm64-v8a") elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
SET(CONFIG_ARCH_ARM64 ON) SET(CONFIG_ARCH_ARM64 ON)
endif() endif()
SET(Tengine_LIB "tengine" CACHE INTERNAL "")
else() else()
# linux system # linux system
if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm) if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
@ -77,7 +76,6 @@ if(BUILD_TENGINE)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) ## AARCH64 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) ## AARCH64
SET(CONFIG_ARCH_ARM64 ON) SET(CONFIG_ARCH_ARM64 ON)
endif() endif()
SET(Tengine_LIB "tengine" CACHE INTERNAL "")
endif() endif()
SET(BUILT_IN_OPENCV ON) ## set for tengine compile discern . SET(BUILT_IN_OPENCV ON) ## set for tengine compile discern .
@ -86,6 +84,6 @@ if(BUILD_TENGINE)
add_subdirectory("${OCV_TENGINE_SOURCE_PATH}" "${OCV_TENGINE_DIR}/build") add_subdirectory("${OCV_TENGINE_SOURCE_PATH}" "${OCV_TENGINE_DIR}/build")
else() else()
message(WARNING "TENGINE: Missing 'CMakeLists.txt' in source code package: ${OCV_TENGINE_SOURCE_PATH}") message(WARNING "TENGINE: Missing 'CMakeLists.txt' in source code package: ${OCV_TENGINE_SOURCE_PATH}")
SET(HAVE_TENGINE 1)
endif() endif()
SET(Tengine_LIB "tengine" CACHE INTERNAL "")
endif() endif()

View File

@ -48,11 +48,31 @@ if(CUDA_FOUND)
endif() endif()
if(WITH_NVCUVID) if(WITH_NVCUVID)
macro(SEARCH_NVCUVID_HEADER _filename _result)
# place header file under CUDA_TOOLKIT_TARGET_DIR or CUDA_TOOLKIT_ROOT_DIR
find_path(_header_result
${_filename}
PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}"
ENV CUDA_PATH
ENV CUDA_INC_PATH
PATH_SUFFIXES include
NO_DEFAULT_PATH
)
if("x${_header_result}" STREQUAL "x_header_result-NOTFOUND")
set(${_result} 0)
else()
set(${_result} 1)
endif()
unset(_header_result CACHE)
endmacro()
SEARCH_NVCUVID_HEADER("nvcuvid.h" HAVE_NVCUVID_HEADER)
SEARCH_NVCUVID_HEADER("dynlink_nvcuvid.h" HAVE_DYNLINK_NVCUVID_HEADER)
find_cuda_helper_libs(nvcuvid) find_cuda_helper_libs(nvcuvid)
if(WIN32) if(WIN32)
find_cuda_helper_libs(nvcuvenc) find_cuda_helper_libs(nvcuvenc)
endif() endif()
if(CUDA_nvcuvid_LIBRARY) if(CUDA_nvcuvid_LIBRARY AND (${HAVE_NVCUVID_HEADER} OR ${HAVE_DYNLINK_NVCUVID_HEADER}))
# make sure to have both header and library before enabling
set(HAVE_NVCUVID 1) set(HAVE_NVCUVID 1)
endif() endif()
if(CUDA_nvcuvenc_LIBRARY) if(CUDA_nvcuvenc_LIBRARY)
@ -98,7 +118,7 @@ if(CUDA_FOUND)
else() else()
set(CC_LIST ${ARGN}) set(CC_LIST ${ARGN})
foreach(target_arch ${CC_LIST}) foreach(target_arch ${CC_LIST})
string(REPLACE "." "" target_arch_short ${target_arch}) string(REPLACE "." "" target_arch_short "${target_arch}")
set(NVCC_OPTION "-gencode;arch=compute_${target_arch_short},code=sm_${target_arch_short}") set(NVCC_OPTION "-gencode;arch=compute_${target_arch_short},code=sm_${target_arch_short}")
execute_process( COMMAND "${CUDA_NVCC_EXECUTABLE}" ${NVCC_OPTION} "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" execute_process( COMMAND "${CUDA_NVCC_EXECUTABLE}" ${NVCC_OPTION} "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
@ -108,7 +128,7 @@ if(CUDA_FOUND)
set(${result_list} "${${result_list}} ${target_arch}") set(${result_list} "${${result_list}} ${target_arch}")
endif() endif()
endforeach() endforeach()
string(STRIP ${${result_list}} ${result_list}) string(STRIP "${${result_list}}" ${result_list})
set(CUDA_SUPPORTED_CC ${${result_list}} CACHE INTERNAL "List of supported compute capability") set(CUDA_SUPPORTED_CC ${${result_list}} CACHE INTERNAL "List of supported compute capability")
endif() endif()
endmacro() endmacro()
@ -122,7 +142,7 @@ if(CUDA_FOUND)
endmacro() endmacro()
macro(ocv_wipeout_deprecated _arch_bin_list) macro(ocv_wipeout_deprecated _arch_bin_list)
string(REPLACE "2.1" "2.1(2.0)" ${_arch_bin_list} ${${_arch_bin_list}}) string(REPLACE "2.1" "2.1(2.0)" ${_arch_bin_list} "${${_arch_bin_list}}")
endmacro() endmacro()
set(__cuda_arch_ptx "") set(__cuda_arch_ptx "")

View File

@ -88,7 +88,7 @@ FOREACH(SEARCH_PATH ${SEARCH_PATHS})
ocv_find_openexr("-${OPENEXR_VERSION}") ocv_find_openexr("-${OPENEXR_VERSION}")
ocv_find_openexr("-${OPENEXR_VERSION}_s") ocv_find_openexr("-${OPENEXR_VERSION}_s")
ocv_find_openexr("-${OPENEXR_VERSION}_d") ocv_find_openexr("-${OPENEXR_VERSION}_d")
ocv_find_openexr("-${OPEXEXR_VERSION}_s_d") ocv_find_openexr("-${OPENEXR_VERSION}_s_d")
ocv_find_openexr("") ocv_find_openexr("")
ocv_find_openexr("_s") ocv_find_openexr("_s")
ocv_find_openexr("_d") ocv_find_openexr("_d")

View File

@ -95,6 +95,8 @@
/* NVIDIA Video Decoding API*/ /* NVIDIA Video Decoding API*/
#cmakedefine HAVE_NVCUVID #cmakedefine HAVE_NVCUVID
#cmakedefine HAVE_NVCUVID_HEADER
#cmakedefine HAVE_DYNLINK_NVCUVID_HEADER
/* NVIDIA Video Encoding API*/ /* NVIDIA Video Encoding API*/
#cmakedefine HAVE_NVCUVENC #cmakedefine HAVE_NVCUVENC

View File

@ -101,6 +101,20 @@ namespace cv { namespace cuda
cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>(); cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
cudaSafeCall( cudaBindTexture2D(0, tex, img.ptr(), &desc, img.cols, img.rows, img.step) ); cudaSafeCall( cudaBindTexture2D(0, tex, img.ptr(), &desc, img.cols, img.rows, img.step) );
} }
template<class T> inline void createTextureObjectPitch2D(cudaTextureObject_t* tex, PtrStepSz<T>& img, const cudaTextureDesc& texDesc)
{
cudaResourceDesc resDesc;
memset(&resDesc, 0, sizeof(resDesc));
resDesc.resType = cudaResourceTypePitch2D;
resDesc.res.pitch2D.devPtr = static_cast<void*>(img.ptr());
resDesc.res.pitch2D.height = img.rows;
resDesc.res.pitch2D.width = img.cols;
resDesc.res.pitch2D.pitchInBytes = img.step;
resDesc.res.pitch2D.desc = cudaCreateChannelDesc<T>();
cudaSafeCall( cudaCreateTextureObject(tex, &resDesc, &texDesc, NULL) );
}
} }
}} }}

View File

@ -51,18 +51,19 @@
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#if defined _MSC_VER && _MSC_VER >= 1200
#define NOMINMAX // fix https://github.com/opencv/opencv/issues/17548
#pragma warning( disable: 4714 ) //__forceinline is not inlined
#pragma warning( disable: 4127 ) //conditional expression is constant
#pragma warning( disable: 4244 ) //conversion from '__int64' to 'int', possible loss of data
#endif
#if EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 \ #if EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 \
&& defined(CV_CXX11) && defined(CV_CXX_STD_ARRAY) && defined(CV_CXX11) && defined(CV_CXX_STD_ARRAY)
#include <unsupported/Eigen/CXX11/Tensor> #include <unsupported/Eigen/CXX11/Tensor>
#define OPENCV_EIGEN_TENSOR_SUPPORT #define OPENCV_EIGEN_TENSOR_SUPPORT
#endif // EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 #endif // EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3
#if defined _MSC_VER && _MSC_VER >= 1200
#pragma warning( disable: 4714 ) //__forceinline is not inlined
#pragma warning( disable: 4127 ) //conditional expression is constant
#pragma warning( disable: 4244 ) //conversion from '__int64' to 'int', possible loss of data
#endif
namespace cv namespace cv
{ {

View File

@ -25,9 +25,26 @@ String dumpInputArray(InputArray argument)
break; // done break; // done
} }
ss << cv::format(" total(-1)=%lld", (long long int)argument.total(-1)); ss << cv::format(" total(-1)=%lld", (long long int)argument.total(-1));
ss << cv::format(" dims(-1)=%d", argument.dims(-1)); int dims = argument.dims(-1);
Size size = argument.size(-1); ss << cv::format(" dims(-1)=%d", dims);
ss << cv::format(" size(-1)=%dx%d", size.width, size.height); if (dims <= 2)
{
Size size = argument.size(-1);
ss << cv::format(" size(-1)=%dx%d", size.width, size.height);
}
else
{
int sz[CV_MAX_DIM] = {0};
argument.sizend(sz, -1);
ss << " size(-1)=[";
for (int i = 0; i < dims; i++)
{
if (i > 0)
ss << ' ';
ss << sz[i];
}
ss << "]";
}
ss << " type(-1)=" << cv::typeToString(argument.type(-1)); ss << " type(-1)=" << cv::typeToString(argument.type(-1));
} while (0); } while (0);
} }
@ -61,10 +78,26 @@ CV_EXPORTS_W String dumpInputArrayOfArrays(InputArrayOfArrays argument)
if (argument.total(-1) > 0) if (argument.total(-1) > 0)
{ {
ss << " type(0)=" << cv::typeToString(argument.type(0)); ss << " type(0)=" << cv::typeToString(argument.type(0));
ss << cv::format(" dims(0)=%d", argument.dims(0)); int dims = argument.dims(0);
size = argument.size(0); ss << cv::format(" dims(0)=%d", dims);
ss << cv::format(" size(0)=%dx%d", size.width, size.height); if (dims <= 2)
ss << " type(0)=" << cv::typeToString(argument.type(0)); {
Size size0 = argument.size(0);
ss << cv::format(" size(0)=%dx%d", size0.width, size0.height);
}
else
{
int sz[CV_MAX_DIM] = {0};
argument.sizend(sz, 0);
ss << " size(0)=[";
for (int i = 0; i < dims; i++)
{
if (i > 0)
ss << ' ';
ss << sz[i];
}
ss << "]";
}
} }
} while (0); } while (0);
} }
@ -92,9 +125,26 @@ CV_EXPORTS_W String dumpInputOutputArray(InputOutputArray argument)
break; // done break; // done
} }
ss << cv::format(" total(-1)=%lld", (long long int)argument.total(-1)); ss << cv::format(" total(-1)=%lld", (long long int)argument.total(-1));
ss << cv::format(" dims(-1)=%d", argument.dims(-1)); int dims = argument.dims(-1);
Size size = argument.size(-1); ss << cv::format(" dims(-1)=%d", dims);
ss << cv::format(" size(-1)=%dx%d", size.width, size.height); if (dims <= 2)
{
Size size = argument.size(-1);
ss << cv::format(" size(-1)=%dx%d", size.width, size.height);
}
else
{
int sz[CV_MAX_DIM] = {0};
argument.sizend(sz, -1);
ss << " size(-1)=[";
for (int i = 0; i < dims; i++)
{
if (i > 0)
ss << ' ';
ss << sz[i];
}
ss << "]";
}
ss << " type(-1)=" << cv::typeToString(argument.type(-1)); ss << " type(-1)=" << cv::typeToString(argument.type(-1));
} while (0); } while (0);
} }
@ -128,10 +178,26 @@ CV_EXPORTS_W String dumpInputOutputArrayOfArrays(InputOutputArrayOfArrays argume
if (argument.total(-1) > 0) if (argument.total(-1) > 0)
{ {
ss << " type(0)=" << cv::typeToString(argument.type(0)); ss << " type(0)=" << cv::typeToString(argument.type(0));
ss << cv::format(" dims(0)=%d", argument.dims(0)); int dims = argument.dims(0);
size = argument.size(0); ss << cv::format(" dims(0)=%d", dims);
ss << cv::format(" size(0)=%dx%d", size.width, size.height); if (dims <= 2)
ss << " type(0)=" << cv::typeToString(argument.type(0)); {
Size size0 = argument.size(0);
ss << cv::format(" size(0)=%dx%d", size0.width, size0.height);
}
else
{
int sz[CV_MAX_DIM] = {0};
argument.sizend(sz, 0);
ss << " size(0)=[";
for (int i = 0; i < dims; i++)
{
if (i > 0)
ss << ' ';
ss << sz[i];
}
ss << "]";
}
} }
} while (0); } while (0);
} }

View File

@ -479,12 +479,12 @@ public:
auto scale_x_y_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, &scale_x_y); auto scale_x_y_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, &scale_x_y);
auto shift_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, std::vector<float>{0.5}); auto shift_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, std::vector<float>{0.5});
auto axis = ngraph::op::Constant::create<int64_t>(ngraph::element::i64, ngraph::Shape{}, {0});
auto splits = ngraph::op::Constant::create<int64_t>(ngraph::element::i64, ngraph::Shape{5}, {1, 1, 1, 1, rows - 4});
auto split = std::make_shared<ngraph::op::v1::VariadicSplit>(input2d, axis, splits);
std::shared_ptr<ngraph::Node> box_x; std::shared_ptr<ngraph::Node> box_x;
{ {
auto lower_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{0, 0}); box_x = std::make_shared<ngraph::op::Sigmoid>(split->output(0));
auto upper_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{1, cols});
box_x = std::make_shared<ngraph::op::v1::StridedSlice>(input2d, lower_bounds, upper_bounds, strides, std::vector<int64_t>{}, std::vector<int64_t>{});
box_x = std::make_shared<ngraph::op::Sigmoid>(box_x);
box_x = std::make_shared<ngraph::op::v1::Subtract>(box_x, shift_node, ngraph::op::AutoBroadcastType::NUMPY); box_x = std::make_shared<ngraph::op::v1::Subtract>(box_x, shift_node, ngraph::op::AutoBroadcastType::NUMPY);
box_x = std::make_shared<ngraph::op::v1::Multiply>(box_x, scale_x_y_node, ngraph::op::AutoBroadcastType::NUMPY); box_x = std::make_shared<ngraph::op::v1::Multiply>(box_x, scale_x_y_node, ngraph::op::AutoBroadcastType::NUMPY);
box_x = std::make_shared<ngraph::op::v1::Add>(box_x, shift_node, ngraph::op::AutoBroadcastType::NUMPY); box_x = std::make_shared<ngraph::op::v1::Add>(box_x, shift_node, ngraph::op::AutoBroadcastType::NUMPY);
@ -510,10 +510,7 @@ public:
std::shared_ptr<ngraph::Node> box_y; std::shared_ptr<ngraph::Node> box_y;
{ {
auto lower_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{1, 0}); box_y = std::make_shared<ngraph::op::Sigmoid>(split->output(1));
auto upper_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{2, cols});
box_y = std::make_shared<ngraph::op::v1::StridedSlice>(input2d, lower_bounds, upper_bounds, strides, std::vector<int64_t>{}, std::vector<int64_t>{});
box_y = std::make_shared<ngraph::op::Sigmoid>(box_y);
box_y = std::make_shared<ngraph::op::v1::Subtract>(box_y, shift_node, ngraph::op::AutoBroadcastType::NUMPY); box_y = std::make_shared<ngraph::op::v1::Subtract>(box_y, shift_node, ngraph::op::AutoBroadcastType::NUMPY);
box_y = std::make_shared<ngraph::op::v1::Multiply>(box_y, scale_x_y_node, ngraph::op::AutoBroadcastType::NUMPY); box_y = std::make_shared<ngraph::op::v1::Multiply>(box_y, scale_x_y_node, ngraph::op::AutoBroadcastType::NUMPY);
box_y = std::make_shared<ngraph::op::v1::Add>(box_y, shift_node, ngraph::op::AutoBroadcastType::NUMPY); box_y = std::make_shared<ngraph::op::v1::Add>(box_y, shift_node, ngraph::op::AutoBroadcastType::NUMPY);
@ -566,45 +563,32 @@ public:
std::copy(bias_h.begin(), bias_h.begin() + h * anchors, bias_h.begin() + i * h * anchors); std::copy(bias_h.begin(), bias_h.begin() + h * anchors, bias_h.begin() + i * h * anchors);
} }
auto lower_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{2, 0}); box_w = std::make_shared<ngraph::op::v0::Exp>(split->output(2));
auto upper_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{3, cols});
box_w = std::make_shared<ngraph::op::v1::StridedSlice>(input2d, lower_bounds, upper_bounds, strides, std::vector<int64_t>{}, std::vector<int64_t>{});
box_w = std::make_shared<ngraph::op::v0::Exp>(box_w);
box_w = std::make_shared<ngraph::op::v1::Reshape>(box_w, shape_3d, true); box_w = std::make_shared<ngraph::op::v1::Reshape>(box_w, shape_3d, true);
auto anchor_w_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, box_broad_shape, bias_w.data()); auto anchor_w_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, box_broad_shape, bias_w.data());
box_w = std::make_shared<ngraph::op::v1::Multiply>(box_w, anchor_w_node, ngraph::op::AutoBroadcastType::NUMPY); box_w = std::make_shared<ngraph::op::v1::Multiply>(box_w, anchor_w_node, ngraph::op::AutoBroadcastType::NUMPY);
lower_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{3, 0}); box_h = std::make_shared<ngraph::op::v0::Exp>(split->output(3));
upper_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{4, cols});
box_h = std::make_shared<ngraph::op::v1::StridedSlice>(input2d, lower_bounds, upper_bounds, strides, std::vector<int64_t>{}, std::vector<int64_t>{});
box_h = std::make_shared<ngraph::op::v0::Exp>(box_h);
box_h = std::make_shared<ngraph::op::v1::Reshape>(box_h, shape_3d, true); box_h = std::make_shared<ngraph::op::v1::Reshape>(box_h, shape_3d, true);
auto anchor_h_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, box_broad_shape, bias_h.data()); auto anchor_h_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, box_broad_shape, bias_h.data());
box_h = std::make_shared<ngraph::op::v1::Multiply>(box_h, anchor_h_node, ngraph::op::AutoBroadcastType::NUMPY); box_h = std::make_shared<ngraph::op::v1::Multiply>(box_h, anchor_h_node, ngraph::op::AutoBroadcastType::NUMPY);
} }
auto region_splits = ngraph::op::Constant::create<int64_t>(ngraph::element::i64, ngraph::Shape{3}, {4, 1, rows - 5});
auto region_split = std::make_shared<ngraph::op::v1::VariadicSplit>(region, axis, region_splits);
std::shared_ptr<ngraph::Node> scale; std::shared_ptr<ngraph::Node> scale;
{ {
auto lower_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{4, 0}); float thr = classfix == -1 ? 0.5 : 0;
auto upper_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{5, cols}); auto thresh_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, std::vector<float>{thr});
scale = std::make_shared<ngraph::op::v1::StridedSlice>(region, lower_bounds, upper_bounds, strides, std::vector<int64_t>{}, std::vector<int64_t>{}); auto mask = std::make_shared<ngraph::op::v1::Less>(region_split->output(1), thresh_node);
auto zero_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, mask->get_shape(), std::vector<float>(cols, 0));
if (classfix == -1) scale = std::make_shared<ngraph::op::v1::Select>(mask, zero_node, region_split->output(1));
{
auto thresh_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, std::vector<float>{0.5});
auto mask = std::make_shared<ngraph::op::v1::Less>(scale, thresh_node);
auto zero_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, mask->get_shape(), std::vector<float>(b * cols, 0));
scale = std::make_shared<ngraph::op::v1::Select>(mask, scale, zero_node);
}
} }
std::shared_ptr<ngraph::Node> probs; std::shared_ptr<ngraph::Node> probs;
{ {
auto lower_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{5, 0}); probs = std::make_shared<ngraph::op::v1::Multiply>(region_split->output(2), scale, ngraph::op::AutoBroadcastType::NUMPY);
auto upper_bounds = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{2}, std::vector<int64_t>{rows, cols});
auto classes = std::make_shared<ngraph::op::v1::StridedSlice>(region, lower_bounds, upper_bounds, strides, std::vector<int64_t>{}, std::vector<int64_t>{});
probs = std::make_shared<ngraph::op::v1::Multiply>(classes, scale, ngraph::op::AutoBroadcastType::NUMPY);
auto thresh_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, &thresh); auto thresh_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, &thresh);
auto mask = std::make_shared<ngraph::op::v1::Greater>(probs, thresh_node); auto mask = std::make_shared<ngraph::op::v1::Greater>(probs, thresh_node);
auto zero_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, mask->get_shape(), std::vector<float>((rows - 5) * cols, 0)); auto zero_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, mask->get_shape(), std::vector<float>((rows - 5) * cols, 0));

View File

@ -347,16 +347,16 @@ struct RGB2YCrCb_i<ushort>
sr0 = sr0 - sy0; sr1 = sr1 - sy1; sr0 = sr0 - sy0; sr1 = sr1 - sy1;
sb0 = sb0 - sy0; sb1 = sb1 - sy1; sb0 = sb0 - sy0; sb1 = sb1 - sy1;
v_int32 scr0, scr1, scb0, scb1; v_int32 v_scr0, v_scr1, v_scb0, v_scb1;
scr0 = (sr0*vc3 + vdd) >> shift; v_scr0 = (sr0*vc3 + vdd) >> shift;
scr1 = (sr1*vc3 + vdd) >> shift; v_scr1 = (sr1*vc3 + vdd) >> shift;
scb0 = (sb0*vc4 + vdd) >> shift; v_scb0 = (sb0*vc4 + vdd) >> shift;
scb1 = (sb1*vc4 + vdd) >> shift; v_scb1 = (sb1*vc4 + vdd) >> shift;
// saturate and pack // saturate and pack
cr = v_pack_u(scr0, scr1); cr = v_pack_u(v_scr0, v_scr1);
cb = v_pack_u(scb0, scb1); cb = v_pack_u(v_scb0, v_scb1);
if(yuvOrder) if(yuvOrder)
{ {
@ -781,36 +781,36 @@ struct YCrCb2RGB_i<uchar>
v_int8 scr = v_reinterpret_as_s8(cr); v_int8 scr = v_reinterpret_as_s8(cr);
v_int8 scb = v_reinterpret_as_s8(cb); v_int8 scb = v_reinterpret_as_s8(cb);
v_int16 scr0, scr1, scb0, scb1; v_int16 v_scr0, v_scr1, v_scb0, v_scb1;
v_expand(scr, scr0, scr1); v_expand(scr, v_scr0, v_scr1);
v_expand(scb, scb0, scb1); v_expand(scb, v_scb0, v_scb1);
v_int32 b00, b01, b10, b11; v_int32 b00, b01, b10, b11;
v_int32 g00, g01, g10, g11; v_int32 g00, g01, g10, g11;
v_int32 r00, r01, r10, r11; v_int32 r00, r01, r10, r11;
v_mul_expand(scb0, vc3, b00, b01); v_mul_expand(v_scb0, vc3, b00, b01);
v_mul_expand(scb1, vc3, b10, b11); v_mul_expand(v_scb1, vc3, b10, b11);
if(yuvOrder) if(yuvOrder)
{ {
// if YUV then C3 > 2^15 // if YUV then C3 > 2^15
// so we fix the multiplication // so we fix the multiplication
v_int32 cb00, cb01, cb10, cb11; v_int32 cb00, cb01, cb10, cb11;
v_expand(scb0, cb00, cb01); v_expand(v_scb0, cb00, cb01);
v_expand(scb1, cb10, cb11); v_expand(v_scb1, cb10, cb11);
b00 += cb00 << 15; b01 += cb01 << 15; b00 += cb00 << 15; b01 += cb01 << 15;
b10 += cb10 << 15; b11 += cb11 << 15; b10 += cb10 << 15; b11 += cb11 << 15;
} }
v_int32 t00, t01, t10, t11; v_int32 t00, t01, t10, t11;
v_mul_expand(scb0, vc2, t00, t01); v_mul_expand(v_scb0, vc2, t00, t01);
v_mul_expand(scb1, vc2, t10, t11); v_mul_expand(v_scb1, vc2, t10, t11);
v_mul_expand(scr0, vc1, g00, g01); v_mul_expand(v_scr0, vc1, g00, g01);
v_mul_expand(scr1, vc1, g10, g11); v_mul_expand(v_scr1, vc1, g10, g11);
g00 += t00; g01 += t01; g00 += t00; g01 += t01;
g10 += t10; g11 += t11; g10 += t10; g11 += t11;
v_mul_expand(scr0, vc0, r00, r01); v_mul_expand(v_scr0, vc0, r00, r01);
v_mul_expand(scr1, vc0, r10, r11); v_mul_expand(v_scr1, vc0, r10, r11);
b00 = (b00 + vdescale) >> shift; b01 = (b01 + vdescale) >> shift; b00 = (b00 + vdescale) >> shift; b01 = (b01 + vdescale) >> shift;
b10 = (b10 + vdescale) >> shift; b11 = (b11 + vdescale) >> shift; b10 = (b10 + vdescale) >> shift; b11 = (b11 + vdescale) >> shift;

View File

@ -105,22 +105,35 @@ class Arguments(NewOpenCVTests):
a = np.array([[[1, 2]], [[3, 4]], [[5, 6]]], dtype=float) a = np.array([[[1, 2]], [[3, 4]], [[5, 6]]], dtype=float)
res5 = cv.utils.dumpInputArray(a) # 64FC2 res5 = cv.utils.dumpInputArray(a) # 64FC2
self.assertEqual(res5, "InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=3 dims(-1)=2 size(-1)=1x3 type(-1)=CV_64FC2") self.assertEqual(res5, "InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=3 dims(-1)=2 size(-1)=1x3 type(-1)=CV_64FC2")
a = np.zeros((2,3,4), dtype='f')
res6 = cv.utils.dumpInputArray(a)
self.assertEqual(res6, "InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=6 dims(-1)=2 size(-1)=3x2 type(-1)=CV_32FC4")
a = np.zeros((2,3,4,5), dtype='f')
res7 = cv.utils.dumpInputArray(a)
self.assertEqual(res7, "InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=120 dims(-1)=4 size(-1)=[2 3 4 5] type(-1)=CV_32FC1")
def test_InputArrayOfArrays(self): def test_InputArrayOfArrays(self):
res1 = cv.utils.dumpInputArrayOfArrays(None) res1 = cv.utils.dumpInputArrayOfArrays(None)
# self.assertEqual(res1, "InputArray: noArray()") # not supported # self.assertEqual(res1, "InputArray: noArray()") # not supported
self.assertEqual(res1, "InputArrayOfArrays: empty()=true kind=0x00050000 flags=0x01050000 total(-1)=0 dims(-1)=1 size(-1)=0x0") self.assertEqual(res1, "InputArrayOfArrays: empty()=true kind=0x00050000 flags=0x01050000 total(-1)=0 dims(-1)=1 size(-1)=0x0")
res2_1 = cv.utils.dumpInputArrayOfArrays((1, 2)) # { Scalar:all(1), Scalar::all(2) } res2_1 = cv.utils.dumpInputArrayOfArrays((1, 2)) # { Scalar:all(1), Scalar::all(2) }
self.assertEqual(res2_1, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=2 dims(-1)=1 size(-1)=2x1 type(0)=CV_64FC1 dims(0)=2 size(0)=1x4 type(0)=CV_64FC1") self.assertEqual(res2_1, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=2 dims(-1)=1 size(-1)=2x1 type(0)=CV_64FC1 dims(0)=2 size(0)=1x4")
res2_2 = cv.utils.dumpInputArrayOfArrays([1.5]) res2_2 = cv.utils.dumpInputArrayOfArrays([1.5])
self.assertEqual(res2_2, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=1 dims(-1)=1 size(-1)=1x1 type(0)=CV_64FC1 dims(0)=2 size(0)=1x4 type(0)=CV_64FC1") self.assertEqual(res2_2, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=1 dims(-1)=1 size(-1)=1x1 type(0)=CV_64FC1 dims(0)=2 size(0)=1x4")
a = np.array([[1, 2], [3, 4], [5, 6]]) a = np.array([[1, 2], [3, 4], [5, 6]])
b = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) b = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
res3 = cv.utils.dumpInputArrayOfArrays([a, b]) res3 = cv.utils.dumpInputArrayOfArrays([a, b])
self.assertEqual(res3, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=2 dims(-1)=1 size(-1)=2x1 type(0)=CV_32SC1 dims(0)=2 size(0)=2x3 type(0)=CV_32SC1") self.assertEqual(res3, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=2 dims(-1)=1 size(-1)=2x1 type(0)=CV_32SC1 dims(0)=2 size(0)=2x3")
c = np.array([[[1, 2], [3, 4], [5, 6]]], dtype='f') c = np.array([[[1, 2], [3, 4], [5, 6]]], dtype='f')
res4 = cv.utils.dumpInputArrayOfArrays([c, a, b]) res4 = cv.utils.dumpInputArrayOfArrays([c, a, b])
self.assertEqual(res4, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=3 dims(-1)=1 size(-1)=3x1 type(0)=CV_32FC2 dims(0)=2 size(0)=3x1 type(0)=CV_32FC2") self.assertEqual(res4, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=3 dims(-1)=1 size(-1)=3x1 type(0)=CV_32FC2 dims(0)=2 size(0)=3x1")
a = np.zeros((2,3,4), dtype='f')
res5 = cv.utils.dumpInputArrayOfArrays([a, b])
self.assertEqual(res5, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=2 dims(-1)=1 size(-1)=2x1 type(0)=CV_32FC4 dims(0)=2 size(0)=3x2")
# TODO: fix conversion error
#a = np.zeros((2,3,4,5), dtype='f')
#res6 = cv.utils.dumpInputArray([a, b])
#self.assertEqual(res6, "InputArrayOfArrays: empty()=false kind=0x00050000 flags=0x01050000 total(-1)=2 dims(-1)=1 size(-1)=2x1 type(0)=CV_32FC1 dims(0)=4 size(0)=[2 3 4 5]")
def test_parse_to_bool_convertible(self): def test_parse_to_bool_convertible(self):
try_to_convert = partial(self._try_to_convert, cv.utils.dumpBool) try_to_convert = partial(self._try_to_convert, cv.utils.dumpBool)

View File

@ -59,6 +59,8 @@ def check_executable(cmd):
try: try:
log.debug("Executing: %s" % cmd) log.debug("Executing: %s" % cmd)
result = subprocess.check_output(cmd, stderr=subprocess.STDOUT) result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
if not isinstance(result, str):
result = result.decode("utf-8")
log.debug("Result: %s" % (result+'\n').split('\n')[0]) log.debug("Result: %s" % (result+'\n').split('\n')[0])
return True return True
except Exception as e: except Exception as e: