我正在做的是在对图像进行预处理(通过阈值处理)之后找到图像的轮廓。
我想获得每个轮廓的离散傅立叶描述符(使用dft()函数)
我的代码如下
vector<Mat> contourLines1;
vector<Mat> contourLines2;
getContourLine(exC1, contourLines1, binThreshold, numOfErosions);
getContourLine(exC2, contourLines2, binThreshold, numOfErosions);
// calculate fourier descriptor
Mat fd1 = makeFD(contourLines1.front());
Mat fd2 = makeFD(contourLines2.front());
/////////////////////////
void getContourLine(Mat& img, vector<Mat>& objList, int thresh, int k){
threshold(img,img,thresh,255,THRESH_BINARY);
erode(img,img,0,cv::Point(-1,-1),k);
cv::findContours(img,objList,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
}
/////////////////////////
Mat makeFD(Mat& contour){
Mat result;
dft(contour,result,DFT_ROWS);
return result;
}
问题是什么???我找不到它。我认为函数的参数类型(例如cv::finContours或dft)是错误的....
最佳答案
findContours的输出是vector >。您正在提供vector 。这是一种合法用法(虽然有点晦涩),但是您必须记住,矩阵中的类型元素是'int'。另一方面,DFT仅适用于浮点矩阵。这就是导致崩溃的原因。您可以使用convertTo函数创建适当类型的矩阵。
另外,我不确定输出对您执行的任何计算是否有意义。据我所知,傅立叶变换应该用于信号,而不是用于从信号中提取的坐标。
只是一个风格上的评论:执行相同阈值的更干净的方法是
img = (img > thresh);