mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 01:13:28 +08:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
commit
318cba4ce3
@ -143,6 +143,7 @@ CV_INTRIN_DEF_TYPE_TRAITS(double, int64, uint64, double, void, void, double, 2);
|
||||
|
||||
#ifndef CV_DOXYGEN
|
||||
|
||||
#ifndef CV_CPU_OPTIMIZATION_HAL_NAMESPACE
|
||||
#ifdef CV_CPU_DISPATCH_MODE
|
||||
#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE __CV_CAT(hal_, CV_CPU_DISPATCH_MODE)
|
||||
#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN namespace __CV_CAT(hal_, CV_CPU_DISPATCH_MODE) {
|
||||
@ -152,6 +153,7 @@ CV_INTRIN_DEF_TYPE_TRAITS(double, int64, uint64, double, void, void, double, 2);
|
||||
#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN namespace hal_baseline {
|
||||
#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END }
|
||||
#endif
|
||||
#endif // CV_CPU_OPTIMIZATION_HAL_NAMESPACE
|
||||
|
||||
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
|
||||
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END
|
||||
@ -168,29 +170,29 @@ using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE;
|
||||
# undef CV_MSA
|
||||
#endif
|
||||
|
||||
#if CV_SSE2 || CV_NEON || CV_VSX || CV_MSA || CV_WASM_SIMD
|
||||
#if (CV_SSE2 || CV_NEON || CV_VSX || CV_MSA || CV_WASM_SIMD) && !defined(CV_FORCE_SIMD128_CPP)
|
||||
#define CV__SIMD_FORWARD 128
|
||||
#include "opencv2/core/hal/intrin_forward.hpp"
|
||||
#endif
|
||||
|
||||
#if CV_SSE2
|
||||
#if CV_SSE2 && !defined(CV_FORCE_SIMD128_CPP)
|
||||
|
||||
#include "opencv2/core/hal/intrin_sse_em.hpp"
|
||||
#include "opencv2/core/hal/intrin_sse.hpp"
|
||||
|
||||
#elif CV_NEON
|
||||
#elif CV_NEON && !defined(CV_FORCE_SIMD128_CPP)
|
||||
|
||||
#include "opencv2/core/hal/intrin_neon.hpp"
|
||||
|
||||
#elif CV_VSX
|
||||
#elif CV_VSX && !defined(CV_FORCE_SIMD128_CPP)
|
||||
|
||||
#include "opencv2/core/hal/intrin_vsx.hpp"
|
||||
|
||||
#elif CV_MSA
|
||||
#elif CV_MSA && !defined(CV_FORCE_SIMD128_CPP)
|
||||
|
||||
#include "opencv2/core/hal/intrin_msa.hpp"
|
||||
|
||||
#elif CV_WASM_SIMD
|
||||
#elif CV_WASM_SIMD && !defined(CV_FORCE_SIMD128_CPP)
|
||||
#include "opencv2/core/hal/intrin_wasm.hpp"
|
||||
|
||||
#else
|
||||
|
@ -365,6 +365,13 @@ template<typename _Tp, int n> struct v_reg
|
||||
return c;
|
||||
}
|
||||
|
||||
v_reg& operator=(const v_reg<_Tp, n> & r)
|
||||
{
|
||||
for( int i = 0; i < n; i++ )
|
||||
s[i] = r.s[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
_Tp s[n];
|
||||
//! @endcond
|
||||
};
|
||||
@ -623,7 +630,7 @@ template<typename _Tp, int n>
|
||||
inline v_reg<typename V_TypeTraits<_Tp>::abs_type, n> v_popcount(const v_reg<_Tp, n>& a)
|
||||
{
|
||||
v_reg<typename V_TypeTraits<_Tp>::abs_type, n> b = v_reg<typename V_TypeTraits<_Tp>::abs_type, n>::zero();
|
||||
for (int i = 0; i < (int)(n*sizeof(_Tp)); i++)
|
||||
for (int i = 0; i < n*(int)sizeof(_Tp); i++)
|
||||
b.s[i/sizeof(_Tp)] += popCountTable[v_reinterpret_as_u8(a).s[i]];
|
||||
return b;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ typedef cuda::Event::CreateFlags Event_CreateFlags;
|
||||
|
||||
template<> struct pyopencvVecConverter<cuda::GpuMat>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<cuda::GpuMat>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<cuda::GpuMat>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
|
@ -4,6 +4,19 @@
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#include "test_intrin128.simd.hpp"
|
||||
|
||||
// see "test_intrin_emulator.cpp"
|
||||
// see "opencv2/core/private/cv_cpu_include_simd_declarations.hpp"
|
||||
#define CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY
|
||||
#undef CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
|
||||
#undef CV_CPU_OPTIMIZATION_NAMESPACE_END
|
||||
#define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace opt_EMULATOR_CPP {
|
||||
#define CV_CPU_OPTIMIZATION_NAMESPACE_END }
|
||||
#include "test_intrin128.simd.hpp"
|
||||
#undef CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
|
||||
#undef CV_CPU_OPTIMIZATION_NAMESPACE_END
|
||||
#undef CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY
|
||||
|
||||
#include "test_intrin128.simd_declarations.hpp"
|
||||
|
||||
#undef CV_CPU_DISPATCH_MODES_ALL
|
||||
@ -22,6 +35,8 @@
|
||||
|
||||
namespace opencv_test { namespace hal {
|
||||
|
||||
#define CV_CPU_CALL_CPP_EMULATOR_(fn, args) return (opt_EMULATOR_CPP::fn args)
|
||||
|
||||
#define CV_CPU_CALL_BASELINE_(fn, args) CV_CPU_CALL_BASELINE(fn, args)
|
||||
|
||||
#define DISPATCH_SIMD128(fn, cpu_opt) do { \
|
||||
@ -53,6 +68,8 @@ TEST(hal_intrin ## simd_size, float64x2_ ## cpu_opt) { DISPATCH_SIMD ## simd_siz
|
||||
|
||||
namespace intrin128 {
|
||||
|
||||
DEFINE_SIMD_TESTS(128, CPP_EMULATOR)
|
||||
|
||||
DEFINE_SIMD_TESTS(128, BASELINE)
|
||||
|
||||
#if defined CV_CPU_DISPATCH_COMPILE_SSE2 || defined CV_CPU_BASELINE_COMPILE_SSE2
|
||||
|
24
modules/core/test/test_intrin_emulator.cpp
Normal file
24
modules/core/test/test_intrin_emulator.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// 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 "test_precomp.hpp"
|
||||
|
||||
// see "opencv2/core/hal/intrin.hpp"
|
||||
#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE hal_EMULATOR_CPP
|
||||
#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN namespace hal_EMULATOR_CPP {
|
||||
#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END }
|
||||
|
||||
// see "opencv2/core/private/cv_cpu_include_simd_declarations.hpp"
|
||||
//#define CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY
|
||||
#define CV_FORCE_SIMD128_CPP
|
||||
#undef CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
|
||||
#undef CV_CPU_OPTIMIZATION_NAMESPACE_END
|
||||
#define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace opt_EMULATOR_CPP {
|
||||
#define CV_CPU_OPTIMIZATION_NAMESPACE_END }
|
||||
#include "test_intrin128.simd.hpp"
|
||||
#undef CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
|
||||
#undef CV_CPU_OPTIMIZATION_NAMESPACE_END
|
||||
#undef CV_CPU_DISPATCH_MODE
|
||||
#undef CV_FORCE_SIMD128_CPP
|
||||
|
||||
// tests implementation is in test_intrin_utils.hpp
|
@ -1383,4 +1383,16 @@ TEST(UMat, testTempObjects_Mat_issue_8693)
|
||||
EXPECT_EQ(0, cvtest::norm(srcUMat.getMat(ACCESS_READ), srcMat, NORM_INF));
|
||||
}
|
||||
|
||||
TEST(UMat, resize_Mat_issue_13577)
|
||||
{
|
||||
// save the current state
|
||||
bool useOCL = cv::ocl::useOpenCL();
|
||||
|
||||
cv::ocl::setUseOpenCL(false);
|
||||
UMat foo(10, 10, CV_32FC1);
|
||||
cv::resize(foo, foo, cv::Size(), .5, .5);
|
||||
|
||||
cv::ocl::setUseOpenCL(useOCL); // restore state
|
||||
}
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
@ -4,9 +4,9 @@ typedef std::vector<dnn::MatShape> vector_MatShape;
|
||||
typedef std::vector<std::vector<dnn::MatShape> > vector_vector_MatShape;
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const char *name)
|
||||
bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if (!o || o == Py_None)
|
||||
return true; //Current state will be used
|
||||
else if (PyLong_Check(o))
|
||||
@ -36,12 +36,6 @@ bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const char *name)
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, std::vector<Mat> &blobs, const char *name) //required for Layer::blobs RW
|
||||
{
|
||||
return pyopencvVecConverter<Mat>::to(o, blobs, ArgInfo(name, false));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
PyObject* pyopencv_from(const dnn::DictValue &dv)
|
||||
{
|
||||
|
@ -610,7 +610,7 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::CNNNetwork& net)
|
||||
{
|
||||
candidates.push_back(param_pluginPath);
|
||||
}
|
||||
|
||||
#if INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R3)
|
||||
if (device_name == "CPU" || device_name == "FPGA")
|
||||
{
|
||||
std::string suffixes[] = {"_avx2", "_sse4", ""};
|
||||
@ -633,6 +633,7 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::CNNNetwork& net)
|
||||
#endif // _WIN32
|
||||
}
|
||||
}
|
||||
#endif
|
||||
bool found = false;
|
||||
for (size_t i = 0; i != candidates.size(); ++i)
|
||||
{
|
||||
|
@ -15,9 +15,9 @@ PyObject* pyopencv_from(const cvflann_flann_distance_t& value)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name)
|
||||
bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
bool ok = true;
|
||||
PyObject* key = NULL;
|
||||
PyObject* item = NULL;
|
||||
@ -71,16 +71,16 @@ bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, cv::flann::SearchParams & value, const char * name)
|
||||
bool pyopencv_to(PyObject* obj, cv::flann::SearchParams & value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to<cv::flann::IndexParams>(obj, value, name);
|
||||
return pyopencv_to<cv::flann::IndexParams>(obj, value, info);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, cvflann::flann_distance_t& dist, const char *name)
|
||||
bool pyopencv_to(PyObject *o, cvflann::flann_distance_t& dist, const ArgInfo& info)
|
||||
{
|
||||
int d = (int)dist;
|
||||
bool ok = pyopencv_to(o, d, name);
|
||||
bool ok = pyopencv_to(o, d, info);
|
||||
dist = (cvflann::flann_distance_t)d;
|
||||
return ok;
|
||||
}
|
||||
|
@ -3738,6 +3738,11 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
|
||||
CV_OCL_RUN(_src.dims() <= 2 && _dst.isUMat() && _src.cols() > 10 && _src.rows() > 10,
|
||||
ocl_resize(_src, _dst, dsize, inv_scale_x, inv_scale_y, interpolation))
|
||||
|
||||
// Fake reference to source. Resolves issue 13577 in case of src == dst.
|
||||
UMat srcUMat;
|
||||
if (_src.isUMat())
|
||||
srcUMat = _src.getUMat();
|
||||
|
||||
Mat src = _src.getMat();
|
||||
_dst.create(dsize, src.type());
|
||||
Mat dst = _dst.getMat();
|
||||
|
@ -59,7 +59,7 @@ QUnit.test('Detectors', function(assert) {
|
||||
|
||||
let akaze = new cv.AKAZE();
|
||||
akaze.detect(image, kp);
|
||||
assert.equal(kp.size(), 52, 'AKAZE');
|
||||
assert.equal(kp.size(), 53, 'AKAZE');
|
||||
});
|
||||
|
||||
QUnit.test('BFMatcher', function(assert) {
|
||||
|
@ -1,16 +1,16 @@
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *obj, CvTermCriteria& dst, const char *name)
|
||||
bool pyopencv_to(PyObject *obj, CvTermCriteria& dst, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "iid", &dst.type, &dst.max_iter, &dst.epsilon) > 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, CvSlice& r, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, CvSlice& r, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
if(PyObject_Size(obj) == 0)
|
||||
|
@ -29,6 +29,9 @@
|
||||
|
||||
#include <numpy/ndarrayobject.h>
|
||||
|
||||
#include "opencv2/core/utils/configuration.private.hpp"
|
||||
#include "opencv2/core/utils/logger.hpp"
|
||||
|
||||
#include "pyopencv_generated_include.h"
|
||||
#include "opencv2/core/types_c.h"
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
@ -37,21 +40,53 @@
|
||||
|
||||
#include <type_traits> // std::enable_if
|
||||
|
||||
class ArgInfo
|
||||
{
|
||||
public:
|
||||
const char * name;
|
||||
bool outputarg;
|
||||
// more fields may be added if necessary
|
||||
|
||||
ArgInfo(const char * name_, bool outputarg_)
|
||||
: name(name_)
|
||||
, outputarg(outputarg_) {}
|
||||
|
||||
private:
|
||||
ArgInfo(const ArgInfo&) = delete;
|
||||
ArgInfo& operator=(const ArgInfo&) = delete;
|
||||
};
|
||||
|
||||
template<typename T, class TEnable = void> // TEnable is used for SFINAE checks
|
||||
struct PyOpenCV_Converter
|
||||
{
|
||||
//static inline bool to(PyObject* obj, T& p, const char* name);
|
||||
//static inline bool to(PyObject* obj, T& p, const ArgInfo& info);
|
||||
//static inline PyObject* from(const T& src);
|
||||
};
|
||||
|
||||
template<typename T> static
|
||||
bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
|
||||
bool pyopencv_to(PyObject* obj, T& p, const ArgInfo& info) { return PyOpenCV_Converter<T>::to(obj, p, info); }
|
||||
|
||||
template<typename T> static
|
||||
PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter<T>::from(src); }
|
||||
|
||||
static PyObject* opencv_error = NULL;
|
||||
|
||||
static bool isPythonBindingsDebugEnabled()
|
||||
{
|
||||
static bool param_debug = cv::utils::getConfigurationParameterBool("OPENCV_PYTHON_DEBUG", false);
|
||||
return param_debug;
|
||||
}
|
||||
|
||||
static void emit_failmsg(PyObject * exc, const char *msg)
|
||||
{
|
||||
static bool param_debug = isPythonBindingsDebugEnabled();
|
||||
if (param_debug)
|
||||
{
|
||||
CV_LOG_WARNING(NULL, "Bindings conversion failed: " << msg);
|
||||
}
|
||||
PyErr_SetString(exc, msg);
|
||||
}
|
||||
|
||||
static int failmsg(const char *fmt, ...)
|
||||
{
|
||||
char str[1000];
|
||||
@ -61,23 +96,22 @@ static int failmsg(const char *fmt, ...)
|
||||
vsnprintf(str, sizeof(str), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, str);
|
||||
emit_failmsg(PyExc_TypeError, str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ArgInfo
|
||||
static PyObject* failmsgp(const char *fmt, ...)
|
||||
{
|
||||
const char * name;
|
||||
bool outputarg;
|
||||
// more fields may be added if necessary
|
||||
char str[1000];
|
||||
|
||||
ArgInfo(const char * name_, bool outputarg_)
|
||||
: name(name_)
|
||||
, outputarg(outputarg_) {}
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(str, sizeof(str), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
// to match with older pyopencv_to function signature
|
||||
operator const char *() const { return name; }
|
||||
};
|
||||
emit_failmsg(PyExc_TypeError, str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
class PyAllowThreads
|
||||
{
|
||||
@ -156,19 +190,6 @@ typedef std::vector<std::vector<Point3f> > vector_vector_Point3f;
|
||||
typedef std::vector<std::vector<DMatch> > vector_vector_DMatch;
|
||||
typedef std::vector<std::vector<KeyPoint> > vector_vector_KeyPoint;
|
||||
|
||||
static PyObject* failmsgp(const char *fmt, ...)
|
||||
{
|
||||
char str[1000];
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(str, sizeof(str), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
class NumpyAllocator : public MatAllocator
|
||||
{
|
||||
public:
|
||||
@ -246,7 +267,7 @@ NumpyAllocator g_numpyAllocator;
|
||||
enum { ARG_NONE = 0, ARG_MAT = 1, ARG_SCALAR = 2 };
|
||||
|
||||
// special case, when the converter needs full ArgInfo structure
|
||||
static bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
|
||||
{
|
||||
bool allowND = true;
|
||||
if(!o || o == Py_None)
|
||||
@ -425,14 +446,8 @@ static bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo info)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* o, Mat& m, const char* name)
|
||||
{
|
||||
return pyopencv_to(o, m, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
template<typename _Tp, int m, int n>
|
||||
bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const ArgInfo info)
|
||||
bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const ArgInfo& info)
|
||||
{
|
||||
Mat tmp;
|
||||
if (!pyopencv_to(o, tmp, info)) {
|
||||
@ -443,10 +458,10 @@ bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const ArgInfo info)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename _Tp, int m, int n>
|
||||
bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const char* name)
|
||||
template<typename _Tp, int cn>
|
||||
bool pyopencv_to(PyObject* o, Vec<_Tp, cn>& vec, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to(o, mx, ArgInfo(name, 0));
|
||||
return pyopencv_to(o, (Matx<_Tp, cn, 1>&)vec, info);
|
||||
}
|
||||
|
||||
template<>
|
||||
@ -481,19 +496,19 @@ struct PyOpenCV_Converter< cv::Ptr<T> >
|
||||
Py_RETURN_NONE;
|
||||
return pyopencv_from(*p);
|
||||
}
|
||||
static bool to(PyObject *o, Ptr<T>& p, const char *name)
|
||||
static bool to(PyObject *o, Ptr<T>& p, const ArgInfo& info)
|
||||
{
|
||||
if (!o || o == Py_None)
|
||||
return true;
|
||||
p = makePtr<T>();
|
||||
return pyopencv_to(o, *p, name);
|
||||
return pyopencv_to(o, *p, info);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, void*& ptr, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, void*& ptr, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if (!obj || obj == Py_None)
|
||||
return true;
|
||||
|
||||
@ -515,7 +530,7 @@ struct SafeSeqItem
|
||||
~SafeSeqItem() { Py_XDECREF(item); }
|
||||
};
|
||||
|
||||
static bool pyopencv_to(PyObject *o, Scalar& s, const ArgInfo info)
|
||||
static bool pyopencv_to(PyObject *o, Scalar& s, const ArgInfo& info)
|
||||
{
|
||||
if(!o || o == Py_None)
|
||||
return true;
|
||||
@ -546,12 +561,6 @@ static bool pyopencv_to(PyObject *o, Scalar& s, const ArgInfo info)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, Scalar& s, const char *name)
|
||||
{
|
||||
return pyopencv_to(o, s, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Scalar& src)
|
||||
{
|
||||
@ -565,9 +574,9 @@ PyObject* pyopencv_from(const bool& value)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, bool& value, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, bool& value, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
int _val = PyObject_IsTrue(obj);
|
||||
@ -584,9 +593,9 @@ PyObject* pyopencv_from(const size_t& value)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, size_t& value, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, size_t& value, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
value = (int)PyLong_AsUnsignedLong(obj);
|
||||
@ -600,9 +609,9 @@ PyObject* pyopencv_from(const int& value)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, int& value, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, int& value, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
if(PyInt_Check(obj))
|
||||
@ -625,9 +634,9 @@ struct PyOpenCV_Converter
|
||||
return PyLong_FromUnsignedLong(value);
|
||||
}
|
||||
|
||||
static inline bool to(PyObject* obj, unsigned int& value, const char* name)
|
||||
static inline bool to(PyObject* obj, unsigned int& value, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
if(PyInt_Check(obj))
|
||||
@ -647,9 +656,9 @@ PyObject* pyopencv_from(const uchar& value)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, uchar& value, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, uchar& value, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
int ivalue = (int)PyInt_AsLong(obj);
|
||||
@ -664,9 +673,9 @@ PyObject* pyopencv_from(const double& value)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, double& value, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, double& value, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
if(!!PyInt_CheckExact(obj))
|
||||
@ -683,9 +692,9 @@ PyObject* pyopencv_from(const float& value)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, float& value, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, float& value, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
if(!!PyInt_CheckExact(obj))
|
||||
@ -708,9 +717,9 @@ PyObject* pyopencv_from(const String& value)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, String &value, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, String &value, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
std::string str;
|
||||
@ -723,9 +732,9 @@ bool pyopencv_to(PyObject* obj, String &value, const char* name)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Size& sz, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Size& sz, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ii", &sz.width, &sz.height) > 0;
|
||||
@ -738,9 +747,9 @@ PyObject* pyopencv_from(const Size& sz)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Size_<float>& sz, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Size_<float>& sz, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ff", &sz.width, &sz.height) > 0;
|
||||
@ -759,9 +768,9 @@ PyObject* pyopencv_from(const Rect& r)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Rect2d& r, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Rect2d& r, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "dddd", &r.x, &r.y, &r.width, &r.height) > 0;
|
||||
@ -774,16 +783,16 @@ PyObject* pyopencv_from(const Rect2d& r)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Range& r, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Range& r, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
while (PySequence_Check(obj))
|
||||
{
|
||||
if (2 != PySequence_Size(obj))
|
||||
{
|
||||
failmsg("Range value for argument '%s' is longer than 2", name);
|
||||
failmsg("Range value for argument '%s' is longer than 2", info.name);
|
||||
return false;
|
||||
}
|
||||
{
|
||||
@ -792,7 +801,7 @@ bool pyopencv_to(PyObject* obj, Range& r, const char* name)
|
||||
if (PyInt_Check(item)) {
|
||||
r.start = (int)PyInt_AsLong(item);
|
||||
} else {
|
||||
failmsg("Range.start value for argument '%s' is not integer", name);
|
||||
failmsg("Range.start value for argument '%s' is not integer", info.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -802,7 +811,7 @@ bool pyopencv_to(PyObject* obj, Range& r, const char* name)
|
||||
if (PyInt_Check(item)) {
|
||||
r.end = (int)PyInt_AsLong(item);
|
||||
} else {
|
||||
failmsg("Range.end value for argument '%s' is not integer", name);
|
||||
failmsg("Range.end value for argument '%s' is not integer", info.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -823,9 +832,9 @@ PyObject* pyopencv_from(const Range& r)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Point& p, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Point& p, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
if(PyComplex_Check(obj))
|
||||
@ -838,9 +847,9 @@ bool pyopencv_to(PyObject* obj, Point& p, const char* name)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Point2f& p, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Point2f& p, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
if (PyComplex_Check(obj))
|
||||
@ -853,9 +862,9 @@ bool pyopencv_to(PyObject* obj, Point2f& p, const char* name)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Point2d& p, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Point2d& p, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
if(PyComplex_Check(obj))
|
||||
@ -868,18 +877,18 @@ bool pyopencv_to(PyObject* obj, Point2d& p, const char* name)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Point3f& p, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Point3f& p, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "fff", &p.x, &p.y, &p.z) > 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Point3d& p, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Point3d& p, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ddd", &p.x, &p.y, &p.z) > 0;
|
||||
@ -903,122 +912,77 @@ PyObject* pyopencv_from(const Point3f& p)
|
||||
return Py_BuildValue("(ddd)", p.x, p.y, p.z);
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec4d& v, ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* obj, Vec4d& v, ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(info);
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "dddd", &v[0], &v[1], &v[2], &v[3]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec4d& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec4f& v, ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* obj, Vec4f& v, ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(info);
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ffff", &v[0], &v[1], &v[2], &v[3]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec4f& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec4i& v, ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* obj, Vec4i& v, ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(info);
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "iiii", &v[0], &v[1], &v[2], &v[3]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec4i& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec3d& v, ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* obj, Vec3d& v, ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(info);
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ddd", &v[0], &v[1], &v[2]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec3d& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec3f& v, ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* obj, Vec3f& v, ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(info);
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "fff", &v[0], &v[1], &v[2]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec3f& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec3i& v, ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* obj, Vec3i& v, ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(info);
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "iii", &v[0], &v[1], &v[2]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec3i& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec2d& v, ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* obj, Vec2d& v, ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(info);
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "dd", &v[0], &v[1]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec2d& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec2f& v, ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* obj, Vec2f& v, ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(info);
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ff", &v[0], &v[1]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec2f& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec2i& v, ArgInfo info)
|
||||
static bool pyopencv_to(PyObject* obj, Vec2i& v, ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(info);
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ii", &v[0], &v[1]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec2i& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Vec4d& v)
|
||||
@ -1121,7 +1085,7 @@ template<typename _Tp> struct pyopencvVecConverter
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static bool to(PyObject* obj, std::vector<_Tp>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<_Tp>& value, const ArgInfo& info)
|
||||
{
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
@ -1201,7 +1165,7 @@ template<typename _Tp> struct pyopencvVecConverter
|
||||
};
|
||||
|
||||
template<typename _Tp>
|
||||
bool pyopencv_to(PyObject* obj, std::vector<_Tp>& value, const ArgInfo info)
|
||||
bool pyopencv_to(PyObject* obj, std::vector<_Tp>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencvVecConverter<_Tp>::to(obj, value, info);
|
||||
}
|
||||
@ -1212,7 +1176,7 @@ PyObject* pyopencv_from(const std::vector<_Tp>& value)
|
||||
return pyopencvVecConverter<_Tp>::from(value);
|
||||
}
|
||||
|
||||
template<typename _Tp> static inline bool pyopencv_to_generic_vec(PyObject* obj, std::vector<_Tp>& value, const ArgInfo info)
|
||||
template<typename _Tp> static inline bool pyopencv_to_generic_vec(PyObject* obj, std::vector<_Tp>& value, const ArgInfo& info)
|
||||
{
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
@ -1256,7 +1220,7 @@ PyObject* pyopencv_from(const std::pair<int, double>& src)
|
||||
|
||||
template<typename _Tp, typename _Tr> struct pyopencvVecConverter<std::pair<_Tp, _Tr> >
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<std::pair<_Tp, _Tr> >& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<std::pair<_Tp, _Tr> >& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -1269,7 +1233,7 @@ template<typename _Tp, typename _Tr> struct pyopencvVecConverter<std::pair<_Tp,
|
||||
|
||||
template<typename _Tp> struct pyopencvVecConverter<std::vector<_Tp> >
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<std::vector<_Tp> >& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<std::vector<_Tp> >& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -1282,7 +1246,7 @@ template<typename _Tp> struct pyopencvVecConverter<std::vector<_Tp> >
|
||||
|
||||
template<> struct pyopencvVecConverter<Mat>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<Mat>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<Mat>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -1295,7 +1259,7 @@ template<> struct pyopencvVecConverter<Mat>
|
||||
|
||||
template<> struct pyopencvVecConverter<UMat>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<UMat>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<UMat>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -1308,7 +1272,7 @@ template<> struct pyopencvVecConverter<UMat>
|
||||
|
||||
template<> struct pyopencvVecConverter<KeyPoint>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<KeyPoint>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<KeyPoint>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -1321,7 +1285,7 @@ template<> struct pyopencvVecConverter<KeyPoint>
|
||||
|
||||
template<> struct pyopencvVecConverter<DMatch>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<DMatch>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<DMatch>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -1334,7 +1298,7 @@ template<> struct pyopencvVecConverter<DMatch>
|
||||
|
||||
template<> struct pyopencvVecConverter<String>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<String>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<String>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -1347,7 +1311,7 @@ template<> struct pyopencvVecConverter<String>
|
||||
|
||||
template<> struct pyopencvVecConverter<RotatedRect>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<RotatedRect>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<RotatedRect>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -1358,9 +1322,9 @@ template<> struct pyopencvVecConverter<RotatedRect>
|
||||
};
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Rect& r, const char* name)
|
||||
bool pyopencv_to(PyObject* obj, Rect& r, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
|
||||
@ -1369,7 +1333,7 @@ bool pyopencv_to(PyObject* obj, Rect& r, const char* name)
|
||||
else
|
||||
{
|
||||
std::vector<int> value(4);
|
||||
pyopencvVecConverter<int>::to(obj, value, ArgInfo(name, 0));
|
||||
pyopencvVecConverter<int>::to(obj, value, info);
|
||||
r = Rect(value[0], value[1], value[2], value[3]);
|
||||
return true;
|
||||
}
|
||||
@ -1377,9 +1341,9 @@ bool pyopencv_to(PyObject* obj, Rect& r, const char* name)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *obj, TermCriteria& dst, const char *name)
|
||||
bool pyopencv_to(PyObject *obj, TermCriteria& dst, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "iid", &dst.type, &dst.maxCount, &dst.epsilon) > 0;
|
||||
@ -1392,9 +1356,9 @@ PyObject* pyopencv_from(const TermCriteria& src)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *obj, RotatedRect& dst, const char *name)
|
||||
bool pyopencv_to(PyObject *obj, RotatedRect& dst, const ArgInfo& info)
|
||||
{
|
||||
CV_UNUSED(name);
|
||||
CV_UNUSED(info);
|
||||
if(!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "(ff)(ff)f", &dst.center.x, &dst.center.y, &dst.size.width, &dst.size.height, &dst.angle) > 0;
|
||||
@ -1634,7 +1598,7 @@ static PyObject *pycvCreateButton(PyObject*, PyObject *args, PyObject *kw)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int convert_to_char(PyObject *o, char *dst, const char *name = "no_name")
|
||||
static int convert_to_char(PyObject *o, char *dst, const ArgInfo& info)
|
||||
{
|
||||
std::string str;
|
||||
if (getUnicodeString(o, str))
|
||||
@ -1643,7 +1607,7 @@ static int convert_to_char(PyObject *o, char *dst, const char *name = "no_name")
|
||||
return 1;
|
||||
}
|
||||
(*dst) = 0;
|
||||
return failmsg("Expected single character string for argument '%s'", name);
|
||||
return failmsg("Expected single character string for argument '%s'", info.name);
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
@ -45,7 +45,7 @@ gen_template_func_body = Template("""$code_decl
|
||||
gen_template_mappable = Template("""
|
||||
{
|
||||
${mappable} _src;
|
||||
if (pyopencv_to(src, _src, name))
|
||||
if (pyopencv_to(src, _src, info))
|
||||
{
|
||||
return cv_mappable_to(_src, dst);
|
||||
}
|
||||
@ -62,7 +62,7 @@ struct PyOpenCV_Converter< ${cname} >
|
||||
{
|
||||
return pyopencv_${name}_Instance(r);
|
||||
}
|
||||
static bool to(PyObject* src, ${cname}& dst, const char* name)
|
||||
static bool to(PyObject* src, ${cname}& dst, const ArgInfo& info)
|
||||
{
|
||||
if(!src || src == Py_None)
|
||||
return true;
|
||||
@ -73,7 +73,7 @@ struct PyOpenCV_Converter< ${cname} >
|
||||
return true;
|
||||
}
|
||||
${mappable_code}
|
||||
failmsg("Expected ${cname} for argument '%s'", name);
|
||||
failmsg("Expected ${cname} for argument '%s'", info.name);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@ -81,7 +81,7 @@ struct PyOpenCV_Converter< ${cname} >
|
||||
""")
|
||||
|
||||
gen_template_map_type_cvt = Template("""
|
||||
template<> bool pyopencv_to(PyObject* src, ${cname}& dst, const char* name);
|
||||
template<> bool pyopencv_to(PyObject* src, ${cname}& dst, const ArgInfo& info);
|
||||
|
||||
""")
|
||||
|
||||
@ -89,7 +89,7 @@ gen_template_set_prop_from_map = Template("""
|
||||
if( PyMapping_HasKeyString(src, (char*)"$propname") )
|
||||
{
|
||||
tmp = PyMapping_GetItemString(src, (char*)"$propname");
|
||||
ok = tmp && pyopencv_to(tmp, dst.$propname);
|
||||
ok = tmp && pyopencv_to(tmp, dst.$propname, ArgInfo("$propname", false));
|
||||
Py_DECREF(tmp);
|
||||
if(!ok) return false;
|
||||
}""")
|
||||
@ -143,7 +143,7 @@ static int pyopencv_${name}_set_${member}(pyopencv_${name}_t* p, PyObject *value
|
||||
PyErr_SetString(PyExc_TypeError, "Cannot delete the ${member} attribute");
|
||||
return -1;
|
||||
}
|
||||
return pyopencv_to(value, p->v${access}${member}) ? 0 : -1;
|
||||
return pyopencv_to(value, p->v${access}${member}, ArgInfo("value", false)) ? 0 : -1;
|
||||
}
|
||||
""")
|
||||
|
||||
@ -161,7 +161,7 @@ static int pyopencv_${name}_set_${member}(pyopencv_${name}_t* p, PyObject *value
|
||||
failmsgp("Incorrect type of object (must be '${name}' or its derivative)");
|
||||
return -1;
|
||||
}
|
||||
return pyopencv_to(value, _self_${access}${member}) ? 0 : -1;
|
||||
return pyopencv_to(value, _self_${access}${member}, ArgInfo("value", false)) ? 0 : -1;
|
||||
}
|
||||
""")
|
||||
|
||||
@ -238,10 +238,10 @@ class ClassInfo(object):
|
||||
|
||||
def gen_map_code(self, codegen):
|
||||
all_classes = codegen.classes
|
||||
code = "static bool pyopencv_to(PyObject* src, %s& dst, const char* name)\n{\n PyObject* tmp;\n bool ok;\n" % (self.cname)
|
||||
code = "static bool pyopencv_to(PyObject* src, %s& dst, const ArgInfo& info)\n{\n PyObject* tmp;\n bool ok;\n" % (self.cname)
|
||||
code += "".join([gen_template_set_prop_from_map.substitute(propname=p.name,proptype=p.tp) for p in self.props])
|
||||
if self.base:
|
||||
code += "\n return pyopencv_to(src, (%s&)dst, name);\n}\n" % all_classes[self.base].cname
|
||||
code += "\n return pyopencv_to(src, (%s&)dst, info);\n}\n" % all_classes[self.base].cname
|
||||
else:
|
||||
code += "\n return true;\n}\n"
|
||||
return code
|
||||
|
@ -101,13 +101,13 @@ static inline bool getUnicodeString(PyObject * obj, std::string &str)
|
||||
|
||||
#define CV_PY_TO_CLASS(TYPE) \
|
||||
template<> \
|
||||
bool pyopencv_to(PyObject* dst, TYPE& src, const char* name) \
|
||||
bool pyopencv_to(PyObject* dst, TYPE& src, const ArgInfo& info) \
|
||||
{ \
|
||||
if (!dst || dst == Py_None) \
|
||||
return true; \
|
||||
Ptr<TYPE> ptr; \
|
||||
\
|
||||
if (!pyopencv_to(dst, ptr, name)) return false; \
|
||||
if (!pyopencv_to(dst, ptr, info)) return false; \
|
||||
src = *ptr; \
|
||||
return true; \
|
||||
}
|
||||
@ -124,13 +124,13 @@ PyObject* pyopencv_from(const TYPE& src)
|
||||
|
||||
#define CV_PY_TO_CLASS_PTR(TYPE) \
|
||||
template<> \
|
||||
bool pyopencv_to(PyObject* dst, TYPE*& src, const char* name) \
|
||||
bool pyopencv_to(PyObject* dst, TYPE*& src, const ArgInfo& info) \
|
||||
{ \
|
||||
if (!dst || dst == Py_None) \
|
||||
return true; \
|
||||
Ptr<TYPE> ptr; \
|
||||
\
|
||||
if (!pyopencv_to(dst, ptr, name)) return false; \
|
||||
if (!pyopencv_to(dst, ptr, info)) return false; \
|
||||
src = ptr; \
|
||||
return true; \
|
||||
}
|
||||
@ -143,13 +143,13 @@ static PyObject* pyopencv_from(TYPE*& src)
|
||||
|
||||
#define CV_PY_TO_ENUM(TYPE) \
|
||||
template<> \
|
||||
bool pyopencv_to(PyObject* dst, TYPE& src, const char* name) \
|
||||
bool pyopencv_to(PyObject* dst, TYPE& src, const ArgInfo& info) \
|
||||
{ \
|
||||
if (!dst || dst == Py_None) \
|
||||
return true; \
|
||||
int underlying = 0; \
|
||||
\
|
||||
if (!pyopencv_to(dst, underlying, name)) return false; \
|
||||
if (!pyopencv_to(dst, underlying, info)) return false; \
|
||||
src = static_cast<TYPE>(underlying); \
|
||||
return true; \
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ typedef std::vector<detail::CameraParams> vector_CameraParams;
|
||||
|
||||
template<> struct pyopencvVecConverter<detail::ImageFeatures>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<detail::ImageFeatures>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<detail::ImageFeatures>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -22,7 +22,7 @@ template<> struct pyopencvVecConverter<detail::ImageFeatures>
|
||||
|
||||
template<> struct pyopencvVecConverter<detail::MatchesInfo>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<detail::MatchesInfo>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<detail::MatchesInfo>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -35,7 +35,7 @@ template<> struct pyopencvVecConverter<detail::MatchesInfo>
|
||||
|
||||
template<> struct pyopencvVecConverter<detail::CameraParams>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<detail::CameraParams>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<detail::CameraParams>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ typedef std::vector<VideoCaptureAPIs> vector_VideoCaptureAPIs;
|
||||
|
||||
template<> struct pyopencvVecConverter<cv::VideoCaptureAPIs>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<cv::VideoCaptureAPIs>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<cv::VideoCaptureAPIs>& value, const ArgInfo& info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
@ -15,9 +15,9 @@ template<> struct pyopencvVecConverter<cv::VideoCaptureAPIs>
|
||||
};
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, std::vector<cv::VideoCaptureAPIs>& apis, const char *name)
|
||||
bool pyopencv_to(PyObject *o, std::vector<cv::VideoCaptureAPIs>& apis, const ArgInfo& info)
|
||||
{
|
||||
return pyopencvVecConverter<cv::VideoCaptureAPIs>::to(o, apis, ArgInfo(name, false));
|
||||
return pyopencvVecConverter<cv::VideoCaptureAPIs>::to(o, apis, info);
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_VIDEOIO
|
||||
|
@ -1058,7 +1058,15 @@ bool CvCapture_FFMPEG::processRawPacket()
|
||||
AVCodecID eVideoCodec = video_st->codec.codec_id;
|
||||
#endif
|
||||
const char* filterName = NULL;
|
||||
if (eVideoCodec == CV_CODEC(CODEC_ID_H264) || eVideoCodec == CV_CODEC(CODEC_ID_H265))
|
||||
if (eVideoCodec == CV_CODEC(CODEC_ID_H264)
|
||||
#if LIBAVCODEC_VERSION_MICRO >= 100 \
|
||||
&& LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(57, 24, 102) // FFmpeg 3.0
|
||||
|| eVideoCodec == CV_CODEC(CODEC_ID_H265)
|
||||
#elif LIBAVCODEC_VERSION_MICRO < 100 \
|
||||
&& LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(55, 34, 1) // libav v10+
|
||||
|| eVideoCodec == CV_CODEC(CODEC_ID_HEVC)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
// check start code prefixed mode (as defined in the Annex B H.264 / H.265 specification)
|
||||
if (packet.size >= 5
|
||||
@ -1105,7 +1113,7 @@ bool CvCapture_FFMPEG::processRawPacket()
|
||||
{
|
||||
if (packet_filtered.data)
|
||||
{
|
||||
av_packet_unref(&packet_filtered);
|
||||
_opencv_ffmpeg_av_packet_unref(&packet_filtered);
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(58, 20, 100)
|
||||
|
@ -114,17 +114,18 @@ TEST_P(videoio_container, read)
|
||||
const string fileNameOut = tempfile(cv::format("test_container_stream.%s", ext_raw.c_str()).c_str());
|
||||
|
||||
// Write encoded video read using VideoContainer to tmp file
|
||||
size_t totalBytes = 0;
|
||||
{
|
||||
VideoCapture container(findDataFile(fileName), api);
|
||||
ASSERT_TRUE(container.isOpened());
|
||||
if (!container.isOpened())
|
||||
throw SkipTestException("Video stream is not supported");
|
||||
if (!container.set(CAP_PROP_FORMAT, -1)) // turn off video decoder (extract stream)
|
||||
throw SkipTestException("Fetching of RAW video streams is not supported");
|
||||
ASSERT_EQ(-1.f, container.get(CAP_PROP_FORMAT)); // check
|
||||
EXPECT_EQ(codec, fourccToString((int)container.get(CAP_PROP_FOURCC)));
|
||||
EXPECT_EQ(pixelFormat, fourccToString((int)container.get(CAP_PROP_CODEC_PIXEL_FORMAT)));
|
||||
|
||||
std::ofstream file(fileNameOut, ios::out | ios::trunc | std::ios::binary);
|
||||
size_t totalBytes = 0;
|
||||
std::ofstream file(fileNameOut.c_str(), ios::out | ios::trunc | std::ios::binary);
|
||||
Mat raw_data;
|
||||
while (true)
|
||||
{
|
||||
@ -144,7 +145,7 @@ TEST_P(videoio_container, read)
|
||||
ASSERT_GE(totalBytes, (size_t)65536) << "Encoded stream is too small";
|
||||
}
|
||||
|
||||
std::cout << "Checking extracted video stream: " << fileNameOut << std::endl;
|
||||
std::cout << "Checking extracted video stream: " << fileNameOut << " (size: " << totalBytes << " bytes)" << std::endl;
|
||||
|
||||
// Check decoded frames read from original media are equal to frames decoded from tmp file
|
||||
{
|
||||
@ -158,7 +159,7 @@ TEST_P(videoio_container, read)
|
||||
{
|
||||
nframes++;
|
||||
ASSERT_TRUE(capActual.read(actual)) << nframes;
|
||||
EXPECT_EQ(0, cvtest::norm(actual, reference, NORM_INF)) << nframes << " err=" << ++n_err;
|
||||
EXPECT_EQ(0, cvtest::norm(actual, reference, NORM_INF)) << "frame=" << nframes << " err=" << ++n_err;
|
||||
}
|
||||
ASSERT_GT(nframes, 0);
|
||||
}
|
||||
@ -168,12 +169,13 @@ TEST_P(videoio_container, read)
|
||||
|
||||
const videoio_container_params_t videoio_container_params[] =
|
||||
{
|
||||
make_tuple(CAP_FFMPEG, "video/big_buck_bunny", "h264", "h264", "h264", "I420"),
|
||||
make_tuple(CAP_FFMPEG, "video/big_buck_bunny", "h265", "h265", "hevc", "I420"),
|
||||
//make_tuple(CAP_FFMPEG, "video/big_buck_bunny", "h264.mkv", "mkv.h264", "h264", "I420"),
|
||||
//make_tuple(CAP_FFMPEG, "video/big_buck_bunny", "h265.mkv", "mkv.h265", "hevc", "I420"),
|
||||
//make_tuple(CAP_FFMPEG, "video/big_buck_bunny", "h264.mp4", "mp4.avc1", "avc1", "I420"),
|
||||
//make_tuple(CAP_FFMPEG, "video/big_buck_bunny", "h265.mp4", "mp4.hev1", "hev1", "I420"),
|
||||
videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h264", "h264", "h264", "I420"),
|
||||
videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h265", "h265", "hevc", "I420"),
|
||||
videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "mjpg.avi", "mjpg", "MJPG", "I420"),
|
||||
//videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h264.mkv", "mkv.h264", "h264", "I420"),
|
||||
//videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h265.mkv", "mkv.h265", "hevc", "I420"),
|
||||
//videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h264.mp4", "mp4.avc1", "avc1", "I420"),
|
||||
//videoio_container_params_t(CAP_FFMPEG, "video/big_buck_bunny", "h265.mp4", "mp4.hev1", "hev1", "I420"),
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/**/, videoio_container, testing::ValuesIn(videoio_container_params));
|
||||
|
Loading…
Reference in New Issue
Block a user