| 227 | } |
| 228 | |
| 229 | static RegressionLine TraceLine(const BitMatrix& image, PointF p, PointF d, int edge) |
| 230 | { |
| 231 | BitMatrixCursorF cur(image, p, d - p); |
| 232 | RegressionLine line; |
| 233 | line.setDirectionInward(cur.back()); |
| 234 | |
| 235 | // collect points inside the black line -> backup on 3rd edge |
| 236 | cur.stepToEdge(edge, 0, edge == 3); |
| 237 | if (edge == 3) |
| 238 | cur.turnBack(); |
| 239 | |
| 240 | auto curI = BitMatrixCursorI(image, PointI(cur.p), PointI(mainDirection(cur.d))); |
| 241 | // make sure curI positioned such that the white->black edge is directly behind |
| 242 | // Test image: fix-traceline.jpg |
| 243 | while (!curI.edgeAtBack()) { |
| 244 | if (curI.edgeAtLeft()) |
| 245 | curI.turnRight(); |
| 246 | else if (curI.edgeAtRight()) |
| 247 | curI.turnLeft(); |
| 248 | else |
| 249 | curI.step(-1); |
| 250 | } |
| 251 | |
| 252 | for (auto dir : {Direction::LEFT, Direction::RIGHT}) { |
| 253 | auto c = BitMatrixCursorI(image, curI.p, curI.direction(dir)); |
| 254 | auto stepCount = static_cast<int>(maxAbsComponent(cur.p - p)); |
| 255 | do { |
| 256 | line.add(centered(c.p)); |
| 257 | } while (--stepCount > 0 && c.stepAlongEdge(dir, true)); |
| 258 | } |
| 259 | |
| 260 | line.evaluate(1.0, true); |
| 261 | |
| 262 | for (auto p : line.points()) |
| 263 | log(p, 2); |
| 264 | |
| 265 | return line; |
| 266 | } |
| 267 | |
| 268 | // estimate how tilted the symbol is (return value between 1 and 2, see also above) |
| 269 | static double EstimateTilt(const FinderPatternSet& fp) |
no test coverage detected