| 273 | } |
| 274 | |
| 275 | void Segmentation::_mask(const float* output, const std::vector<size_t>& invalid_idxs, cv::Mat& maskImg){ |
| 276 | size_t channel_offset = _img_w * _img_h; |
| 277 | unsigned char _n_classes = 3; |
| 278 | std::vector<unsigned char> max; |
| 279 | |
| 280 | for (int pixel_id = 0; pixel_id < channel_offset; pixel_id++){ |
| 281 | int max_idx = pixel_id; |
| 282 | unsigned char out_idx = 0; |
| 283 | for (unsigned char i = 1; i < _n_classes; i++) { |
| 284 | int buffer_idx = channel_offset * i + pixel_id; |
| 285 | // if(output[max_idx] < output[buffer_idx] && output[buffer_idx] > 0.8){ |
| 286 | if(output[max_idx] < output[buffer_idx]){ |
| 287 | max_idx = buffer_idx; |
| 288 | out_idx = static_cast<unsigned char>(i); |
| 289 | } |
| 290 | } |
| 291 | if(out_idx == 2) out_idx = 255; |
| 292 | max.push_back(out_idx); |
| 293 | } |
| 294 | |
| 295 | for(const int idx : invalid_idxs){ |
| 296 | max[idx] = 0; |
| 297 | } |
| 298 | |
| 299 | memcpy(maskImg.data, max.data(), max.size()*sizeof(unsigned char)); |
| 300 | } |
| 301 | |
| 302 | void Segmentation::_preProcessRange(const cv::Mat& img, cv::Mat& pImg, float maxDist) { |
| 303 | std::vector<cv::Mat> channels(2); |
nothing calls this directly
no outgoing calls
no test coverage detected