bearbearsocute
bearbearsocute

Reputation: 95

Hough Transformation OPENCV C++

http://inside.mines.edu/~whoff/courses/EENG512/lectures/HoughInOpenCV.pdf

Hi, i am going through the pdf tutorial in the link above.

I encounter problem on page 6 of the slides.

As we seee that the output of the code after inserting the canny edge detector, it should trace out all the edges on a photo.

I cannot get what is shown at page 6.

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
    printf("Hello world\n");
// read an image
Mat imgInput = imread("a.png");
// create image window named "My Image"
namedWindow("My Image");

// Convert to gray if necessary
if (imgInput.channels() == 3)
    cv::cvtColor(imgInput, imgInput, CV_BGR2GRAY);

// Apply Canny edge detector
Mat imgContours;
double thresh = 105; // try different values to see effect
Canny(imgInput, imgContours, 0.4*thresh, thresh); // low, high threshold


// show the image on window
imshow("My Image", imgInput);
// wait for xx ms (0 means wait until keypress)
waitKey(5000);
return 0;
}

And also, there is a line double thresh = xxx;//try different values What values should i put? and what are the values mean?

Thank you

Upvotes: 0

Views: 481

Answers (2)

Sagar Patel
Sagar Patel

Reputation: 852

Just replace your imshow function with ,

imshow("My Image", imgContours);

and you can use thresh value approximately around 200.

Change threshold value and see effect of it and according to that you can select your threshold value.

Upvotes: 3

Daniel Albertini
Daniel Albertini

Reputation: 389

The imgContours is your output map with all the edges. You should use imshow with imgContours.

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
printf("Hello world\n");
// read an image
Mat imgInput = imread("a.png");
// create image window named "My Image"
namedWindow("My Image");

// Convert to gray if necessary
if (imgInput.channels() == 3)
    cv::cvtColor(imgInput, imgInput, CV_BGR2GRAY);

// Apply Canny edge detector
Mat imgContours;
double thresh = 105; // try different values to see effect
Canny(imgInput, imgContours, 0.4*thresh, thresh); // low, high threshold


// show the image on window
imshow("My Image", imgContours);
// wait for xx ms (0 means wait until keypress)
waitKey(5000);
return 0;
}

Reference:

http://docs.opencv.org/modules/imgproc/doc/feature_detection.html?highlight=canny#canny

Upvotes: 2

Related Questions