You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a very basic question. I say basic because I am new to pybind11 and this is my first attempt to use the library to make python bindings for my C++ code. So here I am using a C++ class which internally uses a Realsense class. When I try to contruct a constructor for it then it gives me a TypeError.
Can someone explain me what I am doing wrong in PYbind11 persepctive? Definitely I can see that there is a type mismatch here but Still I beleive this is a general problem which many of you would have faced. I want to solve this puzzle. Read all documentation but the cutom type caster example also uses an internal pybnd11 template internally. I don't think mine is a similar thing. I want to somhow pass the info from C++ side to python side and vice versa. If you can direct me to some right examples or documentation then it will be awesome.
My C++ Class in Devicemanager.h/cpp :
include <librealsense2/rs.hpp>
class DeviceManager {
public:
explicit DeviceManager(rs2::context& ctx);
td::size_t getNumOfConnectedDevices();
}
My Binder.cpp code
#include <pybind11/pybind11.h>
#include "rsWrap/DeviceManager.h"
#include <librealsense2/rs.hpp>
#include <librealsense2/hpp/rs_context.hpp>
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
int add(int i, int j) {
return i + j;
}
namespace py = pybind11;
using namespace RealSenseWraLib;
PYBIND11_MODULE(qco_py_wrapper, m) {
py::class_<DeviceManager>(m, "DeviceManager")
.def(py::init<rs2::context &>())
.def("getNumOfConnectedDevices", &DeviceManager::getNumOfConnectedDevices);
m.def("add", &add, R"pbdoc(
Add two numbers
Some other explanation about the add function.
)pbdoc");
}
The python Code that I want to make work is:
import pyrealsense2 as rs
import qco_py_wrapper as qco
dmanager = qco.DeviceManager(rs.context());
print(dmanager)
Error That I get is this:
Traceback (most recent call last):
File " *<my Directory>*/build/python_wrapper/test.py", line 5, in <module>
dmanager = qco.DeviceManager(rs.context());
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. qco_py_wrapper.DeviceManager(arg0: rs2::context)
Invoked with: <pyrealsense2.pyrealsense2.context object at 0x7f3cc3c16d30>
When I do a help on qco_py_wrapper then the following appears:
Help(qco_py_wrapper):
`Help on module qco_py_wrapper:
NAME
qco_py_wrapper
CLASSES
pybind11_builtins.pybind11_object(builtins.object)
DeviceManager
class DeviceManager(pybind11_builtins.pybind11_object)
| Method resolution order:
| DeviceManager
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: qco_py_wrapper.DeviceManager, arg0: rs2::context) -> None
|
| getNumOfConnectedDevices(...)
| getNumOfConnectedDevices(self: qco_py_wrapper.DeviceManager) -> int
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) from pybind11_builtins.pybind11_type
| Create and return a new object. See help(type) for accurate signature.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have a very basic question. I say basic because I am new to pybind11 and this is my first attempt to use the library to make python bindings for my C++ code. So here I am using a C++ class which internally uses a Realsense class. When I try to contruct a constructor for it then it gives me a TypeError.
Can someone explain me what I am doing wrong in PYbind11 persepctive? Definitely I can see that there is a type mismatch here but Still I beleive this is a general problem which many of you would have faced. I want to solve this puzzle. Read all documentation but the cutom type caster example also uses an internal pybnd11 template internally. I don't think mine is a similar thing. I want to somhow pass the info from C++ side to python side and vice versa. If you can direct me to some right examples or documentation then it will be awesome.
My C++ Class in Devicemanager.h/cpp :
My Binder.cpp code
The python Code that I want to make work is:
Error That I get is this:
When I do a help on qco_py_wrapper then the following appears:
`
Beta Was this translation helpful? Give feedback.
All reactions