我正在尝试从C ++执行python脚本,
C ++部分:
run
python模块:
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);
当我用opencv 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)
编译它时,它工作正常,但是3.2.0
它会在调用opencv函数2.4.0
是否可以使用cv2.cvtColor(mark, cv2.COLOR_GRAY2RGB)
执行此操作?也许有一些模块初始化程序,如2.4.0
为numpy?
答案 0 :(得分:1)
语法在2.4处不同,因此修改如下
mark = cv2.cvtColor(mark,mark, CV_GRAY2RGB)