Reputation: 413
I tried to Pass the arguments to (c++ opencv ) from my opencv python code
Steps I done:
A.Generating .so for my opencv C++ Code:
1.swig -c++ -python opencvtest.i
2.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
3.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
4.C++ code
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int sample(Mat image,Mat &out)
{
int z=0;
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
}
cvtColor(image, out,COLOR_BGR2GRAY);
// Wait for a keystroke in the window
return z;
}
5.Created Wrapper file(opencvtest_wrap.cxx) and Generated .so file.
6.Sample python code to call C++ code.
import cv2 , numpy
import opencvtest
image = cv2.imread('messi5.jpg',0)
res=opencvtest.sample(image , image1)
cv2.imshow('Source Image',image)
cv2.waitKey(0)
cv2.namedWindow('dst_rt', cv2.WINDOW_NORMAL)
cv2.resizeWindow('dst_rt', window_width, window_height)
cv2.imshow('dst_rt', image1)
cv2.waitKey(0)
cv2.destroyAllWindows()
print res
I am getting this error when i tried to execute sample.py on my machine
Traceback (most recent call last):
File "sample1.py", line 15, in res=opencvtest.sample(image , image1)
TypeError: in method 'sample', argument 1 of type 'cv::Mat'
Any one of the expert can help me to clear the issue.
Upvotes: 1
Views: 559
Reputation: 5231
What is image
? I think you have to use types coming from C++ : opencvtest.Mat
Upvotes: 1