python import文件后 core dumped,从C ++ .so调用python文件时出现Segmentation Fault(Core Dumped)...

I am trying to generate C++ based .SO file along with wrapper by using swig. This .SO was generated to make a call from python(Ubuntu Environment).

It works well if i tried with Simple C++ code, but when i try to build with OpenCV, facing some issues.

opencvtest.cpp:

#include

#include

#include

using namespace cv;

using namespace std;

int main()

{

Mat image;

image = imread("/home/swigtest/MyPic.jpg",1); // Read the file

namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.

imshow( "Display window", image ); // Show our image inside it.

destroyWindow("Display Window");

waitKey(0); // Wait for a keystroke in the window

return 0;

}

opencvtest.i

%module opencvtest

%{

/* Put header files here or function declarations like below */

extern int main();

%}

extern int main();

So for Completed the Following steps:

opencvtest.cpp - Sample code that i wrote.

opencvtest.i - The corresponding intermediate file that i wrote

Executing the command : swig -c++ -python opencvtest.i

GCC command to create .o's(with wrapper) : g++ -fpic -c opencvtest.cpp opencvtest_wrap.cxx -I/usr/include/python2.7 -I/usr/local/include -I/usr/local/include/opencv -I/usr/local/include/opencv2

Command to create .so : g++ -shared opencvtest.o opencvtest_wrap.o -o

_opencvtest.so -L/usr/local/lib /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgcodecs.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_shape.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videoio.so /usr/local/lib/libopencv_videostab.so

6.Generated .so file successfully

Then tried to test the python, followed the steps:

7.python

8.>>> import opencvtest

9.>>> opencvtest.main()

I got the error : Segmentation fault (core dumped)

Any one of the expert can help to clear the issue?

解决方案

Just changed the method name main in opencvtest.cpp.

Remember that change the method name at step 9 also.

It's working fine for me!.

But I don't know the process running behind this method call.

I changed the method name from main to one.

In Step 9: >>> opencvtest.one()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值