| 86 | // ---------------------------------------------------------------------------------------- |
| 87 | |
| 88 | inline void find_candidate_object_locations_py ( |
| 89 | py::array pyimage, |
| 90 | py::list& pyboxes, |
| 91 | py::tuple pykvals, |
| 92 | unsigned long min_size, |
| 93 | unsigned long max_merging_iterations |
| 94 | ) |
| 95 | { |
| 96 | if (py::len(pykvals) != 3) |
| 97 | throw dlib::error("kvals must be a tuple with three elements for start, end, num."); |
| 98 | |
| 99 | double start = pykvals[0].cast<double>(); |
| 100 | double end = pykvals[1].cast<double>(); |
| 101 | long num = pykvals[2].cast<long>(); |
| 102 | matrix_range_exp<double> kvals = linspace(start, end, num); |
| 103 | |
| 104 | std::vector<rectangle> rects; |
| 105 | const long count = py::len(pyboxes); |
| 106 | // Copy any rectangles in the input pyboxes into rects so that any rectangles will be |
| 107 | // properly deduped in the resulting output. |
| 108 | for (long i = 0; i < count; ++i) |
| 109 | rects.push_back(pyboxes[i].cast<rectangle>()); |
| 110 | // Find candidate objects |
| 111 | if (is_image<unsigned char>(pyimage)) |
| 112 | find_candidate_object_locations(numpy_image<unsigned char>(pyimage), rects, kvals, min_size, max_merging_iterations); |
| 113 | else if (is_image<rgb_pixel>(pyimage)) |
| 114 | find_candidate_object_locations(numpy_image<rgb_pixel>(pyimage), rects, kvals, min_size, max_merging_iterations); |
| 115 | else |
| 116 | throw dlib::error("Unsupported image type, must be 8bit gray or RGB image."); |
| 117 | |
| 118 | // Collect boxes containing candidate objects |
| 119 | std::vector<rectangle>::iterator iter; |
| 120 | for (iter = rects.begin(); iter != rects.end(); ++iter) |
| 121 | pyboxes.append(*iter); |
| 122 | } |
| 123 | |
| 124 | // ---------------------------------------------------------------------------------------- |
| 125 | |