我试图实现一个算法来检测通道,我使用gabor过滤器来检测边缘和线然后应用hough变换但是我有一个问题,因为它在尝试做任何一个canny时都会出现异常直接检测或houghline 我想知道Gabor滤波器的输出是什么,它的复杂值是多少?以及如何使用opencv中的复杂值? 这是我的代码的一部分:
int kernel_size = 9;
double sig = 2, th = 0, lm =10, gm =1, ps = CV_PI/4;
cv::Mat kernel = cv::getGaborKernel(cv::Size(kernel_size,kernel_size), sig, th, lm, gm, ps);
cv::filter2D(src_f, src_f, CV_32F, kernel);
imshow("kernel",kernel);
Mat viz;
src_f.convertTo(viz,CV_8U,1.0/255.0);
imshow("d",viz);
imshow("Result", src_f);
std::vector<float> uniquev = unique(src_f, true);
int TotalPixel = uniquev.size();
int nTotalThresholdPixel = TotalPixel * 2.5/100;
float thresholdValue = uniquev[nTotalThresholdPixel-1];
int i = 0;
for (int row = 0; row < MaxHeight; row++)
{
for (int col = 0; col < MaxWidth; col++)
{
if(src_f.at<float>(row, col) <thresholdValue )
{src_f.at<float>(row, col) =0;}
}
}
Mat imgContours;
double thresh = 255;
try{
Canny(src_f,imgContours,0.6*thresh, thresh);
vector<Vec2f> lines;
HoughLines(src_f,lines,1,CV_PI/180,130);
Mat imgOutput;
cvtColor( src_f, imgOutput, CV_GRAY2BGR );
for( size_t i = 0; i < lines.size(); i++ )
{
float theta = lines[i][1];
float rho = lines[i][0];
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
Point pt1(cvRound(x0 + 1000*(-b)),cvRound(y0 + 1000*(a)));
Point pt2(cvRound(x0 - 1000*(-b)),
cvRound(y0 - 1000*(a)));
line( src_f, pt1, pt2, Scalar(0,0,255), 1, 8 );
}
}
catch(exception e ){
}
我认为我在gabor过滤器本身的输出中存在问题,因为它是浮点数和-ve数
我在
中得到了例外 Canny(src_f,imgContours,0.6*thresh, thresh);
或者如果评论Canny
HoughLines(src_f,lines,1,CV_PI/180,130);