48 range_mask_ = algorithm::IAlloc2<char>(
static_cast<int>(height_),
49 static_cast<int>(width_));
50 memset(range_mask_[0], 0,
sizeof(
char) * width_ * height_);
51 float meter_per_pixel = range * 2.0f /
static_cast<float>(width_);
52 size_t half_width = width_ / 2;
53 size_t half_height = height_ / 2;
54 for (
size_t r = 0; r < height_; ++r) {
55 for (
size_t c = 0; c < width_; ++c) {
56 float distance = sqrtf(
57 powf((
static_cast<float>(r) -
static_cast<float>(half_height)), 2.f) +
58 powf((
static_cast<float>(c) -
static_cast<float>(half_width)), 2.f));
59 distance *= meter_per_pixel;
60 if (distance <= boundary_distance) {
61 range_mask_[r][c] = 1;
97 for (
auto& cluster : clusters_) {
99 for (
auto& pixel : cluster->pixels) {
100 sum += confidence_map[pixel];
102 sum = cluster->pixels.size() > 0
103 ? sum /
static_cast<float>(cluster->pixels.size())
105 cluster->confidence = sum;
108 for (
size_t n = 0; n < clusters_.size(); ++n) {
109 if (clusters_[n]->confidence >=
threshold) {
111 clusters_[current] = clusters_[n];
112 for (
auto& pixel : clusters_[current]->pixels) {
113 labels_[0][pixel] =
static_cast<uint16_t
>(current + 1);
118 for (
auto& pixel : clusters_[n]->pixels) {
119 labels_[0][pixel] = 0;
123 clusters_.resize(current);
127 const float* category_map,
128 float confidence_threshold,
129 float category_threshold) {
130 std::vector<bool> is_valid;
131 is_valid.reserve(clusters_.size());
132 for (
auto& cluster : clusters_) {
134 for (
auto& pixel : cluster->pixels) {
135 mask &= range_mask_[0][pixel];
137 float sum_confidence = 0.f;
138 for (
auto& pixel : cluster->pixels) {
139 sum_confidence += confidence_map[pixel];
142 cluster->pixels.size() > 0
143 ? sum_confidence /
static_cast<float>(cluster->pixels.size())
145 cluster->confidence = sum_confidence;
147 is_valid.push_back(cluster->confidence >= confidence_threshold);
149 float sum_category = 0.f;
150 for (
auto& pixel : cluster->pixels) {
151 sum_category += category_map[pixel];
154 cluster->pixels.size() > 0
155 ? sum_category /
static_cast<float>(cluster->pixels.size())
157 is_valid.push_back(sum_category >= category_threshold);
159 cluster->confidence =
160 std::max(sum_confidence, confidence_threshold + 0.01f);
164 for (
size_t n = 0; n < clusters_.size(); ++n) {
167 clusters_[current] = clusters_[n];
168 for (
auto& pixel : clusters_[current]->pixels) {
169 labels_[0][pixel] =
static_cast<uint16_t
>(current + 1);
174 for (
auto& pixel : clusters_[n]->pixels) {
175 labels_[0][pixel] = 0;
179 clusters_.resize(current);
184 for (
auto& cluster : clusters_) {
185 cluster->class_prob.assign(class_num, 0.f);
187 size_t size = width_ * height_;
188 for (
size_t c = 0; c < class_num; ++c) {
189 const float* class_map_ptr = class_map + c * size;
190 for (
auto& cluster : clusters_) {
191 auto& probs = cluster->class_prob;
192 for (
auto& pixel : cluster->pixels) {
193 probs[c] += class_map_ptr[pixel];
197 for (
auto& cluster : clusters_) {
198 auto& probs = cluster->class_prob;
199 float sum = std::accumulate(probs.begin(), probs.end(), 0.f);
201 for (
auto& value : probs) {
205 cluster->type =
static_cast<SppClassType>(std::distance(
206 probs.begin(), std::max_element(probs.begin(), probs.end())));
211 const float* heading_map_x_ptr = heading_map;
212 const float* heading_map_y_ptr = heading_map + width_ * height_;
214 for (
size_t n = 0; n < clusters_.size(); ++n) {
215 float heading_x = 0.f, heading_y = 0.f;
216 for (
auto pixel : clusters_[n]->pixels) {
217 heading_x += heading_map_x_ptr[pixel];
218 heading_y += heading_map_y_ptr[pixel];
220 clusters_[n]->yaw = std::atan2(heading_y, heading_x) * 0.5f;