| 135 | } |
| 136 | |
| 137 | QImage removeBorder(const QImage & mask_id, const Id2Labels & labels, cv::Size win_size) { |
| 138 | QImage result = mask_id.copy(); |
| 139 | |
| 140 | // loop through image |
| 141 | for (int y = 0; y < mask_id.height(); y++) { |
| 142 | const uchar * line_curr = mask_id.scanLine(y); |
| 143 | uchar * line_out = result.scanLine(y); |
| 144 | for (int X = 0; X < mask_id.width(); X++) { |
| 145 | // multiply by 3 to match RGB |
| 146 | int x = X * 3; |
| 147 | int id = line_curr[x]; |
| 148 | if (labels.find(id) == labels.end()) { |
| 149 | // map id # to amount of occurences |
| 150 | std::map<int, int> mapk; |
| 151 | // loop through window (3*3 default size) |
| 152 | for (int yy = -(win_size.height >> 1); yy <= win_size.height >> 1; yy++) { |
| 153 | int yyy = y + yy; |
| 154 | if (yyy < 0 || yyy >= mask_id.height()) continue; |
| 155 | const uchar * l_curr = mask_id.scanLine(yyy); |
| 156 | for (int xx = -(win_size.width >> 1); xx <= win_size.width >> 1; xx++) { |
| 157 | int xxx = x + xx * 3; |
| 158 | if (xxx < 0 || xxx >= mask_id.width() * 3) continue; |
| 159 | if ((yyy == y && xxx == x)) continue; |
| 160 | if (mapk.find(l_curr[xxx]) != mapk.end()) mapk[l_curr[xxx]] ++; |
| 161 | else mapk[l_curr[xxx]] = 1; |
| 162 | } |
| 163 | } |
| 164 | int id_max = 0; |
| 165 | int id_resul = mapk.begin()->first; |
| 166 | std::map<int, int>::iterator it = mapk.begin(); |
| 167 | while (it != mapk.end()) { |
| 168 | if (it->first != 255) { |
| 169 | if (it->second > id_max) { |
| 170 | id_max = it->second; |
| 171 | id_resul = it->first; |
| 172 | } |
| 173 | } |
| 174 | it++; |
| 175 | } |
| 176 | line_out[x] = id_resul; |
| 177 | line_out[x + 1] = id_resul; |
| 178 | line_out[x + 2] = id_resul; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | return result; |
| 183 | } |
| 184 | |
| 185 | bool isFullZero(const QImage& image) { |
| 186 | for (int y = 0; y < image.height(); y++) { |