1

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?

asked Oct 16, 2017 at 17:27

1 Answer 1

1

Syntax is different at 2.4 so modify as following

mark = cv2.cvtColor(mark,mark, CV_GRAY2RGB)
answered Oct 16, 2017 at 17:57

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.