| 83 | typename pixel_type |
| 84 | > |
| 85 | void assert_is_image ( |
| 86 | const py::array& obj |
| 87 | ) |
| 88 | { |
| 89 | if (!is_image<pixel_type>(obj)) |
| 90 | { |
| 91 | assert_correct_num_channels_in_image<pixel_type>(obj); |
| 92 | |
| 93 | using basic_pixel_type = typename pixel_traits<pixel_type>::basic_pixel_type; |
| 94 | const char expected_type = py::dtype::of<basic_pixel_type>().kind(); |
| 95 | const char got_type = obj.dtype().kind(); |
| 96 | |
| 97 | const size_t expected_size = sizeof(basic_pixel_type); |
| 98 | const size_t got_size = obj.itemsize(); |
| 99 | |
| 100 | auto toname = [](char type, size_t size) { |
| 101 | if (type == 'i' && size == 1) return "int8"; |
| 102 | else if (type == 'i' && size == 2) return "int16"; |
| 103 | else if (type == 'i' && size == 4) return "int32"; |
| 104 | else if (type == 'i' && size == 8) return "int64"; |
| 105 | else if (type == 'u' && size == 1) return "uint8"; |
| 106 | else if (type == 'u' && size == 2) return "uint16"; |
| 107 | else if (type == 'u' && size == 4) return "uint32"; |
| 108 | else if (type == 'u' && size == 8) return "uint64"; |
| 109 | else if (type == 'f' && size == 4) return "float32"; |
| 110 | else if (type == 'd' && size == 8) return "float64"; |
| 111 | else DLIB_CASSERT(false, "unknown type"); |
| 112 | }; |
| 113 | |
| 114 | throw dlib::error("Expected numpy array with elements of type " + std::string(toname(expected_type,expected_size)) + " but got " + toname(got_type, got_size) + "."); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // ---------------------------------------------------------------------------------------- |
| 119 | |