| 1449 | |
| 1450 | |
| 1451 | void test_label_connected_blobs() |
| 1452 | { |
| 1453 | array2d<unsigned char> img; |
| 1454 | img.set_size(400,401); |
| 1455 | |
| 1456 | assign_all_pixels(img,0); |
| 1457 | |
| 1458 | rectangle rect1, rect2, rect3; |
| 1459 | |
| 1460 | rect1 = centered_rect(99,120, 50,70); |
| 1461 | rect2 = centered_rect(199,80, 34,68); |
| 1462 | rect3 = centered_rect(249,180, 120,78); |
| 1463 | |
| 1464 | fill_rect(img, rect1, 255); |
| 1465 | fill_rect(img, rect2, 255); |
| 1466 | fill_rect(img, rect3, 255); |
| 1467 | |
| 1468 | array2d<unsigned char> labels; |
| 1469 | unsigned long num; |
| 1470 | num = label_connected_blobs(img, |
| 1471 | zero_pixels_are_background(), |
| 1472 | neighbors_8(), |
| 1473 | connected_if_both_not_zero(), |
| 1474 | labels); |
| 1475 | |
| 1476 | DLIB_TEST(num == 4); |
| 1477 | DLIB_TEST(labels.nr() == img.nr()); |
| 1478 | DLIB_TEST(labels.nc() == img.nc()); |
| 1479 | |
| 1480 | const unsigned char l1 = labels[rect1.top()][rect1.left()]; |
| 1481 | const unsigned char l2 = labels[rect2.top()][rect2.left()]; |
| 1482 | const unsigned char l3 = labels[rect3.top()][rect3.left()]; |
| 1483 | |
| 1484 | DLIB_TEST(l1 != 0 && l2 != 0 && l3 != 0); |
| 1485 | DLIB_TEST(l1 != l2 && l1 != l3 && l2 != l3); |
| 1486 | |
| 1487 | for (long r = 0; r < labels.nr(); ++r) |
| 1488 | { |
| 1489 | for (long c = 0; c < labels.nc(); ++c) |
| 1490 | { |
| 1491 | if (rect1.contains(c,r)) |
| 1492 | { |
| 1493 | DLIB_TEST(labels[r][c] == l1); |
| 1494 | } |
| 1495 | else if (rect2.contains(c,r)) |
| 1496 | { |
| 1497 | DLIB_TEST(labels[r][c] == l2); |
| 1498 | } |
| 1499 | else if (rect3.contains(c,r)) |
| 1500 | { |
| 1501 | DLIB_TEST(labels[r][c] == l3); |
| 1502 | } |
| 1503 | else |
| 1504 | { |
| 1505 | DLIB_TEST(labels[r][c] == 0); |
| 1506 | } |
| 1507 | } |
| 1508 | } |
no test coverage detected