#include <pybind11/pybind11.h>
#include<opencv2/opencv.hpp>
#include <pybind11/numpy.h>
#include<iostream>
using namespace std;
namespace py = pybind11;
double getimg(py::array_t<double> input) {
py::buffer_info buf = input.request();
py::array_t<double> result = py::array_t<double>(buf.size);
double* ptr = (double*)buf.ptr;
double high = buf.shape[0];
double width = buf.shape[1];
cout << "high" << high << endl;
cout << "width" << width << endl;
cout << "ptr" << ptr << endl;
return 1;
}
PYBIND11_MODULE(meiyan, m) {
m.doc() = "Add two vectors using pybind11";
m.def("getimg", &getimg, "Add two NumPy arrays");
}
import numpy as np
import cv2
import meiyan
img = cv2.imread('1.jpg')
print(np.shape(img))
print(type(img))
c = meiyan.getimg(img)
print(c)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2f3a38ec56421c3e54490536cf4d15b9.png)