Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Canny using separate functions

$
0
0
Hi! I've tried to write Canny edge detector using OpenCV's functions for better understanding. As I can see, my own pipeline has wrong results after non-maximum suppression. cv::GaussianBlur(input, blur, cv::Size(5, 5), 1.4, 1.4); cv::Sobel(blur, dx, CV_32F, 1, 0, 3); cv::Sobel(blur, dy, CV_32F, 0, 1, 3); cv::cartToPolar(dx, dy, magnitudes, angles); cv::Mat edges = cv::Mat::zeros(img.size(), CV_8UC1); for (int y = 1; y < angles.rows - 1; ++y) { for (int x = 1; x < angles.cols - 1; ++x) { float a = angles.at(y, x); float m = magnitudes.at(y, x); if (a > CV_PI) { a -= CV_PI; } if (a < CV_PI / 8 || a > CV_PI - CV_PI / 8) { if (m > magnitudes.at(y, x + 1) && m > magnitudes.at(y, x - 1)) { edges.at(y, x) = 255; } } else if (a < 0.5f * CV_PI - CV_PI / 8) { if (m > magnitudes.at(y - 1, x + 1) && m > magnitudes.at(y + 1, x - 1)) { edges.at(y, x) = 255; } } else if (a < 0.5f * CV_PI + CV_PI / 8) { if (m > magnitudes.at(y - 1, x) && m > magnitudes.at(y + 1, x)) { edges.at(y, x) = 255; } } else { if (m > magnitudes.at(y - 1, x - 1) && m > magnitudes.at(y + 1, x + 1)) { edges.at(y, x) = 255; } } } } Float32 input. ![image description](/upfiles/14827448875388754.png) OpenCV's Canny output cv::Canny(input, output, 100, 200, 3, true); ![image description](/upfiles/14827449554883161.png) My ![image description](/upfiles/14827450198832012.png) Next steps of method only reduces number of edge pixels. Thus my mistake already here. Based on [OpenCV 3.2.x doc](http://docs.opencv.org/trunk/da/d22/tutorial_py_canny.html) and [OpenCV 2.4.x doc](http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.html). Version of Opencv: 3.1.0-dev Please tell me if I have obvious misunderstanding. Thanks!

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>