2013-11-10 57 views
0

我正在做的是預處理後的圖像(通過閾值)找到圖像的輪廓。 我希望(使用DFT()函數) 我的代碼如下得到每個輪廓的離散傅里葉描述,如何使用cv :: findcontours和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)是錯誤的....

回答

1

findContours的輸出是矢量<矢量< Point>>。您正在提供矢量<墊>。這是一個合法用途(雖然有點模糊),但是你必須記住矩陣中的類型元素是'int'。另一方面,DFT僅適用於浮動矩陣。這是導致崩潰的原因。您可以使用convertTo函數來創建適當類型的矩陣。

此外,我不確定輸出對任何計算都有任何意義。據我所知傅里葉變換應該與信號一起工作,而不是從它提取的座標。

只是一個文體備註:執行相同的閾值更清潔的方式是

img = (img > thresh);