1
有很多斑點的圖像重繪對象。我需要刪除不符合要求的斑點。但是,滿足要求的斑點在內部有洞。我需要重新繪製成功的blob。以下是我使用的一些代碼。希望有人能指出如何處理它。
/// Find contours
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
cv::findContours(srcImg, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE, Point(0,0));
/// Start to iterate to each contour found
vector<vector<Point> >::iterator itc = contours.begin();
vector<Rect> rects;
Mat dstImg = Mat::zeros(srcImg.size(), CV_8UC1);
//Remove patch that are no inside limits.
while(itc != contours.end()) {
/// eliminating blobs here
}
/// To redraw the contours. Error here since some blobs already been removed
int idx = 0;
for(; idx >= 0; idx = hierarchy[idx][0])
{
Scalar color(255, 255, 255);
drawContours(dstImg, contours, idx, color, CV_FILLED, 8, hierarchy);
}
/// To redraw the contours but the holes also filled
for(unsigned int i = 0; i < rects.size(); i++) {
Scalar color = Scalar(255,255,255);
drawContours(dstImg, contours, i, color, CV_FILLED, 8, noArray(), 0, Point());
}
我必須再次使用findContours?
我明白了。但是,如果我需要使用drawContours,即使這些孔將被填充正確嗎? – Mzk 2013-02-26 01:17:06
參數CV_FILLED表示輪廓將被填充。你可以改變這個值是不是你想要的。 – 2013-02-26 04:35:14
好的。我明白你的觀點。謝謝@Radford。 – Mzk 2013-02-26 06:32:19