Ask Your Question
0

Segmentation fault while using pyopencv_from from cv2.cpp

asked 2017-08-18 02:25:26 -0600

I were trying to embed python in my C++ application. To convert cv::Mat from C++ to PyObject I were using cv2.cpp from opencv pythonwrapper sources.

//Sample Code.

cv::Mat mat = cv::imread("shirt.png", 1); 
pValue = pyopencv_from(mat);

//Segmentaion fault occurs during mat.CopyTo function.

template<> PyObject* pyopencv_from(const Mat& m)
{
    printf("pyopencv_from 1\n");
    if( !m.data )
        Py_RETURN_NONE;
    Mat temp, *p = (Mat*)&m;
    printf("pyopencv_from 2\n");
    if(!p->u || p->allocator != &g_numpyAllocator)
    {
        printf("pyopencv_from 3\n");
        temp.allocator = &g_numpyAllocator;
        printf("pyopencv_from 4\n");
        ERRWRAP2(m.copyTo(temp));
        printf("pyopencv_from 5\n");
        p = &temp;
    }
    printf("pyopencv_from 6\n");
    PyObject* o = (PyObject*)p->u->userdata;
    printf("pyopencv_from 7\n");
    Py_INCREF(o);
    return o;
}

Please provide any hints /solution . Thank you

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-08-18 05:58:19 -0600

Found solution from link text Fixed code import_array(); cv::Mat mat = cv::imread("shirt.png", 1); pValue = pyopencv_from(mat);

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-08-18 02:25:26 -0600

Seen: 459 times

Last updated: Aug 18 '17