python 使用 pybind 到 C++
python to c++ with pybind
我正在使用 pybind 将一个 4,4 numpy 数组从 python 传递到 c++,我在 c++ 端得到的数据不正确。谁能纠正我?
Python side
import modul as md
import bumpy as np
md.send(np.eye(4))
c++ side
我收到数组 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;
我用过这个,后来放弃了 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];
希望这对某人有所帮助
我正在使用 pybind 将一个 4,4 numpy 数组从 python 传递到 c++,我在 c++ 端得到的数据不正确。谁能纠正我?
Python side
import modul as md
import bumpy as np
md.send(np.eye(4))
c++ side
我收到数组 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;
我用过这个,后来放弃了 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];
希望这对某人有所帮助