pybind11 numpy转cv::mat;eigen

python语言灵活易用,但是有时效率较低,c++效率较高,pybind可以较好的结合两者。
在c++代码中引入pybind11相关库,pybind可以利用buffer将python中的一些数据类型转化为c++可用的类型。如下代码:

#include<iostream>
#include<vector>
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<pybind11/pybind11.h>
#include<pybind11/numpy.h>
#include<pybind11/stl.h>
#include"mat_warper.h"
#include<pybind11/eigen.h>
#include<eigen3/Eigen/Dense>

namespace py = pybind11;
using namespace std;
using namespace cv;

Mat numpy_uint8_1c_to_cv_mat(py::array_t<unsigned char>& input) {
    if (input.ndim() != 2)
        throw std::runtime_error("1-channel image must be 2 dims ");
    py::buffer_info buf = input.request();
    cv::Mat mat(buf.shape[0], buf.shape[1], CV_8UC1, (unsigned char*)buf.ptr);
    retur
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值