2024年最新python调用c++之pybind11

本文介绍了如何使用pybind11将C++中的OpenCV功能与Python交互,包括Mat对象的传递,以及在Passenger_pyd模块中的函数定义。重点讨论了在实际应用中遇到的问题,如模块导出函数命名和Mat类的兼容性问题。
摘要由CSDN通过智能技术生成

#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>

#include <opencv2/imgproc/imgproc.hpp>

struct outdata

{

int in;

int out;

};

int test( Mat frame);

outdata* video_test(char* file_path, int channel, int inNum, int outNum);

Passenger_pyd.cpp

#include<pybind11/pybind11.h>

namespace py = pybind11;

PYBIND11_MODULE(Passenger_pyd, m) {

m.doc() = “pybind11 example module”;

py::class_(m, “outdata”)

.def_readonly(“in_num”, &outdata::in)

.def_readonly(“out_num”, &outdata::out);

// Add bindings here

m.def(“Testframe”, &test, “Test frame”);

m.def(“DetectionTrack”, &video_test, “Detection and Track”);

编译生成.pyd和lib

3、python端(pych

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值