Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for python bindings #120

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

patricknaughton01
Copy link

Can build shared library for python bindings by specifying
-DBUILD_PYTHON=ON when calling cmake. This requires pybind11
to be cloned into build's parent directory. The python bindings
expose a very minimal interface: it allows construction of a
GraspDetector and calling detectGrasps which accepts a
previously instantiated GraspDetector and a point cloud as a
numpy array (of shape (n, 3)). This function returns a numpy
array of shape (number of grasps, 14) where the columns specify
the position, orientation (rotation matrix in row-major order), the width
of the gripper, and the score of the grasp.

Can build shared library for python bindings by specifying
-DBUILD_PYTHON=ON when calling cmake. This requires pybind11
to be cloned into build's parent directory. The python bindings
expose a very minimal interface: it allows construction of a
`GraspDetector` and calling `detectGrasps` which accepts a
previously instantiated `GraspDetector` and a point cloud as a
numpy array (of shape (n, 3)). This function returns a numpy
array of shape (number of grasps, 14) where the columns specify
the position, orientation (rotation matrix in row-major order), the width
of the gripper, and the score of the grasp.
@patricknaughton01 patricknaughton01 marked this pull request as draft November 5, 2021 20:40
@patricknaughton01 patricknaughton01 marked this pull request as ready for review November 5, 2021 21:40
@patricknaughton01
Copy link
Author

One remark is that it seems like the Eigen predictor segfaults if the weights file is not found.

@pvmilk
Copy link

pvmilk commented Nov 15, 2021

I am just another user of the repo that looking into these features recently.

Wondering what is the difference between this implementation and the one in https://github.com/atenpas/gpd/blob/master/src/detect_grasps_python.cpp.

P.S. I am not familiar with cpp2python binding at all, so please excuse me for some silly questions.

@pvmilk
Copy link

pvmilk commented Nov 15, 2021

@patricknaughton01
Copy link
Author

I was unaware actually of that method you linked. I just used pybind because I've used it before and it works nicely with numpy arrays. I haven't tried it, but do you know if the cdll/the existing python code will let you pass in a numpy array?

@pvmilk
Copy link

pvmilk commented Nov 15, 2021

I am testing it at the moment. Still cannot get it compiled. But will report back if I got anything from it.
But looking from here, maybe it is ok.

@pvmilk
Copy link

pvmilk commented Nov 19, 2021

FYI, the provide binding detect_grasps_python.cpp works with some modification, and numpy array can be pass through that ctypes python interface. Can provide the patch if anyone needed it (Update as of July 2023).

GPU-Computer and others added 4 commits January 7, 2022 12:40
Accept position of the camera to be input to the point cloud.
Fixed bug introduced with setting camera viewpoint.

Adding some testing code as well.
@tycoer
Copy link

tycoer commented Jul 17, 2022

Can build shared library for python bindings by specifying -DBUILD_PYTHON=ON when calling cmake. This requires pybind11 to be cloned into build's parent directory. The python bindings expose a very minimal interface: it allows construction of a GraspDetector and calling detectGrasps which accepts a previously instantiated GraspDetector and a point cloud as a numpy array (of shape (n, 3)). This function returns a numpy array of shape (number of grasps, 14) where the columns specify the position, orientation (rotation matrix in row-major order), the width of the gripper, and the score of the grasp.

Hi, after I install your branch, I use the commend 'python3 test.py', the python shows "No module named gpd_python".

I use the following commend when I install your branch:
mkdir build && cd build
cmake -DBUILD_PYTHON=ON ..
make -j8
sudo make install

I already installed pybind11 under the parent dir, and no error occurred during compiling.

However, "No module named gpd_python".

Maybe there should be a "setup.py" file that I can "python setup.py develop" to install "gpd_python"?

or

Any step I wrongly ran caused "No module named gpd_python"

@patricknaughton01
Copy link
Author

The library might be inside the build directory in which case you might be able to solve via any one of the following:

  • Move either test.py or the built shared library into the same directory.
  • Add the build directory to the python path (sys.path.append("build/"))
  • Change the import to from build import gpd_python as gpd

Let me know if these don't work. Thanks.

@tycoer
Copy link

tycoer commented Jul 27, 2022

The library might be inside the build directory in which case you might be able to solve via any one of the following:

  • Move either test.py or the built shared library into the same directory.
  • Add the build directory to the python path (sys.path.append("build/"))
  • Change the import to from build import gpd_python as gpd

Let me know if these don't work. Thanks.

It works, Thanks!!

@anmakon
Copy link

anmakon commented Jul 17, 2023

FYI, the provide binding detect_grasps_python.cpp works with some modification, and numpy array can be pass through that ctypes python interface. Can provide the patch if anyone needed it.

Hi @pvmilk,
do you by any chance still have that patch? I'm looking into using GPD in python with an indexed pointcloud, which I think should be possible with the function calcGraspDescriptorsAtIndices, but I can't quite get it to compile yet.

@pvmilk
Copy link

pvmilk commented Jul 26, 2023

@anmakon Sorry for the late response. I searched through my system and cannot find the patch anymore. Sorry to give a false expectation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants