我是一名经验丰富的Python程序员,正在try 学习C++来加快一些项目的速度. 将py::tuple传递给函数,如何访问元素?
这是我正在制作的一个类的构造函数,用于保存视频中的图像.
Buffer::Buffer(int size, py::tuple hw_args_) {
unsigned int frame_height = get<0>(hw_args_);
unsigned int frame_width = get<1>(hw_args_);
Buffer::time_codes = new int[size];
Buffer::time_stamps = new string[size];
Buffer::frames = new unsigned char[size][hw_args[0]][hw_args[1]];
if ((Buffer::time_codes && Buffer::time_stamps) == 0) {
cout << "Error allocating memory\n";
exit(1);
}
}
这给我带来了一个错误"重载函数‘get’的实例没有匹配参数列表,参数类型是pybind 11::tuple"
我还try 过以这种方式设置框架高度和宽度.
unsigned int frame_height = hw_args_[0];
unsigned int frame_width = hw_args_[1];
这会给出一个错误"不存在从‘pybind 11::Details:tuple_accessor’到‘united int’的合适转换函数"
我很困惑,我似乎只能找到有关在C++中创建二元组的信息,而无法从Pythind 11/ Python中访问它们.