Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

python cv2 calls from c++

Hi,

I have embedded python in my c++ code. All other modules work fine, except for the cv2 module. Any call to cv2 functions hangs. For instance cv2.imread

I'm using python 2.7.12

Here is the code

int main()
{
    // initialize python
    Py_Initialize();

    // import our test module
    PyObject * opencv_test_module = PyImport_ImportModule("opencv_test");

    // retrieve read_image() from our module
    PyObject * read_image = PyObject_GetAttrString(numpy_test_module, "read_image");

    // print the array by calling 'print_matrix'
    PyObject* return_value = PyObject_CallObject(read_image, NULL); // program hangs here (!)

    // ... further processing ...
    return 0;
 }

and here is my module opencv_test.py

def read_image(): 
    print "[read_image]" # program reaches here 
    i = cv2.imread("/path/to/file", 0) # program hangs here -- also hangs with other cv2 calls 
    print "[read_image] end"

python cv2 calls from c++

Hi,

I have embedded python in my c++ code. All other modules work fine, except for the cv2 module. Any call to cv2 functions hangs. For instance cv2.imread

I'm using python 2.7.12

Here is the code

int main()
{
    // initialize python
    Py_Initialize();

    // import our test module
    PyObject * opencv_test_module = PyImport_ImportModule("opencv_test");

    // retrieve read_image() from our module
    PyObject * read_image = PyObject_GetAttrString(numpy_test_module, "read_image");

    // print the array by calling 'print_matrix'
    PyObject* return_value = PyObject_CallObject(read_image, NULL); // program hangs here (!)

    // ... further processing ...
    return 0;
 }

and here is my module opencv_test.py

import cv2
def read_image(): 
    print "[read_image]" # program reaches here 
    i = cv2.imread("/path/to/file", 0) # program hangs here -- also hangs with other cv2 calls 
    print "[read_image] end"

python cv2 calls from c++

Hi,

I have embedded python in my c++ code. All other modules work fine, except for the cv2 module. Any call to cv2 functions hangs. For instance cv2.imread

I'm using python 2.7.12

Here is the code

int main()
{
    // initialize python
    Py_Initialize();

    // import our test module
    PyObject * opencv_test_module = PyImport_ImportModule("opencv_test");

    // retrieve read_image() from our module
    PyObject * read_image = PyObject_GetAttrString(numpy_test_module, "read_image");

    // print the array by calling 'print_matrix'
    PyObject* return_value = PyObject_CallObject(read_image, NULL); // program hangs here (!)

    // ... further processing ...
    return 0;
 }

and here is my module opencv_test.py

import cv2
def read_image(): 
    print "[read_image]" # program reaches here 
    i = cv2.imread("/path/to/file", 0) # program hangs here -- also hangs with other cv2 calls 
    print "[read_image] end"

Moreover, if I simply run the following, it also hangs:

PyRun_SimpleString("import cv2");

python cv2 calls from c++

Hi,

I have embedded python in my c++ code. All other modules work fine, except for the cv2 module. Any call to cv2 functions hangs. For instance cv2.imread

I'm using python 2.7.12

Here is the code

int main()
{
    // initialize python
    Py_Initialize();

    // import our test module
    PyObject * opencv_test_module = PyImport_ImportModule("opencv_test");

    // retrieve read_image() from our module
    PyObject * read_image = PyObject_GetAttrString(numpy_test_module, "read_image");

    // print the array by calling 'print_matrix'
    PyObject* return_value = PyObject_CallObject(read_image, NULL); // program hangs here (!)

    // ... further processing ...
    return 0;
 }

and here is my module opencv_test.py

import cv2
def read_image(): 
    print "[read_image]" # program reaches here 
    i = cv2.imread("/path/to/file", 0) # program hangs here -- also hangs with other cv2 calls 
    print "[read_image] end"

Moreover, if I simply run the following, it also hangs:

PyRun_SimpleString("import cv2");

python cv2 calls from c++

Hi,

I have embedded python in my c++ code. All other modules work fine, except for the cv2 module. Any call to cv2 functions hangs. For instance cv2.imread

I'm using python 2.7.12

Here is the code

int main()
{
    // initialize python
    Py_Initialize();

    // import our test module
    PyObject * opencv_test_module = PyImport_ImportModule("opencv_test");

    // retrieve read_image() from our module
    PyObject * read_image = PyObject_GetAttrString(numpy_test_module, "read_image");

    // print the array by calling 'print_matrix'
    PyObject* return_value = PyObject_CallObject(read_image, NULL); // program hangs here (!)

    // ... further processing ...
    return 0;
 }

and here is my module opencv_test.py

import cv2
def read_image(): 
        print cv2.__version__ # 3.3.1-dev
    print "[read_image]" # program reaches here 
    i = cv2.imread("/path/to/file", 0) # program hangs here -- also hangs with other cv2 calls 
    print "[read_image] end"

python cv2 calls from c++

Hi,

I have embedded python in my c++ code. All other modules work fine, except for the cv2 module. Any call to cv2 functions hangs. For instance cv2.imread

I'm using python 2.7.12

Here is the code

int main()
{
    // initialize python
    Py_Initialize();

    // import our test module
    PyObject * opencv_test_module = PyImport_ImportModule("opencv_test");

    // retrieve read_image() from our module
    PyObject * read_image = PyObject_GetAttrString(numpy_test_module, "read_image");

    // print the array by calling 'print_matrix'
    PyObject* return_value = PyObject_CallObject(read_image, NULL); // program hangs here (!)

    // ... further processing ...
    return 0;
 }

and here is my module opencv_test.py

import cv2
def read_image(): 
     print cv2.__version__ # 3.3.1-dev
    print "[read_image]" # program reaches here 
    i = cv2.imread("/path/to/file", 0) # program hangs here -- also hangs with other cv2 calls 
    print "[read_image] end"