Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create Queue
- queue <Point> que;
- Mat visited = Mat::zeros(src.size(), CV_32SC1);
- Mat strong = mag.clone();
- for (int i = 1; i < src.rows - 1; i++)
- {
- for (int j = 1; j < src.cols - 1; j++)
- {
- if (mag.at<uchar>(i, j) == STRONG && visited.at<int>(i, j) == 0)
- {
- strong.at<uchar>(i, j) = STRONG;
- visited.at<int>(i, j) = 1;
- que.push(Point(j, i));
- while (!que.empty())
- {
- //Retrive head
- Point oldest = que.front();
- int jj = oldest.x;
- int ii = oldest.y;
- //Dequeue
- que.pop();
- //Check the neighbors
- int di[8] = { 1, 1, 0, -1, -1, -1, 0, 1 }; // rand (coordonata orizontala)
- int dj[8] = { 0, -1, -1, -1, 0, 1, 1, 1 }; // coloana (coordonata verticala)
- for (int k = 0; k < 8; k++)
- if (mag.at<uchar>(ii + di[k], jj + dj[k]) == WEAK)// && visited.at<int>(i, j) == 0
- {
- que.push(Point(jj + dj[k], ii + di[k]));
- visited.at<int>(ii + di[k], jj + dj[k]) = 1;
- mag.at<uchar>(ii + di[k], jj + dj[k]) = STRONG;
- strong.at<uchar>(ii + di[k], jj + dj[k]) = STRONG;
- }
- }
- }
- else
- strong.at<uchar>(i, j) = 0;
- }
- }
- imshow("Final", strong);
- waitKey(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement