-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimage.cpp
More file actions
116 lines (59 loc) · 1.81 KB
/
Copy pathimage.cpp
File metadata and controls
116 lines (59 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#define PY_ARRAY_UNIQUE_SYMBOL pbcvt_ARRAY_API
#include <boost/python.hpp>
#include <pyboostcvconverter/pyboostcvconverter.hpp>
#include <Python.h>
#include <string>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <sys/time.h>
using namespace cv;
using namespace std;
using namespace pbcvt;
using namespace boost::python;
#if (PY_VERSION_HEX >= 0x03000000)
static void *init_ar() {
#else
static void init_ar(){
#endif
Py_Initialize();
import_array();
return NUMPY_IMPORT_ARRAY_RETVAL;
}
PyObject *pModule,*pFunc,*pDict;
void trans(cv::Mat image){
/* import */
pModule = PyImport_ImportModule("image_module");
if (pModule == NULL) {
cout<<"ERROR importing module"<<endl;
return ;
}
pDict = PyModule_GetDict(pModule);
pFunc = PyDict_GetItemString(pDict, (char*)"trans_image");
PyObject *iArgs = pbcvt::fromMatToNDArray(image);
PyObject *pValue;
if(pFunc != NULL) {
pValue = PyObject_CallFunction(pFunc, "O",iArgs );
}
cv::Mat trans_image = pbcvt::fromNDArrayToMat(pValue);
imshow("a",trans_image);
waitKey(0);
}
int main(int argc, char *argv[])
{
// Py_Initialize();
// import_array();
init_ar();
char str[] = "Python";
Py_SetProgramName(str);
if(!Py_IsInitialized())
cout << "init faild/n" << endl;
// 下面可以只是方便调试,可以不用。
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('../python')");
PyRun_SimpleString("import os");
PyRun_SimpleString("print os.getcwd()");
PyRun_SimpleString("print ('Hello Python!')\n");
cv::Mat image = cv::imread("/home/jason/code/FCRN-DepthPrediction/Images/1.jpg",0);
trans(image);
return 0;
}