All Projects → wkentaro → call-python-from-cpp

wkentaro / call-python-from-cpp

Licence: other
Example Code of Calling Python from C++ with PyBind11.

Programming Languages

C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
CMake
9771 projects

call-python-from-cpp

Example Code of Calling Python from C++, following the instruction Embedding the Interpreter.

Installation

# for example_001 - example_003
sudo python3 -m pip install numpy
sudo python3 -m pip install scipy

# for example_004
sudo python3 -m pip install opencv-python
sudo python3 -m pip install chainer
sudo python3 -m pip install chainercv
sudo python3 -m pip install imgviz
sudo python3 -m pip install pyglet
sudo python3 -m pip install cupy-cuda101     # CUDA10.1, cupy-cuda92 for 9.2
mkdir build
cd build

cmake ..
make

Examples

Hello World! (src/example_001.cpp)

$ cd build
$ ./example_001
Hello, World!

Import SciPy (src/example_002.cpp)

$ cd build
$ ./example_002
sys version: 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609]
scipy version: 1.3.0

Communicate Numpy Array (src/example_003.cpp)

$ cd build
$ ./example_003
shape: 768 1024 3
ndim: 3
==> Saved to: image.jpg


image.jpg

Run Mask R-CNN (src/example_004.cpp)

$ cd build
$ ./example_004
ndim: 3
shape: (600, 956, 3, )


cv::imshow(...)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].