Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. do{
  2. dir = dir % 8;
  3. int r = pcurrent.x + di[dir];
  4. int c = pcurrent.y + dj[dir];
  5. //check if r and c are in the image coordinate space;
  6. if (r >= 0 && c >= 0 && r <= src->rows && c <= src->cols) {
  7. //check if the pixel is black
  8. if (src->at<uchar>(r, c) == 0) {
  9. //if black, we save the p0->p1, and p1 = new point indentified;
  10. plast = pcurrent;
  11. pcurrent = Point(r, c);
  12. directions.push_back(dir);
  13. coloredBorder.at<Vec3b>(r, c) = Vec3b(0, 0, 255);
  14.  
  15. //we find the new direction to search the next pixel based on its parity;
  16. if (dir % 2) {
  17. dir = (dir + 6) % 8;
  18. }
  19. else {
  20. dir = (dir + 7) % 8;
  21. }
  22. }
  23. else {
  24. //if a black pixel is not found, we search to the next neighbours in the neighbourhood;
  25. dir++;
  26. }
  27. }
  28. else {
  29. //not in coordinate space, but we must increment dir;
  30. dir++;
  31. }
  32. conditionSatisfied = pcurrent.x == p1.x && pcurrent.y == p1.y && plast.x == p0.x && plast.y == p0.y;
  33.  
  34. }while (!conditionSatisfied);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement