MCPcopy Create free account
hub / github.com/davisking/dlib / numpy_to_dlib_vect

Function numpy_to_dlib_vect

tools/python/src/vector.cpp:191–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189
190template <typename T>
191dlib::vector<T,2> numpy_to_dlib_vect (
192 const py::array_t<T>& v
193)
194/*!
195 ensures
196 - converts a numpy array with 2 elements into a dlib::vector<T,2>
197!*/
198{
199 DLIB_CASSERT(v.size() == 2, "You can only convert a numpy array to a dlib point or dpoint if it has just 2 elements.");
200 DLIB_CASSERT(v.ndim() == 1 || v.ndim() == 2, "The input needs to be interpretable as a row or column vector.");
201 dpoint temp;
202 if (v.ndim() == 1)
203 {
204 temp.x() = v.at(0);
205 temp.y() = v.at(1);
206 }
207 else if (v.shape(0) == 2)
208 {
209 temp.x() = v.at(0,0);
210 temp.y() = v.at(1,0);
211 }
212 else
213 {
214 temp.x() = v.at(0,0);
215 temp.y() = v.at(0,1);
216 }
217 return temp;
218}
219
220// ----------------------------------------------------------------------------------------
221

Callers

nothing calls this directly

Calls 4

atMethod · 0.80
sizeMethod · 0.45
ndimMethod · 0.45
shapeMethod · 0.45

Tested by

no test coverage detected