How to use opencv functions in C++ file and bind it with Python?
<p>I want to pass an image from python script to c++ code for opencv computations. To bind the two I have followed <a href="https://github.com/Algomorph/pyboostcvconverter" rel="nofollow">this</a>. The binding is working fine But when I use any opencv in-built functions it gives me error. </p>

<p>Traceback (most recent call last):
  File "/home/prashant/Desktop/example.py", line 1, in 
    import pbcvt # your module, also the name of your compiled dynamic library file w/o the extension
ImportError: /usr/local/lib/python2.7/dist-packages/pbcvt.so: undefined symbol: _ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEii</p>

<p>I am using opencv 3.1 and python 2.7.Any help/guidance is much appreciated.`</p>

<p>Code for reference.
Python file.</p>

<pre><code>import pbcvt 
import numpy as np
import cv2
a = cv2.imread("/home/prashant/Documents/opencv-practice/screenshot.png")
c = pbcvt.dot(a)
cv2.imshow("gray image",c)
cv2.waitKey(0)
cv2.destroyAllWindows()
</code></pre>

<p>C++ code:</p>

<pre><code>#include &lt;pyboostcvconverter/pyboostcvconverter.hpp&gt;
#include &lt;opencv2/core/core.hpp&gt;
#include &lt;opencv2/highgui/highgui.hpp&gt;
#include &lt;opencv2/imgproc/imgproc.hpp&gt;
namespace pbcvt {
using namespace std;

using namespace boost::python;
cv::Mat dot(PyObject *image) {

    cv::Mat matImage, greyMat;
    matImage = pbcvt::fromNDArrayToMat(image);
    cv::cvtColor(matImage, greyMat, CV_BGR2GRAY);
    return greyMat;
}
cv::Mat dot2(cv::Mat leftMat, cv::Mat rightMat) {
    auto c1 = leftMat.cols, r2 = rightMat.rows;
    if (c1 != r2) {
        PyErr_SetString(PyExc_TypeError,
                        "Incompatible sizes for matrix multiplication.");
        throw_error_already_set();
    }
    cv::Mat result = leftMat * rightMat;

    return result;
}


#if (PY_VERSION_HEX &gt;= 0x03000000)
    static void *init_ar() {
#else
    static void init_ar(){
#endif
    Py_Initialize();

    import_array();
    return NUMPY_IMPORT_ARRAY_RETVAL;
}

BOOST_PYTHON_MODULE (pbcvt) {
    //using namespace XM;
    init_ar();

    //initialize converters
    to_python_converter&lt;cv::Mat,
            pbcvt::matToNDArrayBoostConverter&gt;();
    pbcvt::matFromNDArrayBoostConverter();

    //expose module-level functions
    def("dot", dot);
    def("dot2", dot2);

    }

} //end namespace pbcvt
</code></pre>

<p>It could be that you have to edit the CMakeLists.txt in line 27 <code>find_package(OpenCV COMPONENTS core REQUIRED)</code> and add more components like <code>find_package(OpenCV COMPONENTS core imgproc highgui REQUIRED)</code></p>

python c++ opencv binding