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?
which opencv version is it ? (there seem to be changes in current 4.0.1, e.g. there's no "module prefix" any more, when calling cv2.py)
I use 4.0.1. It seems nowhere to find the actual usage of current version of gen2.py
have a look here, so, imho your :
python3 gen2.py build header.txt
is correct (maybe "build" needs an absolute path,idk.)also try an absolute path inside headers.txt !
ok, I use absolute path and use some comand like:
now It seems can build a JustATest.so for me to import, when I tried some code in python:
and python report
What should I do?