I'm trying to execute python script from C++,
C++ part:
Py_Initialize();
PyRun_SimpleString("import sys");
PyRun_SimpleString("print(sys.version)");
PyRun_SimpleString("sys.path.append('/path/to/module')");
pName = PyString_FromString("mymodule");
pModule = PyImport_Import(pName);
import_array();
PyArrayObject *np_ret, *np_arg;
pDict = PyModule_GetDict(pModule);
pFunc = PyDict_GetItemString(pDict, "process");
PyObject_CallFunctionObjArgs(pFunc, NULL);
python module:
import random
import numpy as np
import cv2
import sys
import segno
def process():
n = random.randint(1, 1000);
qr = segno.make(n)
mark = np.uint8(np.array(qr.to_pil(scale=2)))*255
mark = cv2.cvtColor(mark, cv2.COLOR_GRAY2RGB)
When I compile it with opencv 3.2.0 it's working fine, but with 2.4.0 it gives segmentation fault on calling opencv function cv2.cvtColor(mark, cv2.COLOR_GRAY2RGB)
Is it possible to do so with 2.4.0? Maybe there is some module initializer such as import_array()for numpy?