Passing contours from OpenCV's findContours from Python to C++ -
have bit of unique problem, wanting pass contours opencv's cv2.findcontours() in python, function written in c++, using boost python.
i found out contours' type by:
>>> type(contours) <type 'list'> >>> type(contours[0]) <type 'numpy.ndarray'> >>> type(contours[0][0]) <type 'numpy.ndarray'> >>> type(contours[0][0][0]) <type 'numpy.ndarray'> >>> type(contours[0][0][0][0]) <type 'numpy.int32'>
this python code:
import numpy np, cv2, py_wrapper img_file = 'an_image.png' img = cv2.imread(img_file); thresh = 100 canny_output = cv2.canny(img, thresh, thresh*2, 3) _, contours, hierarchy = cv2.findcontours(canny_output, cv2.retr_tree, cv2.chain_approx_simple) py_wrapper.ndarrays(contours)
my thinking need pass data list, what's inside can converted numpy ndarray opencv mat using this: numpy ndarray ⇋ opencv mat conversion
and c++:
void ndarrays(boost::python::list obj) { ndarrayconverter cvt; std::cout << boost::python::len(obj) << std::endl; (std::size_t i=0; i<boost::python::len(obj); ++i) { pyobject ndarray = boost::python::extract<pyobject>(obj[i]); } }
but when run it, get:
>>> py_wrapper.ndarrays(contours) 12 traceback (most recent call last): file "<stdin>", line 1, in <module> typeerror: no registered converter able produce c++ rvalue of type _object python object of type numpy.ndarray
any suggestions/insights appreciated. thanks.
Comments
Post a Comment