2014-10-07 42 views

回答

0

使用圖像直接作爲輸入,你將不得不顛倒它(白色=線檢測)。

我會得到這些結果與HoughLinesP

enter image description here

,如果你擴張的倒影,一旦你得到這樣的結果:

enter image description here

與此代碼:

int main() 
{ 
    cv::Mat color = cv::imread("../inputData/LineDetectionCrosses.png"); 
    cv::Mat gray; 

    // convert to grayscale 
    cv::cvtColor(color, gray, CV_BGR2GRAY); 

    cv::Mat mask = 255-gray; 

    //cv::dilate(mask, mask, cv::Mat()); 

    // detect HoughLinesP 
    std::vector<cv::Vec4i> lines; 
    cv::HoughLinesP(mask, lines, 1, CV_PI/2880, 50, 300, 10); 
    for(size_t i = 0; i < lines.size(); i++) 
    { 
     cv::Vec4i l = lines[i]; 
     cv::line(color, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]), cv::Scalar(0,0,255), 3, CV_AA); 
    } 

    // display results 
    cv::imshow("mask",mask); 
    cv::imshow("output", color); 
    cv::waitKey(0); 

} 

但是如果它是我的項目,我可能會嘗試首先檢測這些圓圈,並找到/提取具有已知中心點的行!

相關問題