------------------- GetPointsFromList ------------------- Create an array of points from a Python list. [TODO:DaveP] should really use exceptions here.
| 74 | // [TODO:DaveP] should really use exceptions here. |
| 75 | // |
| 76 | static double ** |
| 77 | GetPointsFromList(PyUtilApiFunction& api, PyObject* listArg, int dim, const std::string& argName) |
| 78 | { |
| 79 | // First check that the listArg is a list. |
| 80 | if (!PyList_Check(listArg)){ |
| 81 | api.error("The " + argName + " argument is not a list."); |
| 82 | return nullptr; |
| 83 | } |
| 84 | |
| 85 | int listSize = PyList_Size(listArg); |
| 86 | if (listSize == 0) { |
| 87 | api.error("The " + argName + " argument is empty."); |
| 88 | return nullptr; |
| 89 | } |
| 90 | |
| 91 | // Convert the Python list to a double array. |
| 92 | // |
| 93 | double **points = cvMath().createArray(listSize, dim); |
| 94 | for (int i = 0; i < listSize; i++) { |
| 95 | PyObject *temp = PyList_GetItem(listArg,i); |
| 96 | if (temp == nullptr) { |
| 97 | api.error("The " + std::to_string(i) + "th element of the " + argName + "argument is not defined."); |
| 98 | return nullptr; |
| 99 | } |
| 100 | if (PyList_Size(temp) != dim) { |
| 101 | api.error("The " + std::to_string(i) + "th element of the " + argName + " argument list != "+std::to_string(dim)+"."); |
| 102 | return nullptr; |
| 103 | } |
| 104 | for (int j = 0; j < dim; j++) { |
| 105 | points[i][j] = PyFloat_AsDouble(PyList_GetItem(temp,j)); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return points; |
| 110 | } |
| 111 | |
| 112 | ////////////////////////////////////////////////////// |
| 113 | // M o d u l e F u n c t i o n s // |
no test coverage detected