diff --git a/modules/python/bindings/include/core.hpp b/modules/python/bindings/include/core.hpp index 67963a3619..6b8fe10c7a 100644 --- a/modules/python/bindings/include/core.hpp +++ b/modules/python/bindings/include/core.hpp @@ -39,6 +39,8 @@ #include "core/images.hpp" #include "core/pixel_meter.hpp" #include "core/image_conversions.hpp" +#include "core/display.hpp" + #endif diff --git a/modules/python/bindings/include/core/display.hpp b/modules/python/bindings/include/core/display.hpp new file mode 100644 index 0000000000..a9f7ceab1a --- /dev/null +++ b/modules/python/bindings/include/core/display.hpp @@ -0,0 +1,104 @@ +/* + * ViSP, open source Visual Servoing Platform software. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file LICENSE.txt at the root directory of this source + * distribution for additional information about the GNU GPL. + * + * For using ViSP with software that can not be combined with the GNU + * GPL, please contact Inria about acquiring a ViSP Professional + * Edition License. + * + * See https://visp.inria.fr for more information. + * + * This software was developed at: + * Inria Rennes - Bretagne Atlantique + * Campus Universitaire de Beaulieu + * 35042 Rennes Cedex + * France + * + * If you have questions regarding the use of this file, please contact + * Inria at visp@inria.fr + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Description: + * Python bindings. + */ + +#ifndef VISP_PYTHON_CORE_DISPLAY_HPP +#define VISP_PYTHON_CORE_DISPLAY_HPP + +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +void bindings_vpDisplay(py::class_> &pyDisplay) +{ + + pyDisplay.def_static("displayCrosses", + [](const vpImage &I, + const py::array_t &is, + const py::array_t &js, + unsigned int size, const vpColor &color, unsigned int thickness = 1) { + + py::buffer_info bufi = is.request(), bufj = js.request(); + if (bufi.ndim != bufj.ndim || bufi.shape != bufj.shape) { + std::stringstream ss; + ss << "is and js must have the same number of dimensions and same number of elements, but got is = " << shape_to_string(bufi.shape); + ss << "and js = " << shape_to_string(bufj.shape); + throw std::runtime_error(ss.str()); + } + + const int *i_ptr = static_cast(bufi.ptr); + const int *j_ptr = static_cast(bufj.ptr); + + for (py::ssize_t i = 0; i < bufi.size; ++i) { + vpDisplay::displayCross(I, i_ptr[i], j_ptr[i], size, color, thickness); + } + + }); + + pyDisplay.def_static("displayLines", + [](const vpImage &I, + const py::array_t &is1, + const py::array_t &js1, + const py::array_t &is2, + const py::array_t &js2, + const vpColor &color, unsigned int thickness = 1, bool segment = true) { + + py::buffer_info bufi1 = is1.request(), bufj1 = js1.request(); + py::buffer_info bufi2 = is2.request(), bufj2 = js2.request(); + + if (bufi1.shape != bufj1.shape || bufi1.shape != bufi2.shape || bufi1.shape != bufj2.shape) { + std::stringstream ss; + ss << "In display lines: numpy arrays must have same dimensions!"; + throw std::runtime_error(ss.str()); + } + + const int *i1_ptr = static_cast(bufi1.ptr); + const int *j1_ptr = static_cast(bufj1.ptr); + + const int *i2_ptr = static_cast(bufi2.ptr); + const int *j2_ptr = static_cast(bufj2.ptr); + + + for (py::ssize_t i = 0; i < bufi1.size; ++i) { + vpDisplay::displayLine(I, i1_ptr[i], j1_ptr[i], i2_ptr[i], j2_ptr[i], color, thickness, segment); + } + + }); + +} + +#endif diff --git a/modules/python/config/core.json b/modules/python/config/core.json index f52116f0dd..3ca4110ba2 100644 --- a/modules/python/config/core.json +++ b/modules/python/config/core.json @@ -1,12 +1,29 @@ { - "ignored_headers": ["vpGEMM.h", "vpDebug.h", "vpEndian.h"], - "ignored_classes": ["vpException", "vpImageException", "vpTrackingException", - "vpFrameGrabberException", "vpIoException", - "vpDisplayException", "vpMatrixException"], - "user_defined_headers": ["core.hpp"], - "config_includes": ["core_image.json", "core_math.json"], + "ignored_headers": [ + "vpGEMM.h", + "vpDebug.h", + "vpEndian.h" + ], + "ignored_classes": [ + "vpException", + "vpImageException", + "vpTrackingException", + "vpFrameGrabberException", + "vpIoException", + "vpDisplayException", + "vpMatrixException" + ], + "user_defined_headers": [ + "core.hpp" + ], + "config_includes": [ + "core_image.json", + "core_math.json" + ], "header_additional_dependencies": { - "vpUKSigmaDrawerMerwe.h": ["vpUnscentedKalman.h"] + "vpUKSigmaDrawerMerwe.h": [ + "vpUnscentedKalman.h" + ] }, "enums": { "vpMunkres::STEP_T": { @@ -95,7 +112,9 @@ ], "classes": { "vpIoTools": { - "ignored_attributes": ["separator"], + "ignored_attributes": [ + "separator" + ], "methods": [ { "signature": "void readBinaryValueLE(std::ifstream&, int16_t&)", @@ -131,70 +150,118 @@ "static": true, "signature": "void getUserName(std::string&)", "use_default_param_policy": false, - "param_is_input": [false], - "param_is_output": [true] + "param_is_input": [ + false + ], + "param_is_output": [ + true + ] }, { "static": true, "signature": "void getVersion(const std::string&, unsigned int&, unsigned int&, unsigned int&)", "use_default_param_policy": false, - "param_is_input": [true, false, false, false], - "param_is_output": [false, true, true, true] + "param_is_input": [ + true, + false, + false, + false + ], + "param_is_output": [ + false, + true, + true, + true + ] }, { "static": true, "signature": "bool readConfigVar(const std::string&, float&)", "custom_name": "readConfigVarFloat", "use_default_param_policy": false, - "param_is_input": [true, false], - "param_is_output": [false, true] + "param_is_input": [ + true, + false + ], + "param_is_output": [ + false, + true + ] }, { "static": true, "signature": "bool readConfigVar(const std::string&, double&)", "custom_name": "readConfigVarDouble", "use_default_param_policy": false, - "param_is_input": [true, false], - "param_is_output": [false, true] + "param_is_input": [ + true, + false + ], + "param_is_output": [ + false, + true + ] }, { "static": true, "signature": "bool readConfigVar(const std::string&, unsigned int&)", "custom_name": "readConfigVarUnsigned", "use_default_param_policy": false, - "param_is_input": [true, false], - "param_is_output": [false, true] + "param_is_input": [ + true, + false + ], + "param_is_output": [ + false, + true + ] }, { "static": true, "signature": "bool readConfigVar(const std::string&, int&)", "custom_name": "readConfigVarInt", "use_default_param_policy": false, - "param_is_input": [true, false], - "param_is_output": [false, true] + "param_is_input": [ + true, + false + ], + "param_is_output": [ + false, + true + ] }, { "static": true, "signature": "bool readConfigVar(const std::string&, bool&)", "custom_name": "readConfigVarBoolean", "use_default_param_policy": false, - "param_is_input": [true, false], - "param_is_output": [false, true] + "param_is_input": [ + true, + false + ], + "param_is_output": [ + false, + true + ] }, { "static": true, "signature": "bool readConfigVar(const std::string&, std::string&)", "custom_name": "readConfigVarString", "use_default_param_policy": false, - "param_is_input": [true, false], - "param_is_output": [false, true] + "param_is_input": [ + true, + false + ], + "param_is_output": [ + false, + true + ] } ] }, - "vpPolygon": { - "methods": - [ + "methods": [ { "static": true, "signature": "bool isInside(const std::vector&, const double&, const double&, const vpPolygon::PointInPolygonMethod&)", @@ -208,61 +275,121 @@ "static": true, "signature": "void getClippedPolygon(const std::vector&, std::vector&, const vpHomogeneousMatrix&, const unsigned int&, const vpCameraParameters&, const double&, const double&)", "use_default_param_policy": false, - "param_is_input": [true, false, true, true, true, true, true], - "param_is_output": [false, true, false, false, false, false, false] + "param_is_input": [ + true, + false, + true, + true, + true, + true, + true + ], + "param_is_output": [ + false, + true, + false, + false, + false, + false, + false + ] }, { "static": false, "signature": "void getPolygonClipped(std::vector&)", "use_default_param_policy": false, - "param_is_input": [false], - "param_is_output": [true] + "param_is_input": [ + false + ], + "param_is_output": [ + true + ] }, { "static": false, "signature": "void getPolygonClipped(std::vector>&)", "custom_name": "getPolygonClippedWithInfo", "use_default_param_policy": false, - "param_is_input": [false], - "param_is_output": [true] + "param_is_input": [ + false + ], + "param_is_output": [ + true + ] }, { "static": false, "signature": "void getRoiClipped(const vpCameraParameters&, std::vector>&, const vpHomogeneousMatrix&)", "use_default_param_policy": false, - "param_is_input": [true, false, true], - "param_is_output": [false, true, false] + "param_is_input": [ + true, + false, + true + ], + "param_is_output": [ + false, + true, + false + ] }, { "static": false, "signature": "void getRoiClipped(const vpCameraParameters&, std::vector>&)", "use_default_param_policy": false, - "param_is_input": [true, false], - "param_is_output": [false, true] + "param_is_input": [ + true, + false + ], + "param_is_output": [ + false, + true + ] }, { "static": false, "signature": "void getRoiClipped(const vpCameraParameters&, std::vector&, const vpHomogeneousMatrix&)", "use_default_param_policy": false, - "param_is_input": [true, false, true], - "param_is_output": [false, true, false] + "param_is_input": [ + true, + false, + true + ], + "param_is_output": [ + false, + true, + false + ] }, { "static": false, "signature": "void getRoiClipped(const vpCameraParameters&, std::vector&)", "use_default_param_policy": false, - "param_is_input": [true, false], - "param_is_output": [false, true] + "param_is_input": [ + true, + false + ], + "param_is_output": [ + false, + true + ] }, { "static": true, "signature": "void getMinMaxRoi(const std::vector&, int&, int&, int&, int&)", "use_default_param_policy": false, "param_is_input": [ - true, false, false, false, false + true, + false, + false, + false, + false ], "param_is_output": [ - false, true, true, true, true + false, + true, + true, + true, + true ] } ] @@ -277,8 +404,7 @@ ] }, "vpPoint": { - "methods": - [ + "methods": [ { "static": false, "ignore": true, @@ -289,7 +415,6 @@ "ignore": true, "signature": "void getWorldCoordinates(double&, double&, double&)" } - ] }, "vpRect": { @@ -298,14 +423,19 @@ "static": false, "signature": "void getCenter(double&, double&)", "use_default_param_policy": false, - "param_is_input": [false,false], - "param_is_output": [true, true] + "param_is_input": [ + false, + false + ], + "param_is_output": [ + true, + true + ] } ] }, "vpBSpline": { - "methods": - [ + "methods": [ { "static": true, "signature": "unsigned int findSpan(double, unsigned int, const std::vector &)", @@ -331,21 +461,28 @@ "static": false, "signature": "void get_knots(std::list&)", "use_default_param_policy": false, - "param_is_input": [false], - "param_is_output": [true] + "param_is_input": [ + false + ], + "param_is_output": [ + true + ] }, { "static": false, "signature": "void get_controlPoints(std::list&)", "use_default_param_policy": false, - "param_is_input": [false], - "param_is_output": [true] + "param_is_input": [ + false + ], + "param_is_output": [ + true + ] } ] }, "vpQuadProg": { - "methods": - [ + "methods": [ { "static": true, "signature": "bool solveQPe(const vpMatrix &, const vpColVector &, vpMatrix, vpColVector, vpColVector &, const double &)", @@ -358,17 +495,17 @@ { "static": true, "signature": "void convertToOpenCV(const std::vector&, std::vector&, bool)", - "ignore" :true + "ignore": true }, { "static": true, "signature": "void convertToOpenCV(const std::vector&, std::vector&, bool)", - "ignore" :true + "ignore": true }, { "static": true, "signature": "void convertToOpenCV(const std::vector&, std::vector&)", - "ignore" :true + "ignore": true }, { "static": true, @@ -413,8 +550,8 @@ ] }, "vpDisplay": { - "methods": - [ + "additional_bindings": "bindings_vpDisplay", + "methods": [ { "static": true, "signature": "unsigned int getDownScalingFactor(const vpImage &)", @@ -527,29 +664,85 @@ "static": true, "signature": "void convertEllipse(const vpCameraParameters&, const vpImagePoint&, double, double, double, double&, double&, double&, double&, double&)", "use_default_param_policy": false, - "param_is_input": [true, true, true, true, true, false, false, false, false, false], - "param_is_output": [false, false, false, false, false, true, true, true, true, true] + "param_is_input": [ + true, + true, + true, + true, + true, + false, + false, + false, + false, + false + ], + "param_is_output": [ + false, + false, + false, + false, + false, + true, + true, + true, + true, + true + ] }, { "static": true, "signature": "void convertLine(const vpCameraParameters&, const double&, const double&, double&, double&)", "use_default_param_policy": false, - "param_is_input": [true,true,true,false,false], - "param_is_output": [false,false,false,true,true] + "param_is_input": [ + true, + true, + true, + false, + false + ], + "param_is_output": [ + false, + false, + false, + true, + true + ] }, { "static": true, "signature": "void convertPoint(const vpCameraParameters&, const double&, const double&, double&, double&)", "use_default_param_policy": false, - "param_is_input": [true,true,true,false,false], - "param_is_output": [false,false,false,true,true] + "param_is_input": [ + true, + true, + true, + false, + false + ], + "param_is_output": [ + false, + false, + false, + true, + true + ] }, { "static": true, "signature": "void convertPoint(const vpCameraParameters&, const vpImagePoint&, double&, double&)", "use_default_param_policy": false, - "param_is_input": [true,true,false,false], - "param_is_output": [false,false,true,true] + "param_is_input": [ + true, + true, + false, + false + ], + "param_is_output": [ + false, + false, + true, + true + ] }, { "static": true, @@ -572,7 +765,6 @@ "ignore": true } ] - }, "vpMeterPixelConversion": { "additional_bindings": "bindings_vpMeterPixelConversion", @@ -581,50 +773,126 @@ "static": true, "signature": "void convertEllipse(const vpCameraParameters&, const vpImagePoint&, double, double, double, double&, double&, double&, double&, double&)", "use_default_param_policy": false, - "param_is_input": [true, true, true, true, true, false, false, false, false, false], - "param_is_output": [false, false, false, false, false, true, true, true, true, true] + "param_is_input": [ + true, + true, + true, + true, + true, + false, + false, + false, + false, + false + ], + "param_is_output": [ + false, + false, + false, + false, + false, + true, + true, + true, + true, + true + ] }, { "static": true, "signature": "void convertEllipse(const vpCameraParameters&, const vpSphere&, vpImagePoint&, double&, double&, double&)", "use_default_param_policy": false, "param_is_input": [ - true, true, true, false, false, false + true, + true, + true, + false, + false, + false ], "param_is_output": [ - false, false, false, true, true, true + false, + false, + false, + true, + true, + true ] }, { "static": true, "signature": "void convertLine(const vpCameraParameters&, const double&, const double&, double&, double&)", "use_default_param_policy": false, - "param_is_input": [true,true,true,false,false], - "param_is_output": [false,false,false,true,true] + "param_is_input": [ + true, + true, + true, + false, + false + ], + "param_is_output": [ + false, + false, + false, + true, + true + ] }, { "static": true, "signature": "void convertPoint(const vpCameraParameters&, const double&, const double&, double&, double&)", "use_default_param_policy": false, - "param_is_input": [true,true,true,false,false], - "param_is_output": [false,false,false,true,true] + "param_is_input": [ + true, + true, + true, + false, + false + ], + "param_is_output": [ + false, + false, + false, + true, + true + ] }, { "static": true, "signature": "void convertPoint(const vpCameraParameters&, const vpImagePoint&, double&, double&)", "use_default_param_policy": false, - "param_is_input": [true,true,false,false], - "param_is_output": [false,false,true,true] + "param_is_input": [ + true, + true, + false, + false + ], + "param_is_output": [ + false, + false, + true, + true + ] }, { "static": true, "signature": "void convertEllipse(const vpCameraParameters&, const vpCircle&, vpImagePoint&, double&, double&, double&)", "use_default_param_policy": false, "param_is_input": [ - true, true, true, true, true, true + true, + true, + true, + true, + true, + true ], "param_is_output": [ - false, false, false, true, true, true + false, + false, + false, + true, + true, + true ] }, { @@ -632,10 +900,28 @@ "signature": "void convertEllipse(const vpCameraParameters&, double, double, double, double, double, vpImagePoint&, double&, double&, double&)", "use_default_param_policy": false, "param_is_input": [ - true, true, true, true, true, true, true, false, false, false + true, + true, + true, + true, + true, + true, + true, + false, + false, + false ], "param_is_output": [ - false, false, false, false, false, false, false, true, true, true + false, + false, + false, + false, + false, + false, + false, + true, + true, + true ] }, { @@ -681,8 +967,22 @@ "static": true, "signature": "void computeIntersectionPoint(const vpCircle&, const vpCameraParameters&, const double&, const double&, double&, double&)", "use_default_param_policy": false, - "param_is_input": [true, true, true, true, false, false], - "param_is_output": [false, false, false, false, true, true] + "param_is_input": [ + true, + true, + true, + true, + false, + false + ], + "param_is_output": [ + false, + false, + false, + false, + true, + true + ] } ] }, @@ -692,14 +992,18 @@ "static": true, "signature": "double derivativeFilterX(const vpImage&, unsigned int, unsigned int)", "specializations": [ - ["TypeFilterable"] + [ + "TypeFilterable" + ] ] }, { "static": true, "signature": "double derivativeFilterY(const vpImage&, unsigned int, unsigned int)", "specializations": [ - ["TypeFilterable"] + [ + "TypeFilterable" + ] ] } ] @@ -709,32 +1013,56 @@ { "static": true, "signature": "void dilatation(vpImage&, const int&)", - "specializations": [["TypeErodableDilatable"]] + "specializations": [ + [ + "TypeErodableDilatable" + ] + ] }, { "static": true, "signature": "void erosion(vpImage&, Type, Type, vpImageMorphology::vpConnexityType)", - "specializations": [["TypeErodableDilatable"]] + "specializations": [ + [ + "TypeErodableDilatable" + ] + ] }, { "static": true, "signature": "void erosion(vpImage&, const vpImageMorphology::vpConnexityType&)", - "specializations": [["TypeErodableDilatable"]] + "specializations": [ + [ + "TypeErodableDilatable" + ] + ] }, { "static": true, "signature": "void dilatation(vpImage&, Type, Type, vpImageMorphology::vpConnexityType)", - "specializations": [["TypeErodableDilatable"]] + "specializations": [ + [ + "TypeErodableDilatable" + ] + ] }, { "static": true, "signature": "void dilatation(vpImage&, const vpImageMorphology::vpConnexityType&)", - "specializations": [["TypeErodableDilatable"]] + "specializations": [ + [ + "TypeErodableDilatable" + ] + ] }, { "static": true, "signature": "void erosion(vpImage&, const int&)", - "specializations": [["TypeErodableDilatable"]] + "specializations": [ + [ + "TypeErodableDilatable" + ] + ] } ] }, @@ -800,15 +1128,29 @@ "static": false, "signature": "int receive(std::string&, std::string&, int)", "use_default_param_policy": false, - "param_is_input": [false, false, true], - "param_is_output": [true, true, false] + "param_is_input": [ + false, + false, + true + ], + "param_is_output": [ + true, + true, + false + ] }, { "static": false, "signature": "int receive(std::string&, int)", "use_default_param_policy": false, - "param_is_input": [false, true], - "param_is_output": [true, false] + "param_is_input": [ + false, + true + ], + "param_is_output": [ + true, + false + ] } ] }, @@ -817,7 +1159,11 @@ { "static": true, "signature": "std::vector shuffleVector(const std::vector&)", - "specializations": [["TypePythonScalar"]] + "specializations": [ + [ + "TypePythonScalar" + ] + ] } ] }, @@ -827,15 +1173,23 @@ "static": false, "signature": "unsigned getPeaks(std::list&)", "use_default_param_policy": false, - "param_is_input": [false], - "param_is_output": [true] + "param_is_input": [ + false + ], + "param_is_output": [ + true + ] }, { "static": false, "signature": "unsigned getValey(std::list&)", "use_default_param_policy": false, - "param_is_input": [false], - "param_is_output": [true] + "param_is_input": [ + false + ], + "param_is_output": [ + true + ] }, { "static": false,