2015-08-13 140 views
0

http://inside.mines.edu/~whoff/courses/EENG512/lectures/HoughInOpenCV.pdf霍夫變換OPENCV C++

嗨,我正在閱讀上面的鏈接中的pdf教程。

我在幻燈片的第6頁遇到問題。

當我們看到插入canny邊緣檢測器後的代碼輸出時,它應該找出照片上的所有邊緣。

我不能在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; 
} 

出什麼,也有一條線double thresh = xxx;//try different values 要我把什麼樣的價值觀?這些值是什麼意思?

謝謝

回答

3

只是取代你imshow功能,

imshow("My Image", imgContours);

,你可以使用thresh值約爲周圍200

更改閾值並查看其效果,並根據該值選擇閾值。

2

imgContours是你所有邊緣的輸出映射。你應該使用imgow和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; 
} 

參考:

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