所以沒辦法看出轉成 hough space 的樣子。
要作到要用 opencv_contrib 中 ximgproc::FastHoughTransform( )
這個 function有附 example:fast_hough_transform.cpp
如果在安裝opencv 時,build example 的 option 有打開,就會 build。
執行檔是: build/bin/example_ximgproc_fast_hough_transform
實際執行時,default read source : building.jpg 的相對位置好像有問題。
所以要加一層目錄,copy 到下一層目錄去..才能執行起來。
要加在自己的 source code 中,看看 hough space 的結果,要加的function ..
#include <opencv2/ximgproc.hpp>
void rescale(Mat const &src, Mat &dst, int const maxHeight=500, int const maxWidth=1000)
{
double scale = min(min( static_cast<double>(maxWidth) /src.cols,
static_cast<double>(maxHeight)/src.rows), 1.0);
resize(src,dst, Size(),scale,scale,INTER_LINEAR_EXACT);
}
void showhough(Mat const &fht)
{
double minv(0),maxv(0);
minMaxLoc(fht,&minv,&maxv);
Mat ucharFht;
fht.convertTo(ucharFht,CV_MAKETYPE(CV_8U,fht.channels()), 255.0/(maxv+minv), minv/(maxv+minv));
rescale(ucharFht,ucharFht);
imshow("fast hough transform", ucharFht);
}
然後才能在主程式 call FastHoughTransform..
Mat hough;
ximgproc::FastHoughTransform(dst,hough, CV_32S,6,2,1); // dst is source image
showhough(hough);
waitKey(0);
Example : building.jpg 做出來的 hough space image 是..

另外有一個人自己寫了 hough transform ,有提供 hough space 輸出:
hough transform c++ implementation
source code 在 github: https://github.com/brunokeymolen/hough
沒有留言:
張貼留言