我想在.so文件中生成C++代碼並在python中導入.so文件。我的C++代碼是爲python(與opencv)包裝C++類,給出錯誤
extern "C" int top(int a, int b){
return a + b;
}
extern "C" int fark(int a, int b){
return a - b;
}
extern "C" int carp(int a, int b){
return a * b;
}
extern "C" int bol(int a, int b){
return a/b;
}
extern "C" void foto(string s)
{
Mat im = imread(s, 1);
if (im.empty())
{
cout << "url hatali" << endl;
}
else
{
imshow("foto", im);
waitKey(1000);
}
}
extern "C" void gri(string s){
Mat im = imread(s, 1);
if (im.empty())
{
cout << "url hatali" << endl;
}
else
{
cvtColor(im, im, CV_RGB2GRAY);
imshow("Gri", im);
waitKey(1000);
}
}
extern "C" void asdf(string s ,int i){
Mat im = imread(s, 1);
if (im.empty())
{
cout << "url hatali" << endl;
}
else
{
cvtColor(im, im, CV_RGB2GRAY);
threshold(im, im, i, 255, THRESH_BINARY);
imshow("Binary", im);
waitKey(1000);
}
}
我的生成命令是:克++ -c -fPIC webcam.cpp -o webcam.o -lopencv_core -lopencv_highgui 克++ -shared -Wl,-soname,webcam.so -o實時影像。所以webcam.o
和我產生.so文件,但是當我輸入我的.so文件在我的Python代碼我得到的錯誤: _ZN2cv6imshowERKNS_6StringERKNS_11_InputArrayE
我的Python代碼:
from ctypes import cdll
mydll=cdll.LoadLibrary('/PATH/deneme.so')
print(mydll.top(123,123))
print(mydll.carp(123,123))
print(mydll.fark(123,123))
print(mydll.bol(123,123))
'std :: string'在C接口中不起作用,它是一個C++類。 –