Advertisement
Guest User

Untitled

a guest
May 27th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. //Create Queue
  2. queue <Point> que;
  3.  
  4. Mat visited = Mat::zeros(src.size(), CV_32SC1);
  5.  
  6. Mat strong = mag.clone();
  7.  
  8. for (int i = 1; i < src.rows - 1; i++)
  9. {
  10. for (int j = 1; j < src.cols - 1; j++)
  11. {
  12. if (mag.at<uchar>(i, j) == STRONG && visited.at<int>(i, j) == 0)
  13. {
  14. strong.at<uchar>(i, j) = STRONG;
  15.  
  16. visited.at<int>(i, j) = 1;
  17. que.push(Point(j, i));
  18. while (!que.empty())
  19. {
  20. //Retrive head
  21. Point oldest = que.front();
  22. int jj = oldest.x;
  23. int ii = oldest.y;
  24.  
  25. //Dequeue
  26. que.pop();
  27.  
  28. //Check the neighbors
  29. int di[8] = { 1, 1, 0, -1, -1, -1, 0, 1 }; // rand (coordonata orizontala)
  30. int dj[8] = { 0, -1, -1, -1, 0, 1, 1, 1 }; // coloana (coordonata verticala)
  31.  
  32. for (int k = 0; k < 8; k++)
  33. if (mag.at<uchar>(ii + di[k], jj + dj[k]) == WEAK)// && visited.at<int>(i, j) == 0
  34. {
  35. que.push(Point(jj + dj[k], ii + di[k]));
  36. visited.at<int>(ii + di[k], jj + dj[k]) = 1;
  37. mag.at<uchar>(ii + di[k], jj + dj[k]) = STRONG;
  38. strong.at<uchar>(ii + di[k], jj + dj[k]) = STRONG;
  39.  
  40. }
  41. }
  42.  
  43. }
  44. else
  45. strong.at<uchar>(i, j) = 0;
  46. }
  47. }
  48.  
  49. imshow("Final", strong);
  50. waitKey(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement