Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to use gen2.py and c++ file to make Python module

I want to make my c++ function as python module in linux, to make the question easy I make a simple sample as:

testcv.h:

#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
namespace JustATest{
CV_EXPORTS_W class TestCV
{
public:
    CV_WRAP TestCV();
    CV_WRAP void TakeALook();
};
}

testcv.cpp

#include "testcv.h"
using namespace JustATest;
TestCV::TestCV()
{

}
void TestCV::TakeALook()
{
    Mat src=imread("a.jpg");
    imshow("see!",src);
    waitKey(0);
}

these two files are in the /src/ folder in the same path of gen2.py

and a header.txt as:

src/testcv.h

now I have some command copy from there

python3 gen2.py pybv build header.txt

and the message shows:

Traceback (most recent call last):
  File "gen2.py", line 1181, in <module>
    with open(sys.argv[2], 'r') as f:
IsADirectoryError: [Errno 21] Is a directory: 'build'

it seems gen2.py don't let me put anything before the build path. so I use

 python3 gen2.py build header.txt

now I see many "pyopencv_generated..." file in the build folder without any content (0 byte). What should I do to make the modules exactly?

How to use gen2.py and c++ file to make Python module

I want to make my c++ function as python module in linux, to make the question easy I make a simple sample as:

testcv.h:

#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
namespace JustATest{
CV_EXPORTS_W class TestCV
{
public:
    CV_WRAP TestCV();
    CV_WRAP void TakeALook();
};
}

testcv.cpp

#include "testcv.h"
using namespace JustATest;
TestCV::TestCV()
{

}
void TestCV::TakeALook()
{
    Mat src=imread("a.jpg");
    imshow("see!",src);
    waitKey(0);
}

these two files are in the /src/ folder in the same path of gen2.py

and a header.txt as:

src/testcv.h

now I have some command copy from there (not really know what the pybv is but I just take a look of gen2.py)

python3 gen2.py pybv build header.txt

and the message shows:

Traceback (most recent call last):
  File "gen2.py", line 1181, in <module>
    with open(sys.argv[2], 'r') as f:
IsADirectoryError: [Errno 21] Is a directory: 'build'

it seems gen2.py don't let me put anything before the build path. so I use

 python3 gen2.py build header.txt

now I see many "pyopencv_generated..." file in the build folder without any content (0 byte). What should I do to make the modules exactly?