-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
progressing on config files, adding some tests for specific cases (tu…
…ple returns etc)
- Loading branch information
Showing
3 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef VISP_PYTHON_BLOB_HPP | ||
#define VISP_PYTHON_BLOB_HPP | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include <pybind11/numpy.h> | ||
|
||
#include <visp3/blob/vpDot2.h> | ||
#include <optional> | ||
|
||
namespace py = pybind11; | ||
|
||
void bindings_vpDot2(py::class_<vpDot2, vpTracker> &pyDot2) | ||
{ | ||
pyDot2.def_static("defineDots", [](std::vector<vpDot2> &dots, | ||
const std::string &dotFile, | ||
vpImage<unsigned char> &I, | ||
vpColor col = vpColor::blue, | ||
bool trackDot = true) { | ||
return vpDot2::defineDots(&dots[0], dots.size(), dotFile, I, col, trackDot); | ||
}, R"doc( | ||
Wrapper for the defineDots method, see the C++ ViSP documentation. | ||
)doc", py::arg("dots"), py::arg("dotFile"), py::arg("I"), py::arg("color"), py::arg("trackDot") = true); | ||
pyDot2.def_static("trackAndDisplay", [](std::vector<vpDot2> &dots, | ||
vpImage<unsigned char> &I, | ||
std::vector<vpImagePoint> &cogs, | ||
std::optional<std::vector<vpImagePoint>> cogStar) { | ||
vpImagePoint *desireds = cogStar ? &((*cogStar)[0]) : nullptr; | ||
vpDot2::trackAndDisplay(&dots[0], dots.size(), I, cogs, desireds); | ||
}, R"doc( | ||
Wrapper for the trackAndDisplay method, see the C++ ViSP documentation. | ||
)doc", py::arg("dots"), py::arg("I"), py::arg("cogs"), py::arg("desiredCogs")); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pytest import approx | ||
from visp.core import Math, ImagePoint, ColVector, ThetaUVector, Point | ||
def test_tuple_return_basic_values_only_output(): | ||
''' | ||
Test that a function that was with signature | ||
double lineFitting(const std::vector<...>& imPts, double& a, double& b, double& c) | ||
is now (with custom configuration) with a signature lineFitting(imPts) -> tuple[double * 4] | ||
all the reference parameters are used as outputs but not as inputs | ||
''' | ||
a = 45.0 | ||
b = 52.0 | ||
points = [ | ||
ImagePoint(a*i+b, i) for i in range(3) | ||
] | ||
res = Math.lineFitting(points) | ||
print(res) | ||
values = (res[0], -res[1] / res[2], res[3] / res[2]) | ||
expected = (0, a, b) | ||
for i, (val, exp) in enumerate(zip(values, expected)): | ||
print(i) | ||
assert val == approx(exp, 0.0001) | ||
|
||
def test_tuple_return_basic_values_only_output_2(): | ||
theta = 3.14 | ||
vec = [0.0, 0.0, 1.0] | ||
thetau = ThetaUVector(*[v * theta for v in vec]) | ||
theta_out, vec_out = thetau.extract() | ||
assert theta_out == theta | ||
assert vec_out == ColVector(vec) | ||
|
||
|
||
def test_pass_by_ref(): | ||
values = [0, 1, 2] | ||
p = Point(values) | ||
vec_ref = ColVector() | ||
p.getWorldCoordinates(vec_ref) | ||
assert vec_ref == p.getWorldCoordinates() | ||
|
||
|
||
def test_tuple_return_basic_values_mixed(): | ||
pass |