python 调用c++ boost

x33g5p2x  于2022-01-09 转载在 C/C++  
字(1.4k)|赞(0)|评价(0)|浏览(468)

https://stackoverflow.com/questions/39110507/call-a-c-function-from-python-and-convert-a-opencv-mat-to-a-numpy-array

testing.cpp:

来源: https://stackoverflow.com/questions/39110507/call-a-c-function-from-python-and-convert-a-opencv-mat-to-a-numpy-array
#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 as np
from testing import visualize

A = 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

相关文章

最新文章

更多