2014-01-24 59 views
0

這個問題已經讓我煩了兩個多星期了。opencv:請幫我找出紙箱的格子

我的目標是分析存放在貨架上紙箱中的一組產品。

現在,我嘗試從OpenCV Python模塊使用以下方法:findContours, canny,HoughLines,cv2.HoughLinesP,但我找不到結果網格。 我的目標是檢查產品是否裝滿紙箱。

  1. 這裏是原始圖像:http://postimg.org/image/hyz1jpd7p/7a4dd87c/
  2. 我的第一個步驟是使用閉合變換:

    閉合= cv2.morphologyEx(開口,cv2.MORPH_CLOSE,內核,迭代= 1)]

這給了我輪廓(我沒有足夠的聲望發佈此網址,此圖像與下面的最後一張圖像相似,但沒有紅線!)。

  1. 最後,問題是,我怎麼能找到紙箱網格(即,它的產品一個接一個)。 我在下圖中添加了紅線。

請給我提示,非常感謝!

紅線:http://postimg.org/image/6i0di4gsx/

+0

我編輯了你的問題,使其更清楚一點,但它仍然不清楚你想要做什麼以及你的問題是什麼。如果你想獲得有價值的答案,你仍然需要一點工作。哦,請在編輯/編寫某些東西時,請參閱問號圖標以獲取語法和格式化命令的一些幫助。 – sansuiso

回答

0

我打得有點與輸入和發現了一種閾值化色相通道之後基本上提取與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

threshholded色調信道:

enter image description here

輸出:

enter image description here

也許別人有一個想法如何提高HoughLinesP沒有那些侵蝕步驟...

希望這方法有助於你一點,你可以進一步提高其使用它爲您的需求。

+0

哦,天啊,結果非常好,我會一一研究,謝謝@Micka !!! – wxd