我打得有點與輸入和發現了一種閾值化色相通道之後基本上提取與HoughLinesP
電網。
編輯:我正在使用C++,但應該可以使用類似的python方法。
cv::Mat image = cv::imread("box1.png");
cv::Mat output; image.copyTo(output);
cv::Mat hsv;
cv::cvtColor(image, hsv, CV_BGR2HSV);
std::vector<cv::Mat> hsv_channels;
cv::split(hsv, hsv_channels);
// thresholding here is a little sloppy, maybe you have to use some smarter way
cv::Mat h_thres = hsv_channels[0] < 50;
// unfortunately, HoughLinesP couldnt detect all the lines if they were too wide
// to make this part more robust I would suggest a ridge detection on the distance transformed image instead of 'some erodes after a dilate'
cv::dilate(h_thres, h_thres, cv::Mat());
cv::erode(h_thres, h_thres, cv::Mat());
cv::erode(h_thres, h_thres, cv::Mat());
cv::erode(h_thres, h_thres, cv::Mat());
std::vector<cv::Vec4i> lines;
cv::HoughLinesP(h_thres, lines, 1, CV_PI/(4*180.0), 50, image.cols/4, 10);
for(size_t i = 0; i < lines.size(); i++)
{
cv::line(output, cv::Point(lines[i][0], lines[i][1]),
cv::Point(lines[i][2], lines[i][3]), cv::Scalar(155,255,155), 1, 8);
}
這裏是圖像:
色相通道HSV轉換之後:
![enter image description here](https://i.stack.imgur.com/C3hzc.png)
threshholded色調信道:
![enter image description here](https://i.stack.imgur.com/9uvt7.png)
輸出:
![enter image description here](https://i.stack.imgur.com/tdniw.jpg)
也許別人有一個想法如何提高HoughLinesP沒有那些侵蝕步驟...
希望這方法有助於你一點,你可以進一步提高其使用它爲您的需求。
我編輯了你的問題,使其更清楚一點,但它仍然不清楚你想要做什麼以及你的問題是什麼。如果你想獲得有價值的答案,你仍然需要一點工作。哦,請在編輯/編寫某些東西時,請參閱問號圖標以獲取語法和格式化命令的一些幫助。 – sansuiso