mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 19:20:28 +08:00
Python wrapper is adapted for cv::String
This commit is contained in:
parent
2ad7b97f1c
commit
707d3e0a62
@ -65,6 +65,8 @@ add_custom_command(
|
||||
DEPENDS ${opencv_hdrs})
|
||||
|
||||
add_library(${the_module} SHARED src2/cv2.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated0.i ${cv2_generated_hdrs} src2/cv2.cv.hpp)
|
||||
set_target_properties(${the_module} PROPERTIES COMPILE_DEFINITIONS OPENCV_NOSTL)
|
||||
|
||||
if(PYTHON_DEBUG_LIBRARIES AND NOT PYTHON_LIBRARIES MATCHES "optimized.*debug")
|
||||
target_link_libraries(${the_module} debug ${PYTHON_DEBUG_LIBRARIES} optimized ${PYTHON_LIBRARIES})
|
||||
else()
|
||||
|
@ -100,8 +100,6 @@ catch (const cv::Exception &e) \
|
||||
using namespace cv;
|
||||
typedef cv::softcascade::ChannelFeatureBuilder softcascade_ChannelFeatureBuilder;
|
||||
|
||||
typedef std::string string;
|
||||
|
||||
typedef std::vector<uchar> vector_uchar;
|
||||
typedef std::vector<int> vector_int;
|
||||
typedef std::vector<float> vector_float;
|
||||
@ -117,7 +115,7 @@ typedef std::vector<Rect> vector_Rect;
|
||||
typedef std::vector<KeyPoint> vector_KeyPoint;
|
||||
typedef std::vector<Mat> vector_Mat;
|
||||
typedef std::vector<DMatch> vector_DMatch;
|
||||
typedef std::vector<std::string> vector_string;
|
||||
typedef std::vector<cv::String> vector_String;
|
||||
typedef std::vector<std::vector<Point> > vector_vector_Point;
|
||||
typedef std::vector<std::vector<Point2f> > vector_vector_Point2f;
|
||||
typedef std::vector<std::vector<Point3f> > vector_vector_Point3f;
|
||||
@ -550,12 +548,12 @@ static PyObject* pyopencv_from(int64 value)
|
||||
return PyLong_FromLongLong(value);
|
||||
}
|
||||
|
||||
static PyObject* pyopencv_from(const std::string& value)
|
||||
static PyObject* pyopencv_from(const cv::String& value)
|
||||
{
|
||||
return PyString_FromString(value.empty() ? "" : value.c_str());
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, std::string& value, const char* name = "<unknown>")
|
||||
static bool pyopencv_to(PyObject* obj, cv::String& value, const char* name = "<unknown>")
|
||||
{
|
||||
(void)name;
|
||||
if(!obj || obj == Py_None)
|
||||
@ -563,7 +561,7 @@ static bool pyopencv_to(PyObject* obj, std::string& value, const char* name = "<
|
||||
char* str = PyString_AsString(obj);
|
||||
if(!str)
|
||||
return false;
|
||||
value = std::string(str);
|
||||
value = cv::String(str);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -906,14 +904,14 @@ template<> struct pyopencvVecConverter<DMatch>
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct pyopencvVecConverter<std::string>
|
||||
template<> struct pyopencvVecConverter<cv::String>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<std::string>& value, const ArgInfo info)
|
||||
static bool to(PyObject* obj, std::vector<cv::String>& value, const ArgInfo info)
|
||||
{
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
|
||||
static PyObject* from(const std::vector<std::string>& value)
|
||||
static PyObject* from(const std::vector<cv::String>& value)
|
||||
{
|
||||
return pyopencv_from_generic_vec(value);
|
||||
}
|
||||
@ -994,7 +992,7 @@ static bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name
|
||||
PyObject* item = PyList_GET_ITEM(values, i);
|
||||
if( !PyString_Check(key) )
|
||||
break;
|
||||
std::string k = PyString_AsString(key);
|
||||
cv::String k = PyString_AsString(key);
|
||||
if( PyString_Check(item) )
|
||||
{
|
||||
const char* value = PyString_AsString(item);
|
||||
|
@ -335,7 +335,7 @@ class CppHeaderParser(object):
|
||||
if pos >= 0:
|
||||
aname = arg[pos+1:].strip()
|
||||
atype = arg[:pos+1].strip()
|
||||
if aname.endswith("&") or aname.endswith("*") or (aname in ["int", "string", "Mat"]):
|
||||
if aname.endswith("&") or aname.endswith("*") or (aname in ["int", "String", "Mat"]):
|
||||
atype = (atype + " " + aname).strip()
|
||||
aname = ""
|
||||
else:
|
||||
|
@ -32,6 +32,19 @@ class NewOpenCVTests(unittest.TestCase):
|
||||
""" Compute a hash for an image, useful for image comparisons """
|
||||
return hashlib.md5(im.tostring()).digest()
|
||||
|
||||
if sys.version_info[:2] == (2, 6):
|
||||
def assertLess(self, a, b, msg=None):
|
||||
if not a < b:
|
||||
self.fail('%s not less than %s' % (repr(a), repr(b)))
|
||||
|
||||
def assertLessEqual(self, a, b, msg=None):
|
||||
if not a <= b:
|
||||
self.fail('%s not less than or equal to %s' % (repr(a), repr(b)))
|
||||
|
||||
def assertGreater(self, a, b, msg=None):
|
||||
if not a > b:
|
||||
self.fail('%s not greater than %s' % (repr(a), repr(b)))
|
||||
|
||||
# Tests to run first; check the handful of basic operations that the later tests rely on
|
||||
|
||||
class Hackathon244Tests(NewOpenCVTests):
|
||||
|
Loading…
Reference in New Issue
Block a user