1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-28 06:43:01 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2024-01-23 17:06:52 +03:00
148 changed files with 3263 additions and 1564 deletions
+1
View File
@@ -46,6 +46,7 @@ if(${PYTHON}_LIMITED_API)
# support only python3.3+
ocv_assert(${PYTHON}_VERSION_MAJOR EQUAL 3 AND ${PYTHON}_VERSION_MINOR GREATER 2)
target_compile_definitions(${the_module} PRIVATE CVPY_DYNAMIC_INIT)
target_compile_definitions(${the_module} PRIVATE PYTHON3_LIMITED_API_VERSION=${PYTHON3_LIMITED_API_VERSION})
if(WIN32)
string(REPLACE
"python${${PYTHON}_VERSION_MAJOR}${${PYTHON}_VERSION_MINOR}.lib"
-9
View File
@@ -2,15 +2,6 @@ if(NOT PYTHON3_INCLUDE_PATH OR NOT PYTHON3_NUMPY_INCLUDE_DIRS)
ocv_module_disable(python3)
endif()
# Problem in numpy >=1.15 <1.17
if(PYTHON3_LIMITED_API
AND NOT PYTHON3_NUMPY_VERSION VERSION_LESS "1.15"
AND PYTHON3_NUMPY_VERSION VERSION_LESS "1.17"
)
message(WARNING "Current NUMPY version (${PYTHON3_NUMPY_VERSION}) is not compatible with LIMITED_API.")
set(PYTHON3_LIMITED_API OFF)
endif()
set(the_description "The python3 bindings")
set(MODULE_NAME python3)
set(MODULE_INSTALL_SUBDIR python3)
+8 -2
View File
@@ -13,7 +13,10 @@
// #define Py_DEBUG
#if defined(CVPY_DYNAMIC_INIT) && !defined(Py_DEBUG)
# define Py_LIMITED_API 0x03030000
# ifndef PYTHON3_LIMITED_API_VERSION
# define PYTHON3_LIMITED_API_VERSION 0x03060000
# endif
# define Py_LIMITED_API PYTHON3_LIMITED_API_VERSION
#endif
#include <cmath>
@@ -42,17 +45,20 @@ class ArgInfo
private:
static const uint32_t arg_outputarg_flag = 0x1;
static const uint32_t arg_arithm_op_src_flag = 0x2;
static const uint32_t arg_pathlike_flag = 0x4;
public:
const char* name;
bool outputarg;
bool arithm_op_src;
bool pathlike;
// more fields may be added if necessary
ArgInfo(const char* name_, uint32_t arg_) :
name(name_),
outputarg((arg_ & arg_outputarg_flag) != 0),
arithm_op_src((arg_ & arg_arithm_op_src_flag) != 0) {}
arithm_op_src((arg_ & arg_arithm_op_src_flag) != 0),
pathlike((arg_ & arg_pathlike_flag) != 0) {}
private:
ArgInfo(const ArgInfo&) = delete;
+12
View File
@@ -701,6 +701,18 @@ bool pyopencv_to(PyObject* obj, String &value, const ArgInfo& info)
return true;
}
std::string str;
#if ((PY_VERSION_HEX >= 0x03060000) && !defined(Py_LIMITED_API)) || (Py_LIMITED_API >= 0x03060000)
if (info.pathlike)
{
obj = PyOS_FSPath(obj);
if (PyErr_Occurred())
{
failmsg("Expected '%s' to be a str or path-like object", info.name);
return false;
}
}
#endif
if (getUnicodeString(obj, str))
{
value = str;
-4
View File
@@ -128,11 +128,7 @@ void pyPopulateArgumentConversionErrors()
PySafeObject exception_message(PyObject_Str(exception_value));
std::string message;
getUnicodeString(exception_message, message);
#ifdef CV_CXX11
conversionErrorsTLS.getRef().push_back(std::move(message));
#else
conversionErrorsTLS.getRef().push_back(message);
#endif
}
}
+5
View File
@@ -500,6 +500,10 @@ class ArgInfo(object):
def outputarg(self):
return '/O' in self._modifiers or '/IO' in self._modifiers
@property
def pathlike(self):
return '/PATH' in self._modifiers
@property
def returnarg(self):
return self.outputarg
@@ -523,6 +527,7 @@ class ArgInfo(object):
def crepr(self):
arg = 0x01 if self.outputarg else 0x0
arg += 0x02 if self.arithm_op_src_arg else 0x0
arg += 0x04 if self.pathlike else 0x0
return "ArgInfo(\"%s\", %d)" % (self.name, arg)
+7 -2
View File
@@ -92,6 +92,10 @@ class CppHeaderParser(object):
modlist.append("/IO")
arg_str = arg_str.replace("CV_IN_OUT", "")
if "CV_WRAP_FILE_PATH" in arg_str:
modlist.append("/PATH")
arg_str = arg_str.replace("CV_WRAP_FILE_PATH", "")
isarray = False
npos = arg_str.find("CV_CARRAY")
if npos >= 0:
@@ -453,8 +457,7 @@ class CppHeaderParser(object):
("CV_INLINE", ""),
("CV_DEPRECATED", ""),
("CV_DEPRECATED_EXTERNAL", ""),
("CV_NODISCARD_STD", ""),
("CV_NODISCARD", "")]).strip()
("CV_NODISCARD_STD", "")]).strip()
if decl_str.strip().startswith('virtual'):
virtual_method = True
@@ -629,6 +632,8 @@ class CppHeaderParser(object):
("noArray", arg_type)]).strip()
if '/IO' in modlist and '/O' in modlist:
modlist.remove('/O')
if (arg_name.lower() == 'filename' or arg_name.lower() == 'filepath') and '/PATH' not in modlist:
modlist.append('/PATH')
args.append([arg_type, arg_name, defval, modlist])
npos = arg_start-1
+38
View File
@@ -0,0 +1,38 @@
from tests_common import NewOpenCVTests, unittest
import cv2 as cv
import os
def import_path():
import sys
if sys.version_info[0] < 3 or sys.version_info[1] < 6:
raise unittest.SkipTest('Python 3.6+ required')
from pathlib import Path
return Path
class CanPassPathLike(NewOpenCVTests):
def test_pathlib_path(self):
Path = import_path()
img_path = self.find_file('cv/imgproc/stuff.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
image_from_str = cv.imread(img_path)
self.assertIsNotNone(image_from_str)
image_from_path = cv.imread(Path(img_path))
self.assertIsNotNone(image_from_path)
def test_type_mismatch(self):
import_path() # checks python version
with self.assertRaises(TypeError) as context:
cv.imread(123)
self.assertTrue('str or path-like' in str(context.exception))
if __name__ == '__main__':
NewOpenCVTests.bootstrap()