I have a C++ portable bag third-party library whose function is camera acquisition. I hope to call it in python. First, I wrote the swigtest.h file and swigtest.cpp file:
#pragma once
#include <iostream>
class CTest
{
public:
void Version();
};
#include "swigtest.h"
#include "swigtest.h"
#include <opencv2/opencv.hpp>
#include <gigex/gigex.h> //this is third-party include file
using namespace std;
void CTest::Version()
{
std::cout << "2024.07.19" << std::endl;
cv::Mat image = cv::imread("d:/1.jpg");
printf("%d, %d", image.rows, image.cols);
CGigeVision gv; //this is third-party class
}
Then I wrote the example.i file
%module SwigTest
%include <opencv.i>
%include "std_vector.i"
%include "std_string.i"
%cv_instantiate_all_defaults
%template(StrVector) std::vector<std::string>;
%{
#include "SwigTest.h"
%}
%include "SwigTest.h"
Finally, use swig to compile and generate cxx and py files.
An error occurs after importing swigtest:
Traceback (most recent call last):
File “.simple.py”, line 1, in
import SwigTest
File “E:vsprocopencvdemoopencvdemoopencvdemoSwigTest.py”, line 12, in
import _SwigTest
ImportError: dynamic module does not define module export function (PyInit__SwigTest)
我希望可以正常import swigtest并且没有出错
jiabin liu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.