OpenPIV / openpiv-c--qt

C++ with Qt frontend (superfast) version of OpenPIV
http://www.openpiv.net
GNU General Public License v3.0
20 stars 17 forks source link

add pybind11 bindings for core classes #15

Open timdewhirst opened 2 years ago

timdewhirst commented 2 years ago

See discussion: https://github.com/OpenPIV/openpiv-python/issues/224

ErichZimmer commented 2 years ago

Should we include the logging functions? It seems quite straight forward without the logging library as there seems to be only standard libraries. I haven't figured out how to install c++ dependencies reliably on different operating systems in setup.py to get a minimum working example.

timdewhirst commented 2 years ago

No real reason to include spdlog if that's causing a problem, and its use is not widespread yet. If you already have some WIP I'd be more than happy to take a look - perhaps raise a PR to a new branch here?

ErichZimmer commented 2 years ago

Please expect some time for a wrapper to be started and or completed since I started learning c++ only 4 weeks ago. However, I'll see how far I can get since I already wrapped a gaussian filter as an experiment.

ErichZimmer commented 2 years ago

For some reason, setup.py doesn't know how to deal with the header files. I'm trying to wrap a modified version of the processing example that has a declaration like;

void correlate_images(
    py::array_t<float> cmatrix,
    py::array_t<float> imgA,
    py::array_t<float> imgB,
    py::tuple window_size,
    py::tuple overlap,
    py::bool_ center_grid_on_image
);

The function can be modified to return a numpy array

ErichZimmer commented 2 years ago

Should we include vcpkg or use setuptools to compile the package?

timdewhirst commented 2 years ago

I was planning on trying vcpkg (for pybind11) and cmake (for compilation) - I have some time over Easter weekend so was planning on sketching this out to make sure it works.

ErichZimmer commented 1 year ago

Currently, the wrapped functions and classes under pycoreopenpiv are not really usable as they have non-native data type returns (For instance, core::image::data() returns a pixel type that cannot be casted into a numpy array and has limited use). When I have time, should I play around with your wrapper to make it more python friendly? I have future plans on utilizing this repository more often so I can add more features while learning more about c++ and pybind11 (e.g., I want to add morphological and convolution filters and make the wrapper more user friendly).

timdewhirst commented 1 year ago

Agreed! it's on my list of things to do - basically python has the concept of a buffer protocol which is what we need to use to allow seamless interchange from numpy to the core image type: https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html

Any/all contributions welcome; the aim is - as the title suggests - to provide python bindings to the core classes and also to allow interoperability with other more commonly used libraries such as numpy, pandas.

ErichZimmer commented 7 months ago

I tried compiling your Python bindings for libopenpiv, but I get a lengthy compiler error, presumably due to pybind11 not handling type-deductions properly for one reason or another.

meson setup log [download]

meson compile cmd log [download]

ErichZimmer commented 7 months ago

Apparently, commenting lines .def(py::self < py::self) .def(py::self <= py::self) .def(py::self > py::self) .def(py::self >= py::self); py::implicitly_convertible<py::list, point_t>(); fixed the issue for Windows 11.

timdewhirst commented 7 months ago

thanks, will take a look

timdewhirst commented 7 months ago

I took a look and apart from a couple of warnings (which are now fixed) the code compiles and works fine:

Of the two install routes covered in README.md, using setup.py doesn't appear to work on windows, but manually building using cmake is fine:

import pyopenpivcore as popc
import numpy as np
from matplotlib import pyplot as plt

ima = popc.load_g_u16('../../../examples/data/test1/exp1_001_a.tiff')
ima_np = np.array(ima, copy=False)
plt.imshow(ima_np, cmap='gray')
plt.show()

This shows a few things: