简体   繁体   中英

python to c++ with pybind

I am passing a 4,4 numpy array from python to c++ using pybind, I am getting the data incorrect on c++ side. Can anyone correct me?

Python side

import modul as md
import bumpy as np 
md.send(np.eye(4))

c++ side I receive the array as py::array_t<double> transfrom

auto buf1 = transfrom.request();
cv::Mat m(buf1.shape[0], buf1.shape[1], CV_32F , (double*)buf1.ptr);
cv::Matx44f gtranform((float*)m.ptr());
cout << "transform  "<< gtranform <<endl;

I used this and gave up on using Mat

auto buf1 = transfrom.request();.
double *ptr1 = (double *) buf1.ptr;
int X = buf1.shape[0];
int Y = buf1.shape[1];
Matx44f gtranform(X,Y);
for (size_t idx = 0; idx < X; idx++)
  for (size_t idy = 0; idy < Y; idy++)
    gtranform(idx,idy) = ptr1[idx*Y+ idy];

Hope this helps someone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM