Call a C++ function from Python and convert a OpenCV Mat to a Numpy array -


background situation

i'm trying use opencv stitching module via python bindings, i'm getting error:

import cv2 stitcher = cv2.createstitcher(false)  imagel = cv2.imread("imagel.jpg") imagec = cv2.imread("imagec.jpg") imager = cv2.imread("imager.jpg")  stitcher.stitch((imagel, imagec)) 

error: /home/user/opencv3.1.0/opencv/modules/python/src2/cv2.cpp:163: error: (-215) data should null! in function allocate

similar people suffering this:

the problem @ hand

so decided use official c++ opencv stitching example , use python call using boost.python. however, i'm still unable figure out how use boost.python + numpy-opencv-converter handle c++ mat vs numpy array conversion.

¿how call numpy-opencv-converter? i've got boost.python in place, , when running python function call c++ file got (expected) outcome:

$ python python_caller.py  traceback (most recent call last):   file "python_caller.py", line 10, in <module>     visualize(a) boost.python.argumenterror: python argument types in     testing.visualize(numpy.ndarray) did not match c++ signature:     visualize(cv::mat) 

thanks.

pd: i'm in ubuntu 14.04, python 2.7.4 using opencv 3.1.0 compiled sources , inside virtualenv.


these files i'm using.

testing.cpp:

#include <stdio.h> #include <opencv2/opencv.hpp> #include <boost/python.hpp>  using namespace cv;  int main(){}  mat visualize(const cv::mat input_image) {     cv::mat image;     image = input_image;      namedwindow("display image", window_autosize );     imshow("display image", image);     waitkey(0);      return image; }  using namespace boost::python; boost_python_module(testing) // file name {        def("visualize", visualize); //function name } 

python_caller.py:

import cv2 import numpy np testing import visualize  = cv2.imread("imagel.jpg")  visualize(a) 

makefile:

cflags=`pkg-config --cflags opencv`  ldflags=`pkg-config --libs opencv`  testing.so: testing.o     g++ -shared -wl,--export-dynamic -o testing.so testing.o -l/usr/lib -lboost_python -l/usr/lib/python2.7/config -lpython2.7 -l/usr/lib/x86_64-linux-gnu/ -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab   testing.o: testing.cpp     g++ -i/usr/include/python2.7 -i/usr/include -fpic -c testing.cpp 

you need convert python ndarray <=> c++ cv::mat. can recommend github repo. contains example should fit needs. using converter on ubuntu 15.10 python 2.7/3.4 , opencv 3.1.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -