| 189 | |
| 190 | template <typename T> |
| 191 | dlib::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 | |